diff options
Diffstat (limited to 'player')
-rw-r--r-- | player/command.c | 19 | ||||
-rw-r--r-- | player/loadfile.c | 4 | ||||
-rw-r--r-- | player/lua.c | 33 | ||||
-rw-r--r-- | player/lua/stats.lua | 39 | ||||
-rw-r--r-- | player/main.c | 3 |
5 files changed, 91 insertions, 7 deletions
diff --git a/player/command.c b/player/command.c index e1f755d46c..a41a636c7d 100644 --- a/player/command.c +++ b/player/command.c @@ -38,6 +38,7 @@ #include "common/codecs.h" #include "common/msg.h" #include "common/msg_control.h" +#include "common/stats.h" #include "filters/f_decoder_wrapper.h" #include "command.h" #include "osdep/timer.h" @@ -2446,6 +2447,23 @@ out: return ret; } +static int mp_property_perf_info(void *ctx, struct m_property *p, int action, + void *arg) +{ + MPContext *mpctx = ctx; + + switch (action) { + case M_PROPERTY_GET_TYPE: + *(struct m_option *)arg = (struct m_option){.type = CONF_TYPE_NODE}; + return M_PROPERTY_OK; + case M_PROPERTY_GET: { + stats_global_query(mpctx->global, (struct mpv_node *)arg); + return M_PROPERTY_OK; + } + } + return M_PROPERTY_NOT_IMPLEMENTED; +} + static int mp_property_vo(void *ctx, struct m_property *p, int action, void *arg) { MPContext *mpctx = ctx; @@ -3425,6 +3443,7 @@ static const struct m_property mp_properties_base[] = { {"current-window-scale", mp_property_current_window_scale}, {"vo-configured", mp_property_vo_configured}, {"vo-passes", mp_property_vo_passes}, + {"perf-info", mp_property_perf_info}, {"current-vo", mp_property_vo}, {"container-fps", mp_property_fps}, {"estimated-vf-fps", mp_property_vf_fps}, diff --git a/player/loadfile.c b/player/loadfile.c index 9efacea766..6af9ac37fd 100644 --- a/player/loadfile.c +++ b/player/loadfile.c @@ -46,6 +46,7 @@ #include "common/common.h" #include "common/encode.h" #include "common/recorder.h" +#include "common/stats.h" #include "input/input.h" #include "audio/out/ao.h" @@ -1772,6 +1773,9 @@ struct playlist_entry *mp_next_file(struct MPContext *mpctx, int direction, // Return if all done. void mp_play_files(struct MPContext *mpctx) { + struct stats_ctx *stats = stats_ctx_create(mpctx, mpctx->global, "main"); + stats_register_thread_cputime(stats, "thread"); + // Wait for all scripts to load before possibly starting playback. if (!mp_clients_all_initialized(mpctx)) { MP_VERBOSE(mpctx, "Waiting for scripts...\n"); diff --git a/player/lua.c b/player/lua.c index c816118b8b..0c5a56ec14 100644 --- a/player/lua.c +++ b/player/lua.c @@ -36,6 +36,7 @@ #include "options/m_property.h" #include "common/msg.h" #include "common/msg_control.h" +#include "common/stats.h" #include "options/m_option.h" #include "input/input.h" #include "options/path.h" @@ -88,6 +89,8 @@ struct script_ctx { struct mp_log *log; struct mpv_handle *client; struct MPContext *mpctx; + size_t lua_malloc_size; + struct stats_ctx *stats; }; #if LUA_VERSION_NUM <= 501 @@ -156,6 +159,30 @@ static void steal_node_alloctions(void *tmp, mpv_node *node) talloc_steal(tmp, node_get_alloc(node)); } +// lua_Alloc compatible. Serves only to retrieve memory usage. +static void *mp_lua_alloc(void *ud, void *ptr, size_t osize, size_t nsize) +{ + struct script_ctx *ctx = ud; + + // Ah, what the fuck, screw whoever introduced this to Lua 5.2. + if (!ptr) + osize = 0; + + if (nsize) { + ptr = realloc(ptr, nsize); + if (!ptr) + return NULL; + } else { + free(ptr); + ptr = NULL; + } + + ctx->lua_malloc_size = ctx->lua_malloc_size - osize + nsize; + stats_size_value(ctx->stats, "mem", ctx->lua_malloc_size); + + return ptr; +} + static struct script_ctx *get_ctx(lua_State *L) { lua_getfield(L, LUA_REGISTRYINDEX, "ctx"); @@ -396,14 +423,18 @@ static int load_lua(struct mp_script_args *args) .log = args->log, .filename = args->filename, .path = args->path, + .stats = stats_ctx_create(ctx, args->mpctx->global, + mp_tprintf(80, "script/%s", mpv_client_name(args->client))), }; + stats_register_thread_cputime(ctx->stats, "cpu"); + if (LUA_VERSION_NUM != 501 && LUA_VERSION_NUM != 502) { MP_FATAL(ctx, "Only Lua 5.1 and 5.2 are supported.\n"); goto error_out; } - lua_State *L = ctx->state = luaL_newstate(); + lua_State *L = ctx->state = lua_newstate(mp_lua_alloc, ctx); if (!L) { MP_FATAL(ctx, "Could not initialize Lua.\n"); goto error_out; diff --git a/player/lua/stats.lua b/player/lua/stats.lua index 98bc1be7c9..93c2c99c18 100644 --- a/player/lua/stats.lua +++ b/player/lua/stats.lua @@ -18,6 +18,7 @@ local o = { key_page_1 = "1", key_page_2 = "2", key_page_3 = "3", + key_page_4 = "4", duration = 4, redraw_delay = 1, -- acts as duration in the toggling case @@ -101,6 +102,7 @@ local function init_buffers() cache_ahead_buf = {0, pos = 1, len = 50, max = 0} cache_speed_buf = {0, pos = 1, len = 50, max = 0} end +local perf_buffers = {} -- Save all properties known to this version of mpv local property_list = {} for p in string.gmatch(mp.get_property("property-list"), "([^,]+)") do property_list[p] = true end @@ -111,6 +113,11 @@ local property_aliases = { ["container-fps"] = "fps", } +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 -- Return deprecated name for the given property local function compat(p) @@ -347,6 +354,21 @@ local function append_perfdata(s, dedicated_page) end end +local function append_general_perfdata(s) + for _, data in ipairs(mp.get_property_native("perf-info") or {}) do + append(s, data.text or data.value, {prefix=data.name..":"}) + + if o.plot_perfdata and o.use_ass and data.value then + buf = perf_buffers[data.name] + if not buf then + buf = {0, pos = 1, len = 50, max = 0} + perf_buffers[data.name] = buf + end + graph_add_value(buf, data.value) + s[#s+1] = generate_graph(buf, buf.pos, buf.len, buf.max, nil, 0.8, 1) + end + end +end local function append_display_sync(s) if not mp.get_property_bool("display-sync-active", false) then @@ -594,6 +616,16 @@ local function vo_stats() return table.concat(stats) end +local function perf_stats() + local stats = {} + eval_ass_formatting() + add_header(stats) + local page = pages[o.key_page_4] + append(stats, "", {prefix=o.nl .. o.nl .. page.desc .. ":", nl="", indent=""}) + append_general_perfdata(stats, true) + return table.concat(stats) +end + local function opt_time(t) if type(t) == type(1.1) then return mp.format_time(t) @@ -693,12 +725,6 @@ 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() @@ -725,6 +751,7 @@ 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 = cache_stats, desc = "Cache Statistics" }, + [o.key_page_4] = { f = perf_stats, desc = "Internal performance info" }, } diff --git a/player/main.c b/player/main.c index b0150b2b80..b5695a663a 100644 --- a/player/main.c +++ b/player/main.c @@ -43,6 +43,7 @@ #include "common/common.h" #include "common/msg.h" #include "common/msg_control.h" +#include "common/stats.h" #include "common/global.h" #include "filters/f_decoder_wrapper.h" #include "options/parse_configfile.h" @@ -275,6 +276,8 @@ struct MPContext *mp_create(void) mpctx->global = talloc_zero(mpctx, struct mpv_global); + stats_global_init(mpctx->global); + // Nothing must call mp_msg*() and related before this mp_msg_init(mpctx->global); mpctx->log = mp_log_new(mpctx, mpctx->global->log, "!cplayer"); |