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 "base/rand_util.h"
8 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
9 #include "chrome/common/channel_info.h"
10 #include "components/version_info/version_info.h"
14 bool IsProfilerEnabledForCurrentChannel() {
15 const version_info::Channel channel
= chrome::GetChannel();
16 return (channel
== version_info::Channel::UNKNOWN
||
17 channel
== version_info::Channel::CANARY
||
18 channel
== version_info::Channel::DEV
);
23 StackSamplingConfiguration::StackSamplingConfiguration()
24 // We must do our own randomization here, rather than relying on a
25 // traditional field trial, because the configuration is needed to start the
26 // profiler before the metrics system is set up.
27 : configuration_(static_cast<ProfileConfiguration
>(
28 base::RandInt(0, PROFILE_COUNT
))) {
31 base::StackSamplingProfiler::SamplingParams
32 StackSamplingConfiguration::GetSamplingParams() const {
33 base::StackSamplingProfiler::SamplingParams params
;
35 const base::TimeDelta duration
= base::TimeDelta::FromSeconds(30);
37 switch (configuration_
) {
38 case PROFILE_DISABLED
:
39 params
.initial_delay
= base::TimeDelta::FromMilliseconds(0);
40 params
.sampling_interval
= base::TimeDelta::FromMilliseconds(0);
41 params
.samples_per_burst
= 0;
44 case PROFILE_NO_SAMPLES
:
45 params
.initial_delay
= duration
;
46 params
.sampling_interval
= base::TimeDelta::FromMilliseconds(0);
47 params
.samples_per_burst
= 0;
51 params
.initial_delay
= base::TimeDelta::FromMilliseconds(0);
52 params
.sampling_interval
= base::TimeDelta::FromMilliseconds(200);
53 params
.samples_per_burst
= duration
/ params
.sampling_interval
;
57 params
.initial_delay
= base::TimeDelta::FromMilliseconds(0);
58 params
.sampling_interval
= base::TimeDelta::FromMilliseconds(100);
59 params
.samples_per_burst
= duration
/ params
.sampling_interval
;
63 params
.initial_delay
= base::TimeDelta::FromMilliseconds(0);
64 params
.sampling_interval
= base::TimeDelta::FromMilliseconds(10);
65 params
.samples_per_burst
= duration
/ params
.sampling_interval
;
71 bool StackSamplingConfiguration::IsProfilerEnabled() const {
72 return IsProfilerEnabledForCurrentChannel() &&
73 configuration_
!= PROFILE_DISABLED
;
76 void StackSamplingConfiguration::RegisterSyntheticFieldTrial() const {
77 if (!IsProfilerEnabledForCurrentChannel())
81 switch (configuration_
) {
82 case PROFILE_DISABLED
:
86 case PROFILE_NO_SAMPLES
:
103 ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrial(
104 "SyntheticStackProfilingConfiguration",