Skip to content

Commit 1fb1e25

Browse files
authored
in_cpu: normalize per-process CPU stats by number of cores (#2543)
Signed-off-by: yang-padawan <25978390+yang-padawan@users.noreply.github.com>
1 parent 7505913 commit 1fb1e25

File tree

2 files changed

+7
-23
lines changed

2 files changed

+7
-23
lines changed

plugins/in_cpu/cpu.c

+7-6
Original file line numberDiff line numberDiff line change
@@ -333,16 +333,17 @@ struct cpu_snapshot *snapshot_pid_percent(struct cpu_stats *cstats,
333333
sum_pre = (snap_pre->v_user + snap_pre->v_system);
334334
sum_now = (snap_now->v_user + snap_now->v_system);
335335

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

338338
/* User space CPU% */
339-
snap_now->p_user = CPU_METRIC_USAGE(snap_pre->v_user, snap_now->v_user,
340-
ctx);
339+
snap_now->p_user = CPU_METRIC_SYS_AVERAGE(snap_pre->v_user,
340+
snap_now->v_user,
341+
ctx);
341342

342343
/* Kernel space CPU% */
343-
snap_now->p_system = CPU_METRIC_USAGE(snap_pre->v_system,
344-
snap_now->v_system,
345-
ctx);
344+
snap_now->p_system = CPU_METRIC_SYS_AVERAGE(snap_pre->v_system,
345+
snap_now->v_system,
346+
ctx);
346347

347348
#ifdef FLB_TRACE
348349
flb_trace("cpu[pid=%i] all=%s%f%s user=%s%f%s system=%s%f%s",

plugins/in_cpu/cpu.h

-17
Original file line numberDiff line numberDiff line change
@@ -131,21 +131,4 @@ static inline double CPU_METRIC_USAGE(unsigned long pre, unsigned long now,
131131
return total;
132132
}
133133

134-
/* Returns the CPU % utilization of a given CPU core */
135-
static inline double CPU_METRIC_PID_USAGE(unsigned long pre, unsigned long now,
136-
struct flb_cpu *ctx)
137-
{
138-
double diff;
139-
double total = 0;
140-
141-
if (pre == now) {
142-
return 0.0;
143-
}
144-
145-
diff = ULL_ABS(now, pre);
146-
total = 100.0 * ((diff / ctx->cpu_ticks) / (ctx->interval_sec + 1e-9*ctx->interval_nsec));
147-
148-
return total;
149-
}
150-
151134
#endif

0 commit comments

Comments
 (0)