2014-04-17 19:47:00 +00:00
|
|
|
#!/usr/bin/env python3
|
2015-01-02 18:26:31 +00:00
|
|
|
import re
|
2024-09-15 12:08:30 +00:00
|
|
|
import sys
|
|
|
|
|
|
|
|
import pyqtgraph as pg
|
|
|
|
from PyQt6 import QtWidgets
|
2014-04-17 19:47:00 +00:00
|
|
|
|
|
|
|
filename = sys.argv[1]
|
|
|
|
|
2015-08-10 16:36:10 +00:00
|
|
|
events = ".*"
|
|
|
|
if len(sys.argv) > 2:
|
|
|
|
events = sys.argv[2]
|
|
|
|
event_regex = re.compile(events)
|
2015-01-02 18:26:31 +00:00
|
|
|
|
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 = {}
|
2024-07-30 00:54:54 +00:00
|
|
|
start = 0.0
|
2015-10-15 20:34:14 +00:00
|
|
|
markers = ["o", "s", "t", "d"]
|
2016-01-12 14:04:55 +00:00
|
|
|
curveno = {}
|
2024-07-30 00:54:54 +00:00
|
|
|
sevents = []
|
2014-08-19 18:09:46 +00:00
|
|
|
|
|
|
|
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:
|
2024-07-30 00:54:54 +00:00
|
|
|
name = None
|
|
|
|
vals = []
|
|
|
|
type = None
|
|
|
|
marker = ""
|
2014-04-17 19:47:00 +00:00
|
|
|
|
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]
|
|
|
|
|
2024-09-15 00:43:15 +00:00
|
|
|
colors = [
|
|
|
|
(0.0, 0.5, 0.0),
|
|
|
|
(0.0, 0.0, 1.0),
|
|
|
|
(0.0, 0.0, 0.0),
|
|
|
|
(1.0, 0.0, 0.0),
|
|
|
|
(0.75, 0.75, 0),
|
|
|
|
(0.0, 0.75, 0.75),
|
2024-09-15 12:08:30 +00:00
|
|
|
(0.75, 0, 0.75),
|
2024-09-15 00:43:15 +00:00
|
|
|
]
|
|
|
|
|
2024-09-15 12:22:22 +00:00
|
|
|
def mk_color(t):
|
2016-01-12 14:04:55 +00:00
|
|
|
return pg.mkColor(int(t[0] * 255), int(t[1] * 255), int(t[2] * 255))
|
|
|
|
|
2015-02-01 17:26:24 +00:00
|
|
|
SCALE = 1e6 # microseconds to seconds
|
|
|
|
|
2024-09-15 12:08:30 +00:00
|
|
|
with open(filename) as file:
|
2024-07-30 15:11:20 +00:00
|
|
|
for line in file:
|
|
|
|
line = line.split("#")[0].strip()
|
|
|
|
if not line:
|
|
|
|
continue
|
|
|
|
ts, event = line.split(" ", 1)
|
|
|
|
ts = int(ts) / SCALE
|
|
|
|
if G.start is None:
|
|
|
|
G.start = ts
|
|
|
|
ts -= G.start
|
|
|
|
|
|
|
|
match event.split(" ", 1):
|
|
|
|
case ["start", name]:
|
|
|
|
e = get_event(name, "event")
|
|
|
|
e.vals.append((ts, 0))
|
|
|
|
e.vals.append((ts, 1))
|
|
|
|
case ["end", name]:
|
|
|
|
e = get_event(name, "event")
|
|
|
|
e.vals.append((ts, 1))
|
|
|
|
e.vals.append((ts, 0))
|
|
|
|
case ["value", rest]:
|
|
|
|
val, name = rest.split(" ", 1)
|
|
|
|
val = float(val)
|
|
|
|
e = get_event(name, "value")
|
|
|
|
e.vals.append((ts, val))
|
|
|
|
case ["event-timed", rest]:
|
|
|
|
val, name = rest.split(" ", 1)
|
|
|
|
val = int(val) / SCALE - G.start
|
|
|
|
e = get_event(name, "event-signal")
|
|
|
|
e.vals.append((val, 1))
|
|
|
|
case ["range-timed", rest]:
|
|
|
|
ts1, ts2, name = rest.split(" ", 2)
|
|
|
|
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))
|
|
|
|
case ["value-timed", rest]:
|
|
|
|
tsval, val, name = rest.split(" ", 2)
|
|
|
|
tsval = int(tsval) / SCALE - G.start
|
|
|
|
val = float(val)
|
|
|
|
e = get_event(name, "value")
|
|
|
|
e.vals.append((tsval, val))
|
|
|
|
case ["signal", name]:
|
|
|
|
e = get_event(name, "event-signal")
|
|
|
|
e.vals.append((ts, 1))
|
|
|
|
case _:
|
|
|
|
e = get_event(event, "event-signal")
|
|
|
|
e.vals.append((ts, 1))
|
2014-04-17 19:47:00 +00:00
|
|
|
|
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
|
2024-07-30 15:11:20 +00:00
|
|
|
|
2015-01-02 18:26:31 +00:00
|
|
|
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
|
|
|
|
2024-09-15 00:55:28 +00:00
|
|
|
pg.setConfigOption("background", "w")
|
|
|
|
pg.setConfigOption("foreground", "k")
|
2024-07-30 00:51:40 +00:00
|
|
|
app = QtWidgets.QApplication([])
|
|
|
|
win = pg.GraphicsLayoutWidget()
|
|
|
|
win.show()
|
2015-10-15 20:34:14 +00:00
|
|
|
|
2015-01-03 01:57:33 +00:00
|
|
|
ax = [None, None]
|
2015-01-02 18:26:31 +00:00
|
|
|
plots = 2 if hasval else 1
|
2015-10-15 20:34:14 +00:00
|
|
|
ax[0] = win.addPlot()
|
2024-07-30 15:11:20 +00:00
|
|
|
|
2015-01-03 01:57:33 +00:00
|
|
|
if hasval:
|
2015-10-15 20:34:14 +00:00
|
|
|
win.nextRow()
|
|
|
|
ax[1] = win.addPlot()
|
|
|
|
ax[1].setXLink(ax[0])
|
2024-07-30 15:11:20 +00:00
|
|
|
|
2015-10-15 20:34:14 +00:00
|
|
|
for cur in ax:
|
2020-02-27 19:46:42 +00:00
|
|
|
if cur is not None:
|
|
|
|
cur.addLegend(offset = (-1, 1))
|
2024-07-30 15:11:20 +00:00
|
|
|
|
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]
|
2024-09-13 17:22:05 +00:00
|
|
|
if cur not in G.curveno:
|
2016-10-06 16:00:23 +00:00
|
|
|
G.curveno[cur] = 0
|
2024-09-15 00:55:28 +00:00
|
|
|
args = {"name": e.name,"antialias":True}
|
2024-09-15 12:22:22 +00:00
|
|
|
color = mk_color(colors[G.curveno[cur] % len(colors)])
|
2014-04-17 19:47:00 +00:00
|
|
|
if e.type == "event-signal":
|
2024-09-15 00:55:28 +00:00
|
|
|
args["symbol"] = e.marker
|
|
|
|
args["symbolBrush"] = pg.mkBrush(color, width=0)
|
2015-10-15 20:34:14 +00:00
|
|
|
else:
|
2024-09-15 00:55:28 +00:00
|
|
|
args["pen"] = pg.mkPen(color, width=0)
|
2016-10-06 16:00:23 +00:00
|
|
|
G.curveno[cur] += 1
|
2024-07-30 15:11:20 +00:00
|
|
|
cur.plot(*zip(*e.vals), **args)
|
2015-10-15 20:34:14 +00:00
|
|
|
|
2024-07-30 00:51:40 +00:00
|
|
|
app.exec()
|