aix-perf.pl 638 B

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