1 # Script to take output from the Transform::multiply tracking REPORT_LOG output
2 # and generate a report of callstacks sorted in descending frequency order.
7 my $callstackFrequency = 0;
11 my %callstacksByFrequency;
15 die "bad callstackFrequency [$callstackFrequency]" if (!($callstackFrequency =~ m/^\d+$/));
16 return if (@
$callstackLinesRef < 1);
18 # Make sure there's an array reference to hold all callstacks mapping to this frequency.
19 if (!exists $callstacksByFrequency{$callstackFrequency})
21 $callstacksByFrequency{$callstackFrequency} = [];
25 my $callstackArrayRef = $callstacksByFrequency{$callstackFrequency};
27 # Add callstack lines array to it.
28 push @
$callstackArrayRef, $callstackLinesRef;
33 $callstackLinesRef = [];
38 #-- Clean up line: remove line number and time info from log.
40 s/\d+\s+\d+\.\d+\s+//;
44 # Check if this matches a start of callstack line.
45 if (m/Transform::multiply/)
49 # Add existing (now complete) callstack, restart a new one immediately following, starting on this line.
54 # Mark that we're now in a callstack so we know to scan following lines.
59 # Parse out frequency.
60 if (m/called (\d+) times/)
62 $callstackFrequency = $1;
66 die "Failed to get call frequency on input line [$_]";
69 # Remove unique callstack numeric info at end since we sort differently (by frequency) than raw output.
70 s/\s\(\d+ of \d+ unique callstacks\)//;
72 # Add header line to callstack lines.
73 push @
$callstackLinesRef, $_;
75 print "Found callstack frequency [$callstackFrequency]\n" if $debug;
79 # Fixiup lines I bumbled output on.
80 s/(\d+) caller \d+/caller $1/;
86 # Looks like a good callstack line, keep it.
87 push @
$callstackLinesRef, $_;
92 # Looks like this callstack is done.
99 # Print out callstacks sorted by descending numeric frequency.
100 my @frequencies = sort { return $b <=> $a; } (keys %callstacksByFrequency);
102 print "There are ", @frequencies + 0, " unique callstack frequencies.\n";
103 foreach my $frequency (@frequencies)
105 my $callstackArrayRef = $callstacksByFrequency{$frequency};
106 my $callstackCount = @
$callstackArrayRef;
108 print "========================================\n";
109 print "FREQUENCY: $frequency ($callstackCount callstacks)\n";
110 print "========================================\n";
112 for (my $i = 0; $i < $callstackCount; ++$i)
114 my $callstackLinesRef = $$callstackArrayRef[$i];
115 my $lineCount = @
$callstackLinesRef;
117 print "$$callstackLinesRef[0]\n";
118 for (my $lineIndex = 1; $lineIndex < $lineCount; ++$lineIndex)
120 print "\t$$callstackLinesRef[$lineIndex]\n";