-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AIX stack probes and stack collapse script
- Loading branch information
Sergey Petrov
committed
Dec 28, 2016
1 parent
ef64564
commit 3374af6
Showing
2 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/perl | ||
|
||
use Getopt::Std; | ||
|
||
getopt('urt'); | ||
|
||
unless ($opt_r && $opt_t){ | ||
print "Usage: $0 [ -u user] -r sample_count -t sleep_time\n"; | ||
exit(0); | ||
} | ||
|
||
my $i; | ||
my @proc = ""; | ||
for ($i = 0; $i < $opt_r ; $i++){ | ||
if ($opt_u){ | ||
$proc = `/usr/sysv/bin/ps -u $opt_u `; | ||
$proc =~ s/^.*\n//; | ||
$proc =~ s/\s*(\d+).*\n/\1 /g; | ||
@proc = split(/\s+/,$proc); | ||
} else { | ||
opendir(my $dh, '/proc') || die "Cant't open /proc: $!"; | ||
@proc = grep { /^[\d]+$/ } readdir($dh); | ||
closedir ($dh); | ||
} | ||
|
||
foreach my $pid (@proc){ | ||
my $command = "/usr/bin/procstack $pid"; | ||
print `$command 2>/dev/null`; | ||
} | ||
select(undef, undef, undef, $opt_t); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/usr/bin/perl -ws | ||
# | ||
# stackcollapse-aix Collapse AIX /usr/bin/procstack backtraces | ||
# | ||
# Parse a list of backtraces as generated with the poor man's aix-perf.pl | ||
# profiler | ||
# | ||
|
||
use strict; | ||
|
||
my $process = ""; | ||
my $current = ""; | ||
my $previous_function = ""; | ||
|
||
my %stacks; | ||
|
||
while(<>) { | ||
chomp; | ||
if (m/^\d+:/) { | ||
if(!($current eq "")) { | ||
$current = $process . ";" . $current; | ||
$stacks{$current} += 1; | ||
$current = ""; | ||
} | ||
m/^\d+: ([^ ]*)/; | ||
$process = $1; | ||
$current = ""; | ||
} | ||
elsif(m/^---------- tid# \d+/){ | ||
if(!($current eq "")) { | ||
$current = $process . ";" . $current; | ||
$stacks{$current} += 1; | ||
} | ||
$current = ""; | ||
} | ||
elsif(m/^(0x[0-9abcdef]*) *([^ ]*) ([^ ]*) ([^ ]*)/) { | ||
my $function = $2; | ||
my $alt = $1; | ||
$function=~s/\(.*\)?//; | ||
if($function =~ /^\[.*\]$/) { | ||
$function = $alt; | ||
} | ||
if ($current) { | ||
$current = $function . ";" . $current; | ||
} | ||
else { | ||
$current = $function; | ||
} | ||
} | ||
} | ||
|
||
if(!($current eq "")) { | ||
$current = $process . ";" . $current; | ||
$stacks{$current} += 1; | ||
$current = ""; | ||
$process = ""; | ||
} | ||
|
||
foreach my $k (sort { $a cmp $b } keys %stacks) { | ||
print "$k $stacks{$k}\n"; | ||
} |