| 9705 |
hornik |
1 |
#! @PERL@
|
| 9869 |
ripley |
2 |
#-*- perl -*- (for Rprof.in)
|
| 9705 |
hornik |
3 |
|
| 9869 |
ripley |
4 |
# Post-process profiling files generated by Rprof().
|
|
|
5 |
|
|
|
6 |
# Copyright (C) 2000 R Development Core Team
|
|
|
7 |
#
|
|
|
8 |
# This program is free software; you can redistribute it and/or modify
|
|
|
9 |
# it under the terms of the GNU General Public License as published by
|
|
|
10 |
# the Free Software Foundation; either version 2, or (at your option)
|
|
|
11 |
# any later version.
|
|
|
12 |
#
|
|
|
13 |
# This program is distributed in the hope that it will be useful, but
|
|
|
14 |
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
15 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
16 |
# General Public License for more details.
|
|
|
17 |
#
|
| 42314 |
ripley |
18 |
# A copy of the GNU General Public License is available at
|
|
|
19 |
# http://www.r-project.org/Licenses/
|
| 9869 |
ripley |
20 |
|
| 10633 |
hornik |
21 |
# Send any bug reports to r-bugs@r-project.org.
|
| 9869 |
ripley |
22 |
|
| 11515 |
hornik |
23 |
use Getopt::Long;
|
|
|
24 |
use R::Utils;
|
|
|
25 |
|
| 37351 |
ripley |
26 |
my $revision = ' $Rev: 47442 $ ';
|
| 11515 |
hornik |
27 |
my $version;
|
|
|
28 |
my $name;
|
|
|
29 |
|
|
|
30 |
$revision =~ / ([\d\.]*) /;
|
|
|
31 |
$version = $1;
|
|
|
32 |
($name = $0) =~ s|.*/||;
|
|
|
33 |
|
|
|
34 |
sub usage {
|
| 47442 |
hornik |
35 |
print <<END;
|
| 11515 |
hornik |
36 |
Usage: R CMD Rprof [options] file
|
|
|
37 |
|
|
|
38 |
Post-process profiling information in file generated by Rprof().
|
|
|
39 |
|
|
|
40 |
Options:
|
|
|
41 |
-h, --help print short help message and exit
|
| 47442 |
hornik |
42 |
-v, --version print version info and exit
|
| 11515 |
hornik |
43 |
|
| 47442 |
hornik |
44 |
Report bugs to <r-bugs\@r-project.org>.
|
| 11515 |
hornik |
45 |
END
|
|
|
46 |
exit 0;
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
@knownoptions = ("h|help", "v|version");
|
|
|
50 |
GetOptions(@knownoptions) || &usage();
|
|
|
51 |
&R_version("R profiling post-processor", $version) if $opt_v;
|
|
|
52 |
&usage() if $opt_h;
|
|
|
53 |
|
| 9705 |
hornik |
54 |
%leafcounts = ();
|
|
|
55 |
%totalcounts = ();
|
|
|
56 |
|
|
|
57 |
while (<>) {
|
| 9869 |
ripley |
58 |
if (/^sample\.interval=/) {
|
|
|
59 |
s/sample\.interval=//;
|
|
|
60 |
$sample = $_ / 1e6;
|
|
|
61 |
} else {
|
| 9705 |
hornik |
62 |
chomp;
|
|
|
63 |
@line = split(/ /);
|
|
|
64 |
%names = ();
|
|
|
65 |
$leaf = @line[0];
|
|
|
66 |
foreach $name (@line) {
|
| 9869 |
ripley |
67 |
$names{$name} = 1;
|
| 9705 |
hornik |
68 |
}
|
| 9869 |
ripley |
69 |
$total = $total + $sample;
|
| 9705 |
hornik |
70 |
foreach $name (keys %names) {
|
| 9869 |
ripley |
71 |
$totalcounts{$name} = $totalcounts{$name} + $sample;
|
| 9705 |
hornik |
72 |
}
|
| 9869 |
ripley |
73 |
$leafcounts{$leaf} = $leafcounts{$leaf} + $sample;
|
| 9705 |
hornik |
74 |
}
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
print "\n";
|
|
|
78 |
print "Each sample represents $sample seconds.\n";
|
| 9869 |
ripley |
79 |
print "Total run time: $total seconds.\n\n";
|
| 9705 |
hornik |
80 |
print "Total seconds: time spent in function and callees.\n";
|
|
|
81 |
print "Self seconds: time spent in function alone.\n";
|
|
|
82 |
|
|
|
83 |
print "\n";
|
|
|
84 |
print " % total % self\n";
|
|
|
85 |
print " total seconds self seconds name\n";
|
|
|
86 |
|
|
|
87 |
@order = sort { $totalcounts{$b} <=> $totalcounts{$a} } keys %totalcounts;
|
|
|
88 |
foreach $name (@order) {
|
|
|
89 |
printf "%6.2f%10.2f%10.2f%10.2f %s\n",
|
| 9869 |
ripley |
90 |
100 * $totalcounts{$name}/$total, $totalcounts{$name},
|
|
|
91 |
100 * $leafcounts{$name}/$total, $leafcounts{$name},
|
| 9705 |
hornik |
92 |
$name;
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
print "\n";
|
|
|
96 |
print " % self % total\n";
|
|
|
97 |
print " self seconds total seconds name\n";
|
|
|
98 |
|
|
|
99 |
@order = sort { $leafcounts{$b} <=> $leafcounts{$a} } keys %leafcounts;
|
|
|
100 |
foreach $name (@order) {
|
|
|
101 |
printf "%6.2f%10.2f%10.2f%10.2f %s\n",
|
| 9869 |
ripley |
102 |
100 * $leafcounts{$name}/$total, $leafcounts{$name},
|
|
|
103 |
100 * $totalcounts{$name}/$total, $totalcounts{$name},
|
| 9705 |
hornik |
104 |
$name;
|
|
|
105 |
}
|