diff options
author | Julian <MyFakeAcc.4@googlemail.com> | 2017-12-26 17:54:03 +0100 |
---|---|---|
committer | Martin Herkt <652892+lachs0r@users.noreply.github.com> | 2017-12-26 18:40:43 +0100 |
commit | 882d8ece57aa683d6908f5f9b9cf42e817bb7b9f (patch) | |
tree | adf55e1a843a4938431826cf60d872f388e346ef /player | |
parent | a4eda0c9844586c10e3804f4a8e5e809aebb6569 (diff) | |
download | mpv-882d8ece57aa683d6908f5f9b9cf42e817bb7b9f.tar.bz2 mpv-882d8ece57aa683d6908f5f9b9cf42e817bb7b9f.tar.xz |
stats: enhance cache stats
Show total cache as well as demuxer cache separately.
This adjusts the presented values to be consistent with status line
and OSC modifications made in https://github.com/mpv-player/mpv/pull/5250
Diffstat (limited to 'player')
-rw-r--r-- | player/lua/stats.lua | 54 |
1 files changed, 35 insertions, 19 deletions
diff --git a/player/lua/stats.lua b/player/lua/stats.lua index bdc3338082..cfb9b0881f 100644 --- a/player/lua/stats.lua +++ b/player/lua/stats.lua @@ -8,6 +8,7 @@ local mp = require 'mp' local options = require 'mp.options' +local utils = require 'mp.utils' -- Options local o = { @@ -232,6 +233,19 @@ local function generate_graph(values, i, len, v_max, v_avg, scale, x_tics) end +local function append(s, str, attr) + attr.prefix_sep = attr.prefix_sep or o.prefix_sep + attr.indent = attr.indent or o.indent + attr.nl = attr.nl or o.nl + attr.suffix = attr.suffix or "" + attr.prefix = attr.prefix or "" + attr.no_prefix_markup = attr.no_prefix_markup or false + attr.prefix = attr.no_prefix_markup and attr.prefix or b(attr.prefix) + s[#s+1] = format("%s%s%s%s%s%s", attr.nl, attr.indent, + attr.prefix, attr.prefix_sep, no_ASS(str), attr.suffix) +end + + -- Format and append a property. -- A property whose value is either `nil` or empty (hereafter called "invalid") -- is skipped and not appended. @@ -253,18 +267,7 @@ local function append_property(s, prop, attr, excluded) end return false end - - attr.prefix_sep = attr.prefix_sep or o.prefix_sep - attr.indent = attr.indent or o.indent - attr.nl = attr.nl or o.nl - attr.suffix = attr.suffix or "" - attr.prefix = attr.prefix or "" - attr.no_prefix_markup = attr.no_prefix_markup or false - attr.prefix = attr.no_prefix_markup and attr.prefix or b(attr.prefix) - ret = attr.no_value and "" or ret - - s[#s+1] = format("%s%s%s%s%s%s", attr.nl, attr.indent, - attr.prefix, attr.prefix_sep, no_ASS(ret), attr.suffix) + append(s, ret, attr) return true end @@ -442,13 +445,26 @@ local function add_file(s) {prefix="(" .. tostring(ch_index + 1) .. "/", suffix=")", nl="", indent=" ", prefix_sep=" ", no_prefix_markup=true}) end - if append_property(s, "cache-used", {prefix="Cache:"}) then - append_property(s, "demuxer-cache-duration", - {prefix="+", suffix=" sec", nl="", indent=o.prefix_sep, - prefix_sep="", no_prefix_markup=true}) - append_property(s, "cache-speed", - {prefix="", suffix="", nl="", indent=o.prefix_sep, - prefix_sep="", no_prefix_markup=true}) + + local demuxer_cache = mp.get_property_native("demuxer-cache-state", {}) + if demuxer_cache["fw-bytes"] then + demuxer_cache = demuxer_cache["fw-bytes"] -- returns bytes + else + demuxer_cache = 0 + end + local demuxer_secs = mp.get_property_number("demuxer-cache-duration", 0) + local stream_cache = mp.get_property_number("cache-used", 0) * 1024 -- returns KiB + if stream_cache + demuxer_cache + demuxer_secs > 0 then + append(s, utils.format_bytes_humanized(stream_cache + demuxer_cache), {prefix="Total Cache:"}) + append(s, utils.format_bytes_humanized(demuxer_cache), {prefix="(Demuxer:", + suffix=",", nl="", no_prefix_markup=true, indent=o.prefix_sep}) + append(s, format("%.1f", demuxer_secs), {suffix=" sec)", nl="", indent="", + no_prefix_markup=true}) + local speed = mp.get_property_number("cache-speed", 0) + if speed > 0 then + append(s, utils.format_bytes_humanized(speed) .. "/s", {prefix="Speed:", nl="", + indent=o.prefix_sep, no_prefix_markup=true}) + end end append_property(s, "file-size", {prefix="Size:"}) end |