test removing string duplicates using hashes
[tridge/junkcode.git] / strace_analyse.pl
1 #!/usr/bin/perl -w
2
3 # analyse a strace in format given by strace -ttT
4 # Andrew Tridgell <tridge@samba.org> March 2006
5 # released under GNU GPL version 2 or later
6
7
8 my %totals;
9 my %cpu;
10 my $total;
11 my $total_cpu;
12
13 my $start = 0;
14
15 while (my $line = <>) {
16         my $call;
17         my $time;
18         my $clock;
19         if ($line =~ /^(\d+):(\d+):(\d+).(\d+) ([a-z0-9]+)\(.* <(\d[^>]+)/ ||
20             $line =~ /^\d+\s+(\d+):(\d+):(\d+).(\d+) ([a-z0-9]+)\(.* <(\d[^>]+)/) {
21                 $clock = ($1 * 3600) + ($2 * 60) + $3 + ($4 * 1.0e-6);
22                 $call = $5;
23                 $time = $6;
24                 $totals{$call} += $time;
25                 $total += $time;
26                 if ($start != 0) {
27                         $cpu{$call} += $clock - $start;
28                         $total_cpu += $clock - $start;
29                 }
30                 $start = $clock + $time;
31         }
32 }
33
34
35 print"
36   CALL       time(sec) percent
37   -----------------------------
38 ";
39
40 foreach my $c (sort { $totals{$b} <=> $totals{$a} } keys %totals) {
41         printf "  %-13s %6.2f  %5.2f%%\n", $c, $totals{$c}, 100.0*$totals{$c}/$total, 
42 }
43 printf("  %-13s %6.2f\n", "TOTAL", $total);
44
45 print"
46   CALL        cpu(sec) percent
47   -----------------------------
48 ";
49
50 foreach my $c (sort { $cpu{$b} <=> $cpu{$a} } keys %cpu) {
51         printf "  %-13s %6.2f  %5.2f%%\n", $c, $cpu{$c}, 100.0*$cpu{$c}/$total_cpu, 
52 }
53 printf("  %-13s %6.2f\n", "TOTAL", $total_cpu);