I have attached a small python script that maps the commit trace generated
by 'TRACE_RIP' and uses object dump information of application to map RIP to
the function. Run '--help' on this script to see all the options.
This script will be added to various utility scripts that Paul (DRAMninja)
has developed.
- Avadh
On Wed, Jun 29, 2011 at 8:34 AM, avadh patel <[email protected]> wrote:
> There is a way, find 'TRACE_RIP' in ptlsim.h file, uncomment it and run the
> simulations. It will dump the trace into 'ptl_rip_trace' file.
>
> - Avadh
>
> On Tue, Jun 28, 2011 at 7:01 PM, Zhaoshi Zheng <[email protected]>wrote:
>
>> Hi,
>>
>> Is there any way to dump out the simulated x86 instructions? I can go with
>> dumping out the translated uops, but native x86 insns would be better.
>>
>> Thanks.
>>
>> _______________________________________________
>> http://www.marss86.org
>> Marss86-Devel mailing list
>> [email protected]
>> https://www.cs.binghamton.edu/mailman/listinfo/marss86-devel
>>
>>
>
#!/usr/bin/env python
# This script read a RIP trace file generated by PQRSim, along with object dump
# of the binary files generated by command 'objdump -t file_name' and gives the
# flow of execution of functions
from __future__ import print_function
import os
import sys
from optparse import OptionParser
# First check if we have enough arguments or not
opt_parser = OptionParser("usage: %prog [options] trace_file outputfile\n\t%prog -h for\
help")
opt_parser.add_option("-o", "--objfiles", dest="obj_file_list",
type="string", help="input object files generated using 'objdump -t',"
+ "add multiple files by comma separated")
(options, args) = opt_parser.parse_args()
if options.obj_file_list == None:
print("%s" % str(opt_parser.get_usage()))
sys.exit(-1)
if args == None or len(args) < 2:
print("Atleast 2 arguments required")
sys.exit(-1)
func_hash_table = {}
max_hash_count = -1
def add_to_hash_table(func_start, func_size, func_name):
global func_hash_table
global max_hash_count
# First get the hash count
hash_count = 0
while (func_size >> hash_count) > 0:
hash_count += 1
if hash_count > max_hash_count:
max_hash_count = hash_count
# Now add the function to table with start addr hash
func_hash_value = ((func_start >> hash_count) << hash_count)
if not func_hash_table.has_key(func_hash_value):
func_hash_table[func_hash_value] = []
func_hash = func_hash_table[func_hash_value]
func_hash.append([func_start, func_size, func_name])
# Now check if the function's end address hash is different
# then add that to the hash table also
func_end = func_start + func_size
if func_hash_value != ((func_end >> hash_count) << hash_count):
func_hash_value = ((func_end >> hash_count) << hash_count)
if not func_hash_table.has_key(func_hash_value):
func_hash_table[func_hash_value] = []
func_hash = func_hash_table[func_hash_value]
func_hash.append([func_start, func_size, func_name])
return
def parse_obj_file(filename):
global func_hash_table
with open(filename, 'r') as obj_file:
for line in obj_file:
l_sp = line.strip().split()
if len(l_sp) < 5:
continue
if len(l_sp) == 5 and l_sp[2] != ".text":
continue
if len(l_sp) >= 6 and not l_sp[3] == ".text":
continue
if len(l_sp) >= 6:
add_i = 1
else:
add_i = 0
try:
func_start = int(l_sp[0], 16)
func_size = int(l_sp[3+add_i], 16)
except ValueError, e:
print("ValueError in line: %s" % line)
print("Error: %s" % str(e))
sys.exit(-1)
func_name = l_sp[4+add_i]
add_to_hash_table(func_start, func_size, func_name)
def find_rip_to_func(rip):
global func_hash_table
global max_hash_count
hash_count = 0
rip_hash = None
while hash_count <= max_hash_count:
hash_count += 1
hash_val = ((rip >> hash_count) << hash_count)
if func_hash_table.has_key(hash_val):
rip_hash = hash_val
func_hash = func_hash_table[rip_hash]
for func in func_hash:
if rip >= func[0] and rip <= (func[0] + func[1]):
return func
if rip_hash == None:
return None
return None
def parse_rip_trace(filename, ofilename):
global func_hash_table
p = os.popen('wc -l %s' % filename)
total_lines = float(p.readline().split()[0])
with open(ofilename, 'w') as output_file:
print("Printing Trace RIP to Functions")
output_file.write("RIP(hex)\t\tSimCycle\tFunctionName\t\tKernelMode\n")
last_rip = -1
counter = 0
with open(filename, 'r') as trace_file:
for line in trace_file:
l_sp = line.strip().split()
if len(l_sp) < 6:
print("Error reading rip trace file.")
continue
rip = int(l_sp[1], 16)
simcycle = int(l_sp[3])
kernel = True if l_sp[5] == '1' else False
print("Reading Line: %.2f%%" % ((float)(counter*100)/total_lines),
end='\r', file=sys.stderr)
counter += 1
if rip == last_rip:
continue
last_rip = rip
func = find_rip_to_func(rip)
if func == None:
func_name = "<Can't Find Function>"
else:
func_name = func[2]
output_file.write("%-16x\t%-10d\t%-30s\t%d\n" %
(rip, simcycle, func_name, kernel))
print("Done")
def parse_rip_trace_only_rip(filename, ofilename):
global func_hash_table
p = os.popen('wc -l %s' % filename)
total_lines = float(p.readline().split()[0])
with open(ofilename, 'w') as output_file:
print("Printing Trace RIP to Functions")
output_file.write("RIP(hex)\t\tSimCycle\tFunctionName\t\tKernelMode\t\tFlags\n")
last_rip = -1
counter = 0
with open(filename, 'r') as trace_file:
for line in trace_file:
l_sp = line.strip().split()
if len(l_sp) < 1:
print("Error reading rip trace file.")
continue
rip = int(l_sp[1], 16)
simcycle = int(l_sp[3])
flags = l_sp[7]
if counter % 100000 == 0:
print("Reading Line: %.2f%%" % ((float)(counter*100)/total_lines),
end='\r', file=sys.stderr)
counter += 1
if rip == last_rip:
continue
last_rip = rip
func = find_rip_to_func(rip)
if func == None:
func_name = "<Can't Find Function>"
else:
func_name = func[2]
output_file.write("%-16x\t%-30s\t%-16d\t%-8s\n" %
(rip, func_name, simcycle, flags))
print("Done")
for obj_fname in options.obj_file_list.split(','):
print("Object file name: %s" % obj_fname)
parse_obj_file(obj_fname)
# Parsing of object files done
#print("Function Hash: %s" % str(func_hash_table))
print("Function hash table rows: %d" % len(func_hash_table))
print("Max Hash count: %d" % max_hash_count)
# Now parse the RIP Trace file and generate the function trace output
# parse_rip_trace(args[0], args[1])
parse_rip_trace_only_rip(args[0], args[1])
_______________________________________________
http://www.marss86.org
Marss86-Devel mailing list
[email protected]
https://www.cs.binghamton.edu/mailman/listinfo/marss86-devel