| 1 | # Schedule::SGE::Status | ||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||
| 3 | # POD docs | ||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||
| 5 | =head1 Schedule::SGE::Status | ||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||
| 7 | Check on the status of the Schedule::SGE queues. You should not use this method directly, rather you should use the Schedule::SGE method that inherits from this, then all the methods herein are available to you. | ||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||
| 9 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||
| 11 | Rob Edwards (rob@salmonella.org) | ||||||||||||||||||||||||||||||||||||
| 12 | 3/24/05 | ||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||
| 14 | =cut | ||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||
| 16 | package Schedule::SGE::Status; | ||||||||||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use Exporter; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use vars qw(@ISA @EXPORT_OK); | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 21 | 1 | @ISA = qw(Schedule::SGE Exporter); | |||||||||||||||||||||||||||||||||||
| 22 | 1 | @EXPORT_OK = qw(user status brief_job_stats all_jobs); | |||||||||||||||||||||||||||||||||||
| 23 | 1 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||
| 25 | =head2 user() | ||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||
| 27 | Set the user of the processes. If not defined will be guess by whoami | ||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||
| 29 | =cut | ||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | sub user { | ||||||||||||||||||||||||||||||||||
|
Subroutine
user: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 32 | 0 | my ($self, $user)=@_; | |||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | $self->{'user'} = $user if ($user); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | unless ($self->{'user'}) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 35 | 0 | $self->{'user'}=`whoami`; | |||||||||||||||||||||||||||||||||||
| 36 | 0 | chomp($self->{'user'}); | |||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||
| 38 | 0 | return $self->{'user'}; | |||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||
| 41 | =head2 status() | ||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||
| 43 | Get the queue status. This will return a hash where each key is the name of a node, and each value is a reference to an array. The array has the following components: | ||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||
| 45 | 0. Queue type (one of B(atch), I(nteractive), C(heckpointing), P(arallel), T(ransfer) or combinations thereof or N(one)) | ||||||||||||||||||||||||||||||||||||
| 46 | 1. Processors used | ||||||||||||||||||||||||||||||||||||
| 47 | 2. Load average | ||||||||||||||||||||||||||||||||||||
| 48 | 3. State | ||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||
| 50 | =cut | ||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | sub status { | ||||||||||||||||||||||||||||||||||
|
Subroutine
status: not called CC=20 SCAR=60.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 53 | 0 | my ($self)=@_; | |||||||||||||||||||||||||||||||||||
| 54 | 0 | my $qstat=$self->executable('qstat'); | |||||||||||||||||||||||||||||||||||
| 55 | 0 | my @status = `$qstat -f`; | |||||||||||||||||||||||||||||||||||
| 56 | 0 | my $node; | |||||||||||||||||||||||||||||||||||
| 57 | my $allstats; | ||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | while (@status) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 59 | 0 | my $line=shift @status; | |||||||||||||||||||||||||||||||||||
| 60 | 0 | chomp($line); | |||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | next if ($line =~ /^\-/); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | next if ($line =~ /queuename/); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | next if (!$line || $line =~ /^\s*$/); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $line or $line =~ /^\s*$/
MC/DC0%0/2
not $line or $line =~ /^\s*$/
not $line
$line =~ /^\s*$/
Truth table0%0/3
not(A) or B
A= not $lineB= $line =~ /^\s*$/
| |||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | if ($line =~ /^\S+/ && $line !~ /^\#/) { | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition0%0/3
$line =~ /^\S+/ and not $line =~ /^\#/
MC/DC0%0/2
$line =~ /^\S+/ and not $line =~ /^\#/
$line =~ /^\S+/
not $line =~ /^\#/
Truth table0%0/3
A and not(B)
A= $line =~ /^\S+/B= not $line =~ /^\#/
| |||||||||||||||||||||||||||||||||||||
| 65 | # it is a node status | ||||||||||||||||||||||||||||||||||||
| 66 | 0 | my @pieces = split /\s+/, $line; | |||||||||||||||||||||||||||||||||||
| 67 | 0 | $node=shift @pieces; | |||||||||||||||||||||||||||||||||||
| 68 | 0 | my $type=shift @pieces; | |||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | if ($type =~ /[^BICPTN]/) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 70 | 0 | die "Received type of $type from \n$line\n\tbut it should not contain anything other than B,I,C,P,T or N"; | |||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||
| 72 | 0 | my $procs=shift @pieces; | |||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | if ($procs !~ m#\d+/\d+#) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 74 | 0 | die "Received procs of $procs from \n$line\n\tbut it should not contain anything other than \\d+/\\d+"; | |||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||
| 76 | 0 | my ($load_avg, $arch, $states)= @pieces; | |||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | if ($self->verbose && $states) {print STDERR "Node $node has state $states\n"} | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->verbose and $states
MC/DC0%0/2
$self->verbose and $states
$self->verbose
$states
Truth table0%0/3
A and B
A= $self->verboseB= $states
| |||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | unless (defined $states) {$states=''} | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 79 | 0 | $allstats->{$node}=[$type, $procs, $load_avg, $states]; | |||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||
| 81 | elsif ($line =~ m#^\s+(\d+)\s+(\d+\.\d+)\s+(\S+.*?)\s+\S+\s+(\S+)\s+(\d+/\d+/\d+\s+\d+\:\d+\:\d+)\s+\S+#) { | ||||||||||||||||||||||||||||||||||||
| 82 | # it is a job | ||||||||||||||||||||||||||||||||||||
| 83 | # something like | ||||||||||||||||||||||||||||||||||||
| 84 | # 1441 0.56000 testing123 rob r 03/25/2005 11:59:12 1 | ||||||||||||||||||||||||||||||||||||
| 85 | 0 | my ($pid, $load, $name, $user, $date)=($1, $2, $3, $4, $5); | |||||||||||||||||||||||||||||||||||
| 86 | 0 | $self->{'job'}->{$pid}=[$node, $pid, $load, $name, $user, $date]; | |||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||
| 88 | ▶ | elsif ($line =~ /^\#/ || $line =~ /PENDING/) { | |||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$line =~ /^\#/ or $line =~ /PENDING/
MC/DC0%0/2
$line =~ /^\#/ or $line =~ /PENDING/
$line =~ /^\#/
$line =~ /PENDING/
Truth table0%0/3
A or B
A= $line =~ /^\#/B= $line =~ /PENDING/
| |||||||||||||||||||||||||||||||||||||
| 89 | # at the end of the list there are some pending jobs | ||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | while (@status) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 91 | 0 | my $pend=shift(@status); | |||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | next if ($pend =~ /PENDING/ || $pend =~ /^\#/); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$pend =~ /PENDING/ or $pend =~ /^\#/
MC/DC0%0/2
$pend =~ /PENDING/ or $pend =~ /^\#/
$pend =~ /PENDING/
$pend =~ /^\#/
Truth table0%0/3
A or B
A= $pend =~ /PENDING/B= $pend =~ /^\#/
| |||||||||||||||||||||||||||||||||||||
| 93 | 0 | $pend =~ s/^\s+//; $pend =~ s/\s+$//; | |||||||||||||||||||||||||||||||||||
| 94 | 0 | my @pieces=split /\s+/, $pend; | |||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | next unless (scalar @pieces > 5); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 96 | 0 | my ($user, $status, $date, $time, $processes)=splice(@pieces, -5, 5); | |||||||||||||||||||||||||||||||||||
| 97 | 0 | my ($pid, $load)=splice(@pieces, 0, 2); | |||||||||||||||||||||||||||||||||||
| 98 | 0 | $date .= " ".$time; | |||||||||||||||||||||||||||||||||||
| 99 | 0 | my $name = join " ", @pieces; | |||||||||||||||||||||||||||||||||||
| 100 | 0 | $self->{'job'}->{$pid}=['pending', $pid, $load, $name, $user, $date]; | |||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||
| 103 | else { | ||||||||||||||||||||||||||||||||||||
| 104 | 0 | print STDERR "We don't know how to parse |$line|\n"; | |||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||
| 109 | 0 | return $allstats; | |||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||
| 113 | =head2 brief_job_stats() | ||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||
| 115 | Get some brief statistics about a job. This method will return a reference to an array with the following statistics: | ||||||||||||||||||||||||||||||||||||
| 116 | Node the job is/was running on | ||||||||||||||||||||||||||||||||||||
| 117 | Process ID of the job | ||||||||||||||||||||||||||||||||||||
| 118 | Load | ||||||||||||||||||||||||||||||||||||
| 119 | Name of process | ||||||||||||||||||||||||||||||||||||
| 120 | Username | ||||||||||||||||||||||||||||||||||||
| 121 | Date and time of submission | ||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||
| 123 | for example, my $stats=$sge->brief_job_stats($job); | ||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||
| 125 | =cut | ||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | sub brief_job_stats { | ||||||||||||||||||||||||||||||||||
|
Subroutine
brief_job_stats: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 128 | 0 | my ($self, $job)=@_; | |||||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | return [] if (!$job); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | return $self->{'job'}->{$job} if ($self->{'job'}->{$job}); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||
| 132 | # if we get this far, we should run status and quickly get the status | ||||||||||||||||||||||||||||||||||||
| 133 | 0 | $self->status(); | |||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | if ($self->{'job'}->{$job}) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 135 | 0 | return $self->{'job'}->{$job}; | |||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||
| 137 | else { | ||||||||||||||||||||||||||||||||||||
| 138 | 0 | return []; | |||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||
| 143 | =head2 all_jobs() | ||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||
| 145 | Returns an array of all jobs that were found in the queues. | ||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||
| 147 | =cut | ||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | sub all_jobs { | ||||||||||||||||||||||||||||||||||
|
Subroutine
all_jobs: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 150 | 0 | my ($self)=@_; | |||||||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | unless ($self->{'job'}) {$self->status()} | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 152 | 0 | return keys %{$self->{'job'}}; | |||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||
| 156 | 1 | 1; | |||||||||||||||||||||||||||||||||||