Chromium Code Reviews| 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 "src/bailout-reason.h" | 10 #include "src/bailout-reason.h" |
| 11 #include "src/base/platform/platform.h" | 11 #include "src/base/platform/platform.h" |
| 12 #include "src/bootstrapper.h" | 12 #include "src/bootstrapper.h" |
| 13 #include "src/code-stubs.h" | 13 #include "src/code-stubs.h" |
| 14 #include "src/deoptimizer.h" | 14 #include "src/deoptimizer.h" |
| 15 #include "src/global-handles.h" | 15 #include "src/global-handles.h" |
| 16 #include "src/interpreter/bytecodes.h" | 16 #include "src/interpreter/bytecodes.h" |
| 17 #include "src/interpreter/interpreter.h" | 17 #include "src/interpreter/interpreter.h" |
| 18 #include "src/libsampler/v8-sampler.h" | |
| 18 #include "src/log-inl.h" | 19 #include "src/log-inl.h" |
| 19 #include "src/log-utils.h" | 20 #include "src/log-utils.h" |
| 20 #include "src/macro-assembler.h" | 21 #include "src/macro-assembler.h" |
| 21 #include "src/perf-jit.h" | 22 #include "src/perf-jit.h" |
| 22 #include "src/profiler/cpu-profiler.h" | 23 #include "src/profiler/cpu-profiler-inl.h" |
| 23 #include "src/runtime-profiler.h" | 24 #include "src/runtime-profiler.h" |
| 24 #include "src/string-stream.h" | 25 #include "src/string-stream.h" |
| 25 #include "src/vm-state-inl.h" | 26 #include "src/vm-state-inl.h" |
| 26 | 27 |
| 27 namespace v8 { | 28 namespace v8 { |
| 28 namespace internal { | 29 namespace internal { |
| 29 | 30 |
| 30 | 31 |
| 31 #define DECLARE_EVENT(ignore1, name) name, | 32 #define DECLARE_EVENT(ignore1, name) name, |
| 32 static const char* const kLogEventsNames[Logger::NUMBER_OF_LOG_EVENTS] = { | 33 static const char* const kLogEventsNames[Logger::NUMBER_OF_LOG_EVENTS] = { |
| (...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 532 JitCodeEvent event; | 533 JitCodeEvent event; |
| 533 memset(&event, 0, sizeof(event)); | 534 memset(&event, 0, sizeof(event)); |
| 534 event.type = JitCodeEvent::CODE_END_LINE_INFO_RECORDING; | 535 event.type = JitCodeEvent::CODE_END_LINE_INFO_RECORDING; |
| 535 event.code_start = code->instruction_start(); | 536 event.code_start = code->instruction_start(); |
| 536 event.user_data = jit_handler_data; | 537 event.user_data = jit_handler_data; |
| 537 | 538 |
| 538 code_event_handler_(&event); | 539 code_event_handler_(&event); |
| 539 } | 540 } |
| 540 | 541 |
| 541 | 542 |
| 543 // TODO(lpy): Keeping sampling thread inside V8 is a workaround currently, | |
| 544 // the reason is to reduce code duplication during migration to sampler library, | |
| 545 // sampling thread, as well as the sampler, will be moved to D8 eventually. | |
| 546 class SamplingThread : public base::Thread { | |
| 547 public: | |
| 548 static const int kSamplingThreadStackSize = 64 * KB; | |
| 549 | |
| 550 SamplingThread(sampler::Sampler* sampler, int interval) | |
| 551 : base::Thread(base::Thread::Options("SamplingThread", | |
| 552 kSamplingThreadStackSize)), | |
| 553 sampler_(sampler), | |
| 554 interval_(interval) {} | |
| 555 void Run() override { | |
| 556 while (true) { | |
|
alph
2016/05/23 23:37:27
while (sampler_->IsProfiling()) {
lpy
2016/05/24 17:07:57
Done.
| |
| 557 if (!sampler_->IsProfiling()) break; | |
| 558 sampler_->DoSample(); | |
| 559 base::OS::Sleep(base::TimeDelta::FromMilliseconds(interval_)); | |
| 560 } | |
| 561 } | |
| 562 | |
| 563 private: | |
| 564 sampler::Sampler* sampler_; | |
| 565 const int interval_; | |
| 566 }; | |
| 567 | |
| 568 | |
| 542 // The Profiler samples pc and sp values for the main thread. | 569 // The Profiler samples pc and sp values for the main thread. |
| 543 // Each sample is appended to a circular buffer. | 570 // Each sample is appended to a circular buffer. |
| 544 // An independent thread removes data and writes it to the log. | 571 // An independent thread removes data and writes it to the log. |
| 545 // This design minimizes the time spent in the sampler. | 572 // This design minimizes the time spent in the sampler. |
| 546 // | 573 // |
| 547 class Profiler: public base::Thread { | 574 class Profiler: public base::Thread { |
| 548 public: | 575 public: |
| 549 explicit Profiler(Isolate* isolate); | 576 explicit Profiler(Isolate* isolate); |
| 550 void Engage(); | 577 void Engage(); |
| 551 void Disengage(); | 578 void Disengage(); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 604 | 631 |
| 605 // Tells whether we are currently recording tick samples. | 632 // Tells whether we are currently recording tick samples. |
| 606 bool paused_; | 633 bool paused_; |
| 607 }; | 634 }; |
| 608 | 635 |
| 609 | 636 |
| 610 // | 637 // |
| 611 // Ticker used to provide ticks to the profiler and the sliding state | 638 // Ticker used to provide ticks to the profiler and the sliding state |
| 612 // window. | 639 // window. |
| 613 // | 640 // |
| 614 class Ticker: public Sampler { | 641 class Ticker: public sampler::Sampler { |
| 615 public: | 642 public: |
| 616 Ticker(Isolate* isolate, int interval): | 643 Ticker(Isolate* isolate, int interval): |
| 617 Sampler(isolate, interval), | 644 sampler::Sampler(reinterpret_cast<v8::Isolate*>(isolate)), |
| 618 profiler_(NULL) {} | 645 profiler_(NULL), |
| 646 sampling_thread_(new SamplingThread(this, interval)) {} | |
| 619 | 647 |
| 620 ~Ticker() { if (IsActive()) Stop(); } | 648 ~Ticker() { |
| 621 | 649 if (IsActive()) Stop(); |
| 622 virtual void Tick(TickSample* sample) { | 650 delete sampling_thread_; |
| 623 if (profiler_) profiler_->Insert(sample); | |
| 624 } | 651 } |
| 625 | 652 |
| 626 void SetProfiler(Profiler* profiler) { | 653 void SetProfiler(Profiler* profiler) { |
| 627 DCHECK(profiler_ == NULL); | 654 DCHECK(profiler_ == NULL); |
| 628 profiler_ = profiler; | 655 profiler_ = profiler; |
| 629 IncreaseProfilingDepth(); | 656 IncreaseProfilingDepth(); |
| 630 if (!IsActive()) Start(); | 657 if (!IsActive()) Start(); |
| 658 sampling_thread_->StartSynchronously(); | |
| 631 } | 659 } |
| 632 | 660 |
| 633 void ClearProfiler() { | 661 void ClearProfiler() { |
| 634 profiler_ = NULL; | 662 profiler_ = NULL; |
| 635 if (IsActive()) Stop(); | 663 if (IsActive()) Stop(); |
| 636 DecreaseProfilingDepth(); | 664 DecreaseProfilingDepth(); |
| 665 sampling_thread_->Join(); | |
| 666 } | |
| 667 | |
| 668 void SampleStack(const v8::RegisterState& state) override { | |
| 669 v8::Isolate* v8_isolate = isolate(); | |
| 670 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); | |
| 671 #if defined(USE_SIMULATOR) | |
| 672 SimulatorHelper::FillRegisters(isolate, | |
| 673 const_cast<v8::RegisterState*>(&state)); | |
| 674 #endif | |
| 675 TickSample* sample = isolate->cpu_profiler()->StartTickSample(); | |
| 676 TickSample sample_obj; | |
| 677 if (sample == NULL) sample = &sample_obj; | |
| 678 sample->Init(isolate, state, TickSample::kIncludeCEntryFrame, true); | |
| 679 if (is_counting_samples_ && !sample->timestamp.IsNull()) { | |
| 680 if (sample->state == JS) ++js_sample_count_; | |
| 681 if (sample->state == EXTERNAL) ++external_sample_count_; | |
| 682 } | |
| 683 if (profiler_) profiler_->Insert(sample); | |
| 684 if (sample != &sample_obj) { | |
| 685 isolate->cpu_profiler()->FinishTickSample(); | |
| 686 } | |
| 637 } | 687 } |
| 638 | 688 |
| 639 private: | 689 private: |
| 640 Profiler* profiler_; | 690 Profiler* profiler_; |
| 691 SamplingThread* sampling_thread_; | |
| 641 }; | 692 }; |
| 642 | 693 |
| 643 | 694 |
| 644 // | 695 // |
| 645 // Profiler implementation. | 696 // Profiler implementation. |
| 646 // | 697 // |
| 647 Profiler::Profiler(Isolate* isolate) | 698 Profiler::Profiler(Isolate* isolate) |
| 648 : base::Thread(Options("v8:Profiler")), | 699 : base::Thread(Options("v8:Profiler")), |
| 649 isolate_(isolate), | 700 isolate_(isolate), |
| 650 head_(0), | 701 head_(0), |
| (...skipping 1152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1803 addCodeEventListener(jit_logger_); | 1854 addCodeEventListener(jit_logger_); |
| 1804 if (options & kJitCodeEventEnumExisting) { | 1855 if (options & kJitCodeEventEnumExisting) { |
| 1805 HandleScope scope(isolate_); | 1856 HandleScope scope(isolate_); |
| 1806 LogCodeObjects(); | 1857 LogCodeObjects(); |
| 1807 LogCompiledFunctions(); | 1858 LogCompiledFunctions(); |
| 1808 } | 1859 } |
| 1809 } | 1860 } |
| 1810 } | 1861 } |
| 1811 | 1862 |
| 1812 | 1863 |
| 1813 Sampler* Logger::sampler() { | 1864 sampler::Sampler* Logger::sampler() { |
| 1814 return ticker_; | 1865 return ticker_; |
| 1815 } | 1866 } |
| 1816 | 1867 |
| 1817 | 1868 |
| 1818 FILE* Logger::TearDown() { | 1869 FILE* Logger::TearDown() { |
| 1819 if (!is_initialized_) return NULL; | 1870 if (!is_initialized_) return NULL; |
| 1820 is_initialized_ = false; | 1871 is_initialized_ = false; |
| 1821 | 1872 |
| 1822 // Stop the profiler before closing the file. | 1873 // Stop the profiler before closing the file. |
| 1823 if (profiler_ != NULL) { | 1874 if (profiler_ != NULL) { |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 1851 removeCodeEventListener(jit_logger_); | 1902 removeCodeEventListener(jit_logger_); |
| 1852 delete jit_logger_; | 1903 delete jit_logger_; |
| 1853 jit_logger_ = NULL; | 1904 jit_logger_ = NULL; |
| 1854 } | 1905 } |
| 1855 | 1906 |
| 1856 return log_->Close(); | 1907 return log_->Close(); |
| 1857 } | 1908 } |
| 1858 | 1909 |
| 1859 } // namespace internal | 1910 } // namespace internal |
| 1860 } // namespace v8 | 1911 } // namespace v8 |
| OLD | NEW |