diff --git a/cobalt/base/process/process_metrics_helper.cc b/cobalt/base/process/process_metrics_helper.cc index 9300ab810362..df20c890cf5c 100644 --- a/cobalt/base/process/process_metrics_helper.cc +++ b/cobalt/base/process/process_metrics_helper.cc @@ -64,7 +64,8 @@ double CalculateCPUUsageSeconds(const std::string& utime_string, // static int ProcessMetricsHelper::GetClockTicksPerS() { - return clock_ticks_per_s.load(); + int result = clock_ticks_per_s.load(); + return result > 0 ? result : 100; } // static @@ -104,15 +105,12 @@ void ProcessMetricsHelper::PopulateClockTicksPerS() { // static TimeDelta ProcessMetricsHelper::GetCumulativeCPUUsage() { - int ticks_per_s = clock_ticks_per_s.load(); - if (ticks_per_s == 0) return TimeDelta(); - return GetCPUUsage(FilePath("/proc/self"), ticks_per_s); + return GetCPUUsage(FilePath("/proc/self"), GetClockTicksPerS()); } // static Value ProcessMetricsHelper::GetCumulativeCPUUsagePerThread() { - int ticks_per_s = clock_ticks_per_s.load(); - if (ticks_per_s == 0) return Value(); + int ticks_per_s = GetClockTicksPerS(); ListValue cpu_per_thread; FileEnumerator file_enum(FilePath("/proc/self/task"), /*recursive=*/false, FileEnumerator::DIRECTORIES);