Popular sites on the NTP: re-download popular suggestions once per Chrome run
[chromium-blink-merge.git] / chrome / browser / stack_sampling_configuration.cc
blob63e1305d5a806584a7ddb37a5f91dab8dbe7c0e3
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"
11 namespace {
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);
20 } // namespace
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;
30 params.bursts = 1;
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;
38 break;
40 case PROFILE_NO_SAMPLES:
41 params.initial_delay = duration;
42 params.sampling_interval = base::TimeDelta::FromMilliseconds(0);
43 params.samples_per_burst = 0;
44 break;
46 case PROFILE_5HZ:
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;
50 break;
52 case PROFILE_10HZ:
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;
56 break;
58 case PROFILE_100HZ:
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;
62 break;
64 return params;
67 bool StackSamplingConfiguration::IsProfilerEnabled() const {
68 return IsProfilerEnabledForCurrentChannel() &&
69 configuration_ != PROFILE_DISABLED;
72 void StackSamplingConfiguration::RegisterSyntheticFieldTrial() const {
73 if (!IsProfilerEnabledForCurrentChannel())
74 return;
76 std::string group;
77 switch (configuration_) {
78 case PROFILE_DISABLED:
79 group = "Disabled";
80 break;
82 case PROFILE_NO_SAMPLES:
83 group = "NoSamples";
84 break;
86 case PROFILE_5HZ:
87 group = "5Hz";
88 break;
90 case PROFILE_10HZ:
91 group = "10Hz";
92 break;
94 case PROFILE_100HZ:
95 group = "100Hz";
96 break;
99 ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrial(
100 "SyntheticStackProfilingConfiguration",
101 group);