aix-perf.pl (638B)
1 #!/usr/bin/perl 2 3 use Getopt::Std; 4 5 getopt('urt'); 6 7 unless ($opt_r && $opt_t){ 8 print "Usage: $0 [ -u user] -r sample_count -t sleep_time\n"; 9 exit(0); 10 } 11 12 my $i; 13 my @proc = ""; 14 for ($i = 0; $i < $opt_r ; $i++){ 15 if ($opt_u){ 16 $proc = `/usr/sysv/bin/ps -u $opt_u `; 17 $proc =~ s/^.*\n//; 18 $proc =~ s/\s*(\d+).*\n/\1 /g; 19 @proc = split(/\s+/,$proc); 20 } else { 21 opendir(my $dh, '/proc') || die "Cant't open /proc: $!"; 22 @proc = grep { /^[\d]+$/ } readdir($dh); 23 closedir ($dh); 24 } 25 26 foreach my $pid (@proc){ 27 my $command = "/usr/bin/procstack $pid"; 28 print `$command 2>/dev/null`; 29 } 30 select(undef, undef, undef, $opt_t); 31 }