Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(539)

Side by Side Diff: src/log.cc

Issue 125256: Implemented processing of compressed log files. (Closed)
Patch Set: Added tests Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/log-utils.cc » ('j') | tools/logreader.js » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009 the V8 project authors. All rights reserved. 1 // Copyright 2009 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 void Logger::DeleteEvent(const char* name, void* object) { 620 void Logger::DeleteEvent(const char* name, void* object) {
621 #ifdef ENABLE_LOGGING_AND_PROFILING 621 #ifdef ENABLE_LOGGING_AND_PROFILING
622 if (!Log::IsEnabled() || !FLAG_log) return; 622 if (!Log::IsEnabled() || !FLAG_log) return;
623 LogMessageBuilder msg; 623 LogMessageBuilder msg;
624 msg.Append("delete,%s,0x%" V8PRIxPTR "\n", name, object); 624 msg.Append("delete,%s,0x%" V8PRIxPTR "\n", name, object);
625 msg.WriteToLogFile(); 625 msg.WriteToLogFile();
626 #endif 626 #endif
627 } 627 }
628 628
629 629
630 #ifdef ENABLE_LOGGING_AND_PROFILING
631
632 // A class that contains all common code dealing with record compression.
633 class CompressionHelper {
634 public:
635 explicit CompressionHelper(int window_size)
636 : compressor_(window_size), repeat_count_(0) { }
637
638 // Handles storing message in compressor, retrieving the previous one and
639 // prefixing it with repeat count, if needed.
640 // Returns true if message needs to be written to log.
641 bool HandleMessage(LogMessageBuilder* msg) {
642 if (!msg->StoreInCompressor(&compressor_)) {
643 // Current message repeats the previous one, don't write it.
644 ++repeat_count_;
645 return false;
646 }
647 if (repeat_count_ == 0) {
648 return msg->RetrieveCompressedPrevious(&compressor_);
649 }
650 OS::SNPrintF(prefix_, "%s,%d,",
651 Logger::log_events_[Logger::REPEAT_META_EVENT],
652 repeat_count_ + 1);
653 repeat_count_ = 0;
654 return msg->RetrieveCompressedPrevious(&compressor_, prefix_.start());
655 }
656
657 private:
658 LogRecordCompressor compressor_;
659 int repeat_count_;
660 EmbeddedVector<char, 20> prefix_;
661 };
662
663 #endif // ENABLE_LOGGING_AND_PROFILING
664
665
630 void Logger::CodeCreateEvent(LogEventsAndTags tag, 666 void Logger::CodeCreateEvent(LogEventsAndTags tag,
631 Code* code, 667 Code* code,
632 const char* comment) { 668 const char* comment) {
633 #ifdef ENABLE_LOGGING_AND_PROFILING 669 #ifdef ENABLE_LOGGING_AND_PROFILING
634 if (!Log::IsEnabled() || !FLAG_log_code) return; 670 if (!Log::IsEnabled() || !FLAG_log_code) return;
635 LogMessageBuilder msg; 671 LogMessageBuilder msg;
636 msg.Append("%s,%s,", log_events_[CODE_CREATION_EVENT], log_events_[tag]); 672 msg.Append("%s,%s,", log_events_[CODE_CREATION_EVENT], log_events_[tag]);
637 msg.AppendAddress(code->address()); 673 msg.AppendAddress(code->address());
638 msg.Append(",%d,\"", code->ExecutableSize()); 674 msg.Append(",%d,\"", code->ExecutableSize());
639 for (const char* p = comment; *p != '\0'; p++) { 675 for (const char* p = comment; *p != '\0'; p++) {
640 if (*p == '"') { 676 if (*p == '"') {
641 msg.Append('\\'); 677 msg.Append('\\');
642 } 678 }
643 msg.Append(*p); 679 msg.Append(*p);
644 } 680 }
645 msg.Append('"'); 681 msg.Append('"');
682 if (FLAG_compress_log) {
683 ASSERT(compression_helper_ != NULL);
684 if (!compression_helper_->HandleMessage(&msg)) return;
685 }
646 msg.Append('\n'); 686 msg.Append('\n');
647 msg.WriteToLogFile(); 687 msg.WriteToLogFile();
648 #endif 688 #endif
649 } 689 }
650 690
651 691
652 void Logger::CodeCreateEvent(LogEventsAndTags tag, Code* code, String* name) { 692 void Logger::CodeCreateEvent(LogEventsAndTags tag, Code* code, String* name) {
653 #ifdef ENABLE_LOGGING_AND_PROFILING 693 #ifdef ENABLE_LOGGING_AND_PROFILING
654 if (!Log::IsEnabled() || !FLAG_log_code) return; 694 if (!Log::IsEnabled() || !FLAG_log_code) return;
655 LogMessageBuilder msg; 695 LogMessageBuilder msg;
656 SmartPointer<char> str = 696 SmartPointer<char> str =
657 name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); 697 name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
658 msg.Append("%s,%s,", log_events_[CODE_CREATION_EVENT], log_events_[tag]); 698 msg.Append("%s,%s,", log_events_[CODE_CREATION_EVENT], log_events_[tag]);
659 msg.AppendAddress(code->address()); 699 msg.AppendAddress(code->address());
660 msg.Append(",%d,\"%s\"\n", code->ExecutableSize(), *str); 700 msg.Append(",%d,\"%s\"", code->ExecutableSize(), *str);
701 if (FLAG_compress_log) {
702 ASSERT(compression_helper_ != NULL);
703 if (!compression_helper_->HandleMessage(&msg)) return;
704 }
705 msg.Append('\n');
661 msg.WriteToLogFile(); 706 msg.WriteToLogFile();
662 #endif 707 #endif
663 } 708 }
664 709
665 710
666 void Logger::CodeCreateEvent(LogEventsAndTags tag, 711 void Logger::CodeCreateEvent(LogEventsAndTags tag,
667 Code* code, String* name, 712 Code* code, String* name,
668 String* source, int line) { 713 String* source, int line) {
669 #ifdef ENABLE_LOGGING_AND_PROFILING 714 #ifdef ENABLE_LOGGING_AND_PROFILING
670 if (!Log::IsEnabled() || !FLAG_log_code) return; 715 if (!Log::IsEnabled() || !FLAG_log_code) return;
671 LogMessageBuilder msg; 716 LogMessageBuilder msg;
672 SmartPointer<char> str = 717 SmartPointer<char> str =
673 name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); 718 name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
674 SmartPointer<char> sourcestr = 719 SmartPointer<char> sourcestr =
675 source->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); 720 source->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
676 msg.Append("%s,%s,", log_events_[CODE_CREATION_EVENT], log_events_[tag]); 721 msg.Append("%s,%s,", log_events_[CODE_CREATION_EVENT], log_events_[tag]);
677 msg.AppendAddress(code->address()); 722 msg.AppendAddress(code->address());
678 msg.Append(",%d,\"%s %s:%d\"\n", 723 msg.Append(",%d,\"%s %s:%d\"",
679 code->ExecutableSize(), *str, *sourcestr, line); 724 code->ExecutableSize(), *str, *sourcestr, line);
725 if (FLAG_compress_log) {
726 ASSERT(compression_helper_ != NULL);
727 if (!compression_helper_->HandleMessage(&msg)) return;
728 }
729 msg.Append('\n');
680 msg.WriteToLogFile(); 730 msg.WriteToLogFile();
681 #endif 731 #endif
682 } 732 }
683 733
684 734
685 void Logger::CodeCreateEvent(LogEventsAndTags tag, Code* code, int args_count) { 735 void Logger::CodeCreateEvent(LogEventsAndTags tag, Code* code, int args_count) {
686 #ifdef ENABLE_LOGGING_AND_PROFILING 736 #ifdef ENABLE_LOGGING_AND_PROFILING
687 if (!Log::IsEnabled() || !FLAG_log_code) return; 737 if (!Log::IsEnabled() || !FLAG_log_code) return;
688 LogMessageBuilder msg; 738 LogMessageBuilder msg;
689 msg.Append("%s,%s,", log_events_[CODE_CREATION_EVENT], log_events_[tag]); 739 msg.Append("%s,%s,", log_events_[CODE_CREATION_EVENT], log_events_[tag]);
690 msg.AppendAddress(code->address()); 740 msg.AppendAddress(code->address());
691 msg.Append(",%d,\"args_count: %d\"\n", code->ExecutableSize(), args_count); 741 msg.Append(",%d,\"args_count: %d\"", code->ExecutableSize(), args_count);
742 if (FLAG_compress_log) {
743 ASSERT(compression_helper_ != NULL);
744 if (!compression_helper_->HandleMessage(&msg)) return;
745 }
746 msg.Append('\n');
692 msg.WriteToLogFile(); 747 msg.WriteToLogFile();
693 #endif 748 #endif
694 } 749 }
695 750
696 751
697 void Logger::RegExpCodeCreateEvent(Code* code, String* source) { 752 void Logger::RegExpCodeCreateEvent(Code* code, String* source) {
698 #ifdef ENABLE_LOGGING_AND_PROFILING 753 #ifdef ENABLE_LOGGING_AND_PROFILING
699 if (!Log::IsEnabled() || !FLAG_log_code) return; 754 if (!Log::IsEnabled() || !FLAG_log_code) return;
700 LogMessageBuilder msg; 755 LogMessageBuilder msg;
701 msg.Append("%s,%s,", 756 msg.Append("%s,%s,",
702 log_events_[CODE_CREATION_EVENT], log_events_[REG_EXP_TAG]); 757 log_events_[CODE_CREATION_EVENT], log_events_[REG_EXP_TAG]);
703 msg.AppendAddress(code->address()); 758 msg.AppendAddress(code->address());
704 msg.Append(",%d,\"", code->ExecutableSize()); 759 msg.Append(",%d,\"", code->ExecutableSize());
705 msg.AppendDetailed(source, false); 760 msg.AppendDetailed(source, false);
706 msg.Append("\"\n"); 761 msg.Append('\"');
762 if (FLAG_compress_log) {
763 ASSERT(compression_helper_ != NULL);
764 if (!compression_helper_->HandleMessage(&msg)) return;
765 }
766 msg.Append('\n');
707 msg.WriteToLogFile(); 767 msg.WriteToLogFile();
708 #endif 768 #endif
709 } 769 }
710 770
711 771
712 #ifdef ENABLE_LOGGING_AND_PROFILING
713
714 // A class that contains all common code dealing with record compression.
715 class CompressionHelper {
716 public:
717 explicit CompressionHelper(int window_size)
718 : compressor_(window_size), repeat_count_(0) { }
719
720 // Handles storing message in compressor, retrieving the previous one and
721 // prefixing it with repeat count, if needed.
722 // Returns true if message needs to be written to log.
723 bool HandleMessage(LogMessageBuilder* msg) {
724 if (!msg->StoreInCompressor(&compressor_)) {
725 // Current message repeats the previous one, don't write it.
726 ++repeat_count_;
727 return false;
728 }
729 if (repeat_count_ == 0) {
730 return msg->RetrieveCompressedPrevious(&compressor_);
731 }
732 OS::SNPrintF(prefix_, "%s,%d,",
733 Logger::log_events_[Logger::REPEAT_META_EVENT],
734 repeat_count_ + 1);
735 repeat_count_ = 0;
736 return msg->RetrieveCompressedPrevious(&compressor_, prefix_.start());
737 }
738
739 private:
740 LogRecordCompressor compressor_;
741 int repeat_count_;
742 EmbeddedVector<char, 20> prefix_;
743 };
744
745 #endif // ENABLE_LOGGING_AND_PROFILING
746
747
748 void Logger::CodeMoveEvent(Address from, Address to) { 772 void Logger::CodeMoveEvent(Address from, Address to) {
749 #ifdef ENABLE_LOGGING_AND_PROFILING 773 #ifdef ENABLE_LOGGING_AND_PROFILING
750 static Address prev_to_ = NULL; 774 static Address prev_to_ = NULL;
751 if (!Log::IsEnabled() || !FLAG_log_code) return; 775 if (!Log::IsEnabled() || !FLAG_log_code) return;
752 LogMessageBuilder msg; 776 LogMessageBuilder msg;
753 msg.Append("%s,", log_events_[CODE_MOVE_EVENT]); 777 msg.Append("%s,", log_events_[CODE_MOVE_EVENT]);
754 msg.AppendAddress(from); 778 msg.AppendAddress(from);
755 msg.Append(','); 779 msg.Append(',');
756 msg.AppendAddress(to, prev_to_); 780 msg.AppendAddress(to, prev_to_);
757 prev_to_ = to; 781 prev_to_ = to;
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
1247 } else if (previous_->state_ == EXTERNAL) { 1271 } else if (previous_->state_ == EXTERNAL) {
1248 // We are leaving V8. 1272 // We are leaving V8.
1249 Heap::Protect(); 1273 Heap::Protect();
1250 } 1274 }
1251 } 1275 }
1252 #endif 1276 #endif
1253 } 1277 }
1254 #endif 1278 #endif
1255 1279
1256 } } // namespace v8::internal 1280 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/log-utils.cc » ('j') | tools/logreader.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698