Changeset 359d12d


Ignore:
Timestamp:
Jun 26, 2020, 2:53:34 PM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
b813f53
Parents:
f2b18d01
Message:

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

Location:
tools/perf
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tools/perf/process_halts.sh

    rf2b18d01 r359d12d  
    11#!/bin/bash -e
    22
    3 DIR=$( dirname "${BASH_SOURCE[0]}")
    4 echo $DIR
    5 tmpfile=$(mktemp)
    6 function finish {
    7   rm -rf "$tmpfile"
    8 }
    9 trap finish EXIT
     3SAVE_TEMPS=false
     4while (( "$#" )); do
     5        case "$1" in
     6        -s|--save-temps)
     7                SAVE_TEMPS=true
     8                shift
     9                ;;
     10        *) # preserve positional arguments
     11                PARAMS="$PARAMS $1"
     12                shift
     13                ;;
     14        esac
     15done
     16# set positional arguments in their proper place
     17eval set -- "$PARAMS"
    1018
     19if $SAVE_TEMPS; then
     20        tmpfile=$(mktemp --tmpdir=$(pwd))
     21        echo "Saving to $tmpfile"
     22else
     23        tmpfile=$(mktemp)
     24        function finish {
     25                rm -rf "$tmpfile"
     26        }
     27        trap finish EXIT
     28fi
    1129# split the wanted and unwanted output
    1230awk "/^Processor|^PH:[0-9]+ - [0-9]+ [0-9]+/ {print \$0 > \"$tmpfile\"; next}{print \$0; fflush()}"
    1331
    1432# pass the data to the python scirpt
    15 $DIR/view_halts.py $tmpfile
     33DIR=$( dirname "${BASH_SOURCE[0]}")
     34cat $tmpfile | $DIR/view_halts.py ${PARAMS}
  • tools/perf/view_halts.py

    rf2b18d01 r359d12d  
    33import re
    44import sys, getopt
     5import fileinput
    56import argparse
    67
     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
    717class Proc:
    818        def __init__(self, id, name, address):
     
    2131#--------------------------------------------------------------------------------
    2232# Parse data
    23 with open(sys.argv[1], "r") as f:
    24         for line in f:
    25                 match = re.match("Processor : ([0-9]+) - (.*) \((0x[0-9a-f]+)\)", line)
    26                 if match :
    27                         id = int(match.group(1))
    28                         processors[id] = Proc(id, match.group(2), match.group(3))
    29                         continue
     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
    3039
    31                 match = re.match("PH:([0-9]+) - ([0-9]+) ([0-9]+)", line)
    32                 if match :
    33                         id = int(match.group(1))
    34                         if not id in data:
    35                                 data[id] = []
    36                         data[id].append(Point(int(match.group(2)), int(match.group(3))))
    37                         continue
     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
    3847
    39                 print("WARNING : line '%s' filterred not matched" % line, file=sys.stderr)
     48        print("WARNING : line '%s' filterred not matched" % line, file=sys.stderr)
    4049
    4150#--------------------------------------------------------------------------------
    4251# Check data
     52if not data:
     53        print("ERROR : no data extracted from '%s'" % args.infile, file=sys.stderr)
     54
    4355for d in data:
    4456        if not d in processors:
     
    6173# Convert data to series
    6274offset = min(data)
    63 print(offset)
    64 
    65 series=dict() ## dict of pairs of arrays
     75series = dict()
    6676for d in data:
    6777        series[d] = ([], [], [])
     
    8797print('number of series={}'.format(len(series)))
    8898for s, xy in series.items():
    89         print('    plotting series {} with {} points'.format(s, len(xy[0])))
     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])) )
    90104        plt.fill_between(xy[0], xy[1], xy[2], step="post", alpha=0.4)
    91105        plt.step(xy[0], xy[1], where='post')
     
    107121# do the plot
    108122plt.tight_layout()
    109 print("saving figure image %s\n" % "out.svg")
    110 plt.savefig("out.svg")
     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 TracChangeset for help on using the changeset viewer.