forked from ClickHouse/ClickHouse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
postprocess-traces.pl
executable file
·49 lines (39 loc) · 1010 Bytes
/
postprocess-traces.pl
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
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
my @current_stack = ();
my $grouped_stacks = {};
while (my $line = <>)
{
chomp $line;
if ($line =~ '^#')
{
$line =~ s/^#\d+\s+//;
$line =~ s/ \([^\)]+=.+\) at / at /g;
push @current_stack, $line;
}
if ($line eq '')
{
my $group = \$grouped_stacks;
for my $frame (reverse @current_stack)
{
$$group->{count} ||= 0;
++$$group->{count};
$group = \$$group->{children}{$frame};
}
@current_stack = ();
}
}
sub print_group
{
my $group = shift;
my $level = shift || 0;
for my $key (sort { $group->{children}{$b}{count} <=> $group->{children}{$a}{count} } keys %{$group->{children}})
{
my $count = $group->{count};
print(('| ' x $level) . $count . (' ' x (5 - (length $count))) . $key . "\n");
print_group($group->{children}{$key}, $level + 1);
}
}
print_group($grouped_stacks);