Based on patches from John W. Woznack <jwoznack@concentric.net>:
[binutils.git] / gprof / bbconv.pl
blob7312f5162fe42cfe8a13fb0d7dcac423392ce6ab
1 #! /usr/bin/perl
3 # This script converts a "bb.out" file into a format
4 # suitable for processing by gprof
6 # Write a new-style gmon header
8 print pack("A4Ix12", "gmon", 1);
11 # The input file format contains header lines and data lines.
12 # Header lines contain a count of how many data lines follow before
13 # the next header line. $blockcount is set to the count that
14 # appears in each header line, then decremented at each data line.
15 # $blockcount should always be zero at the start of a header line,
16 # and should never be zero at the start of a data line.
18 $blockcount=0;
20 while (<>) {
21 if (/^File .*, ([0-9]+) basic blocks/) {
22 print STDERR "Miscount: line $.\n" if ($blockcount != 0);
23 $blockcount = $1;
25 print pack("cI", 2, $blockcount);
27 if (/Block.*executed([ 0-9]+) time.* address= 0x([0-9a-fA-F]*)/) {
28 print STDERR "Miscount: line $.\n" if ($blockcount == 0);
29 $blockcount-- if ($blockcount > 0);
31 $count = $1;
32 $addr = hex $2;
34 print pack("II",$addr,$count);