From 5068d61ef7d879b975eeb6e1cfdf79a0f2d66810 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Thu, 15 Dec 2011 15:19:03 +0100 Subject: cesar/common/tools/cpu-decode: read symbol file --- cesar/common/tools/cpu-decode | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'cesar/common') diff --git a/cesar/common/tools/cpu-decode b/cesar/common/tools/cpu-decode index 1d2be39411..12592eeebd 100755 --- a/cesar/common/tools/cpu-decode +++ b/cesar/common/tools/cpu-decode @@ -3,6 +3,7 @@ use strict; use warnings; use Getopt::Long qw(:config no_ignore_case bundling); use Pod::Usage; +use List::MoreUtils qw(lastval); # Options parsing. my $help; @@ -10,10 +11,12 @@ my $man; my $scale; my $divisor = 25; my $unit = 'us'; +my $syms; GetOptions ( 'help|h' => \$help, 'man' => \$man, 'scale|s=s' => \$scale, + 'syms|t=s' => \$syms, ) or pod2usage (2); pod2usage (-verbose => 2) if $man; pod2usage (1) if $help; @@ -25,6 +28,31 @@ if (defined $scale) ($divisor, $unit) = ($1 + 0, $2); } +# Load symbols. +my %syms; +my @syms; +if (defined $syms) +{ + open SYMS, "<$syms" or die "can not load $syms: $!"; + while () + { + if (/^([0-9a-f]{8})\s.*\s(\S+)$/) + { + $syms{hex ($1)} = $2; + } + } + close SYMS; + @syms = sort { $a <=> $b } keys %syms; +} + +sub symbol +{ + return '' if !@syms; + my ($addr) = @_; + $addr = lastval { $_ < $addr } @syms; + return " ($syms{$addr})"; +} + my %map = ( # For each event: # - event action: @@ -119,7 +147,9 @@ my $sum = 0; $sum += $_ for values %sum; for (sort keys %sum) { - printf "$_: $efmt, %.1f %%\n", + my $c = $_; + $c =~ s/(sp|pc)=(0x[0-9a-f]{8})/"$1=$2" . symbol (hex ($2))/e; + printf "$c: $efmt, %.1f %%\n", $sum{$_} / $divisor, $sum{$_} * 100.0 / $sum; } @@ -139,6 +169,7 @@ cpu-decode [options] [files...] -h, --help brief help message --man output manual -s, --scale=DIVISOR[/UNIT] scale factor and optional unit + -t, --syms=SYMBOL_FILE listing produced by `objdump -t' =head1 DESCRIPTION -- cgit v1.2.3