stats: support UP/DOWN to scroll at page 4 (perf)

Keys and lines-to-scroll are configurabe, and the scroll keys are only
bound on pages which support scrolling (currently only page 4) - also
during oneshot (like the page-switching keys).

Scroll offset is reset for all pages on any key - except scroll keys, so
that entering or switching to a page resets the scroll, as well as when
"re-entering" the same page or "re-activating" the stats oneshot view.

TODO: print_page(..) is highly associated with extending the oneshot
timer if required. The timer handling can probably move into print_page
and removed from all the places which boilerplate its management.
This commit is contained in:
Avi Halachmi (:avih) 2020-04-11 01:20:02 +03:00
parent b4c1554f7a
commit 530a0863b8
2 changed files with 86 additions and 14 deletions

View File

@ -24,7 +24,14 @@ stats:
1 Show usual stats 1 Show usual stats
2 Show frame timings 2 Show frame timings
3 Input cache stats 3 Input cache stats
4 Internal stuff 4 Internal stuff (scroll)
==== ==================
On pages which support scroll, these key bindings are also active:
==== ==================
UP Scroll one line up
DOWN Scroll one line down
==== ================== ==== ==================
Font Font
@ -62,6 +69,15 @@ Configurable Options
Key bindings for page switching while stats are displayed. Key bindings for page switching while stats are displayed.
``key_scroll_up``
Default: UP
``key_scroll_down``
Default: DOWN
``scroll_lines``
Default: 1
Scroll key bindings and number of lines to scroll on pages which support it.
``duration`` ``duration``
Default: 4 Default: 4
@ -183,7 +199,7 @@ The displayed information is accumulated over the redraw delay (shown as
``poll-time`` field). ``poll-time`` field).
This adds entries for each Lua script. If there are too many scripts running, This adds entries for each Lua script. If there are too many scripts running,
parts of the list will simply be out of the screen. parts of the list will simply be out of the screen, but it can be scrolled.
If the underlying platform does not support pthread per thread times, the If the underlying platform does not support pthread per thread times, the
displayed times will be 0 or something random (I suspect that at time of this displayed times will be 0 or something random (I suspect that at time of this

View File

@ -19,6 +19,10 @@ local o = {
key_page_2 = "2", key_page_2 = "2",
key_page_3 = "3", key_page_3 = "3",
key_page_4 = "4", key_page_4 = "4",
-- For pages which support scrolling
key_scroll_up = "UP",
key_scroll_down = "DOWN",
scroll_lines = 1,
duration = 4, duration = 4,
redraw_delay = 1, -- acts as duration in the toggling case redraw_delay = 1, -- acts as duration in the toggling case
@ -89,6 +93,7 @@ local cache_recorder_timer = nil
-- Current page and <page key>:<page function> mappings -- Current page and <page key>:<page function> mappings
local curr_page = o.key_page_1 local curr_page = o.key_page_1
local pages = {} local pages = {}
local scroll_bound = false
-- Save these sequences locally as we'll need them a lot -- Save these sequences locally as we'll need them a lot
local ass_start = mp.get_property_osd("osd-ass-cc/0") local ass_start = mp.get_property_osd("osd-ass-cc/0")
local ass_stop = mp.get_property_osd("osd-ass-cc/1") local ass_stop = mp.get_property_osd("osd-ass-cc/1")
@ -353,9 +358,19 @@ local function append_perfdata(s, dedicated_page)
end end
end end
local function append_general_perfdata(s) local function append_general_perfdata(s, offset)
for _, data in ipairs(mp.get_property_native("perf-info") or {}) do local perf_info = mp.get_property_native("perf-info") or {}
append(s, data.text or data.value, {prefix=data.name..":"}) local count = 0
for _, data in ipairs(perf_info) do
count = count + 1
end
offset = max(1, min((offset or 1), count))
local i = 0
for _, data in ipairs(perf_info) do
i = i + 1
if i >= offset then
append(s, data.text or data.value, {prefix="["..tostring(i).."] "..data.name..":"})
if o.plot_perfdata and o.use_ass and data.value then if o.plot_perfdata and o.use_ass and data.value then
buf = perf_buffers[data.name] buf = perf_buffers[data.name]
@ -368,6 +383,8 @@ local function append_general_perfdata(s)
end end
end end
end end
return offset
end
local function append_display_sync(s) local function append_display_sync(s)
if not mp.get_property_bool("display-sync-active", false) then if not mp.get_property_bool("display-sync-active", false) then
@ -621,7 +638,7 @@ local function perf_stats()
add_header(stats) add_header(stats)
local page = pages[o.key_page_4] local page = pages[o.key_page_4]
append(stats, "", {prefix=o.nl .. o.nl .. page.desc .. ":", nl="", indent=""}) append(stats, "", {prefix=o.nl .. o.nl .. page.desc .. ":", nl="", indent=""})
append_general_perfdata(stats, true) page.offset = append_general_perfdata(stats, page.offset)
return table.concat(stats) return table.concat(stats)
end end
@ -750,7 +767,7 @@ pages = {
[o.key_page_1] = { f = default_stats, desc = "Default" }, [o.key_page_1] = { f = default_stats, desc = "Default" },
[o.key_page_2] = { f = vo_stats, desc = "Extended Frame Timings" }, [o.key_page_2] = { f = vo_stats, desc = "Extended Frame Timings" },
[o.key_page_3] = { f = cache_stats, desc = "Cache Statistics" }, [o.key_page_3] = { f = cache_stats, desc = "Cache Statistics" },
[o.key_page_4] = { f = perf_stats, desc = "Internal performance info" }, [o.key_page_4] = { f = perf_stats, desc = "Internal performance info", scroll = true },
} }
@ -801,11 +818,47 @@ local function clear_screen()
if o.persistent_overlay then mp.set_osd_ass(0, 0, "") else mp.osd_message("", 0) end if o.persistent_overlay then mp.set_osd_ass(0, 0, "") else mp.osd_message("", 0) end
end end
local function scroll_delta(d)
if display_timer.oneshot then display_timer:kill() ; display_timer:resume() end
pages[curr_page].offset = (pages[curr_page].offset or 1) + d
print_page(curr_page)
end
local function scroll_up() scroll_delta(-o.scroll_lines) end
local function scroll_down() scroll_delta(o.scroll_lines) end
local function reset_scroll_offsets()
for _, page in pairs(pages) do
page.offset = nil
end
end
local function bind_scroll()
if not scroll_bound then
mp.add_forced_key_binding(o.key_scroll_up, o.key_scroll_up, scroll_up, {repeatable=true})
mp.add_forced_key_binding(o.key_scroll_down, o.key_scroll_down, scroll_down, {repeatable=true})
scroll_bound = true
end
end
local function unbind_scroll()
if scroll_bound then
mp.remove_key_binding(o.key_scroll_up)
mp.remove_key_binding(o.key_scroll_down)
scroll_bound = false
end
end
local function update_scroll_bindings(k)
if (pages[k].scroll) then
bind_scroll()
else
unbind_scroll()
end
end
-- Add keybindings for every page -- Add keybindings for every page
local function add_page_bindings() local function add_page_bindings()
local function a(k) local function a(k)
return function() return function()
reset_scroll_offsets()
update_scroll_bindings(k)
curr_page = k curr_page = k
print_page(k) print_page(k)
if display_timer.oneshot then display_timer:kill() ; display_timer:resume() end if display_timer.oneshot then display_timer:kill() ; display_timer:resume() end
@ -814,6 +867,7 @@ local function add_page_bindings()
for k, _ in pairs(pages) do for k, _ in pairs(pages) do
mp.add_forced_key_binding(k, k, a(k), {repeatable=true}) mp.add_forced_key_binding(k, k, a(k), {repeatable=true})
end end
update_scroll_bindings(curr_page)
end end
@ -822,10 +876,12 @@ local function remove_page_bindings()
for k, _ in pairs(pages) do for k, _ in pairs(pages) do
mp.remove_key_binding(k) mp.remove_key_binding(k)
end end
unbind_scroll()
end end
local function process_key_binding(oneshot) local function process_key_binding(oneshot)
reset_scroll_offsets()
-- Stats are already being displayed -- Stats are already being displayed
if display_timer:is_enabled() then if display_timer:is_enabled() then
-- Previous and current keys were oneshot -> restart timer -- Previous and current keys were oneshot -> restart timer