File: pprof-latency.py

package info (click to toggle)
crossfire-client 1.75.5-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 16,936 kB
  • sloc: ansic: 17,281; python: 758; perl: 78; sh: 23; xml: 17; makefile: 12
file content (40 lines) | stat: -rw-r--r-- 1,058 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""
pprof-latency.py -- process Crossfire client latency profile
usage:
1. gather a profile using:

   $ crossfire-client-gtk2 --profile-latency > out.txt

2. process the profile:

   $ python3 utils/pprof-latency.py out.txt
"""
import sys

def main():
    if len(sys.argv) < 2:
        print("usage: python3 pprof-latency.py FILE")
        return

    path = sys.argv[1]
    with open(path, 'r') as dat, open(path + ".hist", 'w') as hist:
        data = dat.readlines()
        fields = map(lambda l: l.strip().split('\t'), data)
        pending = {}
        for f in fields:
            if f[0] == 'profile/com':
                n, cmd = f[1:]
                n = int(n)
                pending[n] = cmd
            elif f[0] == 'profile/comc':
                n, t, s, _ = f[1:]
                n = int(n)
                t = int(t)
                tdiff = t
                cmd = pending[n]
                del pending[n]
                print("%d,%s" % (tdiff, cmd))
                print("%d" % tdiff, file=hist)

if __name__ == '__main__':
    main()