Erik Chen | 0fcb876 | 2022-02-10 17:35:06 +0000 | [diff] [blame] | 1 | // 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 | |
| 9 | namespace base { |
| 10 | |
| 11 | namespace { |
| 12 | |
| 13 | // This feature controls whether to enable a series of optimizations that |
| 14 | // reduces total CPU utilization of chrome. |
| 15 | constexpr 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(). |
| 20 | bool g_is_reduce_cpu_enabled = |
| 21 | kReduceCpuUtilization.default_state == FEATURE_ENABLED_BY_DEFAULT; |
| 22 | |
| 23 | } // namespace |
| 24 | |
| 25 | bool IsRunningCpuReductionExperiment() { |
| 26 | return g_is_reduce_cpu_enabled; |
| 27 | } |
| 28 | |
| 29 | void InitializeCpuReductionExperiment() { |
| 30 | g_is_reduce_cpu_enabled = FeatureList::IsEnabled(kReduceCpuUtilization); |
| 31 | } |
| 32 | |
| 33 | bool CpuReductionExperimentFilter::ShouldLogHistograms() { |
| 34 | if (!IsRunningCpuReductionExperiment()) |
| 35 | return true; |
| 36 | |
| 37 | return (++counter_ % 1000) == 1; |
| 38 | } |
| 39 | |
| 40 | } // namespace base |