// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "chrome/browser/metrics/power/process_metrics_recorder_util.h" #include <cmath> #include <optional> #include "base/metrics/histogram_functions.h" #include "base/strings/strcat.h" #include "base/time/time.h" #include "build/build_config.h" namespace { // CPU usage metrics are provided as a double in the [0.0, number of cores * // 100.0] range. The CPU usage is usually below 1%, so the histograms are // reported with a 1/10000 granularity to make analyzing the data easier // (otherwise almost all samples end up in the same [0, 1[ bucket). constexpr int kCPUUsageFactor = …; // We scale up to the equivalent of 2 CPU cores fully loaded. More than this // doesn't really matter, as we're already in a terrible place. This used to // be capped at 64 cores but the data showed that this was way too much, the // per process CPU usage really rarely exceeds 100% of one core. constexpr int kCPUUsageHistogramMin = …; constexpr int kCPUUsageHistogramMax = …; constexpr int kCPUUsageHistogramBucketCount = …; #if BUILDFLAG(IS_WIN) bool HasConstantRateTSC() { #if defined(ARCH_CPU_ARM64) // Constant rate TSC is never support on Arm CPUs. return false; #else // Probe the CPU to detect if constant-rate TSC is supported. return base::time_internal::HasConstantRateTSC(); #endif } #endif // BUILDFLAG(IS_WIN) void RecordAverageCPUUsage(const char* histogram_suffix, const std::optional<double>& cpu_usage) { … } } // namespace void RecordProcessHistograms(const char* histogram_suffix, const ProcessMonitor::Metrics& metrics) { … }