mirror of https://github.com/mpv-player/mpv
TOOLS/stats-conv: minor cleanup
This commit is contained in:
parent
0c72a2f26d
commit
dcb4b491b2
|
@ -76,60 +76,63 @@ def mkColor(t):
|
||||||
|
|
||||||
SCALE = 1e6 # microseconds to seconds
|
SCALE = 1e6 # microseconds to seconds
|
||||||
|
|
||||||
for line in [line.split("#")[0].strip() for line in open(filename, "r")]:
|
with open(filename, "r") as file:
|
||||||
line = line.strip()
|
for line in file:
|
||||||
if not line:
|
line = line.split("#")[0].strip()
|
||||||
continue
|
if not line:
|
||||||
ts, event = line.split(" ", 1)
|
continue
|
||||||
ts = int(ts) / SCALE
|
ts, event = line.split(" ", 1)
|
||||||
if G.start is None:
|
ts = int(ts) / SCALE
|
||||||
G.start = ts
|
if G.start is None:
|
||||||
ts = ts - G.start
|
G.start = ts
|
||||||
if event.startswith("start "):
|
ts -= G.start
|
||||||
e = get_event(event[6:], "event")
|
|
||||||
e.vals.append((ts, 0))
|
match event.split(" ", 1):
|
||||||
e.vals.append((ts, 1))
|
case ["start", name]:
|
||||||
elif event.startswith("end "):
|
e = get_event(name, "event")
|
||||||
e = get_event(event[4:], "event")
|
e.vals.append((ts, 0))
|
||||||
e.vals.append((ts, 1))
|
e.vals.append((ts, 1))
|
||||||
e.vals.append((ts, 0))
|
case ["end", name]:
|
||||||
elif event.startswith("value "):
|
e = get_event(name, "event")
|
||||||
_, val, name = event.split(" ", 2)
|
e.vals.append((ts, 1))
|
||||||
val = float(val)
|
e.vals.append((ts, 0))
|
||||||
e = get_event(name, "value")
|
case ["value", rest]:
|
||||||
e.vals.append((ts, val))
|
val, name = rest.split(" ", 1)
|
||||||
elif event.startswith("event-timed "):
|
val = float(val)
|
||||||
_, val, name = event.split(" ", 2)
|
e = get_event(name, "value")
|
||||||
val = int(val) / SCALE - G.start
|
e.vals.append((ts, val))
|
||||||
e = get_event(name, "event-signal")
|
case ["event-timed", rest]:
|
||||||
e.vals.append((val, 1))
|
val, name = rest.split(" ", 1)
|
||||||
elif event.startswith("range-timed "):
|
val = int(val) / SCALE - G.start
|
||||||
_, ts1, ts2, name = event.split(" ", 3)
|
e = get_event(name, "event-signal")
|
||||||
ts1 = int(ts1) / SCALE - G.start
|
e.vals.append((val, 1))
|
||||||
ts2 = int(ts2) / SCALE - G.start
|
case ["range-timed", rest]:
|
||||||
e = get_event(name, "event")
|
ts1, ts2, name = rest.split(" ", 2)
|
||||||
e.vals.append((ts1, 0))
|
ts1 = int(ts1) / SCALE - G.start
|
||||||
e.vals.append((ts1, 1))
|
ts2 = int(ts2) / SCALE - G.start
|
||||||
e.vals.append((ts2, 1))
|
e = get_event(name, "event")
|
||||||
e.vals.append((ts2, 0))
|
e.vals.append((ts1, 0))
|
||||||
elif event.startswith("value-timed "):
|
e.vals.append((ts1, 1))
|
||||||
_, tsval, val, name = event.split(" ", 3)
|
e.vals.append((ts2, 1))
|
||||||
tsval = int(tsval) / SCALE - G.start
|
e.vals.append((ts2, 0))
|
||||||
val = float(val)
|
case ["value-timed", rest]:
|
||||||
e = get_event(name, "value")
|
tsval, val, name = rest.split(" ", 2)
|
||||||
e.vals.append((tsval, val))
|
tsval = int(tsval) / SCALE - G.start
|
||||||
elif event.startswith("signal "):
|
val = float(val)
|
||||||
name = event.split(" ", 2)[1]
|
e = get_event(name, "value")
|
||||||
e = get_event(name, "event-signal")
|
e.vals.append((tsval, val))
|
||||||
e.vals.append((ts, 1))
|
case ["signal", name]:
|
||||||
else:
|
e = get_event(name, "event-signal")
|
||||||
e = get_event(event, "event-signal")
|
e.vals.append((ts, 1))
|
||||||
e.vals.append((ts, 1))
|
case _:
|
||||||
|
e = get_event(event, "event-signal")
|
||||||
|
e.vals.append((ts, 1))
|
||||||
|
|
||||||
# deterministically sort them; make sure the legend is sorted too
|
# deterministically sort them; make sure the legend is sorted too
|
||||||
G.sevents = list(G.events.values())
|
G.sevents = list(G.events.values())
|
||||||
G.sevents.sort(key=lambda x: x.name)
|
G.sevents.sort(key=lambda x: x.name)
|
||||||
hasval = False
|
hasval = False
|
||||||
|
|
||||||
for e, index in zip(G.sevents, range(len(G.sevents))):
|
for e, index in zip(G.sevents, range(len(G.sevents))):
|
||||||
m = len(G.sevents)
|
m = len(G.sevents)
|
||||||
if e.type == "value":
|
if e.type == "value":
|
||||||
|
@ -146,13 +149,16 @@ win.show()
|
||||||
ax = [None, None]
|
ax = [None, None]
|
||||||
plots = 2 if hasval else 1
|
plots = 2 if hasval else 1
|
||||||
ax[0] = win.addPlot()
|
ax[0] = win.addPlot()
|
||||||
|
|
||||||
if hasval:
|
if hasval:
|
||||||
win.nextRow()
|
win.nextRow()
|
||||||
ax[1] = win.addPlot()
|
ax[1] = win.addPlot()
|
||||||
ax[1].setXLink(ax[0])
|
ax[1].setXLink(ax[0])
|
||||||
|
|
||||||
for cur in ax:
|
for cur in ax:
|
||||||
if cur is not None:
|
if cur is not None:
|
||||||
cur.addLegend(offset = (-1, 1))
|
cur.addLegend(offset = (-1, 1))
|
||||||
|
|
||||||
for e in G.sevents:
|
for e in G.sevents:
|
||||||
cur = ax[1 if e.type == "value" else 0]
|
cur = ax[1 if e.type == "value" else 0]
|
||||||
if not cur in G.curveno:
|
if not cur in G.curveno:
|
||||||
|
@ -165,6 +171,6 @@ for e in G.sevents:
|
||||||
else:
|
else:
|
||||||
args['pen'] = pg.mkPen(color, width=0)
|
args['pen'] = pg.mkPen(color, width=0)
|
||||||
G.curveno[cur] += 1
|
G.curveno[cur] += 1
|
||||||
cur.plot([x for x, _ in e.vals], [y for _, y in e.vals], **args)
|
cur.plot(*zip(*e.vals), **args)
|
||||||
|
|
||||||
app.exec()
|
app.exec()
|
||||||
|
|
Loading…
Reference in New Issue