common/stats: fix incorrect cpu-time value reset

This fixes a bug where if stats reset happened after stats_time_start
and before stats_time_end, then the next reported cpu-time value of
that measurement was from the thread startup.

The long version:

stats resets the time-accumulated values if more than two seconds
ellapsed since last poll.

The reset keeps the elements, but makes them as if no measurement was
yet taken, so that they don't show up at new reports until a new
measurement is taken.

While the events and (untimed) cpu are reset, the timed-cpu value
was only partially reset - the values are reset but the indication
that the element is empty was not enough for stats_time_end.

So when reset happened between start/end calls, stats_time_end was
entered eventhough it shouldn't have, but with reset cpu-time value
it calculated the time since the thread's startup, hence this bug.

Further polls were ok, because they are of the delta since the
previous poll. But at the next reset it happened again.

Now the cpu-value is reset correctly, which fixes this bug.
This commit is contained in:
Avi Halachmi (:avih) authored and Kacper Michajłow committed 2025-02-17 22:50:03 +01:00
1 parent 7162c960e7
commit be68ca94ad
1 file changed
+1 -1
+1 -1
View File
@@ -144,7 +144,7 @@ void stats_global_query(struct mpv_global *global, struct mpv_node *out)
for (int n = 0; n < stats->num_entries; n++) {
struct stat_entry *e = stats->entries[n];
e->cpu_start_ns = 0;
e->cpu_start_ns = e->time_start_ns = 0;
e->val_rt = e->val_th = 0;
if (e->type != VAL_THREAD_CPU_TIME)
e->type = 0;