blob: 81426d558913789a17fe5ba4a8be0078695d219a [file] [log] [blame]
Erik Chen0fcb8762022-02-10 17:35:06 +00001// Copyright 2022 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.
4
5#include "base/cpu_reduction_experiment.h"
6
7#include "base/feature_list.h"
8
9namespace base {
10
11namespace {
12
13// This feature controls whether to enable a series of optimizations that
14// reduces total CPU utilization of chrome.
15constexpr Feature kReduceCpuUtilization{"ReduceCpuUtilization",
16 FEATURE_DISABLED_BY_DEFAULT};
17
18// Cache of the state of the ReduceCpuUtilization feature. This avoids the need
19// to constantly query its enabled state through FeatureList::IsEnabled().
20bool g_is_reduce_cpu_enabled =
21 kReduceCpuUtilization.default_state == FEATURE_ENABLED_BY_DEFAULT;
22
23} // namespace
24
25bool IsRunningCpuReductionExperiment() {
26 return g_is_reduce_cpu_enabled;
27}
28
29void InitializeCpuReductionExperiment() {
30 g_is_reduce_cpu_enabled = FeatureList::IsEnabled(kReduceCpuUtilization);
31}
32
33bool CpuReductionExperimentFilter::ShouldLogHistograms() {
34 if (!IsRunningCpuReductionExperiment())
35 return true;
36
37 return (++counter_ % 1000) == 1;
38}
39
40} // namespace base