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 "base/cpu.h" | 7 #include "base/cpu.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| 11 #include "base/rand_util.h" |
11 #include "base/sys_info.h" | 12 #include "base/sys_info.h" |
12 #include "base/time/time.h" | 13 #include "base/time/time.h" |
13 #include "content/browser/tracing/background_tracing_rule.h" | 14 #include "content/browser/tracing/background_tracing_rule.h" |
14 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
15 #include "content/public/browser/content_browser_client.h" | 16 #include "content/public/browser/content_browser_client.h" |
16 #include "content/public/browser/gpu_data_manager.h" | 17 #include "content/public/browser/gpu_data_manager.h" |
17 #include "content/public/browser/tracing_delegate.h" | 18 #include "content/public/browser/tracing_delegate.h" |
18 #include "content/public/common/content_client.h" | 19 #include "content/public/common/content_client.h" |
19 #include "gpu/config/gpu_info.h" | 20 #include "gpu/config/gpu_info.h" |
20 #include "net/base/network_change_notifier.h" | 21 #include "net/base/network_change_notifier.h" |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 | 275 |
275 triggered_named_event_handle_ = handle; | 276 triggered_named_event_handle_ = handle; |
276 OnRuleTriggered(triggered_rule, callback); | 277 OnRuleTriggered(triggered_rule, callback); |
277 } | 278 } |
278 | 279 |
279 void BackgroundTracingManagerImpl::OnRuleTriggered( | 280 void BackgroundTracingManagerImpl::OnRuleTriggered( |
280 const BackgroundTracingRule* triggered_rule, | 281 const BackgroundTracingRule* triggered_rule, |
281 StartedFinalizingCallback callback) { | 282 StartedFinalizingCallback callback) { |
282 CHECK(config_); | 283 CHECK(config_); |
283 | 284 |
| 285 float trigger_chance = triggered_rule->trigger_chance(); |
| 286 if (trigger_chance < 1.0f && base::RandDouble() > trigger_chance) { |
| 287 if (!callback.is_null()) |
| 288 callback.Run(false); |
| 289 return; |
| 290 } |
| 291 |
284 int trace_timeout = triggered_rule->GetTraceTimeout(); | 292 int trace_timeout = triggered_rule->GetTraceTimeout(); |
285 | 293 |
286 if (config_->tracing_mode() == BackgroundTracingConfigImpl::REACTIVE) { | 294 if (config_->tracing_mode() == BackgroundTracingConfigImpl::REACTIVE) { |
287 // In reactive mode, a trigger starts tracing, or finalizes tracing | 295 // In reactive mode, a trigger starts tracing, or finalizes tracing |
288 // immediately if it's already running. | 296 // immediately if it's already running. |
289 RecordBackgroundTracingMetric(REACTIVE_TRIGGERED); | 297 RecordBackgroundTracingMetric(REACTIVE_TRIGGERED); |
290 | 298 |
291 if (!is_tracing_) { | 299 if (!is_tracing_) { |
292 // It was not already tracing, start a new trace. | 300 // It was not already tracing, start a new trace. |
293 EnableRecording(GetCategoryFilterStringForCategoryPreset( | 301 EnableRecording(GetCategoryFilterStringForCategoryPreset( |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 case BackgroundTracingConfigImpl::CategoryPreset::BENCHMARK_STARTUP: | 557 case BackgroundTracingConfigImpl::CategoryPreset::BENCHMARK_STARTUP: |
550 return "benchmark,toplevel,startup,disabled-by-default-file," | 558 return "benchmark,toplevel,startup,disabled-by-default-file," |
551 "disabled-by-default-toplevel.flow," | 559 "disabled-by-default-toplevel.flow," |
552 "disabled-by-default-ipc.flow"; | 560 "disabled-by-default-ipc.flow"; |
553 } | 561 } |
554 NOTREACHED(); | 562 NOTREACHED(); |
555 return ""; | 563 return ""; |
556 } | 564 } |
557 | 565 |
558 } // namspace content | 566 } // namspace content |
OLD | NEW |