| 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 "src/log.h" | 5 #include "src/log.h" |
| 6 | 6 |
| 7 #include <cstdarg> | 7 #include <cstdarg> |
| 8 #include <sstream> | 8 #include <sstream> |
| 9 | 9 |
| 10 #include "include/v8-profiler.h" |
| 10 #include "src/bailout-reason.h" | 11 #include "src/bailout-reason.h" |
| 11 #include "src/base/platform/platform.h" | 12 #include "src/base/platform/platform.h" |
| 12 #include "src/bootstrapper.h" | 13 #include "src/bootstrapper.h" |
| 13 #include "src/code-stubs.h" | 14 #include "src/code-stubs.h" |
| 14 #include "src/counters.h" | 15 #include "src/counters.h" |
| 15 #include "src/deoptimizer.h" | 16 #include "src/deoptimizer.h" |
| 16 #include "src/global-handles.h" | 17 #include "src/global-handles.h" |
| 17 #include "src/interpreter/bytecodes.h" | 18 #include "src/interpreter/bytecodes.h" |
| 18 #include "src/interpreter/interpreter.h" | 19 #include "src/interpreter/interpreter.h" |
| 19 #include "src/libsampler/v8-sampler.h" | 20 #include "src/libsampler/v8-sampler.h" |
| 20 #include "src/log-inl.h" | 21 #include "src/log-inl.h" |
| 21 #include "src/log-utils.h" | 22 #include "src/log-utils.h" |
| 22 #include "src/macro-assembler.h" | 23 #include "src/macro-assembler.h" |
| 23 #include "src/perf-jit.h" | 24 #include "src/perf-jit.h" |
| 24 #include "src/profiler/cpu-profiler-inl.h" | 25 #include "src/profiler/cpu-profiler-inl.h" |
| 25 #include "src/profiler/profiler-listener.h" | 26 #include "src/profiler/profiler-listener.h" |
| 27 #include "src/profiler/simulator-helper.h" |
| 26 #include "src/runtime-profiler.h" | 28 #include "src/runtime-profiler.h" |
| 27 #include "src/string-stream.h" | 29 #include "src/string-stream.h" |
| 28 #include "src/vm-state-inl.h" | 30 #include "src/vm-state-inl.h" |
| 29 | 31 |
| 30 namespace v8 { | 32 namespace v8 { |
| 31 namespace internal { | 33 namespace internal { |
| 32 | 34 |
| 33 | 35 |
| 34 #define DECLARE_EVENT(ignore1, name) name, | 36 #define DECLARE_EVENT(ignore1, name) name, |
| 35 static const char* kLogEventsNames[CodeEventListener::NUMBER_OF_LOG_EVENTS] = { | 37 static const char* kLogEventsNames[CodeEventListener::NUMBER_OF_LOG_EVENTS] = { |
| (...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 | 640 |
| 639 void ClearProfiler() { | 641 void ClearProfiler() { |
| 640 profiler_ = NULL; | 642 profiler_ = NULL; |
| 641 if (IsActive()) Stop(); | 643 if (IsActive()) Stop(); |
| 642 DecreaseProfilingDepth(); | 644 DecreaseProfilingDepth(); |
| 643 sampling_thread_->Join(); | 645 sampling_thread_->Join(); |
| 644 } | 646 } |
| 645 | 647 |
| 646 void SampleStack(const v8::RegisterState& state) override { | 648 void SampleStack(const v8::RegisterState& state) override { |
| 647 v8::Isolate* v8_isolate = isolate(); | 649 v8::Isolate* v8_isolate = isolate(); |
| 648 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); | 650 Isolate* i_isolate = reinterpret_cast<Isolate*>(v8_isolate); |
| 649 #if defined(USE_SIMULATOR) | 651 #if defined(USE_SIMULATOR) |
| 650 if (!SimulatorHelper::FillRegisters(isolate, | 652 if (!SimulatorHelper::FillRegisters(i_isolate, |
| 651 const_cast<v8::RegisterState*>(&state))) | 653 const_cast<v8::RegisterState*>(&state))) |
| 652 return; | 654 return; |
| 653 #endif | 655 #endif |
| 654 TickSample* sample = isolate->cpu_profiler()->StartTickSample(); | 656 TickSample* sample = i_isolate->cpu_profiler()->StartTickSample(); |
| 655 TickSample sample_obj; | 657 TickSample sample_obj; |
| 656 if (sample == NULL) sample = &sample_obj; | 658 if (sample == NULL) sample = &sample_obj; |
| 657 sample->Init(isolate, state, TickSample::kIncludeCEntryFrame, true); | 659 sample->Init(v8_isolate, state, TickSample::kIncludeCEntryFrame, true); |
| 658 if (is_counting_samples_ && !sample->timestamp.IsNull()) { | 660 if (sample->pc == nullptr) return; |
| 661 if (is_counting_samples_) { |
| 659 if (sample->state == JS) ++js_sample_count_; | 662 if (sample->state == JS) ++js_sample_count_; |
| 660 if (sample->state == EXTERNAL) ++external_sample_count_; | 663 if (sample->state == EXTERNAL) ++external_sample_count_; |
| 661 } | 664 } |
| 662 if (profiler_) profiler_->Insert(sample); | 665 if (profiler_) profiler_->Insert(sample); |
| 663 if (sample != &sample_obj) { | 666 if (sample != &sample_obj) { |
| 664 isolate->cpu_profiler()->FinishTickSample(); | 667 i_isolate->cpu_profiler()->FinishTickSample(); |
| 665 } | 668 } |
| 666 } | 669 } |
| 667 | 670 |
| 668 private: | 671 private: |
| 669 Profiler* profiler_; | 672 Profiler* profiler_; |
| 670 SamplingThread* sampling_thread_; | 673 SamplingThread* sampling_thread_; |
| 671 }; | 674 }; |
| 672 | 675 |
| 673 | 676 |
| 674 // | 677 // |
| (...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1376 msg.WriteToLogFile(); | 1379 msg.WriteToLogFile(); |
| 1377 } | 1380 } |
| 1378 | 1381 |
| 1379 void Logger::TickEvent(TickSample* sample, bool overflow) { | 1382 void Logger::TickEvent(TickSample* sample, bool overflow) { |
| 1380 if (!log_->IsEnabled() || !FLAG_prof_cpp) return; | 1383 if (!log_->IsEnabled() || !FLAG_prof_cpp) return; |
| 1381 if (FLAG_runtime_call_stats) { | 1384 if (FLAG_runtime_call_stats) { |
| 1382 RuntimeCallTimerEvent(); | 1385 RuntimeCallTimerEvent(); |
| 1383 } | 1386 } |
| 1384 Log::MessageBuilder msg(log_); | 1387 Log::MessageBuilder msg(log_); |
| 1385 msg.Append("%s,", kLogEventsNames[CodeEventListener::TICK_EVENT]); | 1388 msg.Append("%s,", kLogEventsNames[CodeEventListener::TICK_EVENT]); |
| 1386 msg.AppendAddress(sample->pc); | 1389 msg.AppendAddress(reinterpret_cast<Address>(sample->pc)); |
| 1387 msg.Append(",%d", static_cast<int>(timer_.Elapsed().InMicroseconds())); | 1390 msg.Append(",%d", static_cast<int>(timer_.Elapsed().InMicroseconds())); |
| 1388 if (sample->has_external_callback) { | 1391 if (sample->has_external_callback) { |
| 1389 msg.Append(",1,"); | 1392 msg.Append(",1,"); |
| 1390 msg.AppendAddress(sample->external_callback_entry); | 1393 msg.AppendAddress( |
| 1394 reinterpret_cast<Address>(sample->external_callback_entry)); |
| 1391 } else { | 1395 } else { |
| 1392 msg.Append(",0,"); | 1396 msg.Append(",0,"); |
| 1393 msg.AppendAddress(sample->tos); | 1397 msg.AppendAddress(reinterpret_cast<Address>(sample->tos)); |
| 1394 } | 1398 } |
| 1395 msg.Append(",%d", static_cast<int>(sample->state)); | 1399 msg.Append(",%d", static_cast<int>(sample->state)); |
| 1396 if (overflow) { | 1400 if (overflow) { |
| 1397 msg.Append(",overflow"); | 1401 msg.Append(",overflow"); |
| 1398 } | 1402 } |
| 1399 for (unsigned i = 0; i < sample->frames_count; ++i) { | 1403 for (unsigned i = 0; i < sample->frames_count; ++i) { |
| 1400 msg.Append(','); | 1404 msg.Append(','); |
| 1401 msg.AppendAddress(sample->stack[i]); | 1405 msg.AppendAddress(reinterpret_cast<Address>(sample->stack[i])); |
| 1402 } | 1406 } |
| 1403 msg.WriteToLogFile(); | 1407 msg.WriteToLogFile(); |
| 1404 } | 1408 } |
| 1405 | 1409 |
| 1406 | 1410 |
| 1407 void Logger::StopProfiler() { | 1411 void Logger::StopProfiler() { |
| 1408 if (!log_->IsEnabled()) return; | 1412 if (!log_->IsEnabled()) return; |
| 1409 if (profiler_ != NULL) { | 1413 if (profiler_ != NULL) { |
| 1410 profiler_->pause(); | 1414 profiler_->pause(); |
| 1411 is_logging_ = false; | 1415 is_logging_ = false; |
| (...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1879 | 1883 |
| 1880 if (profiler_listener_.get() != nullptr) { | 1884 if (profiler_listener_.get() != nullptr) { |
| 1881 removeCodeEventListener(profiler_listener_.get()); | 1885 removeCodeEventListener(profiler_listener_.get()); |
| 1882 } | 1886 } |
| 1883 | 1887 |
| 1884 return log_->Close(); | 1888 return log_->Close(); |
| 1885 } | 1889 } |
| 1886 | 1890 |
| 1887 } // namespace internal | 1891 } // namespace internal |
| 1888 } // namespace v8 | 1892 } // namespace v8 |
| OLD | NEW |