Skip to content

Commit

Permalink
AIX stack probes and stack collapse script
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Petrov committed Dec 28, 2016
1 parent ef64564 commit 3374af6
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
31 changes: 31 additions & 0 deletions aix-perf.pl
@@ -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);
}
61 changes: 61 additions & 0 deletions stackcollapse-aix.pl
@@ -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";
}

0 comments on commit 3374af6

Please sign in to comment.