Blame gprof/bbconv.pl

Packit ba3681
#! /usr/bin/perl
Packit ba3681
Packit ba3681
# This script converts a "bb.out" file into a format
Packit ba3681
# suitable for processing by gprof
Packit ba3681
#
Packit ba3681
# Copyright (C) 2001-2018 Free Software Foundation, Inc.
Packit ba3681
#
Packit ba3681
#   This file is part of GNU Binutils.
Packit ba3681
#
Packit ba3681
#   This program is free software; you can redistribute it and/or modify
Packit ba3681
#   it under the terms of the GNU General Public License as published by
Packit ba3681
#   the Free Software Foundation; either version 3 of the License, or
Packit ba3681
#   (at your option) any later version.
Packit ba3681
#
Packit ba3681
#   This program is distributed in the hope that it will be useful,
Packit ba3681
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit ba3681
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit ba3681
#   GNU General Public License for more details.
Packit ba3681
#
Packit ba3681
#   You should have received a copy of the GNU General Public License
Packit ba3681
#   along with this program; if not, write to the Free Software
Packit ba3681
#   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
Packit ba3681
#   02110-1301, USA.
Packit ba3681
Packit ba3681
# Write a new-style gmon header
Packit ba3681
Packit ba3681
print pack("A4Ix12", "gmon", 1);
Packit ba3681
Packit ba3681
Packit ba3681
# The input file format contains header lines and data lines.
Packit ba3681
# Header lines contain a count of how many data lines follow before
Packit ba3681
# the next header line.  $blockcount is set to the count that
Packit ba3681
# appears in each header line, then decremented at each data line.
Packit ba3681
# $blockcount should always be zero at the start of a header line,
Packit ba3681
# and should never be zero at the start of a data line.
Packit ba3681
Packit ba3681
$blockcount=0;
Packit ba3681
Packit ba3681
while (<>) {
Packit ba3681
    if (/^File .*, ([0-9]+) basic blocks/) {
Packit ba3681
	print STDERR "Miscount: line $.\n" if ($blockcount != 0);
Packit ba3681
	$blockcount = $1;
Packit ba3681
Packit ba3681
	print pack("cI", 2, $blockcount);
Packit ba3681
    }
Packit ba3681
    if (/Block.*executed([ 0-9]+) time.* address= 0x([0-9a-fA-F]*)/) {
Packit ba3681
	print STDERR "Miscount: line $.\n" if ($blockcount == 0);
Packit ba3681
	$blockcount-- if ($blockcount > 0);
Packit ba3681
Packit ba3681
	$count = $1;
Packit ba3681
	$addr = hex $2;
Packit ba3681
Packit ba3681
	print pack("II",$addr,$count);
Packit ba3681
    }
Packit ba3681
}