source: tools/perf/view_halts.py @ 85871478

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 85871478 was 9bbbc8e, checked in by Thierry Delisle <tdelisle@…>, 4 years ago

disabled interactive mode for view_halts

  • Property mode set to 100755
File size: 4.3 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
15print("----- Processing Halts Output -----")
16if not args.outfile:
17        print("ERROR : no output file specified and interactive mode not supported", file=sys.stderr)
18        sys.exit(1)
19
20#--------------------------------------------------------------------------------
21# Process data
22class Proc:
23        def __init__(self, id, name, address):
24                self.name    = name
25                self.address = address
26                self.id      = id
27
28class Point:
29        def __init__(self, time, on):
30                self.time = time
31                self.on = on
32
33processors = {}
34data = {}
35
36#--------------------------------------------------------------------------------
37# Parse data
38for line in args.infile:
39        match = re.match("Processor : ([0-9]+) - (.*) \((0x[0-9a-f]+)\)", line)
40        if match :
41                id = int(match.group(1))
42                processors[id] = Proc(id, match.group(2), match.group(3))
43                continue
44
45        match = re.match("PH:([0-9]+) - ([0-9]+) ([0-9]+)", line)
46        if match :
47                id = int(match.group(1))
48                if not id in data:
49                        data[id] = []
50                data[id].append(Point(int(match.group(2)), int(match.group(3))))
51                continue
52
53        print("WARNING : line '%s' filterred not matched" % line, file=sys.stderr)
54
55#--------------------------------------------------------------------------------
56# Check data
57if not data:
58        print("ERROR : no data extracted from '%s'" % args.infile, file=sys.stderr)
59
60for d in data:
61        if not d in processors:
62                print("WARNING : unkown processor '%s'" % d, file=sys.stderr)
63
64        prevT = data[d][0].time
65        prevO = data[d][0].on
66        for p in data[d][1:]:
67                if prevT > p.time:
68                        print("WARNING : Time is inconsistant for Proc '%s'" % d, file=sys.stderr)
69
70                if prevO == p.on:
71                        print("WARNING : State is inconsistant for Proc '%s' at %s-%s" % (d, prevT, p.time), file=sys.stderr)
72
73                prevT = p.time
74                prevO = p.on
75
76
77#--------------------------------------------------------------------------------
78# Convert data to series
79offset = min(data)
80series = dict()
81for d in data:
82        series[d] = ([], [], [])
83        for p in data[d]:
84                series[d][0].append( p.time )
85                series[d][1].append(p.on + d - offset)
86                series[d][2].append(d - offset)
87
88#--------------------------------------------------------------------------------
89# setup matplotlib
90import matplotlib as mpl
91mpl.use('Agg')
92import matplotlib.pyplot as plt
93import matplotlib.ticker as ticker
94plt.style.use('dark_background')
95
96#--------------------------------------------------------------------------------
97# setup plot
98dots_per_inch = 200
99height_inches = 5
100width_inches = 12
101fig = plt.figure(figsize=(width_inches, height_inches), dpi=dots_per_inch)
102print('number of series={}'.format(len(series)))
103for s, xy in series.items():
104        if s in processors:
105                name = '"{}" ({})'.format(processors[s].name, processors[s].address)
106        else:
107                name = s
108        print( '    plotting series {} with {} points'.format(name, len(xy[0])) )
109        plt.fill_between(xy[0], xy[1], xy[2], step="post", alpha=0.4)
110        plt.step(xy[0], xy[1], where='post')
111
112#--------------------------------------------------------------------------------
113# y axis major, minor
114ax = plt.gca()
115ax.grid(which='major', axis='y', linestyle='-', color='lightgray')
116ax.yaxis.set_minor_locator(ticker.AutoMinorLocator())
117ax.grid(which='minor', axis='y', linestyle='dotted', color='gray')
118
119#--------------------------------------------------------------------------------
120# x axis major, minor
121ax.grid(which='major', axis='x', linestyle='-', color='lightgray')
122ax.xaxis.set_minor_locator(ticker.AutoMinorLocator())
123ax.grid(which='minor', axis='x', linestyle='dotted', color='gray')
124
125#--------------------------------------------------------------------------------
126# do the plot
127plt.tight_layout()
128print("saving figure image %s\n" % args.outfile.name)
129plt.savefig(args.outfile.name)
Note: See TracBrowser for help on using the repository browser.