File: lr_prof_report.in

package info (click to toggle)
lire 20020214-7
  • links: PTS
  • area: main
  • in suites: woody
  • size: 6,180 kB
  • ctags: 1,245
  • sloc: perl: 11,637; xml: 5,725; sh: 3,458; makefile: 1,008
file content (206 lines) | stat: -rw-r--r-- 5,878 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#! @PATHTOPERL@ -w

# vim:syntax=perl

use strict;

use lib '@LR_PERL5LIBDIR@';

use Lire::Program qw( :msg tempfile $PROG );
use Lire::DataTypes qw( :special );

sub save_stats {
    my ( $superservice, $cfg_file, $dlf_file ) = @_;

    my %stats = ();
    open( DLF2XML, "lr_dlf2xml $superservice $cfg_file $dlf_file 2>&1 >/dev/null |")
      or lr_err( "can't fork: $!" );
    while ( <DLF2XML> ) {
	print STDERR $_;
	if ( /vsize=(\d+)K rss=(\d+)K/ ) {
	    $stats{vsize} = $1;
	    $stats{rss} = $2;
	} elsif ( /contains (\d+) records/ ) {
	    $stats{dlf} = $1;
	} elsif ( /real=([.\d]+) user=([.\d]+) system=([.\d]+)/ ) {
	    $stats{real}    = $1;
	    $stats{user}    = $2;
	    $stats{system}  = $3;
	}
    }
    close DLF2XML
      or lr_err( "error executing lr_dlf2xml" );

    return \%stats;
}


my ( $superservice, $cfg_file, $dlf_file ) = @ARGV
  or lr_err( "Usage: $PROG superservice cfg_file dlf_file" );

die "invalid superservice : $superservice\n"
  unless check_superservice( $superservice );


my @reports;
open REPORT_CFG, $cfg_file
  or lr_err( "can't open $cfg_file: $!" );
while (<REPORT_CFG>) {
    chomp;
    next if /^\s*(#.*)?$/; # Skip comments and empty lines
    push @reports, $_;
}
close REPORT_CFG;

my %stats;

# Run empty report
$stats{lr_none} = save_stats( $superservice, "/dev/null", $dlf_file );
$stats{lr_all} = save_stats( $superservice, $cfg_file, $dlf_file );
foreach my $report (@reports) {
    my ($fh,$tmp_cfg_file) = tempfile( "lr_prof_report-XXXXXX", SUFFIX => ".cfg" );
    print $fh $report;
    my $report_name = (split /\s+/, $report)[0];
    $stats{$report_name} = save_stats( $superservice, $tmp_cfg_file, $dlf_file );
    unlink $tmp_cfg_file;
}

# Compute the RSS difference it represents
my $none_rss = $stats{lr_none}{rss};
my $all_rss  = $stats{lr_all}{rss};
my $max_rss_diff = $all_rss - $none_rss;
foreach my $r ( keys %stats ) {
    $stats{$r}{diff} = ($stats{$r}{rss} - $none_rss) / $max_rss_diff;
    $stats{$r}{diff} *= 100;
}

print "Profiling Statistics for $superservice report\n";
printf "%-20s %8s %8s %8s %8s %8s %8s %8s\n", qw( NAME RECORDS VSIZE RSS DIFF% REAL USER SYSTEM );
foreach my $report ( map { $_->[0] } 
		     sort { $b->[1]{rss} <=> $a->[1]{rss} }
		     map { [$_, $stats{$_}] } keys %stats )
{
    my $s = $stats{$report};
      printf "%-20s %8d %7dK %7dK %8.2f %8.2f %8.2f %8.2f\n", $report,
	map { $s->{$_} } qw( dlf vsize rss diff real user system );
}

# Local Variables:
# mode: cperl
# End:

__END__

=pod

=head1 NAME

lr_prof_report - Profile a report configuration.

=head1 SYNOPSIS 

B<lr_prof_report> I<superservice> I<report_cfg_file> I<dlffile>

=head1 DESCRIPTION

B<lr_prof_report> can be used to profile reports for a superservice to
determine which reports are taking the most memory. It will run
B<lr_dlf2xml> with I<report_cfg_file>, with an empty configuration
file and one time for each report present in I<report_cfg_file>. It
will collect performance statistics (time and memory) and print a
statistical report at the end.

=head1 PROFILING REPORT

B<lr_prof_report> will output a column formatted report. Each row
represent the statistics of generating a report from that report
specification. The reports are sorted by physical memory used. The
different columns are :

=over 4

=item NAME

The name of the report. This is the content of the ID attribute in the
report specification. This is also the value used in the report
configuration file. There are two special names. B<lr_all> which is
used for the run using the complete report configuration and
B<lr_none> which is used for the empty configuration file run.

=item RECORDS

The number of DLF records processed.

=item VSIZE

(This will only be available on Linux). Virtual memory used by the
program. This is the size of the virtual memory map. This isn't the
size of the physical memory used by the report.

=item RSS

(This will only be available on Linux). The resident set size of the
process. This is the maximum amount of physical memory used by the
report.

=item DIFF%

(This will only be available on Linux). This is the percentage of the
physical memory used by the report which isn't used by libraries or
the perl interpreter. The formula used is : 

  (RSS - RSS for lr_none) * 100 / (RSS for lr_all - RSS for lr_none)

This means that the value will be 0 for lr_none and 100 for lr_all and
in between values for the other reports. This is useful to find the
report specifications that used huge amount of memory.

=item REAL

The number of wall clock seconds used to generate the report. This
value has a granularity of 1sec.

=item USER

The nuber of CPU time in user space used to generate the report. This
usually has subsecond granularity.

=item SYSTEM

The nuber of CPU time in kernel space used to generate the report.
This usually has subsecond granularity.

=back

=head1 SEE ALSO

lr_dlf2xml(1)

=head1 AUTHOR

Francis J. Lacoste <flacoste@logreport.org>

=head1 VERSION

$Id: lr_prof_report.in,v 1.3 2001/10/18 19:13:17 flacoste Exp $

=head1 COPYRIGHT

Copyright (C) 2001 Stichting LogReport Foundation LogReport@LogReport.org
 
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program (see COPYING); if not, check with
http://www.gnu.org/copyleft/gpl.html or write to the Free Software 
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.

=cut