-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjstack-aggregate
57 lines (39 loc) · 1.44 KB
/
jstack-aggregate
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
#! /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";
}