Refactor WebsiteSettings to operate on a SecurityInfo
[chromium-blink-merge.git] / chrome / browser / stack_sampling_configuration.cc
blobf5ae4921eb2bff513bc9c6f03223ab6ccb2464f9
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"
12 namespace {
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);
21 } // namespace
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;
34 params.bursts = 1;
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;
42 break;
44 case PROFILE_NO_SAMPLES:
45 params.initial_delay = duration;
46 params.sampling_interval = base::TimeDelta::FromMilliseconds(0);
47 params.samples_per_burst = 0;
48 break;
50 case PROFILE_5HZ:
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;
54 break;
56 case PROFILE_10HZ:
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;
60 break;
62 case PROFILE_100HZ:
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;
66 break;
68 return params;
71 bool StackSamplingConfiguration::IsProfilerEnabled() const {
72 return IsProfilerEnabledForCurrentChannel() &&
73 configuration_ != PROFILE_DISABLED;
76 void StackSamplingConfiguration::RegisterSyntheticFieldTrial() const {
77 if (!IsProfilerEnabledForCurrentChannel())
78 return;
80 std::string group;
81 switch (configuration_) {
82 case PROFILE_DISABLED:
83 group = "Disabled";
84 break;
86 case PROFILE_NO_SAMPLES:
87 group = "NoSamples";
88 break;
90 case PROFILE_5HZ:
91 group = "5Hz";
92 break;
94 case PROFILE_10HZ:
95 group = "10Hz";
96 break;
98 case PROFILE_100HZ:
99 group = "100Hz";
100 break;
103 ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrial(
104 "SyntheticStackProfilingConfiguration",
105 group);