From 84bf0756c437294b8aa260f1fa2f1dbe512b3597 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Sun, 3 Jan 2021 14:37:20 -0800 Subject: charts: round up Hz integral of sampling interval Cosmetic change, the plain truncation would occasionally result in unexpected Hz values in the charts like 59Hz particularly using vmon w/arbitrary --hertz values. --- src/charts.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/charts.c b/src/charts.c index da53992..a94714b 100644 --- a/src/charts.c +++ b/src/charts.c @@ -829,6 +829,15 @@ static void draw_chart_rest(vwm_charts_t *charts, vwm_chart_t *chart, vmon_proc_ } +/* convert chart sampling interval back into an integral hertz value, basically + * open-coded ceilf(1.f / charts->sampling_interval) to avoid needing -lm. + */ +static unsigned interval_as_hz(vwm_charts_t *charts) +{ + return (1.f / charts->sampling_interval + .5f); +} + + /* recursive draw function entrypoint, draws the IOWait/Idle/HZ row, then enters draw_chart_rest() */ static void draw_chart(vwm_charts_t *charts, vwm_chart_t *chart, vmon_proc_t *proc, int *depth, int *row) { @@ -843,7 +852,7 @@ static void draw_chart(vwm_charts_t *charts, vwm_chart_t *chart, vmon_proc_t *pr /* only draw the \/\/\ and HZ if necessary */ if (chart->redraw_needed || charts->prev_sampling_interval != charts->sampling_interval) { - str_len = snpf(str, sizeof(str), "\\/\\/\\ %2iHz ", (int)(charts->sampling_interval == INFINITY ? 0 : 1 / charts->sampling_interval)); + str_len = snpf(str, sizeof(str), "\\/\\/\\ %2uHz ", interval_as_hz(charts)); XRenderFillRectangle(xserver->display, PictOpSrc, chart->text_picture, &chart_trans_color, 0, 0, /* dst x, y */ chart->visible_width, CHART_ROW_HEIGHT); /* dst w, h */ -- cgit v1.2.3