~ubuntu-branches/ubuntu/wily/mpv/wily

« back to all changes in this revision

Viewing changes to TOOLS/stats-conv.py

  • Committer: Package Import Robot
  • Author(s): Artur Rona
  • Date: 2015-02-08 11:38:05 UTC
  • mfrom: (28.1.4 vivid-proposed)
  • Revision ID: package-import@ubuntu.com-20150208113805-hb7kk68170y002es
Tags: 0.7.3-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - debian/rules:
    + Disable altivec on ppc64el again, as it FTBFS with it.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/env python3
2
2
import matplotlib.pyplot as plot
3
3
import sys
 
4
import re
4
5
 
5
6
filename = sys.argv[1]
6
7
 
 
8
event_regex = re.compile(".*")
 
9
 
7
10
"""
8
11
This script is meant to display stats written by mpv --dump-stats=filename.
9
12
In general, each line in that file is an event of the form:
18
21
 
19
22
Currently, the following event types are supported:
20
23
 
 
24
    'signal' <name>             singular event
21
25
    'start' <name>              start of the named event
22
26
    'end' <name>                end of the named event
23
27
    'value' <float> <name>      a normal value (as opposed to event)
24
28
    'event-timed' <ts> <name>   singular event at the given timestamp
25
 
    <name>                      singular event
 
29
    'value-timed' <ts> <float> <name>
 
30
                                a value for an event at the given timestamp
 
31
    <name>                      singular event (same as 'signal')
26
32
 
27
33
"""
28
34
 
29
35
class G:
30
36
    events = {}
31
 
    sevents = []  # events, deterministically sorted
32
37
    start = None
33
38
    # http://matplotlib.org/api/markers_api.html#module-matplotlib.markers
34
39
    markers = ["o", "8", "s", "p", "*", "h", "+", "x", "D"]
46
51
def get_event(event, evtype):
47
52
    if event not in G.events:
48
53
        e = Event()
49
 
        G.events[event] = e
50
54
        e.name = event
51
55
        e.vals = []
52
56
        e.type = evtype
53
57
        e.marker = "o"
54
 
        e.numid = len(G.events)
55
 
        G.sevents = list(G.events.values())
56
 
        G.sevents.sort(key=lambda x: x.name)
57
58
        if e.type == "event-signal":
58
59
            e.marker = find_marker()
 
60
        if not event_regex.match(e.name):
 
61
            return e
 
62
        G.events[event] = e
59
63
    return G.events[event]
60
64
 
61
65
for line in [line.split("#")[0].strip() for line in open(filename, "r")]:
85
89
        val = int(val) / 1000 - G.start
86
90
        e = get_event(name, "event-signal")
87
91
        e.vals.append((val, 1))
 
92
    elif event.startswith("value-timed "):
 
93
        _, tsval, val, name = event.split(" ", 3)
 
94
        tsval = int(tsval) / 1000 - G.start
 
95
        val = float(val)
 
96
        e = get_event(name, "value")
 
97
        e.vals.append((tsval, val))
 
98
    elif event.startswith("signal "):
 
99
        name = event.split(" ", 2)[1]
 
100
        e = get_event(name, "event-signal")
 
101
        e.vals.append((ts, 1))
88
102
    else:
89
103
        e = get_event(event, "event-signal")
90
104
        e.vals.append((ts, 1))
91
105
 
92
 
for e in G.sevents:
93
 
    e.vals = [(x, y * e.numid / len(G.events)) for (x, y) in e.vals]
94
 
 
95
 
plot.hold(True)
96
 
mainpl = plot.subplot(2, 1, 1)
97
 
legend = []
98
 
for e in G.sevents:
 
106
# deterministically sort them; make sure the legend is sorted too
 
107
G.sevents = list(G.events.values())
 
108
G.sevents.sort(key=lambda x: x.name)
 
109
hasval = False
 
110
for e, index in zip(G.sevents, range(len(G.sevents))):
 
111
    m = len(G.sevents)
99
112
    if e.type == "value":
100
 
        plot.subplot(2, 1, 2, sharex=mainpl)
 
113
        hasval = True
101
114
    else:
102
 
        plot.subplot(2, 1, 1)
103
 
    pl, = plot.plot([x for x,y in e.vals], [y for x,y in e.vals], label=e.name)
 
115
        e.vals = [(x, y * (m - index) / m) for (x, y) in e.vals]
 
116
 
 
117
fig = plot.figure()
 
118
fig.hold(True)
 
119
ax = [None, None]
 
120
plots = 2 if hasval else 1
 
121
ax[0] = fig.add_subplot(plots, 1, 1)
 
122
if hasval:
 
123
    ax[1] = fig.add_subplot(plots, 1, 2, sharex=ax[0])
 
124
legends = [[], []]
 
125
for e in G.sevents:
 
126
    cur = ax[1 if e.type == "value" else 0]
 
127
    pl, = cur.plot([x for x,y in e.vals], [y for x,y in e.vals], label=e.name)
104
128
    if e.type == "event-signal":
105
129
        plot.setp(pl, marker = e.marker, linestyle = "None")
106
 
    legend.append(pl)
107
 
plot.subplot(2, 1, 1)
108
 
plot.legend(legend, [pl.get_label() for pl in legend])
 
130
for cur in ax:
 
131
    if cur is not None:
 
132
        cur.legend()
109
133
plot.show()