From 1f2fa9c5a61ed86cc4699306cdea0dbb9b38a462 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Sun, 6 Feb 2022 22:20:31 -0800 Subject: charts: ensure first update always samples vmon steps on this edge case, in vwm it was largely benign since nothing ever happens immediately at vwm startup. But in vmon you do things monitor commands which might immediately send SIGUSR1 to vmon for .png snapshots, producing an empty .png because the first update didn't sample because the time delta hadn't passed. This change just maintains a "primed" charts flag to ensure the initial charts update always samples. This way if got_sigusr1 is already set on the first iteration, at least the first charts update will have sampled and composited *something*. --- src/charts.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/charts.c') diff --git a/src/charts.c b/src/charts.c index fc33612..37e4691 100644 --- a/src/charts.c +++ b/src/charts.c @@ -59,7 +59,7 @@ typedef struct _vwm_charts_t { unsigned long long last_idle, last_iowait, idle_delta, iowait_delta; vmon_t vmon; float prev_sampling_interval, sampling_interval; - int sampling_paused, contiguous_drops; + int sampling_paused, contiguous_drops, primed; /* X */ XFontStruct *chart_font; @@ -1596,7 +1596,8 @@ int vwm_charts_update(vwm_charts_t *charts, int *desired_delay) int ret = 0; gettimeofday(&charts->maybe_sample, NULL); - if ((charts->sampling_interval == INFINITY && !charts->sampling_paused) || /* XXX this is kind of a kludge to get the 0 Hz indicator drawn before pausing */ + if (!charts->primed || + (charts->sampling_interval == INFINITY && !charts->sampling_paused) || /* XXX this is kind of a kludge to get the 0 Hz indicator drawn before pausing */ (charts->sampling_interval != INFINITY && ((this_delta = delta(&charts->maybe_sample, &charts->this_sample)) >= charts->sampling_interval))) { vmon_sys_stat_t *sys_stat; @@ -1637,6 +1638,10 @@ int vwm_charts_update(vwm_charts_t *charts, int *desired_delay) charts->sampling_paused = (charts->sampling_interval == INFINITY); charts->prev_sampling_interval = charts->sampling_interval; + + /* "primed" is just a flag to ensure we always perform the first sample */ + if (!charts->primed) + charts->primed = 1; } /* TODO: make some effort to compute how long to sleep, but this is perfectly fine for now. */ -- cgit v1.2.3