mirror of the now-defunct rocklinux.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.2 KiB

  1. #!/usr/bin/perl -w
  2. #
  3. # --- ROCK-COPYRIGHT-NOTE-BEGIN ---
  4. #
  5. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  6. # Please add additional copyright information _after_ the line containing
  7. # the ROCK-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by
  8. # the ./scripts/Create-CopyPatch script. Do not edit this copyright text!
  9. #
  10. # ROCK Linux: rock-src/package/base/oprofile/pulpstoner.pl
  11. # ROCK Linux is Copyright (C) 1998 - 2004 Clifford Wolf
  12. #
  13. # This program is free software; you can redistribute it and/or modify
  14. # it under the terms of the GNU General Public License as published by
  15. # the Free Software Foundation; either version 2 of the License, or
  16. # (at your option) any later version. A copy of the GNU General Public
  17. # License can be found at Documentation/COPYING.
  18. #
  19. # Many people helped and are helping developing ROCK Linux. Please
  20. # have a look at http://www.rocklinux.org/ and the Documentation/TEAM
  21. # file for details.
  22. #
  23. # --- ROCK-COPYRIGHT-NOTE-END ---
  24. use English;
  25. use strict;
  26. my $min_samples = 1000;
  27. my $min_percent = 2;
  28. my $min_points = 10;
  29. my %roots;
  30. my %percents;
  31. my %files;
  32. my %binaries;
  33. my $bin;
  34. sub read_pkgdb($) {
  35. my $root=$_[0];
  36. print "Reading package DB from /$root ...\n";
  37. open(F, "cat /${root}var/adm/flists/*|") || die $!;
  38. while (<F>) {
  39. chomp; @_ = split /:\s+/;
  40. $files{${root}.$_[1]} = $_[0];
  41. }
  42. close F;
  43. }
  44. read_pkgdb("");
  45. my $pc = 0;
  46. open(F, "opreport -f -n | sort -r -g -k 2|") || die $!;
  47. for (<F>) {
  48. @_ = split /\s+/; $pc+=$_[2];
  49. last if $_[1] < $min_samples;
  50. last if $pc > 100-$min_percent;
  51. next unless -f $_[3];
  52. $_[3] =~ s,^/,,;
  53. $binaries{$_[3]} = $_[2];
  54. }
  55. close F;
  56. foreach $bin (keys %binaries) {
  57. if ( $bin =~ m,(.*/root/), and not defined $roots{$1} ) {
  58. $roots{$1} = 1;
  59. read_pkgdb($1);
  60. }
  61. if ( not defined $files{$bin} ) {
  62. print "Not found in package db: $bin\n";
  63. next;
  64. }
  65. open(F, "opreport -g --symbols -n /$bin|") || die $!;
  66. while (<F>) {
  67. next if /\(no location information\)/;
  68. my ($count, $percent, $src, $sym) = split /\s+/; $src =~ s/:.*//;
  69. $percents{sprintf "%-14s\t%-22s\t%s",
  70. $files{$bin}, $src, $bin} += $percent * $binaries{$bin};
  71. }
  72. close F;
  73. }
  74. foreach (keys %percents) {
  75. next if $percents{$_} < $min_points;
  76. printf "** %9.2f:\t%s\n", $percents{$_}, $_;
  77. }