commit 732f2a0967082e275dfda7535d096b8b91b46c0a
parent 862074c1a1d397e1abbbb7e22f1ca0ab7688b148
Author: Brendan Gregg <brendan.d.gregg@gmail.com>
Date: Sun, 5 Feb 2017 12:34:55 -0800
Merge pull request #116 from ioxgrey/master
AIX stack probes and stack collapse script
Diffstat:
2 files changed, 92 insertions(+), 0 deletions(-)
diff --git a/aix-perf.pl b/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);
+}
diff --git a/stackcollapse-aix.pl b/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";
+}