forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This CL has two parts: Part 1: This CL adds an experiment to base called IsRunningCpuReductionExperiment. When enabled, several different unrelated features will change their behavior to reduce overall CPU consumption of chrome. As these features are unrelated, this experiment must live in base as the only common dependency. Part 2: This CL modifies 6 functions that emit UMA metrics to emit at 1/1000th of their current rate. Combined, the UMA metric emission from these 6 functions are responsible for 0.33% of all CPU cycles on ChromeOS, including time from non-chrome processes. This demonstrates why the code in part 1 must live in base. Future CLs will add more CPU-savings to the experiment before it is enabled. Bug: 1295441 Change-Id: I8202c5a1482ff66fc90a7bc64bb36b3cdc773130 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3449251 Reviewed-by: Ken Rockot <rockot@google.com> Reviewed-by: Sunny Sachanandani <sunnyps@chromium.org> Reviewed-by: Daniel Cheng <dcheng@chromium.org> Reviewed-by: Francois Pierre Doray <fdoray@chromium.org> Reviewed-by: Sadrul Chowdhury <sadrul@chromium.org> Commit-Queue: Erik Chen <erikchen@chromium.org> Cr-Commit-Position: refs/heads/main@{#969512}
- Loading branch information
Showing
12 changed files
with
143 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2022 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "base/cpu_reduction_experiment.h" | ||
|
||
#include "base/feature_list.h" | ||
|
||
namespace base { | ||
|
||
namespace { | ||
|
||
// This feature controls whether to enable a series of optimizations that | ||
// reduces total CPU utilization of chrome. | ||
constexpr Feature kReduceCpuUtilization{"ReduceCpuUtilization", | ||
FEATURE_DISABLED_BY_DEFAULT}; | ||
|
||
// Cache of the state of the ReduceCpuUtilization feature. This avoids the need | ||
// to constantly query its enabled state through FeatureList::IsEnabled(). | ||
bool g_is_reduce_cpu_enabled = | ||
kReduceCpuUtilization.default_state == FEATURE_ENABLED_BY_DEFAULT; | ||
|
||
} // namespace | ||
|
||
bool IsRunningCpuReductionExperiment() { | ||
return g_is_reduce_cpu_enabled; | ||
} | ||
|
||
void InitializeCpuReductionExperiment() { | ||
g_is_reduce_cpu_enabled = FeatureList::IsEnabled(kReduceCpuUtilization); | ||
} | ||
|
||
bool CpuReductionExperimentFilter::ShouldLogHistograms() { | ||
if (!IsRunningCpuReductionExperiment()) | ||
return true; | ||
|
||
return (++counter_ % 1000) == 1; | ||
} | ||
|
||
} // namespace base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright 2022 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef BASE_CPU_REDUCTION_EXPERIMENT_H_ | ||
#define BASE_CPU_REDUCTION_EXPERIMENT_H_ | ||
|
||
#include "base/base_export.h" | ||
|
||
namespace base { | ||
|
||
// Returns whether the cpu cycle reduction experiment is running. | ||
// The goal of this experiment is to better understand the relationship between | ||
// total CPU cycles used across the fleet and top-line chrome metrics. | ||
BASE_EXPORT bool IsRunningCpuReductionExperiment(); | ||
|
||
// Must be called after FeatureList initialization and while chrome is still | ||
// single-threaded. | ||
BASE_EXPORT void InitializeCpuReductionExperiment(); | ||
|
||
// This is a helper class to reduce common duplicate code. If the CPU reduction | ||
// experiment is running, then ShouldLogHistograms returns true on every 1000th | ||
// call. Otherwise it always returns true. | ||
class BASE_EXPORT CpuReductionExperimentFilter { | ||
public: | ||
// Returns true on the first call, and every 1000th call after that. | ||
bool ShouldLogHistograms(); | ||
|
||
private: | ||
int counter_ = 0; | ||
}; | ||
|
||
} // namespace base | ||
|
||
#endif // BASE_CPU_REDUCTION_EXPERIMENT_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters