~ubuntu-branches/ubuntu/maverick/lire/maverick

« back to all changes in this revision

Viewing changes to all/script/lr_prof_report.in

  • Committer: Bazaar Package Importer
  • Author(s): Joost van Baal
  • Date: 2002-04-11 23:36:21 UTC
  • Revision ID: james.westby@ubuntu.com-20020411233621-rj3dbr7z5wulfd7z
Tags: upstream-20020214
ImportĀ upstreamĀ versionĀ 20020214

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! @PATHTOPERL@ -w
 
2
 
 
3
# vim:syntax=perl
 
4
 
 
5
use strict;
 
6
 
 
7
use lib '@LR_PERL5LIBDIR@';
 
8
 
 
9
use Lire::Program qw( :msg tempfile $PROG );
 
10
use Lire::DataTypes qw( :special );
 
11
 
 
12
sub save_stats {
 
13
    my ( $superservice, $cfg_file, $dlf_file ) = @_;
 
14
 
 
15
    my %stats = ();
 
16
    open( DLF2XML, "lr_dlf2xml $superservice $cfg_file $dlf_file 2>&1 >/dev/null |")
 
17
      or lr_err( "can't fork: $!" );
 
18
    while ( <DLF2XML> ) {
 
19
        print STDERR $_;
 
20
        if ( /vsize=(\d+)K rss=(\d+)K/ ) {
 
21
            $stats{vsize} = $1;
 
22
            $stats{rss} = $2;
 
23
        } elsif ( /contains (\d+) records/ ) {
 
24
            $stats{dlf} = $1;
 
25
        } elsif ( /real=([.\d]+) user=([.\d]+) system=([.\d]+)/ ) {
 
26
            $stats{real}    = $1;
 
27
            $stats{user}    = $2;
 
28
            $stats{system}  = $3;
 
29
        }
 
30
    }
 
31
    close DLF2XML
 
32
      or lr_err( "error executing lr_dlf2xml" );
 
33
 
 
34
    return \%stats;
 
35
}
 
36
 
 
37
 
 
38
my ( $superservice, $cfg_file, $dlf_file ) = @ARGV
 
39
  or lr_err( "Usage: $PROG superservice cfg_file dlf_file" );
 
40
 
 
41
die "invalid superservice : $superservice\n"
 
42
  unless check_superservice( $superservice );
 
43
 
 
44
 
 
45
my @reports;
 
46
open REPORT_CFG, $cfg_file
 
47
  or lr_err( "can't open $cfg_file: $!" );
 
48
while (<REPORT_CFG>) {
 
49
    chomp;
 
50
    next if /^\s*(#.*)?$/; # Skip comments and empty lines
 
51
    push @reports, $_;
 
52
}
 
53
close REPORT_CFG;
 
54
 
 
55
my %stats;
 
56
 
 
57
# Run empty report
 
58
$stats{lr_none} = save_stats( $superservice, "/dev/null", $dlf_file );
 
59
$stats{lr_all} = save_stats( $superservice, $cfg_file, $dlf_file );
 
60
foreach my $report (@reports) {
 
61
    my ($fh,$tmp_cfg_file) = tempfile( "lr_prof_report-XXXXXX", SUFFIX => ".cfg" );
 
62
    print $fh $report;
 
63
    my $report_name = (split /\s+/, $report)[0];
 
64
    $stats{$report_name} = save_stats( $superservice, $tmp_cfg_file, $dlf_file );
 
65
    unlink $tmp_cfg_file;
 
66
}
 
67
 
 
68
# Compute the RSS difference it represents
 
69
my $none_rss = $stats{lr_none}{rss};
 
70
my $all_rss  = $stats{lr_all}{rss};
 
71
my $max_rss_diff = $all_rss - $none_rss;
 
72
foreach my $r ( keys %stats ) {
 
73
    $stats{$r}{diff} = ($stats{$r}{rss} - $none_rss) / $max_rss_diff;
 
74
    $stats{$r}{diff} *= 100;
 
75
}
 
76
 
 
77
print "Profiling Statistics for $superservice report\n";
 
78
printf "%-20s %8s %8s %8s %8s %8s %8s %8s\n", qw( NAME RECORDS VSIZE RSS DIFF% REAL USER SYSTEM );
 
79
foreach my $report ( map { $_->[0] } 
 
80
                     sort { $b->[1]{rss} <=> $a->[1]{rss} }
 
81
                     map { [$_, $stats{$_}] } keys %stats )
 
82
{
 
83
    my $s = $stats{$report};
 
84
      printf "%-20s %8d %7dK %7dK %8.2f %8.2f %8.2f %8.2f\n", $report,
 
85
        map { $s->{$_} } qw( dlf vsize rss diff real user system );
 
86
}
 
87
 
 
88
# Local Variables:
 
89
# mode: cperl
 
90
# End:
 
91
 
 
92
__END__
 
93
 
 
94
=pod
 
95
 
 
96
=head1 NAME
 
97
 
 
98
lr_prof_report - Profile a report configuration.
 
99
 
 
100
=head1 SYNOPSIS 
 
101
 
 
102
B<lr_prof_report> I<superservice> I<report_cfg_file> I<dlffile>
 
103
 
 
104
=head1 DESCRIPTION
 
105
 
 
106
B<lr_prof_report> can be used to profile reports for a superservice to
 
107
determine which reports are taking the most memory. It will run
 
108
B<lr_dlf2xml> with I<report_cfg_file>, with an empty configuration
 
109
file and one time for each report present in I<report_cfg_file>. It
 
110
will collect performance statistics (time and memory) and print a
 
111
statistical report at the end.
 
112
 
 
113
=head1 PROFILING REPORT
 
114
 
 
115
B<lr_prof_report> will output a column formatted report. Each row
 
116
represent the statistics of generating a report from that report
 
117
specification. The reports are sorted by physical memory used. The
 
118
different columns are :
 
119
 
 
120
=over 4
 
121
 
 
122
=item NAME
 
123
 
 
124
The name of the report. This is the content of the ID attribute in the
 
125
report specification. This is also the value used in the report
 
126
configuration file. There are two special names. B<lr_all> which is
 
127
used for the run using the complete report configuration and
 
128
B<lr_none> which is used for the empty configuration file run.
 
129
 
 
130
=item RECORDS
 
131
 
 
132
The number of DLF records processed.
 
133
 
 
134
=item VSIZE
 
135
 
 
136
(This will only be available on Linux). Virtual memory used by the
 
137
program. This is the size of the virtual memory map. This isn't the
 
138
size of the physical memory used by the report.
 
139
 
 
140
=item RSS
 
141
 
 
142
(This will only be available on Linux). The resident set size of the
 
143
process. This is the maximum amount of physical memory used by the
 
144
report.
 
145
 
 
146
=item DIFF%
 
147
 
 
148
(This will only be available on Linux). This is the percentage of the
 
149
physical memory used by the report which isn't used by libraries or
 
150
the perl interpreter. The formula used is : 
 
151
 
 
152
  (RSS - RSS for lr_none) * 100 / (RSS for lr_all - RSS for lr_none)
 
153
 
 
154
This means that the value will be 0 for lr_none and 100 for lr_all and
 
155
in between values for the other reports. This is useful to find the
 
156
report specifications that used huge amount of memory.
 
157
 
 
158
=item REAL
 
159
 
 
160
The number of wall clock seconds used to generate the report. This
 
161
value has a granularity of 1sec.
 
162
 
 
163
=item USER
 
164
 
 
165
The nuber of CPU time in user space used to generate the report. This
 
166
usually has subsecond granularity.
 
167
 
 
168
=item SYSTEM
 
169
 
 
170
The nuber of CPU time in kernel space used to generate the report.
 
171
This usually has subsecond granularity.
 
172
 
 
173
=back
 
174
 
 
175
=head1 SEE ALSO
 
176
 
 
177
lr_dlf2xml(1)
 
178
 
 
179
=head1 AUTHOR
 
180
 
 
181
Francis J. Lacoste <flacoste@logreport.org>
 
182
 
 
183
=head1 VERSION
 
184
 
 
185
$Id: lr_prof_report.in,v 1.3 2001/10/18 19:13:17 flacoste Exp $
 
186
 
 
187
=head1 COPYRIGHT
 
188
 
 
189
Copyright (C) 2001 Stichting LogReport Foundation LogReport@LogReport.org
 
190
 
 
191
This program is free software; you can redistribute it and/or modify
 
192
it under the terms of the GNU General Public License as published by
 
193
the Free Software Foundation; either version 2 of the License, or
 
194
(at your option) any later version.
 
195
 
 
196
This program is distributed in the hope that it will be useful,
 
197
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
198
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
199
GNU General Public License for more details.
 
200
 
 
201
You should have received a copy of the GNU General Public License
 
202
along with this program (see COPYING); if not, check with
 
203
http://www.gnu.org/copyleft/gpl.html or write to the Free Software 
 
204
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
 
205
 
 
206
=cut