summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2022-02-06 22:20:31 -0800
committerVito Caputo <vcaputo@pengaru.com>2022-02-06 22:20:31 -0800
commit1f2fa9c5a61ed86cc4699306cdea0dbb9b38a462 (patch)
tree384618767afe22b4d5014e0a0ef1e61e8ad72525
parentf908c1e73a81baec74c1a2d312078dabd398bd06 (diff)
charts: ensure first update always samplesHEADmaster
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*.
-rw-r--r--src/charts.c9
1 files changed, 7 insertions, 2 deletions
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. */
© 2021 All Rights Reserved