Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Alan Marchiori
SodorProfiler
Commits
0b608a6f
Commit
0b608a6f
authored
Oct 17, 2018
by
Alan Marchiori
Browse files
initial
parents
Changes
1
Show whitespace changes
Inline
Side-by-side
profile.py
0 → 100755
View file @
0b608a6f
#!/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
=
{
'j'
:
'branch'
,
'nop'
:
'arth'
,
'li'
:
'memory'
,
'sw'
:
'memory'
,
'ret'
:
'branch'
,
'addi'
:
'arth'
,
'bgez'
:
'branch'
,
'bleu'
:
'branch'
,
'ble'
:
'branch'
,
'bgeu'
:
'branch'
,
'bge'
:
'branch'
,
'mv'
:
'memory'
,
'lbu'
:
'memory'
,
'add'
:
'arth'
,
'jal'
:
'branch'
,
'blez'
:
'branch'
,
'jalr'
:
'branch'
,
'blt'
:
'branch'
,
'bltu'
:
'branch'
,
'bnez'
:
'branch'
,
'csrw'
:
'memory'
,
'csrr'
:
'memory'
,
'csrc'
:
'memory'
,
'csrs'
:
'memory'
,
'csrrs'
:
'memory'
,
'csrrc'
:
'memory'
,
'csrrw'
:
'memory'
,
'csr'
:
'memory'
,
'sw'
:
'memory'
,
'fence'
:
'memory'
,
'sub'
:
'arth'
,
'subi'
:
'arth'
,
'lui'
:
'memory'
,
'jr'
:
'branch'
,
'sb'
:
'memory'
,
'sltu'
:
'arth'
,
'sltiu'
:
'arth'
,
'xori'
:
'arth'
,
'andi'
:
'arth'
,
'ori'
:
'arth'
,
'neg'
:
'arth'
,
'xor'
:
'arth'
,
'and'
:
'arth'
,
'or'
:
'arth'
,
'slli'
:
'arth'
,
'srli'
:
'arth'
,
'srai'
:
'arth'
,
'beq'
:
'branch'
,
'srl'
:
'arth'
,
'sll'
:
'arth'
,
'sra'
:
'arth'
,
'addw'
:
'arth'
,
'sllw'
:
'arth'
,
'srlw'
:
'arth'
,
'sraw'
:
'arth'
,
'subw'
:
'arth'
,
'fadd'
:
'arth'
,
'fsub'
:
'arth'
,
'fmul'
:
'arth'
,
'fdiv'
:
'arth'
,
'fadd.s'
:
'arth'
,
'fsub.s'
:
'arth'
,
'fmul.s'
:
'arth'
,
'fdiv.s'
:
'arth'
,
'fnmsub.s'
:
'arth'
,
'bltz'
:
'arth'
,
'auipc'
:
'arth'
,
'beqz'
:
'branch'
,
'eret'
:
'branch'
,
'lw'
:
'memory'
,
'bne'
:
'branch'
,
'ecall'
:
'branch'
,
'rdcycle'
:
'arth'
,
'rdinstret'
:
'arth'
,
'rdtime'
:
'arth'
,
'bgtz'
:
'arth'
,
'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
))
print
(
line
.
strip
())
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
:
pprint
(
profile
(
inputfile
))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment