Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

common/stats: stats formating changes #15958

Merged
merged 3 commits into from
Feb 25, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions common/stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,17 @@ void stats_global_query(struct mpv_global *global, struct mpv_node *out)

node_init(out, MPV_FORMAT_NODE_ARRAY, NULL);

#define FMT_T(e, t) ((t) > 0 ? mp_tprintf(80, "%.3f ms (%.2f%%)", (e), ((e) / (t)) * 100) \
: mp_tprintf(80, "%.3f ms", (e)))

int64_t now = mp_time_ns();
double t_ms = 0;
if (stats->last_time) {
double t_ms = MP_TIME_NS_TO_MS(now - stats->last_time);
t_ms = MP_TIME_NS_TO_MS(now - stats->last_time);
struct mpv_node *ne = node_array_add(out, MPV_FORMAT_NODE_MAP);
node_map_add_string(ne, "name", "poll-time");
node_map_add_double(ne, "value", t_ms);
node_map_add_string(ne, "text", mp_tprintf(80, "%.2f ms", t_ms));
node_map_add_string(ne, "text", FMT_T(t_ms, 0));

// Very dirty way to reset everything if the stats.lua page was probably
// closed. Not enough energy left for clean solution. Fuck it.
Expand Down Expand Up @@ -182,9 +186,9 @@ void stats_global_query(struct mpv_global *global, struct mpv_node *out)
}
double t_cpu = MP_TIME_NS_TO_MS(e->val_th);
if (e->cpu_start_ns >= 0)
add_stat(out, e, "cpu", t_cpu, mp_tprintf(80, "%.2f ms", t_cpu));
add_stat(out, e, "cpu", t_cpu, FMT_T(t_cpu, t_ms));
double t_rt = MP_TIME_NS_TO_MS(e->val_rt);
add_stat(out, e, "time", t_rt, mp_tprintf(80, "%.2f ms", t_rt));
add_stat(out, e, "time", t_rt, FMT_T(t_rt, t_ms));
e->val_rt = e->val_th = 0;
break;
}
Expand All @@ -194,7 +198,7 @@ void stats_global_query(struct mpv_global *global, struct mpv_node *out)
e->cpu_start_ns = t;
double t_msec = MP_TIME_NS_TO_MS(t - e->cpu_start_ns);
if (e->cpu_start_ns >= 0)
add_stat(out, e, NULL, t_msec, mp_tprintf(80, "%.2f ms", t_msec));
add_stat(out, e, NULL, t_msec, FMT_T(t_msec, t_ms));
e->cpu_start_ns = t;
break;
}
Expand Down
Loading