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
3 // found in the LICENSE file.
5 #include "chrome/browser/stack_sampling_configuration.h"
7 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
8 #include "chrome/common/channel_info.h"
9 #include "components/version_info/version_info.h"
13 bool IsProfilerEnabledForCurrentChannel() {
14 const version_info::Channel channel
= chrome::GetChannel();
15 return (channel
== version_info::Channel::UNKNOWN
||
16 channel
== version_info::Channel::CANARY
||
17 channel
== version_info::Channel::DEV
);
22 StackSamplingConfiguration::StackSamplingConfiguration()
23 // Disabled pending fixes for deadlock scenarios. https://crbug.com/528129.
24 : configuration_(PROFILE_DISABLED
) {
27 base::StackSamplingProfiler::SamplingParams
28 StackSamplingConfiguration::GetSamplingParams() const {
29 base::StackSamplingProfiler::SamplingParams params
;
31 const base::TimeDelta duration
= base::TimeDelta::FromSeconds(30);
33 switch (configuration_
) {
34 case PROFILE_DISABLED
:
35 params
.initial_delay
= base::TimeDelta::FromMilliseconds(0);
36 params
.sampling_interval
= base::TimeDelta::FromMilliseconds(0);
37 params
.samples_per_burst
= 0;
40 case PROFILE_NO_SAMPLES
:
41 params
.initial_delay
= duration
;
42 params
.sampling_interval
= base::TimeDelta::FromMilliseconds(0);
43 params
.samples_per_burst
= 0;
47 params
.initial_delay
= base::TimeDelta::FromMilliseconds(0);
48 params
.sampling_interval
= base::TimeDelta::FromMilliseconds(200);
49 params
.samples_per_burst
= duration
/ params
.sampling_interval
;
53 params
.initial_delay
= base::TimeDelta::FromMilliseconds(0);
54 params
.sampling_interval
= base::TimeDelta::FromMilliseconds(100);
55 params
.samples_per_burst
= duration
/ params
.sampling_interval
;
59 params
.initial_delay
= base::TimeDelta::FromMilliseconds(0);
60 params
.sampling_interval
= base::TimeDelta::FromMilliseconds(10);
61 params
.samples_per_burst
= duration
/ params
.sampling_interval
;
67 bool StackSamplingConfiguration::IsProfilerEnabled() const {
68 return IsProfilerEnabledForCurrentChannel() &&
69 configuration_
!= PROFILE_DISABLED
;
72 void StackSamplingConfiguration::RegisterSyntheticFieldTrial() const {
73 if (!IsProfilerEnabledForCurrentChannel())
77 switch (configuration_
) {
78 case PROFILE_DISABLED
:
82 case PROFILE_NO_SAMPLES
:
99 ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrial(
100 "SyntheticStackProfilingConfiguration",