Skip to content

Commit

Permalink
AER-6701 - use a 'running' boolean to detect when there are no previo…
Browse files Browse the repository at this point in the history
…us values when calculating CPU usage stats.
  • Loading branch information
gooding470 committed Jan 30, 2024
1 parent 98ad3cd commit 5fc2115
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion as/src/base/thr_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -713,12 +713,13 @@ sys_cpu_info(uint32_t* user_pct, uint32_t* kernel_pct)

fclose(fh);

static bool running = false;
static uint64_t prev_user = 0;
static uint64_t prev_nice = 0;
static uint64_t prev_kernel = 0;
static uint64_t prev_idle = 0;

if (prev_user != 0) {
if (running) {
uint32_t delta_user = (uint32_t)(user - prev_user);
uint32_t delta_nice = (uint32_t)(nice - prev_nice);
uint32_t delta_kernel = (uint32_t)(kernel - prev_kernel);
Expand All @@ -733,6 +734,7 @@ sys_cpu_info(uint32_t* user_pct, uint32_t* kernel_pct)
0 : delta_kernel * 100 * n_cpus / total;
}

running = true;
prev_user = user;
prev_nice = nice;
prev_kernel = kernel;
Expand Down

0 comments on commit 5fc2115

Please sign in to comment.