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

Side by Side Diff: src/log.cc

Issue 2000323007: Revert of Create libsampler as V8 sampler library. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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"
19 #include "src/log-inl.h" 18 #include "src/log-inl.h"
20 #include "src/log-utils.h" 19 #include "src/log-utils.h"
21 #include "src/macro-assembler.h" 20 #include "src/macro-assembler.h"
22 #include "src/perf-jit.h" 21 #include "src/perf-jit.h"
23 #include "src/profiler/cpu-profiler-inl.h" 22 #include "src/profiler/cpu-profiler.h"
24 #include "src/runtime-profiler.h" 23 #include "src/runtime-profiler.h"
25 #include "src/string-stream.h" 24 #include "src/string-stream.h"
26 #include "src/vm-state-inl.h" 25 #include "src/vm-state-inl.h"
27 26
28 namespace v8 { 27 namespace v8 {
29 namespace internal { 28 namespace internal {
30 29
31 30
32 #define DECLARE_EVENT(ignore1, name) name, 31 #define DECLARE_EVENT(ignore1, name) name,
33 static const char* const kLogEventsNames[Logger::NUMBER_OF_LOG_EVENTS] = { 32 static const char* const kLogEventsNames[Logger::NUMBER_OF_LOG_EVENTS] = {
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 JitCodeEvent event; 532 JitCodeEvent event;
534 memset(&event, 0, sizeof(event)); 533 memset(&event, 0, sizeof(event));
535 event.type = JitCodeEvent::CODE_END_LINE_INFO_RECORDING; 534 event.type = JitCodeEvent::CODE_END_LINE_INFO_RECORDING;
536 event.code_start = code->instruction_start(); 535 event.code_start = code->instruction_start();
537 event.user_data = jit_handler_data; 536 event.user_data = jit_handler_data;
538 537
539 code_event_handler_(&event); 538 code_event_handler_(&event);
540 } 539 }
541 540
542 541
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
568 // The Profiler samples pc and sp values for the main thread. 542 // The Profiler samples pc and sp values for the main thread.
569 // Each sample is appended to a circular buffer. 543 // Each sample is appended to a circular buffer.
570 // An independent thread removes data and writes it to the log. 544 // An independent thread removes data and writes it to the log.
571 // This design minimizes the time spent in the sampler. 545 // This design minimizes the time spent in the sampler.
572 // 546 //
573 class Profiler: public base::Thread { 547 class Profiler: public base::Thread {
574 public: 548 public:
575 explicit Profiler(Isolate* isolate); 549 explicit Profiler(Isolate* isolate);
576 void Engage(); 550 void Engage();
577 void Disengage(); 551 void Disengage();
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 604
631 // Tells whether we are currently recording tick samples. 605 // Tells whether we are currently recording tick samples.
632 bool paused_; 606 bool paused_;
633 }; 607 };
634 608
635 609
636 // 610 //
637 // Ticker used to provide ticks to the profiler and the sliding state 611 // Ticker used to provide ticks to the profiler and the sliding state
638 // window. 612 // window.
639 // 613 //
640 class Ticker: public sampler::Sampler { 614 class Ticker: public Sampler {
641 public: 615 public:
642 Ticker(Isolate* isolate, int interval): 616 Ticker(Isolate* isolate, int interval):
643 sampler::Sampler(reinterpret_cast<v8::Isolate*>(isolate)), 617 Sampler(isolate, interval),
644 profiler_(NULL), 618 profiler_(NULL) {}
645 sampling_thread_(new SamplingThread(this, interval)) {}
646 619
647 ~Ticker() { 620 ~Ticker() { if (IsActive()) Stop(); }
648 if (IsActive()) Stop(); 621
649 delete sampling_thread_; 622 virtual void Tick(TickSample* sample) {
623 if (profiler_) profiler_->Insert(sample);
650 } 624 }
651 625
652 void SetProfiler(Profiler* profiler) { 626 void SetProfiler(Profiler* profiler) {
653 DCHECK(profiler_ == NULL); 627 DCHECK(profiler_ == NULL);
654 profiler_ = profiler; 628 profiler_ = profiler;
655 IncreaseProfilingDepth(); 629 IncreaseProfilingDepth();
656 if (!IsActive()) Start(); 630 if (!IsActive()) Start();
657 sampling_thread_->StartSynchronously();
658 } 631 }
659 632
660 void ClearProfiler() { 633 void ClearProfiler() {
661 profiler_ = NULL; 634 profiler_ = NULL;
662 if (IsActive()) Stop(); 635 if (IsActive()) Stop();
663 DecreaseProfilingDepth(); 636 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 }
686 } 637 }
687 638
688 private: 639 private:
689 Profiler* profiler_; 640 Profiler* profiler_;
690 SamplingThread* sampling_thread_;
691 }; 641 };
692 642
693 643
694 // 644 //
695 // Profiler implementation. 645 // Profiler implementation.
696 // 646 //
697 Profiler::Profiler(Isolate* isolate) 647 Profiler::Profiler(Isolate* isolate)
698 : base::Thread(Options("v8:Profiler")), 648 : base::Thread(Options("v8:Profiler")),
699 isolate_(isolate), 649 isolate_(isolate),
700 head_(0), 650 head_(0),
(...skipping 1152 matching lines...) Expand 10 before | Expand all | Expand 10 after
1853 addCodeEventListener(jit_logger_); 1803 addCodeEventListener(jit_logger_);
1854 if (options & kJitCodeEventEnumExisting) { 1804 if (options & kJitCodeEventEnumExisting) {
1855 HandleScope scope(isolate_); 1805 HandleScope scope(isolate_);
1856 LogCodeObjects(); 1806 LogCodeObjects();
1857 LogCompiledFunctions(); 1807 LogCompiledFunctions();
1858 } 1808 }
1859 } 1809 }
1860 } 1810 }
1861 1811
1862 1812
1863 sampler::Sampler* Logger::sampler() { 1813 Sampler* Logger::sampler() {
1864 return ticker_; 1814 return ticker_;
1865 } 1815 }
1866 1816
1867 1817
1868 FILE* Logger::TearDown() { 1818 FILE* Logger::TearDown() {
1869 if (!is_initialized_) return NULL; 1819 if (!is_initialized_) return NULL;
1870 is_initialized_ = false; 1820 is_initialized_ = false;
1871 1821
1872 // Stop the profiler before closing the file. 1822 // Stop the profiler before closing the file.
1873 if (profiler_ != NULL) { 1823 if (profiler_ != NULL) {
(...skipping 27 matching lines...) Expand all
1901 removeCodeEventListener(jit_logger_); 1851 removeCodeEventListener(jit_logger_);
1902 delete jit_logger_; 1852 delete jit_logger_;
1903 jit_logger_ = NULL; 1853 jit_logger_ = NULL;
1904 } 1854 }
1905 1855
1906 return log_->Close(); 1856 return log_->Close();
1907 } 1857 }
1908 1858
1909 } // namespace internal 1859 } // namespace internal
1910 } // namespace v8 1860 } // 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