Skip to content

Instantly share code, notes, and snippets.

@cornerwings
Created October 31, 2010 01:52
Show Gist options
  • Save cornerwings/656006 to your computer and use it in GitHub Desktop.
Save cornerwings/656006 to your computer and use it in GitHub Desktop.
Small ruby script to prettify dump output from pin
#!/usr/bin/env ruby
# Dump format should be like this
# (STAGE) OP (OP_ID) ... cycle (CYCLE)
# Matching is case insensitive
#
# Examples:
# FE_STAGE OP 0 is fetched at cycle 1
# ID_STAGE OP 0 is scheduled at cycle 3
# IS_STAGE OP 0 is issued at cycle 3
# EX_STAGE OP 0 finished execution at cycle 5
# WB_STAGE OP 0 is retired at cycle 6
#
# Look at the addstage function for stages defined
#
# The following are the current stages
# FE_stage: after instruction is fetched
# ID_stage: after instruction is added to scheduler
# IS_stage: instruction is selected for execution i.e will be in EX stage next cycle
# EX_stage: instruction finished execution
# WB_stage: instruction retired
#
# Dont be confused by ID_stage, Op is added to scheduler in IS_stage, just easier
# to differentiate in the parsing
#
# Usage:
# ../../../pin -t obj-intel64/sim.so -readtrace 1 -printinst 0 -max_sim_count 0 -max_inst_count 2 -print_pipe_freq 0 # -tracename trace2.pzip -- /bin/ls | ruby prettydump.rb
#
# Higher the tab width better the formatting of output
# Monkey patch to NilClass to print "-" instead of "" for nil case
class NilClass
def to_s
return "-"
end
end
# Op class
class Op
attr_accessor :op_id, :fe, :id, :is, :ex, :wb
def initialize(id)
@op_id = id
end
def addstage(stage, cycle)
case stage
when 'FE_STAGE'
@fe = cycle
when 'ID_STAGE'
@id = cycle
when 'IS_STAGE'
@is = cycle
when 'EX_STAGE'
@ex = cycle
when 'WB_STAGE'
@wb = cycle
end
end
def to_s
@fe.to_s+"\t"+@id.to_s+"\t"+@is.to_s+"\t"+@ex.to_s+"\t"+@wb.to_s
end
end
ops = Array.new
op_cnt = -1
op_ex = Regexp.new(/(.+)\s+OP\s+(\d+).+cycle\s+(\d+)/i)
# Iterate over the dump file
ARGF.each{
|line|
matchdata = op_ex.match(line)
# Add stage to the op found in ops, if not create and then add
ops.find(lambda{
op = Op.new(op_cnt+=1)
ops.push(op)
return op
}) {
|op|
op.op_id == matchdata[2].to_i
}.addstage(matchdata[1], matchdata[3]) if matchdata
}
# the actual pretty print
puts <<-STAGE_INFORMATION
# The following are the current stages
# FE: after instruction is fetched
# ID: after instruction is added to scheduler
# IS: instruction is selected for execution
# EX: instruction finished execution
# WB: instruction retired
STAGE_INFORMATION
puts "\n\n "+"\tFE\tID\tIS\tEX\tWB\n"
ops.each{
|op|
puts op.op_id.to_s + "\t" + op.to_s
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment