Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry pick PR #4155: Fallback to 100 ticks per second for CPU usage … #4442

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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
Expand Down Expand Up @@ -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);
Expand Down
Loading