0

Enable Chrome OS support for SystemPowerMonitor

On Chrome OS, energy metrics collection works the same way as on Linux, which also gets data from perf event and requires '/proc/sys/kernel/perf_event_paranoid' set to 0.
Modifying the paranoid's value needs sudo permission, so it requires developer mode to use SystemPowerMonitor on Chrome OS.

Bug: 1385251
Change-Id: Id9e20d54d8e969988c308c78f7795a0bfe472404
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4550470
Reviewed-by: Francois Pierre Doray <fdoray@chromium.org>
Commit-Queue: Shiyi Zou <shiyi.zou@intel.com>
Reviewed-by: Mark Pearson <mpearson@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1152314}
This commit is contained in:
Shiyi Zou
2023-06-02 02:08:32 +00:00
committed by Chromium LUCI CQ
parent d2d08cb7c3
commit 6aeee6592f
4 changed files with 9 additions and 9 deletions

@ -6201,7 +6201,6 @@ static_library("browser") {
"//chrome/browser/enterprise/connectors/device_trust/key_management/core",
"//chrome/browser/enterprise/connectors/device_trust/key_management/core/persistence",
"//chrome/services/system_signals/public/cpp/browser",
"//components/power_metrics",
]
public_deps +=
[ "//chrome/browser/enterprise/connectors/analysis:sdk_manager" ]
@ -6581,6 +6580,7 @@ static_library("browser") {
if (is_win || is_mac || is_linux || is_chromeos) {
deps += [
"//components/power_metrics",
"//components/user_notes:features",
"//components/user_notes/browser",
"//components/user_notes/interfaces",

@ -111,7 +111,7 @@
#include "components/user_manager/user_manager.h"
#endif // BUILDFLAG(IS_CHROMEOS_ASH)
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX)
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#include "components/power_metrics/system_power_monitor.h"
#endif
@ -746,10 +746,10 @@ void ChromeBrowserMainExtraPartsMetrics::PostBrowserStart() {
pressure_metrics_reporter_ = std::make_unique<PressureMetricsReporter>();
#endif // BUILDFLAG(IS_LINUX)
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX)
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
base::trace_event::TraceLog::GetInstance()->AddEnabledStateObserver(
power_metrics::SystemPowerMonitor::GetInstance());
#endif // BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX)
#endif // BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
HandleEnableBenchmarkingCountdownAsync();
}

@ -42,14 +42,14 @@ static_library("power_metrics") {
ldflags = [ "/DELAYLOAD:setupapi.dll" ]
}
if (is_linux) {
if (is_linux || is_chromeos) {
sources += [
"energy_metrics_provider_linux.cc",
"energy_metrics_provider_linux.h",
]
}
if (is_win || is_linux) {
if (is_win || is_linux || is_chromeos) {
sources += [
"system_power_monitor.cc",
"system_power_monitor.h",
@ -78,7 +78,7 @@ source_set("unit_tests") {
data = [ "test/data/" ]
}
if (is_win || is_linux) {
if (is_win || is_linux || is_chromeos) {
sources += [ "system_power_monitor_unittest.cc" ]
deps += [ "//base/test:test_support" ]

@ -7,7 +7,7 @@
#include "build/build_config.h"
#if BUILDFLAG(IS_WIN)
#include "components/power_metrics/energy_metrics_provider_win.h"
#elif BUILDFLAG(IS_LINUX)
#elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#include "components/power_metrics/energy_metrics_provider_linux.h"
#endif // BUILDFLAG(IS_WIN)
@ -20,7 +20,7 @@ EnergyMetricsProvider::~EnergyMetricsProvider() = default;
std::unique_ptr<EnergyMetricsProvider> EnergyMetricsProvider::Create() {
#if BUILDFLAG(IS_WIN)
return EnergyMetricsProviderWin::Create();
#elif BUILDFLAG(IS_LINUX)
#elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
return EnergyMetricsProviderLinux::Create();
#else
return nullptr;