home *** CD-ROM | disk | FTP | other *** search
- #!/usr/bin/perl
- #
- # Simple script to implement "array top".
- #
- # Usage: atop local <name>
- # or: atop merge <file....>
- #
-
- #
- # The local variant: this should be run on each node in the array
- #
- if ($ARGV[0] eq "local") {
-
- #
- # Start up a "top" command and trap its output
- #
- open(ATOP, "/usr/sbin/atop -f 2 |") || die "Couldn't run atop: $!\n";
-
- #
- # Process each line of atop output
- #
- while (<ATOP>) {
-
- #
- # Split out individual fields
- #
- ($user, $pid, $ash, $cpu, $cmd) = split(" ", $_);
-
- #
- # Print the results neatly, tossing ASH "0" (which is normally
- # just system processes)
- #
- printf "0x%16s %-12s %5s %-8.8s %6s %s\n",
- $ash, $ARGV[1], $pid, $user, $cpu, $cmd
- unless $ash eq "0000000000000000"
- }
- }
-
- #
- # The merge variant: this is run only on one node using the output
- # from "aps local" on each node as its input files
- #
- elsif ($ARGV[0] eq "merge") {
-
- #
- # Read all of the input files into a list
- #
- shift @ARGV;
- @all = <ARGV>;
-
- #
- # Sort the list using the "sorttop" subroutine
- #
- @new = sort sorttop @all;
-
- #
- # Print a nice header line
- #
- print " ASH Host PID User %CPU Command\n";
- print "----------------------------------------------------------------\n";
-
- #
- # Print every line
- #
- foreach $line (@new) {
- print $line
- }
- }
-
-
-
- #
- # Sort function: sorts "atop local" lines first by CPU then by user
- #
- sub sorttop {
- ($Aash, $Ahost, $Apid, $Auser, $Acpu, $Acmd) = split(" ", $a);
- ($Bash, $Bhost, $Bpid, $Buser, $Bcpu, $Bcmd) = split(" ", $b);
-
- (($Bcpu <=> $Acpu) || ($Buser cmp $Auser));
- }
-