Skip to content

Commit

Permalink
Fallback to 100 ticks per second for CPU usage calculation. (#4155)
Browse files Browse the repository at this point in the history
b/341774149
  • Loading branch information
aee-google authored Oct 1, 2024
1 parent 8cf0d63 commit 31cb72d
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions cobalt/base/process/process_metrics_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,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
Expand Down Expand Up @@ -102,15 +103,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();
Value::List cpu_per_thread;
FileEnumerator file_enum(FilePath("/proc/self/task"), /*recursive=*/false,
FileEnumerator::DIRECTORIES);
Expand Down

0 comments on commit 31cb72d

Please sign in to comment.