source: tools/perf/view_halts.py @ 6065281f

Last change on this file since 6065281f 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
RevLine 
[f2b18d01]1#!/usr/bin/python3
2import numpy as np
3import re
4import sys, getopt
[359d12d]5import fileinput
[f2b18d01]6import argparse
7
[359d12d]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
[9bbbc8e]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
[359d12d]20#--------------------------------------------------------------------------------
21# Process data
[f2b18d01]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
[359d12d]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)
[f2b18d01]54
55#--------------------------------------------------------------------------------
56# Check data
[359d12d]57if not data:
58        print("ERROR : no data extracted from '%s'" % args.infile, file=sys.stderr)
59
[f2b18d01]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)
[359d12d]80series = dict()
[f2b18d01]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
[9bbbc8e]98dots_per_inch = 200
[f2b18d01]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():
[359d12d]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])) )
[f2b18d01]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()
[9bbbc8e]128print("saving figure image %s\n" % args.outfile.name)
129plt.savefig(args.outfile.name)
Note: See TracBrowser for help on using the repository browser.