bbconv.pl 1.8 KB

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