chiark / gitweb /
Fix HOSTNAME thing in configure.in
[inn-innduct.git] / contrib / stathist.in
1 #!/usr/bin/perl -w
2
3 # Parse log files created by innd history profiler
4 # 2001/01/29 - Fabien Tassin
5
6 use strict;
7 use FileHandle;
8
9 my $file = shift || "stathist.log";
10 if ($file eq '-h' || $file eq '--help') {
11   print "Usage: stathist [logfile]\n";
12   exit 0;
13 }
14
15 sub parse {
16   my $file = shift;
17
18   my $f = new FileHandle $file;
19   unless (defined $f) {
20     print STDERR "Can't open file: $!\n";
21     return {};
22   }
23   my $data = {};
24   my $begin = 1;
25   my @stack = ();
26   while (defined (my $line = <$f>)) {
27     next if $begin && $line !~ / HIS(havearticle|write|setup) begin/;
28     $begin = 0;
29     chomp $line;
30     my @c = split /[\[\]\(\) ]+/, $line;
31     ($c[4] eq 'begin') && do {
32       push @stack, $c[3];
33       my $d = $data;
34       for my $l (@stack) {
35         unless (defined $$d{$l}) {
36           $$d{$l}{'min'} = 1E10;
37           $$d{$l}{'total'} = $$d{$l}{'count'} = $$d{$l}{'max'} = 0;
38         }
39         $d = $$d{$l}
40       }
41     } ||
42     ($c[4] eq 'end') && do {
43       my $d = $data;
44       for my $l (@stack) {
45         $d = $$d{$l};
46       }
47       $$d{'count'}++;
48       $$d{'total'} += $c[5];
49       $$d{'min'} = $c[5] if $$d{'min'} > $c[5];
50       $$d{'max'} = $c[5] if $$d{'max'} < $c[5];
51       pop @stack;
52     };
53   }
54   $f->close;
55   $data;
56 }
57
58 sub report {
59   my $data = shift;
60   my $inc = shift;
61
62   unless (defined $inc) {
63     printf "%-16s %10s %14s %10s %10s %10s\n\n", "Function", "Invoked",
64       "Total(s)", "Min(ms)", "Avg(ms)", "Max(ms)";
65     $inc = 0;
66   }
67
68   for my $key (sort keys %$data) {
69     next unless $key =~ m/^HIS/;
70     printf "%-16s %10d %14.6f %10.3f %10.3f %10.3f\n", ('  ' x $inc) . $key,
71       $$data{$key}{'count'}, $$data{$key}{'total'}, $$data{$key}{'min'} * 1000,
72       $$data{$key}{'total'} / $$data{$key}{'count'} * 1000,
73       $$data{$key}{'max'} * 1000;
74     &report($$data{$key}, $inc + 1)
75   }
76 }
77
78 my $data = &parse($file);
79 &report($data);