aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/flame-graph/aix-perf.pl
blob: 1edd082ecfccb31616262c67c8050e3f3e2351e7 (plain) (blame)
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
#!/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);
}