| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stdarg.h> | 5 #include <stdarg.h> |
| 6 | 6 |
| 7 #include "src/v8.h" | 7 #include "src/v8.h" |
| 8 | 8 |
| 9 #include "src/base/platform/platform.h" | 9 #include "src/base/platform/platform.h" |
| 10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 PerfBasicLogger::~PerfBasicLogger() { | 275 PerfBasicLogger::~PerfBasicLogger() { |
| 276 fclose(perf_output_handle_); | 276 fclose(perf_output_handle_); |
| 277 perf_output_handle_ = NULL; | 277 perf_output_handle_ = NULL; |
| 278 } | 278 } |
| 279 | 279 |
| 280 | 280 |
| 281 void PerfBasicLogger::LogRecordedBuffer(Code* code, | 281 void PerfBasicLogger::LogRecordedBuffer(Code* code, |
| 282 SharedFunctionInfo*, | 282 SharedFunctionInfo*, |
| 283 const char* name, | 283 const char* name, |
| 284 int length) { | 284 int length) { |
| 285 ASSERT(code->instruction_start() == code->address() + Code::kHeaderSize); | 285 DCHECK(code->instruction_start() == code->address() + Code::kHeaderSize); |
| 286 | 286 |
| 287 base::OS::FPrint(perf_output_handle_, "%llx %x %.*s\n", | 287 base::OS::FPrint(perf_output_handle_, "%llx %x %.*s\n", |
| 288 reinterpret_cast<uint64_t>(code->instruction_start()), | 288 reinterpret_cast<uint64_t>(code->instruction_start()), |
| 289 code->instruction_size(), length, name); | 289 code->instruction_size(), length, name); |
| 290 } | 290 } |
| 291 | 291 |
| 292 | 292 |
| 293 // Low-level logging support. | 293 // Low-level logging support. |
| 294 #define LL_LOG(Call) if (ll_logger_) ll_logger_->Call; | 294 #define LL_LOG(Call) if (ll_logger_) ll_logger_->Call; |
| 295 | 295 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 } | 411 } |
| 412 | 412 |
| 413 | 413 |
| 414 void LowLevelLogger::LogRecordedBuffer(Code* code, | 414 void LowLevelLogger::LogRecordedBuffer(Code* code, |
| 415 SharedFunctionInfo*, | 415 SharedFunctionInfo*, |
| 416 const char* name, | 416 const char* name, |
| 417 int length) { | 417 int length) { |
| 418 CodeCreateStruct event; | 418 CodeCreateStruct event; |
| 419 event.name_size = length; | 419 event.name_size = length; |
| 420 event.code_address = code->instruction_start(); | 420 event.code_address = code->instruction_start(); |
| 421 ASSERT(event.code_address == code->address() + Code::kHeaderSize); | 421 DCHECK(event.code_address == code->address() + Code::kHeaderSize); |
| 422 event.code_size = code->instruction_size(); | 422 event.code_size = code->instruction_size(); |
| 423 LogWriteStruct(event); | 423 LogWriteStruct(event); |
| 424 LogWriteBytes(name, length); | 424 LogWriteBytes(name, length); |
| 425 LogWriteBytes( | 425 LogWriteBytes( |
| 426 reinterpret_cast<const char*>(code->instruction_start()), | 426 reinterpret_cast<const char*>(code->instruction_start()), |
| 427 code->instruction_size()); | 427 code->instruction_size()); |
| 428 } | 428 } |
| 429 | 429 |
| 430 | 430 |
| 431 void LowLevelLogger::CodeMoveEvent(Address from, Address to) { | 431 void LowLevelLogger::CodeMoveEvent(Address from, Address to) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 446 void LowLevelLogger::SnapshotPositionEvent(Address addr, int pos) { | 446 void LowLevelLogger::SnapshotPositionEvent(Address addr, int pos) { |
| 447 SnapshotPositionStruct event; | 447 SnapshotPositionStruct event; |
| 448 event.address = addr + Code::kHeaderSize; | 448 event.address = addr + Code::kHeaderSize; |
| 449 event.position = pos; | 449 event.position = pos; |
| 450 LogWriteStruct(event); | 450 LogWriteStruct(event); |
| 451 } | 451 } |
| 452 | 452 |
| 453 | 453 |
| 454 void LowLevelLogger::LogWriteBytes(const char* bytes, int size) { | 454 void LowLevelLogger::LogWriteBytes(const char* bytes, int size) { |
| 455 size_t rv = fwrite(bytes, 1, size, ll_output_handle_); | 455 size_t rv = fwrite(bytes, 1, size, ll_output_handle_); |
| 456 ASSERT(static_cast<size_t>(size) == rv); | 456 DCHECK(static_cast<size_t>(size) == rv); |
| 457 USE(rv); | 457 USE(rv); |
| 458 } | 458 } |
| 459 | 459 |
| 460 | 460 |
| 461 void LowLevelLogger::CodeMovingGCEvent() { | 461 void LowLevelLogger::CodeMovingGCEvent() { |
| 462 const char tag = kCodeMovingGCTag; | 462 const char tag = kCodeMovingGCTag; |
| 463 | 463 |
| 464 LogWriteBytes(&tag, sizeof(tag)); | 464 LogWriteBytes(&tag, sizeof(tag)); |
| 465 } | 465 } |
| 466 | 466 |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 Sampler(isolate, interval), | 665 Sampler(isolate, interval), |
| 666 profiler_(NULL) {} | 666 profiler_(NULL) {} |
| 667 | 667 |
| 668 ~Ticker() { if (IsActive()) Stop(); } | 668 ~Ticker() { if (IsActive()) Stop(); } |
| 669 | 669 |
| 670 virtual void Tick(TickSample* sample) { | 670 virtual void Tick(TickSample* sample) { |
| 671 if (profiler_) profiler_->Insert(sample); | 671 if (profiler_) profiler_->Insert(sample); |
| 672 } | 672 } |
| 673 | 673 |
| 674 void SetProfiler(Profiler* profiler) { | 674 void SetProfiler(Profiler* profiler) { |
| 675 ASSERT(profiler_ == NULL); | 675 DCHECK(profiler_ == NULL); |
| 676 profiler_ = profiler; | 676 profiler_ = profiler; |
| 677 IncreaseProfilingDepth(); | 677 IncreaseProfilingDepth(); |
| 678 if (!IsActive()) Start(); | 678 if (!IsActive()) Start(); |
| 679 } | 679 } |
| 680 | 680 |
| 681 void ClearProfiler() { | 681 void ClearProfiler() { |
| 682 profiler_ = NULL; | 682 profiler_ = NULL; |
| 683 if (IsActive()) Stop(); | 683 if (IsActive()) Stop(); |
| 684 DecreaseProfilingDepth(); | 684 DecreaseProfilingDepth(); |
| 685 } | 685 } |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 777 is_initialized_(false) { | 777 is_initialized_(false) { |
| 778 } | 778 } |
| 779 | 779 |
| 780 | 780 |
| 781 Logger::~Logger() { | 781 Logger::~Logger() { |
| 782 delete log_; | 782 delete log_; |
| 783 } | 783 } |
| 784 | 784 |
| 785 | 785 |
| 786 void Logger::addCodeEventListener(CodeEventListener* listener) { | 786 void Logger::addCodeEventListener(CodeEventListener* listener) { |
| 787 ASSERT(!hasCodeEventListener(listener)); | 787 DCHECK(!hasCodeEventListener(listener)); |
| 788 listeners_.Add(listener); | 788 listeners_.Add(listener); |
| 789 } | 789 } |
| 790 | 790 |
| 791 | 791 |
| 792 void Logger::removeCodeEventListener(CodeEventListener* listener) { | 792 void Logger::removeCodeEventListener(CodeEventListener* listener) { |
| 793 ASSERT(hasCodeEventListener(listener)); | 793 DCHECK(hasCodeEventListener(listener)); |
| 794 listeners_.RemoveElement(listener); | 794 listeners_.RemoveElement(listener); |
| 795 } | 795 } |
| 796 | 796 |
| 797 | 797 |
| 798 bool Logger::hasCodeEventListener(CodeEventListener* listener) { | 798 bool Logger::hasCodeEventListener(CodeEventListener* listener) { |
| 799 return listeners_.Contains(listener); | 799 return listeners_.Contains(listener); |
| 800 } | 800 } |
| 801 | 801 |
| 802 | 802 |
| 803 void Logger::ProfilerBeginEvent() { | 803 void Logger::ProfilerBeginEvent() { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 852 Log::MessageBuilder msg(log_); | 852 Log::MessageBuilder msg(log_); |
| 853 msg.Append("%s,0x%" V8PRIxPTR, name, location); | 853 msg.Append("%s,0x%" V8PRIxPTR, name, location); |
| 854 msg.WriteToLogFile(); | 854 msg.WriteToLogFile(); |
| 855 } | 855 } |
| 856 | 856 |
| 857 | 857 |
| 858 // ApiEvent is private so all the calls come from the Logger class. It is the | 858 // ApiEvent is private so all the calls come from the Logger class. It is the |
| 859 // caller's responsibility to ensure that log is enabled and that | 859 // caller's responsibility to ensure that log is enabled and that |
| 860 // FLAG_log_api is true. | 860 // FLAG_log_api is true. |
| 861 void Logger::ApiEvent(const char* format, ...) { | 861 void Logger::ApiEvent(const char* format, ...) { |
| 862 ASSERT(log_->IsEnabled() && FLAG_log_api); | 862 DCHECK(log_->IsEnabled() && FLAG_log_api); |
| 863 Log::MessageBuilder msg(log_); | 863 Log::MessageBuilder msg(log_); |
| 864 va_list ap; | 864 va_list ap; |
| 865 va_start(ap, format); | 865 va_start(ap, format); |
| 866 msg.AppendVA(format, ap); | 866 msg.AppendVA(format, ap); |
| 867 va_end(ap); | 867 va_end(ap); |
| 868 msg.WriteToLogFile(); | 868 msg.WriteToLogFile(); |
| 869 } | 869 } |
| 870 | 870 |
| 871 | 871 |
| 872 void Logger::ApiNamedSecurityCheck(Object* key) { | 872 void Logger::ApiNamedSecurityCheck(Object* key) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 899 if (!log_->IsEnabled() || !FLAG_prof) return; | 899 if (!log_->IsEnabled() || !FLAG_prof) return; |
| 900 Log::MessageBuilder msg(log_); | 900 Log::MessageBuilder msg(log_); |
| 901 msg.Append("shared-library,\"%s\",0x%08" V8PRIxPTR ",0x%08" V8PRIxPTR, | 901 msg.Append("shared-library,\"%s\",0x%08" V8PRIxPTR ",0x%08" V8PRIxPTR, |
| 902 library_path.c_str(), start, end); | 902 library_path.c_str(), start, end); |
| 903 msg.WriteToLogFile(); | 903 msg.WriteToLogFile(); |
| 904 } | 904 } |
| 905 | 905 |
| 906 | 906 |
| 907 void Logger::CodeDeoptEvent(Code* code) { | 907 void Logger::CodeDeoptEvent(Code* code) { |
| 908 if (!log_->IsEnabled()) return; | 908 if (!log_->IsEnabled()) return; |
| 909 ASSERT(FLAG_log_internal_timer_events); | 909 DCHECK(FLAG_log_internal_timer_events); |
| 910 Log::MessageBuilder msg(log_); | 910 Log::MessageBuilder msg(log_); |
| 911 int since_epoch = static_cast<int>(timer_.Elapsed().InMicroseconds()); | 911 int since_epoch = static_cast<int>(timer_.Elapsed().InMicroseconds()); |
| 912 msg.Append("code-deopt,%ld,%d", since_epoch, code->CodeSize()); | 912 msg.Append("code-deopt,%ld,%d", since_epoch, code->CodeSize()); |
| 913 msg.WriteToLogFile(); | 913 msg.WriteToLogFile(); |
| 914 } | 914 } |
| 915 | 915 |
| 916 | 916 |
| 917 void Logger::CurrentTimeEvent() { | 917 void Logger::CurrentTimeEvent() { |
| 918 if (!log_->IsEnabled()) return; | 918 if (!log_->IsEnabled()) return; |
| 919 ASSERT(FLAG_log_internal_timer_events); | 919 DCHECK(FLAG_log_internal_timer_events); |
| 920 Log::MessageBuilder msg(log_); | 920 Log::MessageBuilder msg(log_); |
| 921 int since_epoch = static_cast<int>(timer_.Elapsed().InMicroseconds()); | 921 int since_epoch = static_cast<int>(timer_.Elapsed().InMicroseconds()); |
| 922 msg.Append("current-time,%ld", since_epoch); | 922 msg.Append("current-time,%ld", since_epoch); |
| 923 msg.WriteToLogFile(); | 923 msg.WriteToLogFile(); |
| 924 } | 924 } |
| 925 | 925 |
| 926 | 926 |
| 927 void Logger::TimerEvent(Logger::StartEnd se, const char* name) { | 927 void Logger::TimerEvent(Logger::StartEnd se, const char* name) { |
| 928 if (!log_->IsEnabled()) return; | 928 if (!log_->IsEnabled()) return; |
| 929 ASSERT(FLAG_log_internal_timer_events); | 929 DCHECK(FLAG_log_internal_timer_events); |
| 930 Log::MessageBuilder msg(log_); | 930 Log::MessageBuilder msg(log_); |
| 931 int since_epoch = static_cast<int>(timer_.Elapsed().InMicroseconds()); | 931 int since_epoch = static_cast<int>(timer_.Elapsed().InMicroseconds()); |
| 932 const char* format = (se == START) ? "timer-event-start,\"%s\",%ld" | 932 const char* format = (se == START) ? "timer-event-start,\"%s\",%ld" |
| 933 : "timer-event-end,\"%s\",%ld"; | 933 : "timer-event-end,\"%s\",%ld"; |
| 934 msg.Append(format, name, since_epoch); | 934 msg.Append(format, name, since_epoch); |
| 935 msg.WriteToLogFile(); | 935 msg.WriteToLogFile(); |
| 936 } | 936 } |
| 937 | 937 |
| 938 | 938 |
| 939 void Logger::EnterExternal(Isolate* isolate) { | 939 void Logger::EnterExternal(Isolate* isolate) { |
| 940 LOG(isolate, TimerEvent(START, TimerEventExternal::name())); | 940 LOG(isolate, TimerEvent(START, TimerEventExternal::name())); |
| 941 ASSERT(isolate->current_vm_state() == JS); | 941 DCHECK(isolate->current_vm_state() == JS); |
| 942 isolate->set_current_vm_state(EXTERNAL); | 942 isolate->set_current_vm_state(EXTERNAL); |
| 943 } | 943 } |
| 944 | 944 |
| 945 | 945 |
| 946 void Logger::LeaveExternal(Isolate* isolate) { | 946 void Logger::LeaveExternal(Isolate* isolate) { |
| 947 LOG(isolate, TimerEvent(END, TimerEventExternal::name())); | 947 LOG(isolate, TimerEvent(END, TimerEventExternal::name())); |
| 948 ASSERT(isolate->current_vm_state() == EXTERNAL); | 948 DCHECK(isolate->current_vm_state() == EXTERNAL); |
| 949 isolate->set_current_vm_state(JS); | 949 isolate->set_current_vm_state(JS); |
| 950 } | 950 } |
| 951 | 951 |
| 952 | 952 |
| 953 void Logger::DefaultTimerEventsLogger(const char* name, int se) { | 953 void Logger::DefaultTimerEventsLogger(const char* name, int se) { |
| 954 Isolate* isolate = Isolate::Current(); | 954 Isolate* isolate = Isolate::Current(); |
| 955 LOG(isolate, TimerEvent(static_cast<StartEnd>(se), name)); | 955 LOG(isolate, TimerEvent(static_cast<StartEnd>(se), name)); |
| 956 } | 956 } |
| 957 | 957 |
| 958 | 958 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1031 | 1031 |
| 1032 void Logger::ApiIndexedSecurityCheck(uint32_t index) { | 1032 void Logger::ApiIndexedSecurityCheck(uint32_t index) { |
| 1033 if (!log_->IsEnabled() || !FLAG_log_api) return; | 1033 if (!log_->IsEnabled() || !FLAG_log_api) return; |
| 1034 ApiEvent("api,check-security,%u", index); | 1034 ApiEvent("api,check-security,%u", index); |
| 1035 } | 1035 } |
| 1036 | 1036 |
| 1037 | 1037 |
| 1038 void Logger::ApiNamedPropertyAccess(const char* tag, | 1038 void Logger::ApiNamedPropertyAccess(const char* tag, |
| 1039 JSObject* holder, | 1039 JSObject* holder, |
| 1040 Object* name) { | 1040 Object* name) { |
| 1041 ASSERT(name->IsName()); | 1041 DCHECK(name->IsName()); |
| 1042 if (!log_->IsEnabled() || !FLAG_log_api) return; | 1042 if (!log_->IsEnabled() || !FLAG_log_api) return; |
| 1043 String* class_name_obj = holder->class_name(); | 1043 String* class_name_obj = holder->class_name(); |
| 1044 SmartArrayPointer<char> class_name = | 1044 SmartArrayPointer<char> class_name = |
| 1045 class_name_obj->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); | 1045 class_name_obj->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
| 1046 if (name->IsString()) { | 1046 if (name->IsString()) { |
| 1047 SmartArrayPointer<char> property_name = | 1047 SmartArrayPointer<char> property_name = |
| 1048 String::cast(name)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); | 1048 String::cast(name)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
| 1049 ApiEvent("api,%s,\"%s\",\"%s\"", tag, class_name.get(), | 1049 ApiEvent("api,%s,\"%s\",\"%s\"", tag, class_name.get(), |
| 1050 property_name.get()); | 1050 property_name.get()); |
| 1051 } else { | 1051 } else { |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1156 | 1156 |
| 1157 void Logger::SetterCallbackEvent(Name* name, Address entry_point) { | 1157 void Logger::SetterCallbackEvent(Name* name, Address entry_point) { |
| 1158 PROFILER_LOG(SetterCallbackEvent(name, entry_point)); | 1158 PROFILER_LOG(SetterCallbackEvent(name, entry_point)); |
| 1159 CallbackEventInternal("set ", name, entry_point); | 1159 CallbackEventInternal("set ", name, entry_point); |
| 1160 } | 1160 } |
| 1161 | 1161 |
| 1162 | 1162 |
| 1163 static void AppendCodeCreateHeader(Log::MessageBuilder* msg, | 1163 static void AppendCodeCreateHeader(Log::MessageBuilder* msg, |
| 1164 Logger::LogEventsAndTags tag, | 1164 Logger::LogEventsAndTags tag, |
| 1165 Code* code) { | 1165 Code* code) { |
| 1166 ASSERT(msg); | 1166 DCHECK(msg); |
| 1167 msg->Append("%s,%s,%d,", | 1167 msg->Append("%s,%s,%d,", |
| 1168 kLogEventsNames[Logger::CODE_CREATION_EVENT], | 1168 kLogEventsNames[Logger::CODE_CREATION_EVENT], |
| 1169 kLogEventsNames[tag], | 1169 kLogEventsNames[tag], |
| 1170 code->kind()); | 1170 code->kind()); |
| 1171 msg->AppendAddress(code->address()); | 1171 msg->AppendAddress(code->address()); |
| 1172 msg->Append(",%d,", code->ExecutableSize()); | 1172 msg->Append(",%d,", code->ExecutableSize()); |
| 1173 } | 1173 } |
| 1174 | 1174 |
| 1175 | 1175 |
| 1176 void Logger::CodeCreateEvent(LogEventsAndTags tag, | 1176 void Logger::CodeCreateEvent(LogEventsAndTags tag, |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1570 | 1570 |
| 1571 virtual void VisitFunction(JSFunction* function) { | 1571 virtual void VisitFunction(JSFunction* function) { |
| 1572 SharedFunctionInfo* sfi = SharedFunctionInfo::cast(function->shared()); | 1572 SharedFunctionInfo* sfi = SharedFunctionInfo::cast(function->shared()); |
| 1573 Object* maybe_script = sfi->script(); | 1573 Object* maybe_script = sfi->script(); |
| 1574 if (maybe_script->IsScript() | 1574 if (maybe_script->IsScript() |
| 1575 && !Script::cast(maybe_script)->HasValidSource()) return; | 1575 && !Script::cast(maybe_script)->HasValidSource()) return; |
| 1576 if (sfis_ != NULL) { | 1576 if (sfis_ != NULL) { |
| 1577 sfis_[*count_] = Handle<SharedFunctionInfo>(sfi); | 1577 sfis_[*count_] = Handle<SharedFunctionInfo>(sfi); |
| 1578 } | 1578 } |
| 1579 if (code_objects_ != NULL) { | 1579 if (code_objects_ != NULL) { |
| 1580 ASSERT(function->code()->kind() == Code::OPTIMIZED_FUNCTION); | 1580 DCHECK(function->code()->kind() == Code::OPTIMIZED_FUNCTION); |
| 1581 code_objects_[*count_] = Handle<Code>(function->code()); | 1581 code_objects_[*count_] = Handle<Code>(function->code()); |
| 1582 } | 1582 } |
| 1583 *count_ = *count_ + 1; | 1583 *count_ = *count_ + 1; |
| 1584 } | 1584 } |
| 1585 | 1585 |
| 1586 private: | 1586 private: |
| 1587 Handle<SharedFunctionInfo>* sfis_; | 1587 Handle<SharedFunctionInfo>* sfis_; |
| 1588 Handle<Code>* code_objects_; | 1588 Handle<Code>* code_objects_; |
| 1589 int* count_; | 1589 int* count_; |
| 1590 }; | 1590 }; |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1936 if (jit_logger_) { | 1936 if (jit_logger_) { |
| 1937 removeCodeEventListener(jit_logger_); | 1937 removeCodeEventListener(jit_logger_); |
| 1938 delete jit_logger_; | 1938 delete jit_logger_; |
| 1939 jit_logger_ = NULL; | 1939 jit_logger_ = NULL; |
| 1940 } | 1940 } |
| 1941 | 1941 |
| 1942 return log_->Close(); | 1942 return log_->Close(); |
| 1943 } | 1943 } |
| 1944 | 1944 |
| 1945 } } // namespace v8::internal | 1945 } } // namespace v8::internal |
| OLD | NEW |