| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 | 553 |
| 554 if (Succ(head_) == tail_) { | 554 if (Succ(head_) == tail_) { |
| 555 overflow_ = true; | 555 overflow_ = true; |
| 556 } else { | 556 } else { |
| 557 buffer_[head_] = *sample; | 557 buffer_[head_] = *sample; |
| 558 head_ = Succ(head_); | 558 head_ = Succ(head_); |
| 559 buffer_semaphore_->Signal(); // Tell we have an element. | 559 buffer_semaphore_->Signal(); // Tell we have an element. |
| 560 } | 560 } |
| 561 } | 561 } |
| 562 | 562 |
| 563 virtual void Run(); |
| 564 |
| 565 // Pause and Resume TickSample data collection. |
| 566 bool paused() const { return paused_; } |
| 567 void pause() { paused_ = true; } |
| 568 void resume() { paused_ = false; } |
| 569 |
| 570 private: |
| 563 // Waits for a signal and removes profiling data. | 571 // Waits for a signal and removes profiling data. |
| 564 bool Remove(TickSample* sample) { | 572 bool Remove(TickSample* sample) { |
| 565 buffer_semaphore_->Wait(); // Wait for an element. | 573 buffer_semaphore_->Wait(); // Wait for an element. |
| 566 *sample = buffer_[tail_]; | 574 *sample = buffer_[tail_]; |
| 567 bool result = overflow_; | 575 bool result = overflow_; |
| 568 tail_ = Succ(tail_); | 576 tail_ = Succ(tail_); |
| 569 overflow_ = false; | 577 overflow_ = false; |
| 570 return result; | 578 return result; |
| 571 } | 579 } |
| 572 | 580 |
| 573 void Run(); | |
| 574 | |
| 575 // Pause and Resume TickSample data collection. | |
| 576 bool paused() const { return paused_; } | |
| 577 void pause() { paused_ = true; } | |
| 578 void resume() { paused_ = false; } | |
| 579 | |
| 580 private: | |
| 581 // Returns the next index in the cyclic buffer. | 581 // Returns the next index in the cyclic buffer. |
| 582 int Succ(int index) { return (index + 1) % kBufferSize; } | 582 int Succ(int index) { return (index + 1) % kBufferSize; } |
| 583 | 583 |
| 584 Isolate* isolate_; | 584 Isolate* isolate_; |
| 585 // Cyclic buffer for communicating profiling samples | 585 // Cyclic buffer for communicating profiling samples |
| 586 // between the signal handler and the worker thread. | 586 // between the signal handler and the worker thread. |
| 587 static const int kBufferSize = 128; | 587 static const int kBufferSize = 128; |
| 588 TickSample buffer_[kBufferSize]; // Buffer storage. | 588 TickSample buffer_[kBufferSize]; // Buffer storage. |
| 589 int head_; // Index to the buffer head. | 589 int head_; // Index to the buffer head. |
| 590 int tail_; // Index to the buffer tail. | 590 int tail_; // Index to the buffer tail. |
| 591 bool overflow_; // Tell whether a buffer overflow has occurred. | 591 bool overflow_; // Tell whether a buffer overflow has occurred. |
| 592 Semaphore* buffer_semaphore_; // Sempahore used for buffer synchronization. | 592 // Sempahore used for buffer synchronization. |
| 593 SmartPointer<Semaphore> buffer_semaphore_; |
| 593 | 594 |
| 594 // Tells whether profiler is engaged, that is, processing thread is stated. | 595 // Tells whether profiler is engaged, that is, processing thread is stated. |
| 595 bool engaged_; | 596 bool engaged_; |
| 596 | 597 |
| 597 // Tells whether worker thread should continue running. | 598 // Tells whether worker thread should continue running. |
| 598 bool running_; | 599 bool running_; |
| 599 | 600 |
| 600 // Tells whether we are currently recording tick samples. | 601 // Tells whether we are currently recording tick samples. |
| 601 bool paused_; | 602 bool paused_; |
| 602 }; | 603 }; |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 899 } | 900 } |
| 900 | 901 |
| 901 | 902 |
| 902 void Logger::TimerEventScope::LogTimerEvent(StartEnd se) { | 903 void Logger::TimerEventScope::LogTimerEvent(StartEnd se) { |
| 903 LOG(isolate_, TimerEvent(se, name_)); | 904 LOG(isolate_, TimerEvent(se, name_)); |
| 904 } | 905 } |
| 905 | 906 |
| 906 | 907 |
| 907 const char* Logger::TimerEventScope::v8_recompile_synchronous = | 908 const char* Logger::TimerEventScope::v8_recompile_synchronous = |
| 908 "V8.RecompileSynchronous"; | 909 "V8.RecompileSynchronous"; |
| 909 const char* Logger::TimerEventScope::v8_recompile_parallel = | 910 const char* Logger::TimerEventScope::v8_recompile_concurrent = |
| 910 "V8.RecompileParallel"; | 911 "V8.RecompileConcurrent"; |
| 911 const char* Logger::TimerEventScope::v8_compile_full_code = | 912 const char* Logger::TimerEventScope::v8_compile_full_code = |
| 912 "V8.CompileFullCode"; | 913 "V8.CompileFullCode"; |
| 913 const char* Logger::TimerEventScope::v8_execute = "V8.Execute"; | 914 const char* Logger::TimerEventScope::v8_execute = "V8.Execute"; |
| 914 const char* Logger::TimerEventScope::v8_external = "V8.External"; | 915 const char* Logger::TimerEventScope::v8_external = "V8.External"; |
| 915 | 916 |
| 916 | 917 |
| 917 void Logger::LogRegExpSource(Handle<JSRegExp> regexp) { | 918 void Logger::LogRegExpSource(Handle<JSRegExp> regexp) { |
| 918 // Prints "/" + re.source + "/" + | 919 // Prints "/" + re.source + "/" + |
| 919 // (re.global?"g":"") + (re.ignorecase?"i":"") + (re.multiline?"m":"") | 920 // (re.global?"g":"") + (re.ignorecase?"i":"") + (re.multiline?"m":"") |
| 920 Log::MessageBuilder msg(log_); | 921 Log::MessageBuilder msg(log_); |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1226 } | 1227 } |
| 1227 | 1228 |
| 1228 | 1229 |
| 1229 // Although, it is possible to extract source and line from | 1230 // Although, it is possible to extract source and line from |
| 1230 // the SharedFunctionInfo object, we left it to caller | 1231 // the SharedFunctionInfo object, we left it to caller |
| 1231 // to leave logging functions free from heap allocations. | 1232 // to leave logging functions free from heap allocations. |
| 1232 void Logger::CodeCreateEvent(LogEventsAndTags tag, | 1233 void Logger::CodeCreateEvent(LogEventsAndTags tag, |
| 1233 Code* code, | 1234 Code* code, |
| 1234 SharedFunctionInfo* shared, | 1235 SharedFunctionInfo* shared, |
| 1235 CompilationInfo* info, | 1236 CompilationInfo* info, |
| 1236 Name* source, int line) { | 1237 Name* source, int line, int column) { |
| 1237 PROFILER_LOG(CodeCreateEvent(tag, code, shared, info, source, line)); | 1238 PROFILER_LOG(CodeCreateEvent(tag, code, shared, info, source, line)); |
| 1238 | 1239 |
| 1239 if (!is_logging_code_events()) return; | 1240 if (!is_logging_code_events()) return; |
| 1240 CALL_LISTENERS(CodeCreateEvent(tag, code, shared, info, source, line)); | 1241 CALL_LISTENERS(CodeCreateEvent(tag, code, shared, info, source, line)); |
| 1241 | 1242 |
| 1242 if (!FLAG_log_code || !log_->IsEnabled()) return; | 1243 if (!FLAG_log_code || !log_->IsEnabled()) return; |
| 1243 Log::MessageBuilder msg(log_); | 1244 Log::MessageBuilder msg(log_); |
| 1244 AppendCodeCreateHeader(&msg, tag, code); | 1245 AppendCodeCreateHeader(&msg, tag, code); |
| 1245 SmartArrayPointer<char> name = | 1246 SmartArrayPointer<char> name = |
| 1246 shared->DebugName()->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); | 1247 shared->DebugName()->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
| 1247 msg.Append("\"%s ", *name); | 1248 msg.Append("\"%s ", *name); |
| 1248 if (source->IsString()) { | 1249 if (source->IsString()) { |
| 1249 SmartArrayPointer<char> sourcestr = | 1250 SmartArrayPointer<char> sourcestr = |
| 1250 String::cast(source)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); | 1251 String::cast(source)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
| 1251 msg.Append("%s", *sourcestr); | 1252 msg.Append("%s", *sourcestr); |
| 1252 } else { | 1253 } else { |
| 1253 msg.AppendSymbolName(Symbol::cast(source)); | 1254 msg.AppendSymbolName(Symbol::cast(source)); |
| 1254 } | 1255 } |
| 1255 msg.Append(":%d\",", line); | 1256 msg.Append(":%d:%d\",", line, column); |
| 1256 msg.AppendAddress(shared->address()); | 1257 msg.AppendAddress(shared->address()); |
| 1257 msg.Append(",%s", ComputeMarker(code)); | 1258 msg.Append(",%s", ComputeMarker(code)); |
| 1258 msg.Append('\n'); | 1259 msg.Append('\n'); |
| 1259 msg.WriteToLogFile(); | 1260 msg.WriteToLogFile(); |
| 1260 } | 1261 } |
| 1261 | 1262 |
| 1262 | 1263 |
| 1263 void Logger::CodeCreateEvent(LogEventsAndTags tag, | 1264 void Logger::CodeCreateEvent(LogEventsAndTags tag, |
| 1264 Code* code, | 1265 Code* code, |
| 1265 int args_count) { | 1266 int args_count) { |
| (...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1705 } | 1706 } |
| 1706 } | 1707 } |
| 1707 | 1708 |
| 1708 | 1709 |
| 1709 void Logger::LogExistingFunction(Handle<SharedFunctionInfo> shared, | 1710 void Logger::LogExistingFunction(Handle<SharedFunctionInfo> shared, |
| 1710 Handle<Code> code) { | 1711 Handle<Code> code) { |
| 1711 Handle<String> func_name(shared->DebugName()); | 1712 Handle<String> func_name(shared->DebugName()); |
| 1712 if (shared->script()->IsScript()) { | 1713 if (shared->script()->IsScript()) { |
| 1713 Handle<Script> script(Script::cast(shared->script())); | 1714 Handle<Script> script(Script::cast(shared->script())); |
| 1714 int line_num = GetScriptLineNumber(script, shared->start_position()) + 1; | 1715 int line_num = GetScriptLineNumber(script, shared->start_position()) + 1; |
| 1716 int column_num = |
| 1717 GetScriptColumnNumber(script, shared->start_position()) + 1; |
| 1715 if (script->name()->IsString()) { | 1718 if (script->name()->IsString()) { |
| 1716 Handle<String> script_name(String::cast(script->name())); | 1719 Handle<String> script_name(String::cast(script->name())); |
| 1717 if (line_num > 0) { | 1720 if (line_num > 0) { |
| 1718 PROFILE(isolate_, | 1721 PROFILE(isolate_, |
| 1719 CodeCreateEvent( | 1722 CodeCreateEvent( |
| 1720 Logger::ToNativeByScript(Logger::LAZY_COMPILE_TAG, *script), | 1723 Logger::ToNativeByScript(Logger::LAZY_COMPILE_TAG, *script), |
| 1721 *code, *shared, NULL, | 1724 *code, *shared, NULL, |
| 1722 *script_name, line_num)); | 1725 *script_name, line_num, column_num)); |
| 1723 } else { | 1726 } else { |
| 1724 // Can't distinguish eval and script here, so always use Script. | 1727 // Can't distinguish eval and script here, so always use Script. |
| 1725 PROFILE(isolate_, | 1728 PROFILE(isolate_, |
| 1726 CodeCreateEvent( | 1729 CodeCreateEvent( |
| 1727 Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script), | 1730 Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script), |
| 1728 *code, *shared, NULL, *script_name)); | 1731 *code, *shared, NULL, *script_name)); |
| 1729 } | 1732 } |
| 1730 } else { | 1733 } else { |
| 1731 PROFILE(isolate_, | 1734 PROFILE(isolate_, |
| 1732 CodeCreateEvent( | 1735 CodeCreateEvent( |
| 1733 Logger::ToNativeByScript(Logger::LAZY_COMPILE_TAG, *script), | 1736 Logger::ToNativeByScript(Logger::LAZY_COMPILE_TAG, *script), |
| 1734 *code, *shared, NULL, | 1737 *code, *shared, NULL, |
| 1735 isolate_->heap()->empty_string(), line_num)); | 1738 isolate_->heap()->empty_string(), line_num, column_num)); |
| 1736 } | 1739 } |
| 1737 } else if (shared->IsApiFunction()) { | 1740 } else if (shared->IsApiFunction()) { |
| 1738 // API function. | 1741 // API function. |
| 1739 FunctionTemplateInfo* fun_data = shared->get_api_func_data(); | 1742 FunctionTemplateInfo* fun_data = shared->get_api_func_data(); |
| 1740 Object* raw_call_data = fun_data->call_code(); | 1743 Object* raw_call_data = fun_data->call_code(); |
| 1741 if (!raw_call_data->IsUndefined()) { | 1744 if (!raw_call_data->IsUndefined()) { |
| 1742 CallHandlerInfo* call_data = CallHandlerInfo::cast(raw_call_data); | 1745 CallHandlerInfo* call_data = CallHandlerInfo::cast(raw_call_data); |
| 1743 Object* callback_obj = call_data->callback(); | 1746 Object* callback_obj = call_data->callback(); |
| 1744 Address entry_point = v8::ToCData<Address>(callback_obj); | 1747 Address entry_point = v8::ToCData<Address>(callback_obj); |
| 1745 PROFILE(isolate_, CallbackEvent(*func_name, entry_point)); | 1748 PROFILE(isolate_, CallbackEvent(*func_name, entry_point)); |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1947 if (jit_logger_) { | 1950 if (jit_logger_) { |
| 1948 removeCodeEventListener(jit_logger_); | 1951 removeCodeEventListener(jit_logger_); |
| 1949 delete jit_logger_; | 1952 delete jit_logger_; |
| 1950 jit_logger_ = NULL; | 1953 jit_logger_ = NULL; |
| 1951 } | 1954 } |
| 1952 | 1955 |
| 1953 return log_->Close(); | 1956 return log_->Close(); |
| 1954 } | 1957 } |
| 1955 | 1958 |
| 1956 } } // namespace v8::internal | 1959 } } // namespace v8::internal |
| OLD | NEW |