2003-01-31 Frank Ch. Eigler <fche@redhat.com>
[binutils-gdb.git] / gprof / bbconv.pl
blobd83c00e2db9d92c7d7d98ecfa2f133235e125901
1 #! /usr/bin/perl
3 # This script converts a "bb.out" file into a format
4 # suitable for processing by gprof
6 # Copyright 2001 Free Software Foundation, Inc.
8 # This file is part of GNU Binutils.
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write to the Free Software
22 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23 # 02111-1307, USA.
25 # Write a new-style gmon header
27 print pack("A4Ix12", "gmon", 1);
30 # The input file format contains header lines and data lines.
31 # Header lines contain a count of how many data lines follow before
32 # the next header line. $blockcount is set to the count that
33 # appears in each header line, then decremented at each data line.
34 # $blockcount should always be zero at the start of a header line,
35 # and should never be zero at the start of a data line.
37 $blockcount=0;
39 while (<>) {
40 if (/^File .*, ([0-9]+) basic blocks/) {
41 print STDERR "Miscount: line $.\n" if ($blockcount != 0);
42 $blockcount = $1;
44 print pack("cI", 2, $blockcount);
46 if (/Block.*executed([ 0-9]+) time.* address= 0x([0-9a-fA-F]*)/) {
47 print STDERR "Miscount: line $.\n" if ($blockcount == 0);
48 $blockcount-- if ($blockcount > 0);
50 $count = $1;
51 $addr = hex $2;
53 print pack("II",$addr,$count);