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

Side by Side Diff: src/log.cc

Issue 119304: Add log compression ability. (Closed)
Patch Set: 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 | « src/log.h ('k') | src/stub-cache.cc » ('j') | src/stub-cache.cc » ('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 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 OS::LogSharedLibraryAddresses(); 255 OS::LogSharedLibraryAddresses();
256 256
257 // Start thread processing the profiler buffer. 257 // Start thread processing the profiler buffer.
258 running_ = true; 258 running_ = true;
259 Start(); 259 Start();
260 260
261 // Register to get ticks. 261 // Register to get ticks.
262 Logger::ticker_->SetProfiler(this); 262 Logger::ticker_->SetProfiler(this);
263 263
264 Logger::ProfilerBeginEvent(); 264 Logger::ProfilerBeginEvent();
265 Logger::LogAliases();
265 } 266 }
266 267
267 268
268 void Profiler::Disengage() { 269 void Profiler::Disengage() {
269 // Stop receiving ticks. 270 // Stop receiving ticks.
270 Logger::ticker_->ClearProfiler(); 271 Logger::ticker_->ClearProfiler();
271 272
272 // Terminate the worker thread by setting running_ to false, 273 // Terminate the worker thread by setting running_ to false,
273 // inserting a fake element in the queue and then wait for 274 // inserting a fake element in the queue and then wait for
274 // the thread to terminate. 275 // the thread to terminate.
(...skipping 19 matching lines...) Expand all
294 295
295 296
296 // 297 //
297 // Logger class implementation. 298 // Logger class implementation.
298 // 299 //
299 Ticker* Logger::ticker_ = NULL; 300 Ticker* Logger::ticker_ = NULL;
300 Profiler* Logger::profiler_ = NULL; 301 Profiler* Logger::profiler_ = NULL;
301 VMState* Logger::current_state_ = NULL; 302 VMState* Logger::current_state_ = NULL;
302 VMState Logger::bottom_state_(EXTERNAL); 303 VMState Logger::bottom_state_(EXTERNAL);
303 SlidingStateWindow* Logger::sliding_state_window_ = NULL; 304 SlidingStateWindow* Logger::sliding_state_window_ = NULL;
305 const char** Logger::log_events_ = NULL;
306
307 #define DECLARE_LONG_EVENT(ignore1, long_name, ignore2) long_name,
308 const char* kLongLogEventsNames[Logger::NUMBER_OF_LOG_EVENTS] = {
309 LOG_EVENTS_AND_TAGS_LIST(DECLARE_LONG_EVENT)
310 };
311 #undef DECLARE_LONG_EVENT
312
313 #define DECLARE_SHORT_EVENT(ignore1, ignore2, short_name) short_name,
314 const char* kCompressedLogEventsNames[Logger::NUMBER_OF_LOG_EVENTS] = {
315 LOG_EVENTS_AND_TAGS_LIST(DECLARE_SHORT_EVENT)
316 };
317 #undef DECLARE_SHORT_EVENT
304 318
305 319
306 bool Logger::IsEnabled() { 320 bool Logger::IsEnabled() {
307 return Log::IsEnabled(); 321 return Log::IsEnabled();
308 } 322 }
309 323
310 324
311 void Logger::ProfilerBeginEvent() { 325 void Logger::ProfilerBeginEvent() {
312 if (!Log::IsEnabled()) return; 326 if (!Log::IsEnabled()) return;
313 LogMessageBuilder msg; 327 LogMessageBuilder msg;
314 msg.Append("profiler,\"begin\",%d\n", kSamplingIntervalMs); 328 msg.Append("profiler,\"begin\",%d\n", kSamplingIntervalMs);
315 msg.WriteToLogFile(); 329 msg.WriteToLogFile();
316 } 330 }
317 331
332
333 void Logger::LogAliases() {
334 if (!Log::IsEnabled() || !FLAG_compress_log) return;
335 LogMessageBuilder msg;
336 for (int i = 0; i < NUMBER_OF_LOG_EVENTS; ++i) {
337 msg.Append("alias,%s,%s\n",
338 kCompressedLogEventsNames[i], kLongLogEventsNames[i]);
339 }
340 msg.WriteToLogFile();
341 }
342
318 #endif // ENABLE_LOGGING_AND_PROFILING 343 #endif // ENABLE_LOGGING_AND_PROFILING
319 344
320 345
321 void Logger::Preamble(const char* content) { 346 void Logger::Preamble(const char* content) {
322 #ifdef ENABLE_LOGGING_AND_PROFILING 347 #ifdef ENABLE_LOGGING_AND_PROFILING
323 if (!Log::IsEnabled() || !FLAG_log_code) return; 348 if (!Log::IsEnabled() || !FLAG_log_code) return;
324 LogMessageBuilder msg; 349 LogMessageBuilder msg;
325 msg.WriteCStringToLogFile(content); 350 msg.WriteCStringToLogFile(content);
326 #endif 351 #endif
327 } 352 }
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 void Logger::DeleteEvent(const char* name, void* object) { 612 void Logger::DeleteEvent(const char* name, void* object) {
588 #ifdef ENABLE_LOGGING_AND_PROFILING 613 #ifdef ENABLE_LOGGING_AND_PROFILING
589 if (!Log::IsEnabled() || !FLAG_log) return; 614 if (!Log::IsEnabled() || !FLAG_log) return;
590 LogMessageBuilder msg; 615 LogMessageBuilder msg;
591 msg.Append("delete,%s,0x%" V8PRIxPTR "\n", name, object); 616 msg.Append("delete,%s,0x%" V8PRIxPTR "\n", name, object);
592 msg.WriteToLogFile(); 617 msg.WriteToLogFile();
593 #endif 618 #endif
594 } 619 }
595 620
596 621
597 void Logger::CodeCreateEvent(const char* tag, Code* code, const char* comment) { 622 void Logger::CodeCreateEvent(
Søren Thygesen Gjesse 2009/06/08 12:28:47 I think we normally use the following format for l
Mikhail Naganov 2009/06/08 13:39:09 OK, fixed.
623 LogEventsAndTags tag, Code* code, const char* comment) {
598 #ifdef ENABLE_LOGGING_AND_PROFILING 624 #ifdef ENABLE_LOGGING_AND_PROFILING
599 if (!Log::IsEnabled() || !FLAG_log_code) return; 625 if (!Log::IsEnabled() || !FLAG_log_code) return;
600 LogMessageBuilder msg; 626 LogMessageBuilder msg;
601 msg.Append("code-creation,%s,0x%" V8PRIxPTR ",%d,\"", tag, code->address(), 627 msg.Append("%s,%s,0x%" V8PRIxPTR ",%d,\"",
602 code->ExecutableSize()); 628 log_events_[CODE_CREATION_EVENT], log_events_[tag],
629 code->address(), code->ExecutableSize());
603 for (const char* p = comment; *p != '\0'; p++) { 630 for (const char* p = comment; *p != '\0'; p++) {
604 if (*p == '"') { 631 if (*p == '"') {
605 msg.Append('\\'); 632 msg.Append('\\');
606 } 633 }
607 msg.Append(*p); 634 msg.Append(*p);
608 } 635 }
609 msg.Append('"'); 636 msg.Append('"');
610 msg.Append('\n'); 637 msg.Append('\n');
611 msg.WriteToLogFile(); 638 msg.WriteToLogFile();
612 #endif 639 #endif
613 } 640 }
614 641
615 642
616 void Logger::CodeCreateEvent(const char* tag, Code* code, String* name) { 643 void Logger::CodeCreateEvent(LogEventsAndTags tag, Code* code, String* name) {
617 #ifdef ENABLE_LOGGING_AND_PROFILING 644 #ifdef ENABLE_LOGGING_AND_PROFILING
618 if (!Log::IsEnabled() || !FLAG_log_code) return; 645 if (!Log::IsEnabled() || !FLAG_log_code) return;
619 LogMessageBuilder msg; 646 LogMessageBuilder msg;
620 SmartPointer<char> str = 647 SmartPointer<char> str =
621 name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); 648 name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
622 msg.Append("code-creation,%s,0x%" V8PRIxPTR ",%d,\"%s\"\n", 649 msg.Append("%s,%s,0x%" V8PRIxPTR ",%d,\"%s\"\n",
623 tag, code->address(), code->ExecutableSize(), *str); 650 log_events_[CODE_CREATION_EVENT], log_events_[tag],
651 code->address(), code->ExecutableSize(), *str);
624 msg.WriteToLogFile(); 652 msg.WriteToLogFile();
625 #endif 653 #endif
626 } 654 }
627 655
628 656
629 void Logger::CodeCreateEvent(const char* tag, Code* code, String* name, 657 void Logger::CodeCreateEvent(LogEventsAndTags tag, Code* code, String* name,
630 String* source, int line) { 658 String* source, int line) {
631 #ifdef ENABLE_LOGGING_AND_PROFILING 659 #ifdef ENABLE_LOGGING_AND_PROFILING
632 if (!Log::IsEnabled() || !FLAG_log_code) return; 660 if (!Log::IsEnabled() || !FLAG_log_code) return;
633 LogMessageBuilder msg; 661 LogMessageBuilder msg;
634 SmartPointer<char> str = 662 SmartPointer<char> str =
635 name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); 663 name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
636 SmartPointer<char> sourcestr = 664 SmartPointer<char> sourcestr =
637 source->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); 665 source->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
638 msg.Append("code-creation,%s,0x%" V8PRIxPTR ",%d,\"%s %s:%d\"\n", 666 msg.Append("%s,%s,0x%" V8PRIxPTR ",%d,\"%s %s:%d\"\n",
639 tag, code->address(), 667 log_events_[CODE_CREATION_EVENT],
668 log_events_[tag], code->address(),
640 code->ExecutableSize(), 669 code->ExecutableSize(),
641 *str, *sourcestr, line); 670 *str, *sourcestr, line);
642 msg.WriteToLogFile(); 671 msg.WriteToLogFile();
643 #endif 672 #endif
644 } 673 }
645 674
646 675
647 void Logger::CodeCreateEvent(const char* tag, Code* code, int args_count) { 676 void Logger::CodeCreateEvent(LogEventsAndTags tag, Code* code, int args_count) {
648 #ifdef ENABLE_LOGGING_AND_PROFILING 677 #ifdef ENABLE_LOGGING_AND_PROFILING
649 if (!Log::IsEnabled() || !FLAG_log_code) return; 678 if (!Log::IsEnabled() || !FLAG_log_code) return;
650 LogMessageBuilder msg; 679 LogMessageBuilder msg;
651 msg.Append("code-creation,%s,0x%" V8PRIxPTR ",%d,\"args_count: %d\"\n", tag, 680 msg.Append("%s,%s,0x%" V8PRIxPTR ",%d,\"args_count: %d\"\n",
681 log_events_[CODE_CREATION_EVENT],
682 log_events_[tag],
652 code->address(), 683 code->address(),
653 code->ExecutableSize(), 684 code->ExecutableSize(),
654 args_count); 685 args_count);
655 msg.WriteToLogFile(); 686 msg.WriteToLogFile();
656 #endif 687 #endif
657 } 688 }
658 689
659 690
660 void Logger::RegExpCodeCreateEvent(Code* code, String* source) { 691 void Logger::RegExpCodeCreateEvent(Code* code, String* source) {
661 #ifdef ENABLE_LOGGING_AND_PROFILING 692 #ifdef ENABLE_LOGGING_AND_PROFILING
662 if (!Log::IsEnabled() || !FLAG_log_code) return; 693 if (!Log::IsEnabled() || !FLAG_log_code) return;
663 LogMessageBuilder msg; 694 LogMessageBuilder msg;
664 msg.Append("code-creation,%s,0x%" V8PRIxPTR ",%d,\"", "RegExp", 695 msg.Append("%s,%s,0x%" V8PRIxPTR ",%d,\"",
696 log_events_[CODE_CREATION_EVENT],
697 log_events_[REG_EXP_TAG],
665 code->address(), 698 code->address(),
666 code->ExecutableSize()); 699 code->ExecutableSize());
667 msg.AppendDetailed(source, false); 700 msg.AppendDetailed(source, false);
668 msg.Append("\"\n"); 701 msg.Append("\"\n");
669 msg.WriteToLogFile(); 702 msg.WriteToLogFile();
670 #endif 703 #endif
671 } 704 }
672 705
673 706
674 void Logger::CodeAllocateEvent(Code* code, Assembler* assem) {
675 #ifdef ENABLE_LOGGING_AND_PROFILING
676 if (!Log::IsEnabled() || !FLAG_log_code) return;
677 LogMessageBuilder msg;
678 msg.Append("code-allocate,0x%" V8PRIxPTR ",0x%" V8PRIxPTR "\n",
679 code->address(),
680 assem);
681 msg.WriteToLogFile();
682 #endif
683 }
684
685
686 void Logger::CodeMoveEvent(Address from, Address to) { 707 void Logger::CodeMoveEvent(Address from, Address to) {
687 #ifdef ENABLE_LOGGING_AND_PROFILING 708 #ifdef ENABLE_LOGGING_AND_PROFILING
688 if (!Log::IsEnabled() || !FLAG_log_code) return; 709 if (!Log::IsEnabled() || !FLAG_log_code) return;
689 LogMessageBuilder msg; 710 LogMessageBuilder msg;
690 msg.Append("code-move,0x%" V8PRIxPTR ",0x%" V8PRIxPTR "\n", from, to); 711 msg.Append("%s,0x%" V8PRIxPTR ",0x%" V8PRIxPTR "\n",
712 log_events_[CODE_MOVE_EVENT], from, to);
691 msg.WriteToLogFile(); 713 msg.WriteToLogFile();
692 #endif 714 #endif
693 } 715 }
694 716
695 717
696 void Logger::CodeDeleteEvent(Address from) { 718 void Logger::CodeDeleteEvent(Address from) {
697 #ifdef ENABLE_LOGGING_AND_PROFILING 719 #ifdef ENABLE_LOGGING_AND_PROFILING
698 if (!Log::IsEnabled() || !FLAG_log_code) return; 720 if (!Log::IsEnabled() || !FLAG_log_code) return;
699 LogMessageBuilder msg; 721 LogMessageBuilder msg;
700 msg.Append("code-delete,0x%" V8PRIxPTR "\n", from); 722 msg.Append("%s,0x%" V8PRIxPTR "\n", log_events_[CODE_DELETE_EVENT], from);
701 msg.WriteToLogFile(); 723 msg.WriteToLogFile();
702 #endif 724 #endif
703 } 725 }
704 726
705 727
706 void Logger::ResourceEvent(const char* name, const char* tag) { 728 void Logger::ResourceEvent(const char* name, const char* tag) {
707 #ifdef ENABLE_LOGGING_AND_PROFILING 729 #ifdef ENABLE_LOGGING_AND_PROFILING
708 if (!Log::IsEnabled() || !FLAG_log) return; 730 if (!Log::IsEnabled() || !FLAG_log) return;
709 LogMessageBuilder msg; 731 LogMessageBuilder msg;
710 msg.Append("%s,%s,", name, tag); 732 msg.Append("%s,%s,", name, tag);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
796 DeleteArray(parameter_string); 818 DeleteArray(parameter_string);
797 msg.WriteToLogFile(); 819 msg.WriteToLogFile();
798 #endif 820 #endif
799 } 821 }
800 822
801 823
802 #ifdef ENABLE_LOGGING_AND_PROFILING 824 #ifdef ENABLE_LOGGING_AND_PROFILING
803 void Logger::TickEvent(TickSample* sample, bool overflow) { 825 void Logger::TickEvent(TickSample* sample, bool overflow) {
804 if (!Log::IsEnabled() || !FLAG_prof) return; 826 if (!Log::IsEnabled() || !FLAG_prof) return;
805 LogMessageBuilder msg; 827 LogMessageBuilder msg;
806 msg.Append("tick,0x%" V8PRIxPTR ",0x%" V8PRIxPTR ",%d", 828 msg.Append("%s,0x%" V8PRIxPTR ",0x%" V8PRIxPTR ",%d",
829 log_events_[TICK_EVENT],
807 sample->pc, sample->sp, static_cast<int>(sample->state)); 830 sample->pc, sample->sp, static_cast<int>(sample->state));
808 if (overflow) { 831 if (overflow) {
809 msg.Append(",overflow"); 832 msg.Append(",overflow");
810 } 833 }
834 uintptr_t prev_ptr = sample->pc;
811 for (int i = 0; i < sample->frames_count; ++i) { 835 for (int i = 0; i < sample->frames_count; ++i) {
812 msg.Append(",0x%" V8PRIxPTR, sample->stack[i]); 836 if (FLAG_compress_log) {
837 const uintptr_t ptr = OffsetFrom(sample->stack[i]);
838 intptr_t delta = ptr - prev_ptr;
839 prev_ptr = ptr;
840 // To avoid printing negative offsets in an unsigned form,
841 // we are printing an absolute value with a sign.
842 const char sign = delta >= 0 ? '+' : '-';
843 if (sign == '-') { delta = -delta; }
844 msg.Append(",%c0x%" V8PRIxPTR, sign, delta);
845 } else {
846 msg.Append(",0x%" V8PRIxPTR, sample->stack[i]);
847 }
813 } 848 }
814 msg.Append('\n'); 849 msg.Append('\n');
815 msg.WriteToLogFile(); 850 msg.WriteToLogFile();
816 } 851 }
817 852
818 853
819 bool Logger::IsProfilerPaused() { 854 bool Logger::IsProfilerPaused() {
820 return profiler_->paused(); 855 return profiler_->paused();
821 } 856 }
822 857
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 Handle<String> name(String::cast(shared->name())); 941 Handle<String> name(String::cast(shared->name()));
907 Handle<String> func_name(name->length() > 0 ? 942 Handle<String> func_name(name->length() > 0 ?
908 *name : shared->inferred_name()); 943 *name : shared->inferred_name());
909 if (shared->script()->IsScript()) { 944 if (shared->script()->IsScript()) {
910 Handle<Script> script(Script::cast(shared->script())); 945 Handle<Script> script(Script::cast(shared->script()));
911 if (script->name()->IsString()) { 946 if (script->name()->IsString()) {
912 Handle<String> script_name(String::cast(script->name())); 947 Handle<String> script_name(String::cast(script->name()));
913 int line_num = GetScriptLineNumber(script, shared->start_position()); 948 int line_num = GetScriptLineNumber(script, shared->start_position());
914 if (line_num > 0) { 949 if (line_num > 0) {
915 line_num += script->line_offset()->value() + 1; 950 line_num += script->line_offset()->value() + 1;
916 LOG(CodeCreateEvent("LazyCompile", shared->code(), *func_name, 951 LOG(CodeCreateEvent(Logger::LAZY_COMPILE_TAG,
952 shared->code(), *func_name,
917 *script_name, line_num)); 953 *script_name, line_num));
918 } else { 954 } else {
919 // Can't distinguish enum and script here, so always use Script. 955 // Can't distinguish enum and script here, so always use Script.
920 LOG(CodeCreateEvent("Script", shared->code(), *script_name)); 956 LOG(CodeCreateEvent(Logger::SCRIPT_TAG,
957 shared->code(), *script_name));
921 } 958 }
922 continue; 959 continue;
923 } 960 }
924 } 961 }
925 // If no script or script has no name. 962 // If no script or script has no name.
926 LOG(CodeCreateEvent("LazyCompile", shared->code(), *func_name)); 963 LOG(CodeCreateEvent(Logger::LAZY_COMPILE_TAG, shared->code(), *func_name));
927 } 964 }
928 965
929 DeleteArray(sfis); 966 DeleteArray(sfis);
930 } 967 }
931 968
932 #endif 969 #endif
933 970
934 971
935 bool Logger::Setup() { 972 bool Logger::Setup() {
936 #ifdef ENABLE_LOGGING_AND_PROFILING 973 #ifdef ENABLE_LOGGING_AND_PROFILING
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1015 1052
1016 if (FLAG_prof) { 1053 if (FLAG_prof) {
1017 profiler_ = new Profiler(); 1054 profiler_ = new Profiler();
1018 if (!FLAG_prof_auto) 1055 if (!FLAG_prof_auto)
1019 profiler_->pause(); 1056 profiler_->pause();
1020 profiler_->Engage(); 1057 profiler_->Engage();
1021 } 1058 }
1022 1059
1023 LogMessageBuilder::set_write_failure_handler(StopLoggingAndProfiling); 1060 LogMessageBuilder::set_write_failure_handler(StopLoggingAndProfiling);
1024 1061
1062 log_events_ = FLAG_compress_log ?
1063 kCompressedLogEventsNames : kLongLogEventsNames;
1064
1025 return true; 1065 return true;
1026 1066
1027 #else 1067 #else
1028 return false; 1068 return false;
1029 #endif 1069 #endif
1030 } 1070 }
1031 1071
1032 1072
1033 void Logger::TearDown() { 1073 void Logger::TearDown() {
1034 #ifdef ENABLE_LOGGING_AND_PROFILING 1074 #ifdef ENABLE_LOGGING_AND_PROFILING
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1146 } else if (previous_->state_ == EXTERNAL) { 1186 } else if (previous_->state_ == EXTERNAL) {
1147 // We are leaving V8. 1187 // We are leaving V8.
1148 Heap::Protect(); 1188 Heap::Protect();
1149 } 1189 }
1150 } 1190 }
1151 #endif 1191 #endif
1152 } 1192 }
1153 #endif 1193 #endif
1154 1194
1155 } } // namespace v8::internal 1195 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/log.h ('k') | src/stub-cache.cc » ('j') | src/stub-cache.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698