source: tools/perf/view_halts.py @ 359d12d

arm-ehjacob/cs343-translationnew-astnew-ast-unique-expr
Last change on this file since 359d12d was 359d12d, checked in by Thierry Delisle <tdelisle@…>, 18 months ago

added --save-temps and --outfile to halts viewing

  • Property mode set to 100755
File size: 4.2 KB
Line 
1#!/usr/bin/python3
2import numpy as np
3import re
4import sys, getopt
5import fileinput
6import argparse
7
8#--------------------------------------------------------------------------------
9# Parse arguments
10parser = argparse.ArgumentParser(description='Produce a graph representing CPU activity over time.')
11parser.add_argument('-i', '--input' , dest='infile' , type=argparse.FileType('r'), default=sys.stdin, help='input file containing processor activity; if none specified then will use stdin.')
12parser.add_argument('-o', '--output', dest='outfile', type=argparse.FileType('w'), default=None, help='output file with any image format extension such as .png or .svg; if none specified then plt.show() will be used')
13args = parser.parse_args()
14
15#--------------------------------------------------------------------------------
16# Process data
17class Proc:
18        def __init__(self, id, name, address):
19                self.name    = name
20                self.address = address
21                self.id      = id
22
23class Point:
24        def __init__(self, time, on):
25                self.time = time
26                self.on = on
27
28processors = {}
29data = {}
30
31#--------------------------------------------------------------------------------
32# Parse data
33for line in args.infile:
34        match = re.match("Processor : ([0-9]+) - (.*) \((0x[0-9a-f]+)\)", line)
35        if match :
36                id = int(match.group(1))
37                processors[id] = Proc(id, match.group(2), match.group(3))
38                continue
39
40        match = re.match("PH:([0-9]+) - ([0-9]+) ([0-9]+)", line)
41        if match :
42                id = int(match.group(1))
43                if not id in data:
44                        data[id] = []
45                data[id].append(Point(int(match.group(2)), int(match.group(3))))
46                continue
47
48        print("WARNING : line '%s' filterred not matched" % line, file=sys.stderr)
49
50#--------------------------------------------------------------------------------
51# Check data
52if not data:
53        print("ERROR : no data extracted from '%s'" % args.infile, file=sys.stderr)
54
55for d in data:
56        if not d in processors:
57                print("WARNING : unkown processor '%s'" % d, file=sys.stderr)
58
59        prevT = data[d][0].time
60        prevO = data[d][0].on
61        for p in data[d][1:]:
62                if prevT > p.time:
63                        print("WARNING : Time is inconsistant for Proc '%s'" % d, file=sys.stderr)
64
65                if prevO == p.on:
66                        print("WARNING : State is inconsistant for Proc '%s' at %s-%s" % (d, prevT, p.time), file=sys.stderr)
67
68                prevT = p.time
69                prevO = p.on
70
71
72#--------------------------------------------------------------------------------
73# Convert data to series
74offset = min(data)
75series = dict()
76for d in data:
77        series[d] = ([], [], [])
78        for p in data[d]:
79                series[d][0].append( p.time )
80                series[d][1].append(p.on + d - offset)
81                series[d][2].append(d - offset)
82
83#--------------------------------------------------------------------------------
84# setup matplotlib
85import matplotlib as mpl
86mpl.use('Agg')
87import matplotlib.pyplot as plt
88import matplotlib.ticker as ticker
89plt.style.use('dark_background')
90
91#--------------------------------------------------------------------------------
92# setup plot
93dots_per_inch = 2000
94height_inches = 5
95width_inches = 12
96fig = plt.figure(figsize=(width_inches, height_inches), dpi=dots_per_inch)
97print('number of series={}'.format(len(series)))
98for s, xy in series.items():
99        if s in processors:
100                name = '"{}" ({})'.format(processors[s].name, processors[s].address)
101        else:
102                name = s
103        print( '    plotting series {} with {} points'.format(name, len(xy[0])) )
104        plt.fill_between(xy[0], xy[1], xy[2], step="post", alpha=0.4)
105        plt.step(xy[0], xy[1], where='post')
106
107#--------------------------------------------------------------------------------
108# y axis major, minor
109ax = plt.gca()
110ax.grid(which='major', axis='y', linestyle='-', color='lightgray')
111ax.yaxis.set_minor_locator(ticker.AutoMinorLocator())
112ax.grid(which='minor', axis='y', linestyle='dotted', color='gray')
113
114#--------------------------------------------------------------------------------
115# x axis major, minor
116ax.grid(which='major', axis='x', linestyle='-', color='lightgray')
117ax.xaxis.set_minor_locator(ticker.AutoMinorLocator())
118ax.grid(which='minor', axis='x', linestyle='dotted', color='gray')
119
120#--------------------------------------------------------------------------------
121# do the plot
122plt.tight_layout()
123if not args.outfile:
124        plt.show()
125else:
126        print("saving figure image %s\n" % args.outfile.name)
127        plt.savefig(args.outfile.name)
Note: See TracBrowser for help on using the repository browser.