diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2025-02-20 23:57:09 -0800 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2025-02-20 23:57:09 -0800 |
commit | 44041a498aaee2143cf5368c2207a5695ff9885c (patch) | |
tree | ee587c6e14b35b88c1ea1c89850d093c61dfd3e7 | |
parent | 2b47813cc720dc48b94672efdeb8ed260b83d835 (diff) |
There's potential for spending a whole lot of cycles filling a
huge time delta from the time things became paused to the current
time.
The output from that is pretty much pointless, so let's prevent
it from happening by simply bumping the sample time to the
current time whenever we're unpausing.
-rw-r--r-- | src/charts.c | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/src/charts.c b/src/charts.c index ed1a315..297991f 100644 --- a/src/charts.c +++ b/src/charts.c @@ -1283,17 +1283,29 @@ void vwm_chart_render(vwm_charts_t *charts, vwm_chart_t *chart, vcr_present_op_t } +static void set_sampling_interval(vwm_charts_t *charts, float interval) +{ + assert(charts); + assert(interval > 0.f); + + /* if we're unpausing, make this_sample current so we don't have some + * potentially huge time delta to then try fill in with nonsense + */ + if (charts->sampling_interval_secs == INFINITY) + clock_gettime(CLOCK_MONOTONIC_RAW, &charts->this_sample); + + charts->sampling_interval_secs = interval; +} + + /* increase the sample rate relative to current using the table of intervals */ void vwm_charts_rate_increase(vwm_charts_t *charts) { - int i; - assert(charts); - for (i = 0; i < NELEMS(sampling_intervals); i++) { + for (int i = 0; i < NELEMS(sampling_intervals); i++) { if (sampling_intervals[i] < charts->sampling_interval_secs) { - charts->sampling_interval_secs = sampling_intervals[i]; - break; + return set_sampling_interval(charts, sampling_intervals[i]); } } } @@ -1302,14 +1314,11 @@ void vwm_charts_rate_increase(vwm_charts_t *charts) /* decrease the sample rate relative to current using the table of intervals */ void vwm_charts_rate_decrease(vwm_charts_t *charts) { - int i; - assert(charts); - for (i = NELEMS(sampling_intervals) - 1; i >= 0; i--) { + for (int i = NELEMS(sampling_intervals) - 1; i >= 0; i--) { if (sampling_intervals[i] > charts->sampling_interval_secs) { - charts->sampling_interval_secs = sampling_intervals[i]; - break; + return set_sampling_interval(charts, sampling_intervals[i]); } } } @@ -1321,7 +1330,7 @@ void vwm_charts_rate_set(vwm_charts_t *charts, unsigned hertz) assert(charts); /* XXX: note floating point divide by 0 simply results in infinity */ - charts->sampling_interval_secs = 1.f / (float)hertz; + set_sampling_interval(charts, 1.f / (float)hertz); } |