diff options
author | wm4 <wm4@nowhere> | 2020-04-09 00:27:54 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2020-04-09 00:33:38 +0200 |
commit | fd3caa264ea0848e7e30db94390063c87e247003 (patch) | |
tree | 3eb8268c1afc7a0bab5a544e4664cce23d2ab712 /player/lua | |
parent | c5f8ec76b16268b05d1e3af8f1931eddf5165b8b (diff) | |
download | mpv-fd3caa264ea0848e7e30db94390063c87e247003.tar.bz2 mpv-fd3caa264ea0848e7e30db94390063c87e247003.tar.xz |
stats: some more performance graphs
Add an infrastructure for collecting performance-related data, use it in
some places. Add rendering of them to stats.lua.
There were two main goals: minimal impact on the normal code and normal
playback. So all these stats_* function calls either happen only during
initialization, or return immediately if no stats collection is going
on. That's why it does this lazily adding of stats entries etc. (a first
iteration made each stats entry an API thing, instead of just a single
stats_ctx, but I thought that was getting too intrusive in the "normal"
code, even if everything gets worse inside of stats.c).
You could get most of this information from various profilers (including
the extremely primitive --dump-stats thing in mpv), but this makes it
easier to see the most important information at once (at least in
theory), partially because we know best about the context of various
things.
Not very happy with this. It's all pretty primitive and dumb. At this
point I just wanted to get over with it, without necessarily having to
revisit it later, but with having my stupid statistics.
Somehow the code feels terrible. There are a lot of meh decisions in
there that could be better or worse (but mostly could be better), and it
just sucks but it's also trivial and uninteresting and does the job. I
guess I hate programming. It's so tedious and the result is always shit.
Anyway, enjoy.
Diffstat (limited to 'player/lua')
-rw-r--r-- | player/lua/stats.lua | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/player/lua/stats.lua b/player/lua/stats.lua index 98bc1be7c9..93c2c99c18 100644 --- a/player/lua/stats.lua +++ b/player/lua/stats.lua @@ -18,6 +18,7 @@ local o = { key_page_1 = "1", key_page_2 = "2", key_page_3 = "3", + key_page_4 = "4", duration = 4, redraw_delay = 1, -- acts as duration in the toggling case @@ -101,6 +102,7 @@ local function init_buffers() cache_ahead_buf = {0, pos = 1, len = 50, max = 0} cache_speed_buf = {0, pos = 1, len = 50, max = 0} end +local perf_buffers = {} -- Save all properties known to this version of mpv local property_list = {} for p in string.gmatch(mp.get_property("property-list"), "([^,]+)") do property_list[p] = true end @@ -111,6 +113,11 @@ local property_aliases = { ["container-fps"] = "fps", } +local function graph_add_value(graph, value) + graph.pos = (graph.pos % graph.len) + 1 + graph[graph.pos] = value + graph.max = max(graph.max, value) +end -- Return deprecated name for the given property local function compat(p) @@ -347,6 +354,21 @@ local function append_perfdata(s, dedicated_page) end end +local function append_general_perfdata(s) + for _, data in ipairs(mp.get_property_native("perf-info") or {}) do + append(s, data.text or data.value, {prefix=data.name..":"}) + + if o.plot_perfdata and o.use_ass and data.value then + buf = perf_buffers[data.name] + if not buf then + buf = {0, pos = 1, len = 50, max = 0} + perf_buffers[data.name] = buf + end + graph_add_value(buf, data.value) + s[#s+1] = generate_graph(buf, buf.pos, buf.len, buf.max, nil, 0.8, 1) + end + end +end local function append_display_sync(s) if not mp.get_property_bool("display-sync-active", false) then @@ -594,6 +616,16 @@ local function vo_stats() return table.concat(stats) end +local function perf_stats() + local stats = {} + eval_ass_formatting() + add_header(stats) + local page = pages[o.key_page_4] + append(stats, "", {prefix=o.nl .. o.nl .. page.desc .. ":", nl="", indent=""}) + append_general_perfdata(stats, true) + return table.concat(stats) +end + local function opt_time(t) if type(t) == type(1.1) then return mp.format_time(t) @@ -693,12 +725,6 @@ local function cache_stats() return table.concat(stats) end -local function graph_add_value(graph, value) - graph.pos = (graph.pos % graph.len) + 1 - graph[graph.pos] = value - graph.max = max(graph.max, value) -end - -- Record 1 sample of cache statistics. -- (Unlike record_data(), this does not return a function, but runs directly.) local function record_cache_stats() @@ -725,6 +751,7 @@ pages = { [o.key_page_1] = { f = default_stats, desc = "Default" }, [o.key_page_2] = { f = vo_stats, desc = "Extended Frame Timings" }, [o.key_page_3] = { f = cache_stats, desc = "Cache Statistics" }, + [o.key_page_4] = { f = perf_stats, desc = "Internal performance info" }, } |