Created
February 7, 2017 09:55
-
-
Save win32asm/96dca779362bbd04a1730b109e452fce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# usage: | |
# filter.pl <stacktraces file> | |
# stacktraces file is to be acquired by "foreach bt" in crash | |
my $dbg_filter = 0; | |
my $use_filter = 1; | |
if ( scalar (@ARGV) == 0 || ! -e $ARGV[0] ) { | |
print "backtraces file name expected\n"; | |
exit 1; | |
} | |
for ($idx=1; $idx < scalar(@ARGV); ++$idx) { | |
$dbg_filter = 1 if ($ARGV[$idx] eq "-d"); | |
$use_filter = 0 if ($ARGV[$idx] eq "-n"); | |
} | |
my @all_trc=(); | |
my @all_names=(); | |
my @trc=(); | |
my $bt_lines = 0, my $fru=0; | |
open (FH, $ARGV[0]) or die "trying"; | |
while (<FH>) { | |
chomp; | |
next if ($_ eq ""); | |
if ( m/PID.*COMMAND/ ) { | |
&process_one(); | |
@trc = (); | |
$bt_lines = 0; | |
} | |
++$bt_lines if ($_ =~ m|^\s*#[0-9]+\s|); | |
push @trc, $_; | |
} | |
#final stack: | |
process_one(); | |
# print all names and stacks | |
for ($idx=0; $idx < scalar(@all_trc); ++$idx) { | |
my @names = @ {$all_names[$idx]}; | |
foreach (@names){ | |
print "$_\n"; | |
} | |
my @stk = @{$all_trc[$idx]}; | |
foreach (@stk) { | |
print "$_\n"; | |
} | |
print "\n"; | |
} | |
sub process_one() { | |
$fru = 0; | |
$fru = &filter() if $use_filter; | |
if ( $fru ) { | |
if ($dbg_filter && scalar(@trc) != 0) { | |
print "${trc[0]} - filtered out ($fru)\n"; | |
} | |
} else { | |
$fru = &find_same(); | |
if ($fru>=0) { | |
push @{ $all_names[$fru] }, $trc[0]; | |
} else { | |
my @names=(); | |
push @all_trc, [ @trc ]; | |
push @all_names, [ @names ]; | |
} | |
} | |
} | |
sub find_same { | |
my $idx, my $ln, my $same; | |
for($idx=0; $idx < scalar(@all_trc); ++$idx) { | |
my @stk = @{$all_trc[$idx]}; | |
next if scalar(@stk) != scalar(@trc); | |
$same = $idx; | |
for ($ln=1; $ln < scalar(@stk); ++$ln) { | |
my $stkln = @stk[$ln]; | |
my $trcln = @trc[$ln]; | |
$stkln =~ s/\[[0-9a-f]{16}\]//; | |
$trcln =~ s/\[[0-9a-f]{16}\]//; | |
next if ( ($stkln !~ m/^\s*#[0-9]/) && ($trcln !~ m/^\s*#[0-9]/) ); | |
if ( $stkln ne $trcln ) { | |
$same = -1; | |
last; # for each trace line | |
} | |
} | |
if ($same >= 0) { | |
# print "match: '${trc[0]}' vs '${stk[0]}'\n"; | |
return $same; | |
} | |
} | |
return -1; | |
} | |
sub filter { | |
# small stacks | |
if (scalar(@trc)<=6) { return 1 } | |
if ($bt_lines < 3) {return 13} | |
# futexes | |
foreach ( @trc ) { | |
if (m/futex/) { return 2 } | |
if (m/pipe_read/) {return 3} | |
if (m/sys_wait/) {return 4} | |
if (m/poll/) {return 5} | |
if (m/kthread_stop/) {return 6} | |
if (m/sys_exit_group/) {return 7} | |
if (m/"sleep"/) {return 8} | |
if (m/"tail"/) {return 9} | |
if (m/vfs_read/) {return 10} | |
if (m/tty_ioctl/) {return 11} | |
if (m/intel_idle/) {return 12} | |
if (m/bash/) {return 14} | |
if (m/nanosleep/) {return 15} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment