From 0090477d85c61c456979aa18ac18ec4ec2260113 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Sat, 21 Sep 2024 17:22:35 -0700 Subject: charts: scale % bars by num_cpus when appropriate For rows reflecting threads and single/non-threaded processes, let's scale the bar % by the number of cpus, so they can use the full height of the row. These tasks can't scale to multiple CPUs, so it's pointless to leave vertical space for the other cores' capacity, if present. For multi-threaded process rows, the vertical space continues to accomodate all cores. I've been on the fence about this change for a while because it increases the cognitive load of reading the graphs, now the scales are inconsistent. But when you've got 16 cores like on my AMD P14s thinkpad, combined with a row height of 16 pixels, you start wishing these rows used the full height of the row for their single-core-constrained %ages. --- src/charts.c | 17 ++++++++++++----- src/vcr.c | 4 ++++ 2 files changed, 16 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/charts.c b/src/charts.c index 31f3ea2..57e3dc9 100644 --- a/src/charts.c +++ b/src/charts.c @@ -364,13 +364,13 @@ static int proc_hierarchy_changed(vmon_proc_t *proc) /* helper for drawing the vertical bars in the graph layers */ -static void draw_bars(vwm_charts_t *charts, vwm_chart_t *chart, int row, double a_fraction, double a_total, double b_fraction, double b_total) +static void draw_bars(vwm_charts_t *charts, vwm_chart_t *chart, int row, double mult, double a_fraction, double a_total, double b_fraction, double b_total) { float a_t, b_t; /* compute the bar %ages for this sample */ - a_t = a_fraction / a_total; - b_t = b_fraction / b_total; + a_t = a_fraction / a_total * mult; /* TODO: these divides could be turned into multiplies, since the totals are sys-wide uniforms throughout the sample */ + b_t = b_fraction / b_total * mult; /* ensure at least 1 pixel when the scaled result is a fraction less than 1, * I want to at least see 1 pixel blips for the slightest cpu utilization */ @@ -921,7 +921,14 @@ static void draw_chart_rest(vwm_charts_t *charts, vwm_chart_t *chart, vmon_proc_ utime_delta = proc_ctxt->utime_delta; } - draw_bars(charts, chart, *row, stime_delta, charts->total_delta, utime_delta, charts->total_delta); + draw_bars(charts, + chart, + *row, + (proc->is_thread || !proc->is_threaded) ? charts->vmon.num_cpus : 1.0, + stime_delta, + charts->total_delta, + utime_delta, + charts->total_delta); } draw_overlay_row(charts, chart, proc, *depth, *row, deferred_pass); @@ -948,7 +955,7 @@ static void draw_chart(vwm_charts_t *charts, vwm_chart_t *chart, vmon_proc_t *pr int prev_redraw_needed; /* IOWait and Idle % @ row 0 */ - draw_bars(charts, chart, 0, charts->iowait_delta, charts->total_delta, charts->idle_delta, charts->total_delta); + draw_bars(charts, chart, 0, 1.0, charts->iowait_delta, charts->total_delta, charts->idle_delta, charts->total_delta); /* only draw the \/\/\ and HZ if necessary */ if (deferred_pass || (!charts->defer_maintenance && (chart->redraw_needed || charts->prev_sampling_interval != charts->sampling_interval))) { diff --git a/src/vcr.c b/src/vcr.c index 4366421..d90243d 100644 --- a/src/vcr.c +++ b/src/vcr.c @@ -1194,6 +1194,10 @@ void vcr_draw_bar(vcr_t *vcr, vcr_layer_t layer, int row, double t, int min_heig if (height < min_height) height = min_height; + /* clamp the height to not potentially overflow */ + if (height > (VCR_ROW_HEIGHT - 1)) + height = (VCR_ROW_HEIGHT - 1); + switch (vcr->backend->type) { #ifdef USE_XLIB case VCR_BACKEND_TYPE_XLIB: { -- cgit v1.2.3