summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorBert Lange <b.lange@fzd.de>2010-11-19 11:26:02 +0100
committerBert Lange <b.lange@fzd.de>2010-11-19 11:26:02 +0100
commitd5416de5d3a276bf73be15c62c0a4120316cfa8c (patch)
tree13e2d8ba3aef0ba2b9d3a8b543171d4ddb3a705b /tools
parent85f89df61839beb476116da8b5fa3c7c8512ac2e (diff)
downloadzpu-d5416de5d3a276bf73be15c62c0a4120316cfa8c.zip
zpu-d5416de5d3a276bf73be15c62c0a4120316cfa8c.tar.gz
add: debugging tools
Diffstat (limited to 'tools')
-rw-r--r--tools/debugging/convert_trace.py82
-rw-r--r--tools/debugging/statistic_trace.py113
2 files changed, 195 insertions, 0 deletions
diff --git a/tools/debugging/convert_trace.py b/tools/debugging/convert_trace.py
new file mode 100644
index 0000000..289ccd1
--- /dev/null
+++ b/tools/debugging/convert_trace.py
@@ -0,0 +1,82 @@
+#!/usr/bin/python
+"""
+es wird benoetigt:
+
+# Disassemblerlisting
+zpu-elf-objdump --disassemble --source greth.elf > greth.diss
+
+# Simulationsoutput
+# Simulator -> trace.txt
+
+convert_trace.py sucht die zu einer trace-zeile
+passende Zeilennummer aus dem Disassemblerlisting
+
+
+# das Ausgabeformat kann von vim/quickfix gelesen werden
+# Achtung! Ggf lange Laufzeit
+# (ca. 3min fuer 1 MB trace.txt)
+convert_trace.py > greth_conv.txt
+
+
+Verwendung in vim:
+
+"" """"""""""""""""""""
+" quickfix-Handling
+" Alt-2 bzw. Alt-3 um durch die Fehlerliste zu gehen
+set errorformat +=$f:%l:%m
+noremap <M-2> :cp<CR>
+noremap <M-3> :cn<CR>
+
+"""
+
+import profile
+
+import string
+import re
+
+
+def get_line_number( src, pattern):
+ lineno = 0
+ for m in re.finditer( pattern, src):
+ start = m.start()
+ lineno = src.count('\n', 0, start)+2
+ #offset = start - src.rfind('\n',0 ,start)
+ #word = m.group(0)
+ #print "greth.diss(%s,%s): %s" % (lineno, offset, word)
+ break
+ return lineno
+
+
+def do_stuff():
+
+
+ src = open('greth.diss').read()
+
+ with open("trace.txt", "rU") as fobj:
+
+ line_count = 0
+
+ for line in fobj:
+
+ #if line_count < 10000:
+ # line_count += 1
+ #else:
+ # break
+
+ line.strip()
+
+ if line.lstrip().startswith("#"):
+ continue
+ if line.lstrip() == '':
+ continue
+
+ zuordnung = line.split(" ")
+ pc = string.atoi( zuordnung[0], 16)
+ search_str = "\s+%x:.*" % (pc)
+
+ print "greth.diss:%d:%s" % ( get_line_number( src, search_str), line.rstrip('\r\n'))
+
+
+profile.run('do_stuff()')
+
+
diff --git a/tools/debugging/statistic_trace.py b/tools/debugging/statistic_trace.py
new file mode 100644
index 0000000..02b55f1
--- /dev/null
+++ b/tools/debugging/statistic_trace.py
@@ -0,0 +1,113 @@
+#!/usr/bin/python
+
+"""
+
+Erzeugt eine Statistik in welcher Programmfunktion die Taktzyklen
+verbraten werden.
+
+benoetigt den Simulationstrace -> trace.txt
+und eine Liste mit den Symbolen (sortiert)
+
+dabei sollten die Symbole mit 'N' und 't' ignoriert werden
+
+zpu-elf-nm --numeric-sort greth.elf | grep -v " N " | grep -v " t " > greth.symbols
+
+
+Aufruf:
+statistic_trace.py > greth_statistic.txt
+
+"""
+
+import string
+import re
+
+
+def get_symbol_line( src, number):
+
+ lastline = ""
+ lastaddr = -1
+
+ for lineno, line in enumerate( src):
+
+ line = line.strip()
+
+ try:
+ addr = string.atoi( "0x0"+line.split(" ")[0], 16)
+
+ except ValueError:
+ #print "ignore: %s" % line
+ addr = -1
+
+ if (number >= lastaddr) and (number < addr):
+ result = " ".join( lastline.split(" ")[1:] )
+ #return result
+ return lastline.split(" ")[2]
+ #return lastaddr
+
+ lastline = line
+ lastaddr = addr
+
+# lineno = 0
+# for m in re.finditer( pattern, src):
+# start = m.start()
+# lineno = src.count('\n', 0, start)+2
+# #offset = start - src.rfind('\n',0 ,start)
+# #word = m.group(0)
+# #print "greth.diss(%s,%s): %s" % (lineno, offset, word)
+# break
+# return lineno
+ return ""
+# return 0
+
+
+
+def sortkey( (k,v)):
+ return (-v, k)
+
+
+
+def do_stuff():
+
+ statistik = {}
+
+ src = open('greth.symbols').readlines()
+
+ with open("trace.txt", "rU") as fobj:
+
+ line_count = 0
+
+ for line in fobj:
+
+# if line_count < 100:
+# line_count += 1
+# else:
+# print "attention debug shortcut!"
+# break
+
+ line = line.strip()
+
+ if line.startswith("#"):
+ continue
+ if len(line) == 0:
+ continue
+
+ zuordnung = line.split(" ")
+ pc = string.atoi( zuordnung[0], 16)
+ #print "%s --- %s" % ( get_symbol_line( src, pc), line)
+ value = get_symbol_line( src, pc)
+ if not value in statistik:
+ statistik[ value ] = 1
+ else:
+ statistik[ value ] += 1
+
+
+ items = statistik.items()
+ items.sort( key=sortkey)
+
+
+ for value, key in items:
+ print "%30s , %s" % (value, key)
+
+do_stuff()
+
+
OpenPOWER on IntegriCloud