TOOLS/stats-conv: better output

Sort the legend by the used y value of binary events/signals, add a way
to filter branches (although that requires editing the script), and use
the full screen if the second subplot is not used.
This commit is contained in:
wm4 2015-01-02 19:26:31 +01:00
parent 43faae7a1e
commit 83349a0e73
1 changed files with 20 additions and 11 deletions

View File

@ -1,9 +1,12 @@
#!/usr/bin/env python3
import matplotlib.pyplot as plot
import sys
import re
filename = sys.argv[1]
event_regex = re.compile(".*")
"""
This script is meant to display stats written by mpv --dump-stats=filename.
In general, each line in that file is an event of the form:
@ -28,7 +31,6 @@ Currently, the following event types are supported:
class G:
events = {}
sevents = [] # events, deterministically sorted
start = None
# http://matplotlib.org/api/markers_api.html#module-matplotlib.markers
markers = ["o", "8", "s", "p", "*", "h", "+", "x", "D"]
@ -46,16 +48,15 @@ class Event:
def get_event(event, evtype):
if event not in G.events:
e = Event()
G.events[event] = e
e.name = event
e.vals = []
e.type = evtype
e.marker = "o"
e.numid = len(G.events)
G.sevents = list(G.events.values())
G.sevents.sort(key=lambda x: x.name)
if e.type == "event-signal":
e.marker = find_marker()
if not event_regex.match(e.name):
return e
G.events[event] = e
return G.events[event]
for line in [line.split("#")[0].strip() for line in open(filename, "r")]:
@ -89,21 +90,29 @@ for line in [line.split("#")[0].strip() for line in open(filename, "r")]:
e = get_event(event, "event-signal")
e.vals.append((ts, 1))
for e in G.sevents:
e.vals = [(x, y * e.numid / len(G.events)) for (x, y) in e.vals]
# deterministically sort them; make sure the legend is sorted too
G.sevents = list(G.events.values())
G.sevents.sort(key=lambda x: x.name)
hasval = False
for e, index in zip(G.sevents, range(len(G.sevents))):
m = len(G.sevents)
e.vals = [(x, y * (m - index) / m) for (x, y) in e.vals]
if e.type == "value":
hasval = True
plot.hold(True)
mainpl = plot.subplot(2, 1, 1)
plots = 2 if hasval else 1
mainpl = plot.subplot(plots, 1, 1)
legend = []
for e in G.sevents:
if e.type == "value":
plot.subplot(2, 1, 2, sharex=mainpl)
plot.subplot(plots, 1, 2, sharex=mainpl)
else:
plot.subplot(2, 1, 1)
plot.subplot(plots, 1, 1)
pl, = plot.plot([x for x,y in e.vals], [y for x,y in e.vals], label=e.name)
if e.type == "event-signal":
plot.setp(pl, marker = e.marker, linestyle = "None")
legend.append(pl)
plot.subplot(2, 1, 1)
plot.subplot(plots, 1, 1)
plot.legend(legend, [pl.get_label() for pl in legend])
plot.show()