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

Side by Side Diff: src/log.cc

Issue 1922303002: Create libsampler as V8 sampler library. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix TSAN failure Created 4 years, 7 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/profiler/cpu-profiler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 (sampler_->IsProfiling()) {
557 sampler_->DoSample();
558 base::OS::Sleep(base::TimeDelta::FromMilliseconds(interval_));
559 }
560 }
561
562 private:
563 sampler::Sampler* sampler_;
564 const int interval_;
565 };
566
567
542 // The Profiler samples pc and sp values for the main thread. 568 // The Profiler samples pc and sp values for the main thread.
543 // Each sample is appended to a circular buffer. 569 // Each sample is appended to a circular buffer.
544 // An independent thread removes data and writes it to the log. 570 // An independent thread removes data and writes it to the log.
545 // This design minimizes the time spent in the sampler. 571 // This design minimizes the time spent in the sampler.
546 // 572 //
547 class Profiler: public base::Thread { 573 class Profiler: public base::Thread {
548 public: 574 public:
549 explicit Profiler(Isolate* isolate); 575 explicit Profiler(Isolate* isolate);
550 void Engage(); 576 void Engage();
551 void Disengage(); 577 void Disengage();
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 630
605 // Tells whether we are currently recording tick samples. 631 // Tells whether we are currently recording tick samples.
606 bool paused_; 632 bool paused_;
607 }; 633 };
608 634
609 635
610 // 636 //
611 // Ticker used to provide ticks to the profiler and the sliding state 637 // Ticker used to provide ticks to the profiler and the sliding state
612 // window. 638 // window.
613 // 639 //
614 class Ticker: public Sampler { 640 class Ticker: public sampler::Sampler {
615 public: 641 public:
616 Ticker(Isolate* isolate, int interval): 642 Ticker(Isolate* isolate, int interval):
617 Sampler(isolate, interval), 643 sampler::Sampler(reinterpret_cast<v8::Isolate*>(isolate)),
618 profiler_(NULL) {} 644 profiler_(NULL),
645 sampling_thread_(new SamplingThread(this, interval)) {}
619 646
620 ~Ticker() { if (IsActive()) Stop(); } 647 ~Ticker() {
621 648 if (IsActive()) Stop();
622 virtual void Tick(TickSample* sample) { 649 delete sampling_thread_;
623 if (profiler_) profiler_->Insert(sample);
624 } 650 }
625 651
626 void SetProfiler(Profiler* profiler) { 652 void SetProfiler(Profiler* profiler) {
627 DCHECK(profiler_ == NULL); 653 DCHECK(profiler_ == NULL);
628 profiler_ = profiler; 654 profiler_ = profiler;
629 IncreaseProfilingDepth(); 655 IncreaseProfilingDepth();
630 if (!IsActive()) Start(); 656 if (!IsActive()) Start();
657 sampling_thread_->StartSynchronously();
631 } 658 }
632 659
633 void ClearProfiler() { 660 void ClearProfiler() {
634 profiler_ = NULL; 661 profiler_ = NULL;
635 if (IsActive()) Stop(); 662 if (IsActive()) Stop();
636 DecreaseProfilingDepth(); 663 DecreaseProfilingDepth();
664 sampling_thread_->Join();
665 }
666
667 void SampleStack(const v8::RegisterState& state) override {
668 v8::Isolate* v8_isolate = isolate();
669 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate);
670 #if defined(USE_SIMULATOR)
671 SimulatorHelper::FillRegisters(isolate,
672 const_cast<v8::RegisterState*>(&state));
673 #endif
674 TickSample* sample = isolate->cpu_profiler()->StartTickSample();
675 TickSample sample_obj;
676 if (sample == NULL) sample = &sample_obj;
677 sample->Init(isolate, state, TickSample::kIncludeCEntryFrame, true);
678 if (is_counting_samples_ && !sample->timestamp.IsNull()) {
679 if (sample->state == JS) ++js_sample_count_;
680 if (sample->state == EXTERNAL) ++external_sample_count_;
681 }
682 if (profiler_) profiler_->Insert(sample);
683 if (sample != &sample_obj) {
684 isolate->cpu_profiler()->FinishTickSample();
685 }
637 } 686 }
638 687
639 private: 688 private:
640 Profiler* profiler_; 689 Profiler* profiler_;
690 SamplingThread* sampling_thread_;
641 }; 691 };
642 692
643 693
644 // 694 //
645 // Profiler implementation. 695 // Profiler implementation.
646 // 696 //
647 Profiler::Profiler(Isolate* isolate) 697 Profiler::Profiler(Isolate* isolate)
648 : base::Thread(Options("v8:Profiler")), 698 : base::Thread(Options("v8:Profiler")),
649 isolate_(isolate), 699 isolate_(isolate),
650 head_(0), 700 head_(0),
(...skipping 1152 matching lines...) Expand 10 before | Expand all | Expand 10 after
1803 addCodeEventListener(jit_logger_); 1853 addCodeEventListener(jit_logger_);
1804 if (options & kJitCodeEventEnumExisting) { 1854 if (options & kJitCodeEventEnumExisting) {
1805 HandleScope scope(isolate_); 1855 HandleScope scope(isolate_);
1806 LogCodeObjects(); 1856 LogCodeObjects();
1807 LogCompiledFunctions(); 1857 LogCompiledFunctions();
1808 } 1858 }
1809 } 1859 }
1810 } 1860 }
1811 1861
1812 1862
1813 Sampler* Logger::sampler() { 1863 sampler::Sampler* Logger::sampler() {
1814 return ticker_; 1864 return ticker_;
1815 } 1865 }
1816 1866
1817 1867
1818 FILE* Logger::TearDown() { 1868 FILE* Logger::TearDown() {
1819 if (!is_initialized_) return NULL; 1869 if (!is_initialized_) return NULL;
1820 is_initialized_ = false; 1870 is_initialized_ = false;
1821 1871
1822 // Stop the profiler before closing the file. 1872 // Stop the profiler before closing the file.
1823 if (profiler_ != NULL) { 1873 if (profiler_ != NULL) {
(...skipping 27 matching lines...) Expand all
1851 removeCodeEventListener(jit_logger_); 1901 removeCodeEventListener(jit_logger_);
1852 delete jit_logger_; 1902 delete jit_logger_;
1853 jit_logger_ = NULL; 1903 jit_logger_ = NULL;
1854 } 1904 }
1855 1905
1856 return log_->Close(); 1906 return log_->Close();
1857 } 1907 }
1858 1908
1859 } // namespace internal 1909 } // namespace internal
1860 } // namespace v8 1910 } // namespace v8
OLDNEW
« no previous file with comments | « src/log.h ('k') | src/profiler/cpu-profiler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698