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

Side by Side Diff: content/browser/tracing/background_tracing_manager_impl.cc

Issue 1243743002: Slow Reports - Add message filter to trigger background traces from child processes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments. Created 5 years, 5 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium 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 "content/browser/tracing/background_tracing_manager_impl.h" 5 #include "content/browser/tracing/background_tracing_manager_impl.h"
6 6
7 #include "base/json/json_writer.h" 7 #include "base/json/json_writer.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/metrics/histogram_macros.h" 9 #include "base/metrics/histogram_macros.h"
10 #include "base/metrics/statistics_recorder.h" 10 #include "base/metrics/statistics_recorder.h"
11 #include "base/time/time.h" 11 #include "base/time/time.h"
12 #include "components/tracing/tracing_messages.h"
13 #include "content/browser/tracing/trace_message_filter.h"
12 #include "content/public/browser/background_tracing_preemptive_config.h" 14 #include "content/public/browser/background_tracing_preemptive_config.h"
13 #include "content/public/browser/background_tracing_reactive_config.h" 15 #include "content/public/browser/background_tracing_reactive_config.h"
14 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/content_browser_client.h" 17 #include "content/public/browser/content_browser_client.h"
16 #include "content/public/browser/tracing_delegate.h" 18 #include "content/public/browser/tracing_delegate.h"
17 #include "content/public/common/content_client.h" 19 #include "content/public/common/content_client.h"
18 20
19 namespace content { 21 namespace content {
20 22
21 namespace { 23 namespace {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 BackgroundTracingManagerImpl* BackgroundTracingManagerImpl::GetInstance() { 82 BackgroundTracingManagerImpl* BackgroundTracingManagerImpl::GetInstance() {
81 return g_controller.Pointer(); 83 return g_controller.Pointer();
82 } 84 }
83 85
84 BackgroundTracingManagerImpl::BackgroundTracingManagerImpl() 86 BackgroundTracingManagerImpl::BackgroundTracingManagerImpl()
85 : delegate_(GetContentClient()->browser()->GetTracingDelegate()), 87 : delegate_(GetContentClient()->browser()->GetTracingDelegate()),
86 is_gathering_(false), 88 is_gathering_(false),
87 is_tracing_(false), 89 is_tracing_(false),
88 requires_anonymized_data_(true), 90 requires_anonymized_data_(true),
89 trigger_handle_ids_(0) { 91 trigger_handle_ids_(0) {
92 TracingControllerImpl::GetInstance()->SetTraceMessageFilterAddedCallback(
93 base::Bind(&BackgroundTracingManagerImpl::OnTraceMessageFilterAdded,
94 base::Unretained(this)));
dcheng 2015/07/27 17:19:58 Personally, I think it's better to annotate uses o
shatch 2015/07/27 19:08:04 Yeah that's fair enough, added some explanation.
90 } 95 }
91 96
92 BackgroundTracingManagerImpl::~BackgroundTracingManagerImpl() { 97 BackgroundTracingManagerImpl::~BackgroundTracingManagerImpl() {
93 NOTREACHED(); 98 NOTREACHED();
94 } 99 }
95 100
96 void BackgroundTracingManagerImpl::WhenIdle( 101 void BackgroundTracingManagerImpl::WhenIdle(
97 base::Callback<void()> idle_callback) { 102 base::Callback<void()> idle_callback) {
98 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 103 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
99 idle_callback_ = idle_callback; 104 idle_callback_ = idle_callback;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 MONITOR_AND_DUMP_WHEN_SPECIFIC_HISTOGRAM_AND_VALUE) { 158 MONITOR_AND_DUMP_WHEN_SPECIFIC_HISTOGRAM_AND_VALUE) {
154 continue; 159 continue;
155 } 160 }
156 161
157 if (mode == CLEAR_CALLBACKS) { 162 if (mode == CLEAR_CALLBACKS) {
158 base::StatisticsRecorder::ClearCallback( 163 base::StatisticsRecorder::ClearCallback(
159 configs[i].histogram_trigger_info.histogram_name); 164 configs[i].histogram_trigger_info.histogram_name);
160 } else { 165 } else {
161 base::StatisticsRecorder::SetCallback( 166 base::StatisticsRecorder::SetCallback(
162 configs[i].histogram_trigger_info.histogram_name, 167 configs[i].histogram_trigger_info.histogram_name,
163 base::Bind(&BackgroundTracingManagerImpl::OnHistogramChanged, 168 base::Bind(&BackgroundTracingManagerImpl::OnHistogramChangedCallback,
164 base::Unretained(this), 169 base::Unretained(this),
165 configs[i].histogram_trigger_info.histogram_name, 170 configs[i].histogram_trigger_info.histogram_name,
166 configs[i].histogram_trigger_info.histogram_value)); 171 configs[i].histogram_trigger_info.histogram_value));
167 } 172 }
168 } 173 }
174
175 SetupFiltersFromConfig(mode);
169 } 176 }
170 177
171 void BackgroundTracingManagerImpl::OnHistogramChanged( 178 void BackgroundTracingManagerImpl::OnHistogramTrigger(
172 const std::string& histogram_name, 179 const std::string& histogram_name) {
173 base::Histogram::Sample reference_value,
174 base::Histogram::Sample actual_value) {
175 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { 180 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) {
176 content::BrowserThread::PostTask( 181 content::BrowserThread::PostTask(
177 content::BrowserThread::UI, FROM_HERE, 182 content::BrowserThread::UI, FROM_HERE,
178 base::Bind(&BackgroundTracingManagerImpl::OnHistogramChanged, 183 base::Bind(&BackgroundTracingManagerImpl::OnHistogramTrigger,
179 base::Unretained(this), histogram_name, reference_value, 184 base::Unretained(this), histogram_name));
180 actual_value));
181 return; 185 return;
182 } 186 }
183 187
184 CHECK(config_ && 188 CHECK(config_ &&
185 config_->mode == BackgroundTracingConfig::PREEMPTIVE_TRACING_MODE); 189 config_->mode == BackgroundTracingConfig::PREEMPTIVE_TRACING_MODE);
186 190
191 if (!is_tracing_ || is_gathering_)
192 return;
193
194 BackgroundTracingPreemptiveConfig* preemptive_config =
195 static_cast<BackgroundTracingPreemptiveConfig*>(config_.get());
196 for (const auto& config : preemptive_config->configs) {
197 if (config.type != BackgroundTracingPreemptiveConfig::
198 MONITOR_AND_DUMP_WHEN_SPECIFIC_HISTOGRAM_AND_VALUE) {
199 continue;
200 }
201
202 if (config.histogram_trigger_info.histogram_name == histogram_name) {
203 RecordBackgroundTracingMetric(PREEMPTIVE_TRIGGERED);
204 BeginFinalizing(StartedFinalizingCallback());
205 }
206 }
207 }
208
209 void BackgroundTracingManagerImpl::OnHistogramChangedCallback(
210 const std::string& histogram_name,
211 base::Histogram::Sample reference_value,
212 base::Histogram::Sample actual_value) {
187 if (reference_value > actual_value) 213 if (reference_value > actual_value)
188 return; 214 return;
189 215
190 if (!is_tracing_ || is_gathering_) 216 OnHistogramTrigger(histogram_name);
191 return;
192
193 RecordBackgroundTracingMetric(PREEMPTIVE_TRIGGERED);
194 BeginFinalizing(StartedFinalizingCallback());
195 } 217 }
196 218
197 bool BackgroundTracingManagerImpl::SetActiveScenario( 219 bool BackgroundTracingManagerImpl::SetActiveScenario(
198 scoped_ptr<BackgroundTracingConfig> config, 220 scoped_ptr<BackgroundTracingConfig> config,
199 const BackgroundTracingManager::ReceiveCallback& receive_callback, 221 const BackgroundTracingManager::ReceiveCallback& receive_callback,
200 DataFiltering data_filtering) { 222 DataFiltering data_filtering) {
201 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 223 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
202 RecordBackgroundTracingMetric(SCENARIO_ACTIVATION_REQUESTED); 224 RecordBackgroundTracingMetric(SCENARIO_ACTIVATION_REQUESTED);
203 225
204 if (is_tracing_) 226 if (is_tracing_)
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 EnableRecordingIfConfigNeedsIt(); 263 EnableRecordingIfConfigNeedsIt();
242 264
243 RecordBackgroundTracingMetric(SCENARIO_ACTIVATED_SUCCESSFULLY); 265 RecordBackgroundTracingMetric(SCENARIO_ACTIVATED_SUCCESSFULLY);
244 return true; 266 return true;
245 } 267 }
246 268
247 bool BackgroundTracingManagerImpl::HasActiveScenarioForTesting() { 269 bool BackgroundTracingManagerImpl::HasActiveScenarioForTesting() {
248 return config_; 270 return config_;
249 } 271 }
250 272
273 void BackgroundTracingManagerImpl::OnTraceMessageFilterAdded(
274 TraceMessageFilter* filter) {
275 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
276 SetupFilterFromConfig(filter, BIND_CALLBACKS);
277 }
278
279 void BackgroundTracingManagerImpl::SetupFiltersFromConfig(
280 BackgroundTracingManagerImpl::SetupUMACallMode mode) {
281 TracingControllerImpl::TraceMessageFilterSet filters;
282 TracingControllerImpl::GetInstance()->GetTraceMessageFilters(&filters);
283
284 for (auto& filter : filters)
285 SetupFilterFromConfig(filter, mode);
286 }
287
288 void BackgroundTracingManagerImpl::SetupFilterFromConfig(
289 scoped_refptr<TraceMessageFilter> filter,
290 BackgroundTracingManagerImpl::SetupUMACallMode mode) {
291 if (!config_ ||
292 config_->mode != BackgroundTracingConfig::PREEMPTIVE_TRACING_MODE)
293 return;
294
295 BackgroundTracingPreemptiveConfig* preemptive_config =
296 static_cast<BackgroundTracingPreemptiveConfig*>(config_.get());
297
298 const std::vector<BackgroundTracingPreemptiveConfig::MonitoringRule>&
299 configs = preemptive_config->configs;
dcheng 2015/07/27 17:19:58 You don't technically need this line anymore: just
shatch 2015/07/27 19:08:04 Done.
300
301 for (const auto& config : configs) {
302 if (config.type != BackgroundTracingPreemptiveConfig::
303 MONITOR_AND_DUMP_WHEN_SPECIFIC_HISTOGRAM_AND_VALUE) {
304 continue;
305 }
306
307 if (mode == CLEAR_CALLBACKS) {
308 filter->Send(new TracingMsg_ClearUMACallback(
309 config.histogram_trigger_info.histogram_name));
310 } else {
311 filter->Send(new TracingMsg_SetUMACallback(
312 config.histogram_trigger_info.histogram_name,
313 config.histogram_trigger_info.histogram_value));
314 }
315 }
316 }
317
251 void BackgroundTracingManagerImpl::ValidateStartupScenario() { 318 void BackgroundTracingManagerImpl::ValidateStartupScenario() {
252 if (!config_ || !delegate_) 319 if (!config_ || !delegate_)
253 return; 320 return;
254 321
255 if (!delegate_->IsAllowedToBeginBackgroundScenario( 322 if (!delegate_->IsAllowedToBeginBackgroundScenario(
256 *config_.get(), requires_anonymized_data_)) { 323 *config_.get(), requires_anonymized_data_)) {
257 AbortScenario(); 324 AbortScenario();
258 } 325 }
259 } 326 }
260 327
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 RecordBackgroundTracingMetric(FINALIZATION_DISALLOWED); 578 RecordBackgroundTracingMetric(FINALIZATION_DISALLOWED);
512 } 579 }
513 580
514 content::TracingController::GetInstance()->DisableRecording(trace_data_sink); 581 content::TracingController::GetInstance()->DisableRecording(trace_data_sink);
515 582
516 if (!callback.is_null()) 583 if (!callback.is_null())
517 callback.Run(is_allowed_finalization); 584 callback.Run(is_allowed_finalization);
518 } 585 }
519 586
520 void BackgroundTracingManagerImpl::AbortScenario() { 587 void BackgroundTracingManagerImpl::AbortScenario() {
588 SetupUMACallbacks(CLEAR_CALLBACKS);
589
521 is_tracing_ = false; 590 is_tracing_ = false;
522 config_.reset(); 591 config_.reset();
523 592
524 content::TracingController::GetInstance()->DisableRecording(nullptr); 593 content::TracingController::GetInstance()->DisableRecording(nullptr);
525 } 594 }
526 595
527 std::string 596 std::string
528 BackgroundTracingManagerImpl::GetCategoryFilterStringForCategoryPreset( 597 BackgroundTracingManagerImpl::GetCategoryFilterStringForCategoryPreset(
529 BackgroundTracingConfig::CategoryPreset preset) const { 598 BackgroundTracingConfig::CategoryPreset preset) const {
530 switch (preset) { 599 switch (preset) {
531 case BackgroundTracingConfig::CategoryPreset::BENCHMARK: 600 case BackgroundTracingConfig::CategoryPreset::BENCHMARK:
532 return "benchmark,toplevel"; 601 return "benchmark,toplevel";
533 case BackgroundTracingConfig::CategoryPreset::BENCHMARK_DEEP: 602 case BackgroundTracingConfig::CategoryPreset::BENCHMARK_DEEP:
534 return "*,disabled-by-default-benchmark.detailed"; 603 return "*,disabled-by-default-benchmark.detailed";
535 } 604 }
536 NOTREACHED(); 605 NOTREACHED();
537 return ""; 606 return "";
538 } 607 }
539 608
540 } // namspace content 609 } // namspace content
OLDNEW
« no previous file with comments | « content/browser/tracing/background_tracing_manager_impl.h ('k') | content/browser/tracing/trace_message_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698