Skip to content

Commit

Permalink
in_cpu: Normalize per-process CPU stats by number of cores.
Browse files Browse the repository at this point in the history
Signed-off-by: yang-padawan <25978390+yang-padawan@users.noreply.github.com>
  • Loading branch information
matej-staron committed Sep 17, 2020
1 parent ff56f5c commit cc4566d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 23 deletions.
13 changes: 7 additions & 6 deletions plugins/in_cpu/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,16 +333,17 @@ struct cpu_snapshot *snapshot_pid_percent(struct cpu_stats *cstats,
sum_pre = (snap_pre->v_user + snap_pre->v_system);
sum_now = (snap_now->v_user + snap_now->v_system);

snap_now->p_cpu = CPU_METRIC_USAGE(sum_pre, sum_now, ctx);
snap_now->p_cpu = CPU_METRIC_SYS_AVERAGE(sum_pre, sum_now, ctx);

/* User space CPU% */
snap_now->p_user = CPU_METRIC_USAGE(snap_pre->v_user, snap_now->v_user,
ctx);
snap_now->p_user = CPU_METRIC_SYS_AVERAGE(snap_pre->v_user,
snap_now->v_user,
ctx);

/* Kernel space CPU% */
snap_now->p_system = CPU_METRIC_USAGE(snap_pre->v_system,
snap_now->v_system,
ctx);
snap_now->p_system = CPU_METRIC_SYS_AVERAGE(snap_pre->v_system,
snap_now->v_system,
ctx);

#ifdef FLB_TRACE
flb_trace("cpu[pid=%i] all=%s%f%s user=%s%f%s system=%s%f%s",
Expand Down
17 changes: 0 additions & 17 deletions plugins/in_cpu/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,21 +131,4 @@ static inline double CPU_METRIC_USAGE(unsigned long pre, unsigned long now,
return total;
}

/* Returns the CPU % utilization of a given CPU core */
static inline double CPU_METRIC_PID_USAGE(unsigned long pre, unsigned long now,
struct flb_cpu *ctx)
{
double diff;
double total = 0;

if (pre == now) {
return 0.0;
}

diff = ULL_ABS(now, pre);
total = 100.0 * ((diff / ctx->cpu_ticks) / (ctx->interval_sec + 1e-9*ctx->interval_nsec));

return total;
}

#endif

0 comments on commit cc4566d

Please sign in to comment.