SGE/Status.pm

filter: Statementstmt 18.0% 13 / 72 Branchbran 0.0% 0 / 40 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 42.8% 3 / 7 Podpod 100% 4 / 4 totaltotal 13.5% 20 / 148 CC 26 SCAR 55.9
CC
26
Cov
10%
status
420.0
brief_job_stats
20.0
user
12.0
CRAP 266.6
↑ Summary SGE/Run.pm »
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
BranchTrueFalseTotal
if $user 0 0 0
34 0 ▶ unless ($self->{'user'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"user"}) 0 0 0
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
BranchTrueFalseTotal
if (@status) 0 0 0
59 0 my $line=shift @status;
60 0 chomp($line);
61 0 ▶ next if ($line =~ /^\-/);
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\-/ 0 0 0
62 0 ▶ next if ($line =~ /queuename/);
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /queuename/ 0 0 0
63 0 ▶ next if (!$line || $line =~ /^\s*$/);
Branch: 1 branch
BranchTrueFalseTotal
if not $line or $line =~ /^\s*$/ 0 0 0
Condition0%0/3
not $line or $line =~ /^\s*$/
l!l&&r!l&&!r
000
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*$/
ABresult
1X1
011
000
64 0 ▶ if ($line =~ /^\S+/ && $line !~ /^\#/) {
Branch: 3 branches
BranchTrueFalseTotal
if ($line =~ /^\S+/ and not $line =~ /^\#/) { } 0 0 0
elsif ($line =~ m[^\s+(\d+)\s+(\d+\.\d+)\s+(\S+.*?)\s+\S+\s+(\S+)\s+(\d+/\d+/\d+\s+\d+\:\d+\:\d+)\s+\S+]) { } 0 0 0
elsif ($line =~ /^\#/ or $line =~ /PENDING/) { } 0 0 0
Condition0%0/3
$line =~ /^\S+/ and not $line =~ /^\#/
!ll&&!rl&&r
000
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 =~ /^\#/
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if ($type =~ /[^BICPTN]/) 0 0 0
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
BranchTrueFalseTotal
unless ($procs =~ m[\d+/\d+]) 0 0 0
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
BranchTrueFalseTotal
if ($self->verbose and $states) 0 0 0
Condition0%0/3
$self->verbose and $states
!ll&&!rl&&r
000
MC/DC0%0/2
$self->verbose and $states
$self->verbose $states
Truth table0%0/3
A and B
A= $self->verboseB= $states
ABresult
0X0
100
111
78 0 ▶ unless (defined $states) {$states=''}
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $states) 0 0 0
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/
l!l&&r!l&&!r
000
MC/DC0%0/2
$line =~ /^\#/ or $line =~ /PENDING/
$line =~ /^\#/ $line =~ /PENDING/
Truth table0%0/3
A or B
A= $line =~ /^\#/B= $line =~ /PENDING/
ABresult
1X1
011
000
89 # at the end of the list there are some pending jobs
90 0 ▶ while (@status) {
Branch: 1 branch
BranchTrueFalseTotal
if (@status) 0 0 0
91 0 my $pend=shift(@status);
92 0 ▶ next if ($pend =~ /PENDING/ || $pend =~ /^\#/);
Branch: 1 branch
BranchTrueFalseTotal
if $pend =~ /PENDING/ or $pend =~ /^\#/ 0 0 0
Condition0%0/3
$pend =~ /PENDING/ or $pend =~ /^\#/
l!l&&r!l&&!r
000
MC/DC0%0/2
$pend =~ /PENDING/ or $pend =~ /^\#/
$pend =~ /PENDING/ $pend =~ /^\#/
Truth table0%0/3
A or B
A= $pend =~ /PENDING/B= $pend =~ /^\#/
ABresult
1X1
011
000
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
BranchTrueFalseTotal
unless scalar @pieces > 5 0 0 0
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
BranchTrueFalseTotal
unless $job 0 0 0
130 0 ▶ return $self->{'job'}->{$job} if ($self->{'job'}->{$job});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"job"}{$job} 0 0 0
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
BranchTrueFalseTotal
if ($self->{'job'}{$job}) { } 0 0 0
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
BranchTrueFalseTotal
unless ($self->{"job"}) 0 0 0
152 0 return keys %{$self->{'job'}};
153 }
154  
155  
156 1 1;
↑ Summary SGE/Run.pm »