From d34550930b208c1b24474a2a25b44fc44ab6dc0a Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 14 Jun 2019 20:14:42 +0200 Subject: stats.lua: add cache info page Uses page 3, which was apparently reserved for filter info. --- player/lua/stats.lua | 73 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 69 insertions(+), 4 deletions(-) diff --git a/player/lua/stats.lua b/player/lua/stats.lua index 45e1c3855b..81f5ab8774 100644 --- a/player/lua/stats.lua +++ b/player/lua/stats.lua @@ -595,10 +595,75 @@ local function vo_stats() return table.concat(stats) end +local function opt_time(t) + if type(t) == type(1.1) then + return mp.format_time(t) + end + return "?" +end + +-- Returns an ASS string with stats about the demuxer cache etc. +local function cache_stats() + local stats = {} + + add_header(stats) + append(stats, "", {prefix=o.nl .. o.nl .. "Cache info:", nl="", indent=""}) + + local info = mp.get_property_native("demuxer-cache-state") + if info == nil then + append(stats, "Unavailable.", {}) + return table.concat(stats) + end + + append(stats, opt_time(info["reader-pts"]) .. " - " .. + opt_time(info["cache-end"]), + {prefix = "Packet queue:"}) + + -- These states are not necessarily exclusive. They're about potentially + -- separate mechanisms, whose states may be decoupled. + local state = "reading" + local seek_ts = info["debug-seeking"] + if seek_ts ~= nil then + state = "seeking (to " .. mp.format_time(seek_ts) .. ")" + elseif info["eof"] == true then + state = "eof" + elseif info["underrun"] then + state = "underrun" + elseif info["idle"] == true then + state = "inactive" + end + append(stats, state, {prefix = "State:"}) + + append(stats, utils.format_bytes_humanized(info["total-bytes"]), + {prefix = "Total RAM:"}) + append(stats, utils.format_bytes_humanized(info["fw-bytes"]), + {prefix = "Forward RAM:"}) + + local fc = info["file-cache-bytes"] + if fc ~= nil then + fc = utils.format_bytes_humanized(fc) + else + fc = "(disabled)" + end + append(stats, fc, {prefix = "Disk cache:"}) + + append(stats, info["debug-low-level-seeks"], {prefix = "Media seeks:"}) + + append(stats, "", {prefix=o.nl .. o.nl .. "Ranges:", nl="", indent=""}) + + append(stats, info["bof-cached"] and "yes" or "no", + {prefix = "Start cached:"}) + append(stats, info["eof-cached"] and "yes" or "no", + {prefix = "End cached:"}) --- Returns an ASS string with stats about filters/profiles/shaders -local function filter_stats() - return "coming soon" + local ranges = info["seekable-ranges"] or {} + for n, r in ipairs(ranges) do + append(stats, mp.format_time(r["start"]) .. " - " .. + mp.format_time(r["end"]), + {prefix = format("Range %s:", n)}) + end + + return table.concat(stats) end @@ -607,7 +672,7 @@ curr_page = o.key_page_1 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 = filter_stats, desc = "Dummy" }, + [o.key_page_3] = { f = cache_stats, desc = "Cache Statistics" }, } -- cgit v1.2.3