summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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