Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
58 lines (39 sloc) 1.44 KB
#! /usr/bin/env perl
=pod
=head1 NAME
jstack-aggregate - Aggregate and print Java backtraces.
=head1 SYNOPSIS
jstack `jps -q | head -1` > jstack.txt; jstack-aggregate jstack.txt
jstack `jps -q | head -1` | jstack-aggregate
=head1 AUTHOR
Joseph Jang
=head1 HISTORY
This script is a fork of bt-aggregate that is part of Aspersa (http://code.google.com/p/aspersa/) authored by Baron Schwartz.
=head1 LICENSE
New BSD License
http://www.opensource.org/licenses/bsd-license.php
=cut
use strict;
use warnings FATAL => 'all';
use English qw(-no_match_vars);
local $INPUT_RECORD_SEPARATOR = ''; # Paragraph mode
my %traces;
while ( my $chunk = <> ) {
next unless my ( $tid ) = $chunk =~ m/tid=/;
$chunk =~ s/.*tid=.*$//m; # Delete first line
$chunk =~ s/.*java.lang.Thread.State:.*$//m; # Delete second line
$chunk =~ s/locked <.*>/locked <******>/mg; # Hide Lock ID
$chunk =~ s/lock <.*>/lock <******>/mg; # Hides Lock ID
$chunk =~ s/parking to wait for <.*>/parking to wait for <******>/mg; # Hides Lock ID
$chunk =~ s/waiting on <.*>/waiting on <******>/mg; # Hides Lock ID
$chunk =~ s/(\A\s+)|(\s+\Z)//g; # Trim whitespace
$traces{$chunk}->{count}++;
push @{$traces{$chunk}->{tids}}, $tid;
}
foreach my $trace (
reverse sort { $traces{$a}->{count} <=> $traces{$b}->{count} } keys %traces
) {
print $traces{$trace}->{count}, " threads with the following stack trace:\n";
$trace =~ s/^/\t/gm;
print $trace, "\n\n";
}