cpu_reduction_experiment.cc 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. #include "base/cpu_reduction_experiment.h"
  5. #include "base/feature_list.h"
  6. namespace base {
  7. namespace {
  8. // This feature controls whether to enable a series of optimizations that
  9. // reduces total CPU utilization of chrome.
  10. constexpr Feature kReduceCpuUtilization{"ReduceCpuUtilization",
  11. FEATURE_DISABLED_BY_DEFAULT};
  12. // Cache of the state of the ReduceCpuUtilization feature. This avoids the need
  13. // to constantly query its enabled state through FeatureList::IsEnabled().
  14. bool g_is_reduce_cpu_enabled =
  15. kReduceCpuUtilization.default_state == FEATURE_ENABLED_BY_DEFAULT;
  16. } // namespace
  17. bool IsRunningCpuReductionExperiment() {
  18. return g_is_reduce_cpu_enabled;
  19. }
  20. void InitializeCpuReductionExperiment() {
  21. g_is_reduce_cpu_enabled = FeatureList::IsEnabled(kReduceCpuUtilization);
  22. }
  23. bool CpuReductionExperimentFilter::ShouldLogHistograms() {
  24. if (!IsRunningCpuReductionExperiment())
  25. return true;
  26. return (++counter_ % 1000) == 1;
  27. }
  28. } // namespace base