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

Side by Side Diff: src/profiler/tracing-cpu-profiler.cc

Issue 2676403002: [tracing] The CPU profiler should only be enabled for specific modes of tracing (Closed)
Patch Set: Use TRACE_EVENT_CATEGORY_GROUP_ENABLED. Created 3 years, 10 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 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/profiler/tracing-cpu-profiler.h" 5 #include "src/profiler/tracing-cpu-profiler.h"
6 6
7 #include "src/profiler/cpu-profiler.h" 7 #include "src/profiler/cpu-profiler.h"
8 #include "src/tracing/trace-event.h" 8 #include "src/tracing/trace-event.h"
9 #include "src/v8.h" 9 #include "src/v8.h"
10 10
11 #define PROFILER_TRACE_CATEGORY_ENABLED(cat) \ 11 #define PROFILER_TRACE_CATEGORY_ENABLED(cat, ret) \
alph 2017/02/09 18:23:56 Don't think this macro makes sense now. You can ju
ssid 2017/02/10 01:47:41 Done.
12 (*TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(TRACE_DISABLED_BY_DEFAULT(cat))) 12 TRACE_EVENT_CATEGORY_GROUP_ENABLED(TRACE_DISABLED_BY_DEFAULT(cat), ret)
13 13
14 namespace v8 { 14 namespace v8 {
15 15
16 std::unique_ptr<TracingCpuProfiler> TracingCpuProfiler::Create( 16 std::unique_ptr<TracingCpuProfiler> TracingCpuProfiler::Create(
17 v8::Isolate* isolate) { 17 v8::Isolate* isolate) {
18 return std::unique_ptr<TracingCpuProfiler>( 18 return std::unique_ptr<TracingCpuProfiler>(
19 new internal::TracingCpuProfilerImpl( 19 new internal::TracingCpuProfilerImpl(
20 reinterpret_cast<internal::Isolate*>(isolate))); 20 reinterpret_cast<internal::Isolate*>(isolate)));
21 } 21 }
22 22
23 namespace internal { 23 namespace internal {
24 24
25 TracingCpuProfilerImpl::TracingCpuProfilerImpl(Isolate* isolate) 25 TracingCpuProfilerImpl::TracingCpuProfilerImpl(Isolate* isolate)
26 : isolate_(isolate), profiling_enabled_(false) { 26 : isolate_(isolate), profiling_enabled_(false) {
27 // Make sure tracing system notices profiler categories. 27 // Make sure tracing system notices profiler categories.
28 PROFILER_TRACE_CATEGORY_ENABLED("v8.cpu_profiler"); 28 TRACE_EVENT_WARMUP_CATEGORY(TRACE_DISABLED_BY_DEFAULT("v8.cpu_profiler"));
29 PROFILER_TRACE_CATEGORY_ENABLED("v8.cpu_profiler.hires"); 29 TRACE_EVENT_WARMUP_CATEGORY(
30 TRACE_DISABLED_BY_DEFAULT("v8.cpu_profiler.hires"));
30 V8::GetCurrentPlatform()->AddTraceStateObserver(this); 31 V8::GetCurrentPlatform()->AddTraceStateObserver(this);
31 } 32 }
32 33
33 TracingCpuProfilerImpl::~TracingCpuProfilerImpl() { 34 TracingCpuProfilerImpl::~TracingCpuProfilerImpl() {
34 StopProfiling(); 35 StopProfiling();
35 V8::GetCurrentPlatform()->RemoveTraceStateObserver(this); 36 V8::GetCurrentPlatform()->RemoveTraceStateObserver(this);
36 } 37 }
37 38
38 void TracingCpuProfilerImpl::OnTraceEnabled() { 39 void TracingCpuProfilerImpl::OnTraceEnabled() {
39 if (!PROFILER_TRACE_CATEGORY_ENABLED("v8.cpu_profiler")) return; 40 bool enabled;
41 PROFILER_TRACE_CATEGORY_ENABLED("v8.cpu_profiler", &enabled);
42 if (!enabled) return;
40 profiling_enabled_ = true; 43 profiling_enabled_ = true;
41 isolate_->RequestInterrupt( 44 isolate_->RequestInterrupt(
42 [](v8::Isolate*, void* data) { 45 [](v8::Isolate*, void* data) {
43 reinterpret_cast<TracingCpuProfilerImpl*>(data)->StartProfiling(); 46 reinterpret_cast<TracingCpuProfilerImpl*>(data)->StartProfiling();
44 }, 47 },
45 this); 48 this);
46 } 49 }
47 50
48 void TracingCpuProfilerImpl::OnTraceDisabled() { 51 void TracingCpuProfilerImpl::OnTraceDisabled() {
49 base::LockGuard<base::Mutex> lock(&mutex_); 52 base::LockGuard<base::Mutex> lock(&mutex_);
50 if (!profiling_enabled_) return; 53 if (!profiling_enabled_) return;
51 profiling_enabled_ = false; 54 profiling_enabled_ = false;
52 isolate_->RequestInterrupt( 55 isolate_->RequestInterrupt(
53 [](v8::Isolate*, void* data) { 56 [](v8::Isolate*, void* data) {
54 reinterpret_cast<TracingCpuProfilerImpl*>(data)->StopProfiling(); 57 reinterpret_cast<TracingCpuProfilerImpl*>(data)->StopProfiling();
55 }, 58 },
56 this); 59 this);
57 } 60 }
58 61
59 void TracingCpuProfilerImpl::StartProfiling() { 62 void TracingCpuProfilerImpl::StartProfiling() {
60 base::LockGuard<base::Mutex> lock(&mutex_); 63 base::LockGuard<base::Mutex> lock(&mutex_);
61 if (!profiling_enabled_ || profiler_) return; 64 if (!profiling_enabled_ || profiler_) return;
62 int sampling_interval_us = 65 bool enabled;
63 PROFILER_TRACE_CATEGORY_ENABLED("v8.cpu_profiler.hires") ? 100 : 1000; 66 PROFILER_TRACE_CATEGORY_ENABLED("v8.cpu_profiler.hires", &enabled);
67 int sampling_interval_us = enabled ? 100 : 1000;
64 profiler_.reset(new CpuProfiler(isolate_)); 68 profiler_.reset(new CpuProfiler(isolate_));
65 profiler_->set_sampling_interval( 69 profiler_->set_sampling_interval(
66 base::TimeDelta::FromMicroseconds(sampling_interval_us)); 70 base::TimeDelta::FromMicroseconds(sampling_interval_us));
67 profiler_->StartProfiling("", true); 71 profiler_->StartProfiling("", true);
68 } 72 }
69 73
70 void TracingCpuProfilerImpl::StopProfiling() { 74 void TracingCpuProfilerImpl::StopProfiling() {
71 base::LockGuard<base::Mutex> lock(&mutex_); 75 base::LockGuard<base::Mutex> lock(&mutex_);
72 if (!profiler_) return; 76 if (!profiler_) return;
73 profiler_->StopProfiling(""); 77 profiler_->StopProfiling("");
74 profiler_.reset(); 78 profiler_.reset();
75 } 79 }
76 80
77 } // namespace internal 81 } // namespace internal
78 } // namespace v8 82 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698