-
Notifications
You must be signed in to change notification settings - Fork 0
/
uniqstack
executable file
·64 lines (55 loc) · 1.26 KB
/
uniqstack
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
#!/usr/bin/perl
# Summarize gdb backtrace output
use strict;
my %uniqstacks = ();
my $pid;
while(<>) {
chomp();
if ( /^Thread \d+/) {
my @frames = ();
while(<>) {
chomp();
if (/__kernel_vsyscall/) {
# skip this frame, the actual syscall is below it
}
elsif (/No core file now/) {
# no-care
}
elsif (/#\d+\s+0x[0-9a-fA-F]+ in (\S+)/) {
push @frames, $1
}
elsif (/#\d+\s+([a-zA-Z]+)/) {
push @frames, $1
}
# #3 <signal handler called>
elsif (/#\d+\s+(\<signal handler called\>.*)/) {
push @frames, $1
}
elsif (/(?:^$|Detaching from program.*process (\d+))/) {
# end of a thread
my $line = join('>', @frames);
if (defined($1)) {
$pid = $1;
}
if (!defined $uniqstacks{$line}) {
$uniqstacks{$line} = 1;
}
else {
$uniqstacks{$line} = $uniqstacks{$line} + 1;
}
last;
}
elsif (/\s+at/) {
# XXX continuation line
}
else {
die "teach me about '$_'";
}
}
}
}
my ($k, $v);
print "Backtraces for PID $pid\n";
while (($k, $v) = each(%uniqstacks)) {
print "$v: $k\n";
}