OLD | NEW |
---|---|
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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
(...skipping 28 matching lines...) Expand all Loading... | |
39 FINALIZATION_COMPLETE = 8, | 39 FINALIZATION_COMPLETE = 8, |
40 SCENARIO_ACTION_FAILED_LOWRES_CLOCK = 9, | 40 SCENARIO_ACTION_FAILED_LOWRES_CLOCK = 9, |
41 NUMBER_OF_BACKGROUND_TRACING_METRICS, | 41 NUMBER_OF_BACKGROUND_TRACING_METRICS, |
42 }; | 42 }; |
43 | 43 |
44 void RecordBackgroundTracingMetric(BackgroundTracingMetrics metric) { | 44 void RecordBackgroundTracingMetric(BackgroundTracingMetrics metric) { |
45 UMA_HISTOGRAM_ENUMERATION("Tracing.Background.ScenarioState", metric, | 45 UMA_HISTOGRAM_ENUMERATION("Tracing.Background.ScenarioState", metric, |
46 NUMBER_OF_BACKGROUND_TRACING_METRICS); | 46 NUMBER_OF_BACKGROUND_TRACING_METRICS); |
47 } | 47 } |
48 | 48 |
49 // Tracing enabled callback for BENCHMARK_MEMORY_LIGHT category preset. | |
oystein (OOO til 10th of July)
2016/06/02 06:11:33
Maybe add a TODO that the special-casing here shou
ssid
2016/06/03 06:34:33
Done.
| |
50 void BenchmarkMemoryLight_TracingEnabledCallback() { | |
51 base::trace_event::MemoryDumpManager::GetInstance()->RequestGlobalDump( | |
52 base::trace_event::MemoryDumpType::EXPLICITLY_TRIGGERED, | |
53 base::trace_event::MemoryDumpLevelOfDetail::BACKGROUND); | |
54 } | |
55 | |
49 } // namespace | 56 } // namespace |
50 | 57 |
51 BackgroundTracingManagerImpl::TracingTimer::TracingTimer( | 58 BackgroundTracingManagerImpl::TracingTimer::TracingTimer( |
52 StartedFinalizingCallback callback) : callback_(callback) { | 59 StartedFinalizingCallback callback) : callback_(callback) { |
53 } | 60 } |
54 | 61 |
55 BackgroundTracingManagerImpl::TracingTimer::~TracingTimer() { | 62 BackgroundTracingManagerImpl::TracingTimer::~TracingTimer() { |
56 } | 63 } |
57 | 64 |
58 void BackgroundTracingManagerImpl::TracingTimer::StartTimer(int seconds) { | 65 void BackgroundTracingManagerImpl::TracingTimer::StartTimer(int seconds) { |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
203 *config_.get(), requires_anonymized_data_)) { | 210 *config_.get(), requires_anonymized_data_)) { |
204 AbortScenario(); | 211 AbortScenario(); |
205 } | 212 } |
206 } | 213 } |
207 | 214 |
208 void BackgroundTracingManagerImpl::StartTracingIfConfigNeedsIt() { | 215 void BackgroundTracingManagerImpl::StartTracingIfConfigNeedsIt() { |
209 if (!config_) | 216 if (!config_) |
210 return; | 217 return; |
211 | 218 |
212 if (config_->tracing_mode() == BackgroundTracingConfigImpl::PREEMPTIVE) { | 219 if (config_->tracing_mode() == BackgroundTracingConfigImpl::PREEMPTIVE) { |
213 StartTracing( | 220 StartTracing(config_->category_preset(), |
214 GetCategoryFilterStringForCategoryPreset(config_->category_preset()), | 221 base::trace_event::RECORD_CONTINUOUSLY); |
215 base::trace_event::RECORD_CONTINUOUSLY); | |
216 } | 222 } |
217 // There is nothing to do in case of reactive tracing. | 223 // There is nothing to do in case of reactive tracing. |
218 } | 224 } |
219 | 225 |
220 BackgroundTracingRule* | 226 BackgroundTracingRule* |
221 BackgroundTracingManagerImpl::GetRuleAbleToTriggerTracing( | 227 BackgroundTracingManagerImpl::GetRuleAbleToTriggerTracing( |
222 TriggerHandle handle) const { | 228 TriggerHandle handle) const { |
223 if (!config_) | 229 if (!config_) |
224 return nullptr; | 230 return nullptr; |
225 | 231 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
306 | 312 |
307 int trace_delay = triggered_rule->GetTraceDelay(); | 313 int trace_delay = triggered_rule->GetTraceDelay(); |
308 | 314 |
309 if (config_->tracing_mode() == BackgroundTracingConfigImpl::REACTIVE) { | 315 if (config_->tracing_mode() == BackgroundTracingConfigImpl::REACTIVE) { |
310 // In reactive mode, a trigger starts tracing, or finalizes tracing | 316 // In reactive mode, a trigger starts tracing, or finalizes tracing |
311 // immediately if it's already running. | 317 // immediately if it's already running. |
312 RecordBackgroundTracingMetric(REACTIVE_TRIGGERED); | 318 RecordBackgroundTracingMetric(REACTIVE_TRIGGERED); |
313 | 319 |
314 if (!is_tracing_) { | 320 if (!is_tracing_) { |
315 // It was not already tracing, start a new trace. | 321 // It was not already tracing, start a new trace. |
316 StartTracing(GetCategoryFilterStringForCategoryPreset( | 322 StartTracing(triggered_rule->category_preset(), |
317 triggered_rule->category_preset()), | |
318 base::trace_event::RECORD_UNTIL_FULL); | 323 base::trace_event::RECORD_UNTIL_FULL); |
319 } else { | 324 } else { |
320 // Reactive configs that trigger again while tracing should just | 325 // Reactive configs that trigger again while tracing should just |
321 // end right away (to not capture multiple navigations, for example). | 326 // end right away (to not capture multiple navigations, for example). |
322 trace_delay = -1; | 327 trace_delay = -1; |
323 } | 328 } |
324 } else { | 329 } else { |
325 // In preemptive mode, a trigger starts finalizing a trace if one is | 330 // In preemptive mode, a trigger starts finalizing a trace if one is |
326 // running and we're not got a finalization timer running, | 331 // running and we're not got a finalization timer running, |
327 // otherwise we do nothing. | 332 // otherwise we do nothing. |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
381 const base::Closure& callback) { | 386 const base::Closure& callback) { |
382 rule_triggered_callback_for_testing_ = callback; | 387 rule_triggered_callback_for_testing_ = callback; |
383 }; | 388 }; |
384 | 389 |
385 void BackgroundTracingManagerImpl::FireTimerForTesting() { | 390 void BackgroundTracingManagerImpl::FireTimerForTesting() { |
386 DCHECK(tracing_timer_); | 391 DCHECK(tracing_timer_); |
387 tracing_timer_->FireTimerForTesting(); | 392 tracing_timer_->FireTimerForTesting(); |
388 } | 393 } |
389 | 394 |
390 void BackgroundTracingManagerImpl::StartTracing( | 395 void BackgroundTracingManagerImpl::StartTracing( |
391 std::string category_filter_str, | 396 BackgroundTracingConfigImpl::CategoryPreset preset, |
392 base::trace_event::TraceRecordMode record_mode) { | 397 base::trace_event::TraceRecordMode record_mode) { |
393 base::trace_event::TraceConfig trace_config(category_filter_str, record_mode); | 398 base::trace_event::TraceConfig trace_config( |
399 GetCategoryFilterStringForCategoryPreset(preset), record_mode); | |
394 if (requires_anonymized_data_) | 400 if (requires_anonymized_data_) |
395 trace_config.EnableArgumentFilter(); | 401 trace_config.EnableArgumentFilter(); |
396 | 402 |
403 base::Closure tracing_enabled_callback; | |
404 if (!tracing_enabled_callback_for_testing_.is_null()) { | |
405 tracing_enabled_callback = tracing_enabled_callback_for_testing_; | |
406 } else if (preset == BackgroundTracingConfigImpl::CategoryPreset:: | |
407 BENCHMARK_MEMORY_LIGHT) { | |
408 // On memory light mode, the periodic memory dumps are disabled and a single | |
409 // memory dump is requested after tracing is enabled in all the processes. | |
410 trace_config.ResetMemoryDumpConfig( | |
411 base::trace_event::TraceConfig::MemoryDumpConfig()); | |
412 tracing_enabled_callback = | |
413 base::Bind(&BenchmarkMemoryLight_TracingEnabledCallback); | |
414 } | |
415 | |
397 is_tracing_ = TracingController::GetInstance()->StartTracing( | 416 is_tracing_ = TracingController::GetInstance()->StartTracing( |
398 trace_config, tracing_enabled_callback_for_testing_); | 417 trace_config, tracing_enabled_callback); |
399 RecordBackgroundTracingMetric(RECORDING_ENABLED); | 418 RecordBackgroundTracingMetric(RECORDING_ENABLED); |
400 } | 419 } |
401 | 420 |
402 void BackgroundTracingManagerImpl::OnFinalizeStarted( | 421 void BackgroundTracingManagerImpl::OnFinalizeStarted( |
403 std::unique_ptr<const base::DictionaryValue> metadata, | 422 std::unique_ptr<const base::DictionaryValue> metadata, |
404 base::RefCountedString* file_contents) { | 423 base::RefCountedString* file_contents) { |
405 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 424 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
406 | 425 |
407 RecordBackgroundTracingMetric(FINALIZATION_STARTED); | 426 RecordBackgroundTracingMetric(FINALIZATION_STARTED); |
408 UMA_HISTOGRAM_MEMORY_KB("Tracing.Background.FinalizingTraceSizeInKB", | 427 UMA_HISTOGRAM_MEMORY_KB("Tracing.Background.FinalizingTraceSizeInKB", |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
512 return "benchmark,toplevel,gpu"; | 531 return "benchmark,toplevel,gpu"; |
513 case BackgroundTracingConfigImpl::CategoryPreset::BENCHMARK_IPC: | 532 case BackgroundTracingConfigImpl::CategoryPreset::BENCHMARK_IPC: |
514 return "benchmark,toplevel,ipc"; | 533 return "benchmark,toplevel,ipc"; |
515 case BackgroundTracingConfigImpl::CategoryPreset::BENCHMARK_STARTUP: | 534 case BackgroundTracingConfigImpl::CategoryPreset::BENCHMARK_STARTUP: |
516 return "benchmark,toplevel,startup,disabled-by-default-file," | 535 return "benchmark,toplevel,startup,disabled-by-default-file," |
517 "disabled-by-default-toplevel.flow," | 536 "disabled-by-default-toplevel.flow," |
518 "disabled-by-default-ipc.flow"; | 537 "disabled-by-default-ipc.flow"; |
519 case BackgroundTracingConfigImpl::CategoryPreset::BENCHMARK_BLINK_GC: | 538 case BackgroundTracingConfigImpl::CategoryPreset::BENCHMARK_BLINK_GC: |
520 return "blink_gc,disabled-by-default-blink_gc"; | 539 return "blink_gc,disabled-by-default-blink_gc"; |
521 case BackgroundTracingConfigImpl::CategoryPreset::BENCHMARK_MEMORY_HEAVY: | 540 case BackgroundTracingConfigImpl::CategoryPreset::BENCHMARK_MEMORY_HEAVY: |
541 case BackgroundTracingConfigImpl::CategoryPreset::BENCHMARK_MEMORY_LIGHT: | |
522 return "-*,disabled-by-default-memory-infra"; | 542 return "-*,disabled-by-default-memory-infra"; |
523 case BackgroundTracingConfigImpl::CategoryPreset:: | 543 case BackgroundTracingConfigImpl::CategoryPreset:: |
524 BENCHMARK_EXECUTION_METRIC: | 544 BENCHMARK_EXECUTION_METRIC: |
525 return "blink.console,v8"; | 545 return "blink.console,v8"; |
526 case BackgroundTracingConfigImpl::CategoryPreset::BLINK_STYLE: | 546 case BackgroundTracingConfigImpl::CategoryPreset::BLINK_STYLE: |
527 return "blink_style"; | 547 return "blink_style"; |
528 case BackgroundTracingConfigImpl::CategoryPreset::CATEGORY_PRESET_UNSET: | 548 case BackgroundTracingConfigImpl::CategoryPreset::CATEGORY_PRESET_UNSET: |
529 NOTREACHED(); | 549 NOTREACHED(); |
530 } | 550 } |
531 NOTREACHED(); | 551 NOTREACHED(); |
532 return ""; | 552 return ""; |
533 } | 553 } |
534 | 554 |
535 } // namspace content | 555 } // namspace content |
OLD | NEW |