summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2019-06-23 00:30:56 +0200
committerwm4 <wm4@nowhere>2019-09-19 20:37:05 +0200
commitf5d6edd4a271f4dd9c4dcbba69d67ec12ed3a87b (patch)
tree5b8641a44783593c288c23b9e68ad07f1e365eaf
parent9083bbda08f7e217b14f2117e20ca1d8f2142613 (diff)
downloadmpv-f5d6edd4a271f4dd9c4dcbba69d67ec12ed3a87b.tar.bz2
mpv-f5d6edd4a271f4dd9c4dcbba69d67ec12ed3a87b.tar.xz
stats.lua: add graphs for readahead time and total byte usage
The readahead time should be interesting for latency vs. underruns (which idiot protocols like HLS suffer from). The total byte usage is less interesting than I hoped; maybe the frequency at which it samples should be reduced. (Kind of dumb - you want high frequency for the readahead field, but much lower for byte usage.) Of course, the code was copy&pasted from the DS ratio/jitter stuff. Some of the choices may not make any sense for the new code.
-rw-r--r--player/lua/stats.lua64
1 files changed, 58 insertions, 6 deletions
diff --git a/player/lua/stats.lua b/player/lua/stats.lua
index 81f5ab8774..8df192db2a 100644
--- a/player/lua/stats.lua
+++ b/player/lua/stats.lua
@@ -83,6 +83,8 @@ local min = math.min
local recorder = nil
-- Timer used for redrawing (toggling) and clearing the screen (oneshot)
local display_timer = nil
+-- Timer used to update cache stats.
+local cache_recorder_timer = nil
-- Current page and <page key>:<page function> mappings
local curr_page = o.key_page_1
local pages = {}
@@ -92,10 +94,12 @@ local ass_stop = mp.get_property_osd("osd-ass-cc/1")
-- Ring buffers for the values used to construct a graph.
-- .pos denotes the current position, .len the buffer length
-- .max is the max value in the corresponding buffer
-local vsratio_buf, vsjitter_buf
+local vsratio_buf, vsjitter_buf, cache_ahead_buf, cache_total_buf
local function init_buffers()
vsratio_buf = {0, pos = 1, len = 50, max = 0}
vsjitter_buf = {0, pos = 1, len = 50, max = 0}
+ cache_ahead_buf = {0, pos = 1, len = 50, max = 0}
+ cache_total_buf = {0, pos = 1, len = 50, max = 0}
end
-- Save all properties known to this version of mpv
local property_list = {}
@@ -615,9 +619,24 @@ local function cache_stats()
return table.concat(stats)
end
- append(stats, opt_time(info["reader-pts"]) .. " - " ..
- opt_time(info["cache-end"]),
- {prefix = "Packet queue:"})
+ local a = info["reader-pts"]
+ local b = info["cache-end"]
+
+ append(stats, opt_time(a) .. " - " .. opt_time(b), {prefix = "Packet queue:"})
+
+ local r = nil
+ if (a ~= nil) and (b ~= nil) then
+ r = b - a
+ end
+
+ local r_graph = nil
+ if not display_timer.oneshot and o.use_ass then
+ r_graph = generate_graph(cache_ahead_buf, cache_ahead_buf.pos,
+ cache_ahead_buf.len, cache_ahead_buf.max,
+ nil, 0.8, 1)
+ r_graph = o.prefix_sep .. r_graph
+ end
+ append(stats, opt_time(r), {prefix = "Read-ahead:", suffix = r_graph})
-- These states are not necessarily exclusive. They're about potentially
-- separate mechanisms, whose states may be decoupled.
@@ -634,8 +653,15 @@ local function cache_stats()
end
append(stats, state, {prefix = "State:"})
+ local total_graph = nil
+ if not display_timer.oneshot and o.use_ass then
+ total_graph = generate_graph(cache_total_buf, cache_total_buf.pos,
+ cache_total_buf.len, cache_total_buf.max,
+ nil, 0.8, 1)
+ total_graph = o.prefix_sep .. total_graph
+ end
append(stats, utils.format_bytes_humanized(info["total-bytes"]),
- {prefix = "Total RAM:"})
+ {prefix = "Total RAM:", suffix = total_graph})
append(stats, utils.format_bytes_humanized(info["fw-bytes"]),
{prefix = "Forward RAM:"})
@@ -666,6 +692,31 @@ 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()
+ local info = mp.get_property_native("demuxer-cache-state")
+ if info == nil then
+ return
+ end
+
+ local a = info["reader-pts"]
+ local b = info["cache-end"]
+ if (a ~= nil) and (b ~= nil) then
+ graph_add_value(cache_ahead_buf, b - a)
+ end
+
+ graph_add_value(cache_total_buf, info["total-bytes"])
+end
+
+cache_recorder_timer = mp.add_periodic_timer(0.25, record_cache_stats)
+cache_recorder_timer:kill()
-- Current page and <page key>:<page function> mapping
curr_page = o.key_page_1
@@ -709,7 +760,6 @@ local function record_data(skip)
end
end
-
-- Call the function for `page` and print it to OSD
local function print_page(page)
if o.persistent_overlay then
@@ -759,6 +809,7 @@ local function process_key_binding(oneshot)
-- Previous and current keys were toggling -> end toggling
elseif not display_timer.oneshot and not oneshot then
display_timer:kill()
+ cache_recorder_timer:stop()
clear_screen()
remove_page_bindings()
if recorder then
@@ -771,6 +822,7 @@ local function process_key_binding(oneshot)
if not oneshot and (o.plot_vsync_jitter or o.plot_vsync_ratio) then
recorder = record_data(o.skip_frames)
mp.register_event("tick", recorder)
+ cache_recorder_timer:resume()
end
display_timer:kill()
display_timer.oneshot = oneshot