summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2024-09-29 13:55:11 -0700
committerVito Caputo <vcaputo@pengaru.com>2024-10-05 11:00:54 -0700
commitf253cc169062d65a941e7d9a55ab1bcc2ca14e5f (patch)
treeac46013155a319192908da06cb04bd92027d653c /src
parentaa8de38476e60bfebf349be709b6fe913ce1c885 (diff)
charts: compute a "sample duration" for current sample
This turns the time passed since the last sample taken into a "sample duration". Ideally this would always be 1, and up until now in the main use case, vwm, it's been assumed to generally be 1 and drops in the timeline treated benign/fleeting because of the live viewing. But with the introduction of --headless and increasing use on my servers / embedded interests, this has become more problematic. In this commit the duration is only being maintained, but not applied. Subsequent commits will have to repeat the current sample in the graphs (this_sample_duration - 1) times.
Diffstat (limited to 'src')
-rw-r--r--src/charts.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/charts.c b/src/charts.c
index b4916df..4bb87e2 100644
--- a/src/charts.c
+++ b/src/charts.c
@@ -54,6 +54,7 @@ typedef struct _vwm_charts_t {
/* libvmon */
struct timeval maybe_sample, last_sample, this_sample;
+ unsigned this_sample_duration;
typeof(((vmon_sys_stat_t *)0)->user) last_user_cpu;
typeof(((vmon_sys_stat_t *)0)->system) last_system_cpu;
unsigned long long last_total, this_total, total_delta;
@@ -1272,13 +1273,23 @@ int vwm_charts_update(vwm_charts_t *charts, int *desired_delay_us)
charts->sampling_interval <= charts->prev_sampling_interval &&
this_delta >= (charts->sampling_interval * 1.5)) {
+ /* adjust charts->this_sample_duration as needed since we've missed our deadline.
+ * This is more of an issue in headless mode, especially when run on slower/embedded
+ * devices, even worse when periodically snapshoting costly PNGs that may take
+ * several seconds during which no sampling occurs.
+ */
+ charts->this_sample_duration = (this_delta / charts->sampling_interval) + .5f /* rounded to int */;
+
/* require > 1 contiguous drops before lowering the rate, tolerates spurious one-off stalls */
if (++charts->contiguous_drops > 2)
vwm_charts_rate_decrease(charts);
} else {
charts->contiguous_drops = 0;
+ charts->this_sample_duration = 1; /* ideally always 1, but > 1 when sample deadline missed (repeat sample) */
}
+ VWM_TRACE("sample_duration=%u", charts->this_sample_duration);
+
/* age the sys-wide sample data into "last" variables, before the new sample overwrites them. */
charts->last_sample = charts->this_sample;
charts->this_sample = charts->maybe_sample;
© All Rights Reserved