Commit 0b608a6f authored by Alan Marchiori's avatar Alan Marchiori
Browse files


#!/usr/bin/env python3
# generic profiler
# alan marchiori
# 2018
# assumes .out files include disassembled instructions, like the sample lines:
# Instantiated DTM.
# Cyc= 0 Op1=[0x00000000] Op2=[0x00000000] W[W, 1= 0x00000000] Mem[0: R:0x00000093 W:0x00000000] PC= 0x80000000 li ra, 0
# Cyc= 1 Op1=[0x00000000] Op2=[0x00000000] W[W, 2= 0x00000000] Mem[0: R:0x00000093 W:0x00000000] PC= 0x80000004 li sp, 0
# Cyc= 2 Op1=[0x00000000] Op2=[0x00000000] W[W, 3= 0x00000000] Mem[0: R:0x00000093 W:0x00000000] PC= 0x80000008 li gp, 0
# Cyc= 3 Op1=[0x00000000] Op2=[0x00000000] W[W, 4= 0x00000000] Mem[0: R:0x00000093 W:0x00000000] PC= 0x8000000c li tp, 0
# Cyc= 4 Op1=[0x00000000] Op2=[0x00000000] W[W, 5= 0x00000000] Mem[0: R:0x00000093 W:0x00000000] PC= 0x80000010 li t0, 0
import argparse
import sys
type_lut = {
'bgeu': 'branch',
'bge': 'branch',
'not': 'arth',
'csrwi': 'misc',
'csrrci': 'misc',
'mret': 'misc',
'csrrsi': 'misc',
'csrrwi': 'misc',
'c.addi4spn': 'arth',
'ebreak': 'misc',
'lh': 'memory',
'sh': 'memory',
'lhu': 'memory',
'shu': 'memory',
'fence.i': 'misc',
'lb': 'memory',
'sb': 'memory',
'slti': 'arth',
'slt': 'arth',
'snez': 'arth',
def profile(f, itypes = type_lut):
"profile the file given the instruciton types"
print("Processing {}.".format(f))
# init counters
results = {k:0 for k in set(itypes.values())}
i = 0
with open(f, 'r') as of:
i += 1
for line in of:
if line.startswith('Cyc'):
#someone change this to a regex.
instruction = line[124:-1] #strip newline
op = instruction.split(" ")[0]
if op not in itypes:
print("Insturction on line {}: {}, is not supported.".format(
i, op
results[itypes[op]] += 1
return results
if __name__== "__main__":
parser = argparse.ArgumentParser(description='Count instruction types from a .out file.')
parser.add_argument('outfile', default = None, nargs='*',
help='the .out file to process.')
args = parser.parse_args()
from pprint import pprint
for inputfile in args.outfile:
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment