1
0
mirror of https://github.com/mpv-player/mpv synced 2025-03-31 07:51:55 +00:00

stats: align graphs

Graphs are now aligned. This required a change in the layout of
performance data. Reason is a wrong (but intended) calculation
of vector drawing sizes in libass to maintain compatibility.
This essentially prevents text following the graph.
To achieve alignment only monospaced text can precede the graph.
This led to the layout changing slightly when graphs are shown.
This commit is contained in:
Julian 2016-07-13 00:46:40 +09:00 committed by wm4
parent 946d45a421
commit 5e0d36c515

View File

@ -6,6 +6,7 @@
-- Please note: not every property is always available and therefore not always -- Please note: not every property is always available and therefore not always
-- visible. -- visible.
local mp = require 'mp'
local options = require 'mp.options' local options = require 'mp.options'
-- Options -- Options
@ -15,22 +16,25 @@ local o = {
key_toggle = "I", key_toggle = "I",
duration = 3, duration = 3,
redraw_delay = 1, -- acts as duration in the toggling case redraw_delay = 1, -- acts as duration in the toggling case
timing_warning = true,
ass_formatting = true, ass_formatting = true,
debug = false, debug = false,
-- Graph options and style -- Graph options and style
skip_frames = 5,
plot_graphs = true, plot_graphs = true,
skip_frames = 5,
global_max = true,
plot_bg_border_color = "0000FF", plot_bg_border_color = "0000FF",
plot_bg_color = "262626", plot_bg_color = "262626",
plot_color = "FFFFFF", plot_color = "FFFFFF",
-- Text style -- Text style
font = "Source Sans Pro", font = "Source Sans Pro",
font_mono = "Source Sans Pro", -- monospaced digits are sufficient
font_size = 9, font_size = 9,
font_color = "FFFFFF", font_color = "FFFFFF",
border_size = 1.0, border_size = 0.8,
border_color = "262626", border_color = "262626",
shadow_x_offset = 0.0, shadow_x_offset = 0.0,
shadow_y_offset = 0.0, shadow_y_offset = 0.0,
@ -59,8 +63,8 @@ local o = {
options.read_options(o) options.read_options(o)
local format = string.format local format = string.format
local plast = {{}, {}, {}} local plast = {{0}, {0}, {0}}
local ppos = 0 local ppos = 1
local plen = 50 local plen = 50
local recorder = nil local recorder = nil
local timer = mp.add_periodic_timer(o.redraw_delay, function() print_stats(o.redraw_delay + 1) end) local timer = mp.add_periodic_timer(o.redraw_delay, function() print_stats(o.redraw_delay + 1) end)
@ -245,34 +249,27 @@ function append_property(s, prop, attr, excluded)
end end
function generate_graph(values) function generate_graph(values, v_max, scale)
-- check if at least one value was recorded yet -- check if at least one value was recorded yet
if ppos < 1 then if ppos < 1 then
return "" return ""
end end
local pmax = 1
for e = 1, plen do
if values[e] and values[e] > pmax then
pmax = values[e]
end
end
local x_tics = 1 local x_tics = 1
local x_max = (plen - 1) * x_tics local x_max = (plen - 1) * x_tics
local y_offset = o.border_size local y_offset = o.border_size
local y_max = o.font_size / 1.5 local y_max = o.font_size * 0.66
local x = 0 local x = 0
local i = ppos local i = ppos
local s = {format("m 0 0 n %f %f l ", x, y_max - (y_max * values[i] / pmax * 0.8))} local s = {format("m 0 0 n %f %f l ", x, y_max - (y_max * values[i] / v_max * scale))}
i = ((i - 2) % plen) + 1 i = ((i - 2) % plen) + 1
while i ~= ppos do for p = 1, plen - 1 do
if values[i] then if values[i] then
x = x - x_tics x = x - x_tics
s[#s+1] = format("%f %f ", x, y_max - (y_max * values[i] / pmax * 0.8)) s[#s+1] = format("%f %f ", x, y_max - (y_max * values[i] / v_max * scale))
end end
i = ((i - 2) % plen) + 1 i = ((i - 2) % plen) + 1
end end
@ -315,16 +312,6 @@ function append_perfdata(s)
return return
end end
local graph_render = ""
local graph_present = ""
local graph_upload = ""
if o.plot_graphs and timer:is_enabled() then
graph_render = generate_graph(plast[1])
graph_present = generate_graph(plast[2])
graph_upload = generate_graph(plast[3])
end
local dfps = mp.get_property_number("display-fps", 0) local dfps = mp.get_property_number("display-fps", 0)
dfps = dfps > 0 and (1 / dfps * 1e6) dfps = dfps > 0 and (1 / dfps * 1e6)
@ -333,23 +320,57 @@ function append_perfdata(s)
local peak_s = vo_p["render-peak"] + vo_p["present-peak"] + vo_p["upload-peak"] local peak_s = vo_p["render-peak"] + vo_p["present-peak"] + vo_p["upload-peak"]
-- highlight i with a red border when t exceeds the time for one frame -- highlight i with a red border when t exceeds the time for one frame
function hl(i, t) local function hl(i, t)
if t > dfps and dfps > 0 then if o.timing_warning and t > dfps and dfps > 0 then
return format("{\\bord0.5}{\\3c&H0000FF&}%s{\\bord%s}{\\3c&H%s&}", return format("{\\bord0.5}{\\3c&H0000FF&}%05d{\\bord%s}{\\3c&H%s&}",
i, o.border_size, o.border_color) i, o.border_size, o.border_color)
end end
return i return format("%05d", i)
end end
s[#s+1] = format("%s%s%s%s%s / %s / %s μs %s", o.nl, o.indent, b("Render Time:"),
o.prefix_sep, hl(vo_p["render-last"], last_s), hl(vo_p["render-avg"], avg_s), local rsuffix, psuffix, usuffix
hl(vo_p["render-peak"], peak_s), graph_render)
s[#s+1] = format("%s%s%s%s%s / %s / %s μs %s", o.nl, o.indent, b("Present Time:"), if o.plot_graphs and timer:is_enabled() then
o.prefix_sep, hl(vo_p["present-last"], last_s), hl(vo_p["present-avg"], avg_s), local max = {1, 1, 1}
hl(vo_p["present-peak"], peak_s), graph_present) for e = 1, plen do
s[#s+1] = format("%s%s%s%s%s / %s / %s μs %s", o.nl, o.indent, b("Upload Time:"), if plast[1][e] and plast[1][e] > max[1] then max[1] = plast[1][e] end
o.prefix_sep, hl(vo_p["upload-last"], last_s), hl(vo_p["upload-avg"], avg_s), if plast[2][e] and plast[2][e] > max[2] then max[2] = plast[2][e] end
hl(vo_p["upload-peak"], peak_s), graph_upload) if plast[3][e] and plast[3][e] > max[3] then max[3] = plast[3][e] end
end
if o.global_max then
max[1] = math.max(max[1], max[2], max[3])
max[2], max[3] = max[1], max[1]
end
rsuffix = generate_graph(plast[1], max[1], 0.8)
psuffix = generate_graph(plast[2], max[2], 0.8)
usuffix = generate_graph(plast[3], max[3], 0.8)
s[#s+1] = format("%s%s%s%s{\\fs%s}%s%s%s{\\fs%s}", o.nl, o.indent,
b("Timings:"), o.prefix_sep, o.font_size * 0.66,
"Render ⏎ Present ⏎ Upload", o.prefix_sep,
"(last/average/peak μs)", o.font_size)
else
rsuffix = "Render"
psuffix = "Present"
usuffix = "Upload"
s[#s+1] = format("%s%s%s%s{\\fs%s}%s{\\fs%s}", o.nl, o.indent,
b("Timings:"), o.prefix_sep, o.font_size * 0.66,
"(last/average/peak μs)", o.font_size)
end
local f = "%s%s%s{\\fn%s}%s / %s / %s{\\fn%s}%s%s"
s[#s+1] = format(f, o.nl, o.indent, o.indent, o.font_mono,
hl(vo_p["render-last"], last_s), hl(vo_p["render-avg"], avg_s),
hl(vo_p["render-peak"], peak_s), o.font, o.prefix_sep, rsuffix)
s[#s+1] = format(f, o.nl, o.indent, o.indent, o.font_mono,
hl(vo_p["present-last"], last_s), hl(vo_p["present-avg"], avg_s),
hl(vo_p["present-peak"], peak_s), o.font, o.prefix_sep, psuffix)
s[#s+1] = format(f, o.nl, o.indent, o.indent, o.font_mono,
hl(vo_p["upload-last"], last_s), hl(vo_p["upload-avg"], avg_s),
hl(vo_p["upload-peak"], peak_s), o.font, o.prefix_sep, usuffix)
end end
@ -416,9 +437,9 @@ end
if not pcall(function() timer:is_enabled() end) then if not pcall(function() timer:is_enabled() end) then
local txt = "Stats.lua: your version of mpv does not possess required functionality. \nPlease upgrade mpv." local txt = "Stats.lua: your version of mpv does not possess required functionality. \nPlease upgrade mpv or use an older version of this script."
print(txt) print(txt)
mp.osd_message(txt, 12) mp.osd_message(txt, 15)
return return
end end
@ -434,5 +455,3 @@ mp.register_event("video-reconfig",
print_stats(o.redraw_delay + 1) print_stats(o.redraw_delay + 1)
end end
end) end)
print("test")