2014-04-17 19:47:00 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import matplotlib.pyplot as plot
|
|
|
|
import sys
|
2015-01-02 18:26:31 +00:00
|
|
|
import re
|
2014-04-17 19:47:00 +00:00
|
|
|
|
|
|
|
filename = sys.argv[1]
|
|
|
|
|
2015-01-02 18:26:31 +00:00
|
|
|
event_regex = re.compile(".*")
|
|
|
|
|
2014-04-17 19:47:00 +00:00
|
|
|
"""
|
|
|
|
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:
|
|
|
|
|
|
|
|
<timestamp in microseconds> <text> '#' <comment>
|
|
|
|
|
|
|
|
e.g.:
|
|
|
|
|
|
|
|
10474959 start flip #cplayer
|
|
|
|
|
|
|
|
<text> is what MP_STATS(log, "...") writes. The rest is added by msg.c.
|
|
|
|
|
|
|
|
Currently, the following event types are supported:
|
|
|
|
|
2015-01-03 01:57:33 +00:00
|
|
|
'signal' <name> singular event
|
2014-08-19 18:09:46 +00:00
|
|
|
'start' <name> start of the named event
|
|
|
|
'end' <name> end of the named event
|
|
|
|
'value' <float> <name> a normal value (as opposed to event)
|
|
|
|
'event-timed' <ts> <name> singular event at the given timestamp
|
2015-05-11 15:20:30 +00:00
|
|
|
'value-timed' <ts> <float> <name> a value for an event at the given timestamp
|
|
|
|
'range-timed' <ts1> <ts2> <name> like start/end, but explicit times
|
2015-01-03 01:57:33 +00:00
|
|
|
<name> singular event (same as 'signal')
|
2014-04-17 19:47:00 +00:00
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
class G:
|
|
|
|
events = {}
|
|
|
|
start = None
|
2014-08-19 18:09:46 +00:00
|
|
|
# http://matplotlib.org/api/markers_api.html#module-matplotlib.markers
|
|
|
|
markers = ["o", "8", "s", "p", "*", "h", "+", "x", "D"]
|
|
|
|
|
|
|
|
def find_marker():
|
|
|
|
if len(G.markers) == 0:
|
|
|
|
return "o"
|
|
|
|
m = G.markers[0]
|
|
|
|
G.markers = G.markers[1:]
|
|
|
|
return m
|
2014-04-17 19:47:00 +00:00
|
|
|
|
|
|
|
class Event:
|
|
|
|
pass
|
|
|
|
|
2014-08-19 18:09:46 +00:00
|
|
|
def get_event(event, evtype):
|
2014-04-17 19:47:00 +00:00
|
|
|
if event not in G.events:
|
|
|
|
e = Event()
|
|
|
|
e.name = event
|
|
|
|
e.vals = []
|
2014-08-19 18:09:46 +00:00
|
|
|
e.type = evtype
|
|
|
|
e.marker = "o"
|
|
|
|
if e.type == "event-signal":
|
|
|
|
e.marker = find_marker()
|
2015-01-02 18:26:31 +00:00
|
|
|
if not event_regex.match(e.name):
|
|
|
|
return e
|
|
|
|
G.events[event] = e
|
2014-04-17 19:47:00 +00:00
|
|
|
return G.events[event]
|
|
|
|
|
2015-02-01 17:26:24 +00:00
|
|
|
SCALE = 1e6 # microseconds to seconds
|
|
|
|
|
2014-04-17 19:47:00 +00:00
|
|
|
for line in [line.split("#")[0].strip() for line in open(filename, "r")]:
|
2014-05-11 16:16:33 +00:00
|
|
|
line = line.strip()
|
|
|
|
if not line:
|
|
|
|
continue
|
2014-04-17 19:47:00 +00:00
|
|
|
ts, event = line.split(" ", 1)
|
2015-02-01 17:26:24 +00:00
|
|
|
ts = int(ts) / SCALE
|
2014-04-17 19:47:00 +00:00
|
|
|
if G.start is None:
|
|
|
|
G.start = ts
|
|
|
|
ts = ts - G.start
|
|
|
|
if event.startswith("start "):
|
2014-08-19 18:09:46 +00:00
|
|
|
e = get_event(event[6:], "event")
|
2014-04-17 19:47:00 +00:00
|
|
|
e.vals.append((ts, 0))
|
|
|
|
e.vals.append((ts, 1))
|
|
|
|
elif event.startswith("end "):
|
2014-08-19 18:09:46 +00:00
|
|
|
e = get_event(event[4:], "event")
|
2014-04-17 19:47:00 +00:00
|
|
|
e.vals.append((ts, 1))
|
|
|
|
e.vals.append((ts, 0))
|
|
|
|
elif event.startswith("value "):
|
|
|
|
_, val, name = event.split(" ", 2)
|
|
|
|
val = float(val)
|
2014-08-19 18:09:46 +00:00
|
|
|
e = get_event(name, "value")
|
2014-04-17 19:47:00 +00:00
|
|
|
e.vals.append((ts, val))
|
2014-08-19 18:09:46 +00:00
|
|
|
elif event.startswith("event-timed "):
|
|
|
|
_, val, name = event.split(" ", 2)
|
2015-02-01 17:26:24 +00:00
|
|
|
val = int(val) / SCALE - G.start
|
2014-08-19 18:09:46 +00:00
|
|
|
e = get_event(name, "event-signal")
|
|
|
|
e.vals.append((val, 1))
|
2015-05-11 15:20:30 +00:00
|
|
|
elif event.startswith("range-timed "):
|
|
|
|
_, ts1, ts2, name = event.split(" ", 3)
|
|
|
|
ts1 = int(ts1) / SCALE - G.start
|
|
|
|
ts2 = int(ts2) / SCALE - G.start
|
|
|
|
e = get_event(name, "event")
|
|
|
|
e.vals.append((ts1, 0))
|
|
|
|
e.vals.append((ts1, 1))
|
|
|
|
e.vals.append((ts2, 1))
|
|
|
|
e.vals.append((ts2, 0))
|
2015-01-02 18:27:07 +00:00
|
|
|
elif event.startswith("value-timed "):
|
|
|
|
_, tsval, val, name = event.split(" ", 3)
|
2015-02-01 17:26:24 +00:00
|
|
|
tsval = int(tsval) / SCALE - G.start
|
2015-01-02 18:27:07 +00:00
|
|
|
val = float(val)
|
|
|
|
e = get_event(name, "value")
|
|
|
|
e.vals.append((tsval, val))
|
2015-01-03 01:57:33 +00:00
|
|
|
elif event.startswith("signal "):
|
|
|
|
name = event.split(" ", 2)[1]
|
|
|
|
e = get_event(name, "event-signal")
|
|
|
|
e.vals.append((ts, 1))
|
2014-04-17 19:47:00 +00:00
|
|
|
else:
|
2014-08-19 18:09:46 +00:00
|
|
|
e = get_event(event, "event-signal")
|
2014-04-17 19:47:00 +00:00
|
|
|
e.vals.append((ts, 1))
|
|
|
|
|
2015-01-02 18:26:31 +00:00
|
|
|
# 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)
|
|
|
|
if e.type == "value":
|
|
|
|
hasval = True
|
2015-01-03 01:57:33 +00:00
|
|
|
else:
|
|
|
|
e.vals = [(x, y * (m - index) / m) for (x, y) in e.vals]
|
2014-05-11 15:06:25 +00:00
|
|
|
|
2015-01-03 01:57:33 +00:00
|
|
|
fig = plot.figure()
|
|
|
|
fig.hold(True)
|
|
|
|
ax = [None, None]
|
2015-01-02 18:26:31 +00:00
|
|
|
plots = 2 if hasval else 1
|
2015-01-03 01:57:33 +00:00
|
|
|
ax[0] = fig.add_subplot(plots, 1, 1)
|
|
|
|
if hasval:
|
|
|
|
ax[1] = fig.add_subplot(plots, 1, 2, sharex=ax[0])
|
|
|
|
legends = [[], []]
|
2014-04-17 19:47:00 +00:00
|
|
|
for e in G.sevents:
|
2015-01-03 01:57:33 +00:00
|
|
|
cur = ax[1 if e.type == "value" else 0]
|
|
|
|
pl, = cur.plot([x for x,y in e.vals], [y for x,y in e.vals], label=e.name)
|
2014-04-17 19:47:00 +00:00
|
|
|
if e.type == "event-signal":
|
2014-08-19 18:09:46 +00:00
|
|
|
plot.setp(pl, marker = e.marker, linestyle = "None")
|
2015-01-03 01:57:33 +00:00
|
|
|
for cur in ax:
|
|
|
|
if cur is not None:
|
|
|
|
cur.legend()
|
2014-04-17 19:47:00 +00:00
|
|
|
plot.show()
|