blib/lib/Slurm/Sshare.pm

filter: Statementstmt 89.4% 560 / 626 Branchbran 68.6% 236 / 344 Conditioncond 52.6% 91 / 173 MC/DCmcdc 23.8% 26 / 109 Subroutinesub 100% 39 / 39 Podpod 64.7% 11 / 17 totaltotal 73.6% 963 / 1308 CC 247 SCAR 33.6
CC
247
Cov
78%
collect_usage_records_by_account
94.1
sshare_usage_for_account_user
37.3
combine_sshare_usage_records
34.8
CRAP 28.9
« bin/sbalance ↑ Summary
1 #!/usr/local/bin/perl
2 #
3 #Perl wrappers for Slurm sshare cmd
4  
5 package Slurm::Sshare;
6 670 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 670 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 670 ▶use base qw(Class::Accessor);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 670 ▶use Carp qw(carp croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 670 ▶use UNIVERSAL;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 670 ▶use version; our $VERSION = qw(1.2.2);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 #-------------------------------------------------------------------
15 # Globals
16 #-------------------------------------------------------------------
17  
18 670 my $VERBOSE;
19  
20 #By default, use the sshare command found in your PATH
21 670 my $SSHARE_CMD = 'sshare';
22 #IF you wish to default to something else, uncomment and change line below
23 #$SSHARE_CMD = '/usr/local/bin/sshare';
24 #It is also recommended that you set $SSHARE_CMD_CAPABILITIES to a hash ref
25 #showing the capabilities of the sshare command you designated above --- failure
26 #to do so might result in the package needing to test the command capabilities which
27 #is inefficient. The value of $SSHARE_CMD_CAPABILITIES is a hash ref with keys
28 #based on the name of the capability, and a value of 1 (true) if the capability is
29 #supported, or 0 (false) otherwise. You can use standard Perl Boolean semantics
30 #EXCEPT THAT YOU SHOULD NOT USE undef for false. Any missing keys, keys with undef
31 #values, or missing/undef $SSHARE_CMD_CAPABILITIES are interpretted as the status
32 #of the capability is unknown and might need to run sshare to determine.
33 #
34 #Recognized capabilities are listed below in definition of @SSHARE_CMD_CAPABILITIES_LIST
35 670 my $SSHARE_CMD_CAPABILITIES = {};
36 #
37 #To indicate that the --partition flag is supported, use
38 # $SSHARE_CMD_CAPABILITIES = { can_display_partition => 1 };
39 #To indicate that the --partition flag is not supported, use
40 # $SSHARE_CMD_CAPABILITIES = { can_display_partition => 0 };
41 #Alternatively, to get (our best guess) of capabilities by Slurm version number, do
42 # Slurm::Sshare->set_sshare_capabilities_by_version('15.08.2');
43 #replacing 15.08.2 with your Slurm version
44  
45 #These are the capabilities of sshare cmd we recognize
46 670 my @SSHARE_CMD_CAPABILITIES_LIST =
47 ( 'can_display_partition', #Whether sshare supports --partition flag to
48 #cause it to display partition information
49 );
50 670 my %SSHARE_CMD_CAPABILITIES_HASH = map { $_ => undef } @SSHARE_CMD_CAPABILITIES_LIST;
51  
52 #This is for the caching of discovered sshare cmd capabilities, should be left undef
53 670 my $_CACHED_SSHARE_CMD_CAPABILITIES;
54  
55 #These are intended for regression tests only
56 my $_last_raw_output;
57 sub _sshare_last_raw_output($)
58 26929 ▶{ return $_last_raw_output;
Subroutine _sshare_last_raw_output: called CC=1 SCAR=0.0
59 }
60  
61 #And because each sshare_list can result in multiple calls to sshare,
62 #a variant which saves all output from give sshare_list command
63 670 my $_sslist_last_raw_output;
64 sub _sshare_list_last_raw_output($)
65 82 ▶{ return $_sslist_last_raw_output;
Subroutine _sshare_list_last_raw_output: called CC=1 SCAR=0.0
66 }
67  
68 #And allow clearing for some tests
69 sub _clear_sshare_last_raw_output($)
70 54 ▶{ $_last_raw_output = undef;
Subroutine _clear_sshare_last_raw_output: called CC=1 SCAR=0.0
71 }
72  
73 #-------------------------------------------------------------------
74 # Class methods
75 #-------------------------------------------------------------------
76  
77 sub verbose($;$)
78 27646 ▶{ my $class = shift;
Subroutine verbose: called CC=3 SCAR=11.0
Pod undocumented
79 27646 my $new = shift;
80 27646 ▶ if ( defined $new )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $new) 327 27319 27646
81 327 ▶ { $VERBOSE = $new?1:0;
Branch: 1 branch
BranchTrueFalseTotal
$new ? : 2 325 327
82 }
83 27646 return $VERBOSE;
84 }
85  
86 sub sshare($;$$)
87 28710 ▶{ my $class = shift;
Subroutine sshare: called CC=7 SCAR=19.5
Pod documented
88 28710 my $new = shift;
89 28710 my $caps = shift;
90 28710 my $me = __PACKAGE__ . '::sshare';
91 28710 ▶ if ( $new )
Branch: 1 branch
BranchTrueFalseTotal
if ($new) 1388 27322 28710
92 1388 { $SSHARE_CMD = $new;
93 1388 ▶ if ( $caps && ref($caps) eq 'HASH' )
Branch: 2 branches
BranchTrueFalseTotal
if ($caps and ref $caps eq 'HASH') { } 23 1365 1388
elsif ($caps and not ref $caps) { } 132 1233 1365
Condition100%3/3
$caps and ref $caps eq "HASH"
!ll&&!rl&&r
123313223
MC/DC100%2/2
$caps and ref $caps eq "HASH"
$caps ref $caps eq "HASH"
Truth table100%3/3
A and B
A= $capsB= ref $caps eq "HASH"
ABresult
0X0
100
111
94 23 { $SSHARE_CMD_CAPABILITIES = $caps;
95 ▶ } elsif ( $caps && ! ref($caps) )
Condition66%2/3
$caps and not ref $caps
!ll&&!rl&&r
12330132
MC/DC50%1/2
$caps and not ref $caps
$caps not ref $caps
Truth table66%2/3
A and not(B)
A= $capsB= not ref $caps
ABresult
0X0
100
111
96 132 { $class->set_sshare_capabilities_by_version($caps);
97 } else
98 1233 { $SSHARE_CMD_CAPABILITIES = undef;
99 1233 ▶ croak "$me: Invalid value '$caps' for sshare capabilities (expecting version number or hash ref) at "
Branch: 1 branch
BranchTrueFalseTotal
if $caps 0 1233 1233
100 if $caps;
101 }
102 1388 $_CACHED_SSHARE_CMD_CAPABILITIES = undef;
103
104 }
105 28710 return $SSHARE_CMD;
106 }
107  
108 sub sshare_cmd_supports($$;$)
109 #This checks if the current sshare command supports the named capability.
110 #It will use user given answer first, then try to used cached information,
111 #and only if necessary invoke an actual sshare command to find out.
112 #Returns 1 (true) if sshare supports the capability
113 #Returns 0 (false) if sshare does NOT support the capability
114 #If $cachedonly flag is given and set, will never invoke an sshare to determine the
115 #result, and may return undef (also false) indicating we do not know.
116 10730 ▶{ my $class = shift;
Subroutine sshare_cmd_supports: called CC=11 SCAR=24.2
Pod undocumented
117 10730 my $capname = shift;
118 10730 my $cacheonly = shift;
119 10730 my $me = __PACKAGE__ . '::sshare_cmd_supports';
120  
121 10730 ▶ unless ( exists $SSHARE_CMD_CAPABILITIES_HASH{$capname} )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $SSHARE_CMD_CAPABILITIES_HASH{$capname}) 0 10730 10730
122 0 { warn "$me: Unrecognized capability '$capname', ignoring, at ";
123 0 return 0; #Unrecognized capabilities are NOT supported
124 }
125  
126 10730 my $canwe;
127 10730 ▶ if ( $SSHARE_CMD_CAPABILITIES && ref($SSHARE_CMD_CAPABILITIES) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if ($SSHARE_CMD_CAPABILITIES and ref $SSHARE_CMD_CAPABILITIES eq "HASH") 1494 9236 10730
Condition66%2/3
$SSHARE_CMD_CAPABILITIES and ref $SSHARE_CMD_CAPABILITIES eq "HASH"
!ll&&!rl&&r
923601494
MC/DC50%1/2
$SSHARE_CMD_CAPABILITIES and ref $SSHARE_CMD_CAPABILITIES eq "HASH"
$SSHARE_CMD_CAPABILITIES ref $SSHARE_CMD_CAPABILITIES eq "HASH"
Truth table66%2/3
A and B
A= $SSHARE_CMD_CAPABILITIESB= ref $SSHARE_CMD_CAPABILITIES eq "HASH"
ABresult
0X0
100
111
128 1494 { $canwe = $SSHARE_CMD_CAPABILITIES->{$capname};
129 }
130  
131 #User provided a value, return it
132 10730 ▶ return ($canwe?1:0) if defined $canwe;
Branch: 2 branches
BranchTrueFalseTotal
if defined $canwe 1472 9258 10730
$canwe ? : 542 930 1472
133  
134 #See if we have cached a value
135 9258 $canwe = undef;
136 9258 ▶ if ( $_CACHED_SSHARE_CMD_CAPABILITIES && ref($_CACHED_SSHARE_CMD_CAPABILITIES) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if ($_CACHED_SSHARE_CMD_CAPABILITIES and ref $_CACHED_SSHARE_CMD_CAPABILITIES eq "HASH") 8608 650 9258
Condition66%2/3
$_CACHED_SSHARE_CMD_CAPABILITIES and ref $_CACHED_SSHARE_CMD_CAPABILITIES eq "HASH"
!ll&&!rl&&r
65008608
MC/DC50%1/2
$_CACHED_SSHARE_CMD_CAPABILITIES and ref $_CACHED_SSHARE_CMD_CAPABILITIES eq "HASH"
$_CACHED_SSHARE_CMD_CAPABILITIES ref $_CACHED_SSHARE_CMD_CAPABILITIES eq "HASH"
Truth table66%2/3
A and B
A= $_CACHED_SSHARE_CMD_CAPABILITIESB= ref $_CACHED_SSHARE_CMD_CAPABILITIES eq "HASH"
ABresult
0X0
100
111
137 8608 { $canwe = $_CACHED_SSHARE_CMD_CAPABILITIES->{$capname};
138 }
139  
140 #Return a cached value if we have it
141 9258 ▶ return ($canwe?1:0) if defined $canwe;
Branch: 2 branches
BranchTrueFalseTotal
if defined $canwe 8608 650 9258
$canwe ? : 1526 7082 8608
142  
143 #We only requested cached value, so exit with unknown result (undef)
144 650 ▶ return if $cacheonly;
Branch: 1 branch
BranchTrueFalseTotal
if $cacheonly 23 627 650
145  
146 #No cached value, we need to determine it
147 627 return $class->_determine_sshare_cmd_capability($capname);
148 }
149
150 sub _determine_sshare_cmd_capability($$)
151 #Determine whether sshare cmd can do $capname
152 #Will update $_CACHED_SSHARE_CMD_CAPABILITIES and return result
153 627 ▶{ my $class = shift;
Subroutine _determine_sshare_cmd_capability: called CC=2 SCAR=7.0
154 627 my $capname = shift;
155 627 my $me = __PACKAGE__ . '::_determine_sshare_cmd_capability';
156  
157 627 ▶ if ( $capname eq 'can_display_partition' )
Branch: 1 branch
BranchTrueFalseTotal
if ($capname eq "can_display_partition") 627 0 627
158 627 { $class->_determine_sshare_caps_from_help;
159 541 return $_CACHED_SSHARE_CMD_CAPABILITIES->{$capname};
160 }
161 }
162
163 sub _determine_sshare_caps_from_help($)
164 #This runs a sshare --help command, and sets what sshare cmd capabilities
165 #we can (in _CACHED_SSHARE_CMD_CAPABILITIES)
166 627 ▶{ my $class = shift;
Subroutine _determine_sshare_caps_from_help: called CC=1 SCAR=0.0
167  
168 627 my $output = $class->run_generic_sshare_cmd( '--help');
169 541 my (@tmp);
170
171 #Check for 'can_display_partition' (--partition flag)
172 541 @tmp = grep /--partition/, @$output;
173 541 $class->_set_sshare_caps_cache('can_display_partition', scalar(@tmp) );
174  
175 }
176  
177 sub _set_sshare_caps_cache($$$)
178 #This will set _CACHED_SSHARE_CMD_CAPABILITIES for $capname to $val
179 59241 ▶{ my $class = shift;
Subroutine _set_sshare_caps_cache: called CC=4 SCAR=13.9
180 59241 my $capname = shift;
181 59241 my $val = shift;
182  
183 59241 ▶ $val = $val?1:0;
Branch: 1 branch
BranchTrueFalseTotal
$val ? : 58880 361 59241
184 59241 ▶ $_CACHED_SSHARE_CMD_CAPABILITIES={}
Branch: 1 branch
BranchTrueFalseTotal
unless $_CACHED_SSHARE_CMD_CAPABILITIES and ref $_CACHED_SSHARE_CMD_CAPABILITIES eq "HASH" 698 58543 59241
Condition66%2/3
$_CACHED_SSHARE_CMD_CAPABILITIES and ref $_CACHED_SSHARE_CMD_CAPABILITIES eq "HASH"
!ll&&!rl&&r
698058543
MC/DC50%1/2
$_CACHED_SSHARE_CMD_CAPABILITIES and ref $_CACHED_SSHARE_CMD_CAPABILITIES eq "HASH"
$_CACHED_SSHARE_CMD_CAPABILITIES ref $_CACHED_SSHARE_CMD_CAPABILITIES eq "HASH"
Truth table66%2/3
A and B
A= $_CACHED_SSHARE_CMD_CAPABILITIESB= ref $_CACHED_SSHARE_CMD_CAPABILITIES eq "HASH"
ABresult
0X0
100
111
185 unless $_CACHED_SSHARE_CMD_CAPABILITIES &&
186 ref($_CACHED_SSHARE_CMD_CAPABILITIES) eq 'HASH';
187  
188 59241 $_CACHED_SSHARE_CMD_CAPABILITIES->{$capname} = $val;
189 }
190  
191 sub _sshare_capabilities_by_version($$)
192 #Return the appropriate sshare_capabilities hash by Slurm version number
193 #This is our "guess" of what different versions can do
194 #Returns hash ref.
195 132 ▶{ my $class = shift;
Subroutine _sshare_capabilities_by_version: called CC=4 SCAR=13.9
196 132 my $slurm_version = shift;
197 132 my $me = __PACKAGE__ . '::_sshare_capabilities_by_version';
198  
199 #Leave everything on autodiscovery if no version given
200 132 ▶ return unless defined $slurm_version;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $slurm_version 0 132 132
201  
202 #Strip leading/trailing whitespace
203 132 $slurm_version =~ s/^\s*//; $slurm_version =~ s/\s*$//;
204
205 132 my @vcomps = split /\./, $slurm_version;
206 132 my $slurm_major = $vcomps[0];
207  
208
209 #Leave everything on autodiscovery if bad version given
210 132 ▶ return unless $slurm_major =~ /^\d+$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $slurm_major =~ /^\d+$/ 0 132 132
211  
212  
213 #Guess at capabilities
214 132 ▶ if ( $slurm_major < 15 )
Branch: 1 branch
BranchTrueFalseTotal
if ($slurm_major < 15) { } 79 53 132
215 { #Looks like an old version of slurm
216 #At least before partition info in sshare
217 return
218 79 { can_display_partition => 0,
219 };
220 } else
221 { #Assuming a newer version which can display partition info in sshare
222 return
223 53 { can_display_partition => 1,
224 };
225 }
226 }
227  
228 sub set_sshare_capabilities_by_version($$)
229 #Sets the sshare capabilities hash to appropriate value based on slurm version
230 132 ▶{ my $class = shift;
Subroutine set_sshare_capabilities_by_version: called CC=4 SCAR=17.9
Pod undocumented
231 132 my $slurm_version = shift;
232 132 my $me = __PACKAGE__ . '::set_sshare_capabilities_by_version';
233  
234 132 my $caphash = $class->_sshare_capabilities_by_version($slurm_version);
235 132 ▶ unless ( defined $caphash && ref($caphash) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $caphash and ref $caphash eq "HASH") 0 132 132
Condition33%1/3
defined $caphash and ref $caphash eq "HASH"
!ll&&!rl&&r
00132
MC/DC0%0/2
defined $caphash and ref $caphash eq "HASH"
defined $caphash ref $caphash eq "HASH"
Truth table33%1/3
A and B
A= defined $caphashB= ref $caphash eq "HASH"
ABresult
0X0
100
111
236 0 ▶ { $caphash = '' unless defined $caphash;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $caphash 0 0 0
237 0 warn "$me: Ignoring invalid/missing version $slurm_version at ";
238 0 return;
239 }
240  
241 132 $SSHARE_CMD_CAPABILITIES = $caphash;
242 }
243  
244
245  
246 #-------------------------------------------------------------------
247 # Accessors
248 #-------------------------------------------------------------------
249  
250 670 my @rw_accessors = qw(
251 );
252  
253 #We include partition, and not grptresmins/tresrunmins. The latter
254 #are added separately to @ro_accessors, and sshare list either ends
255 # in grpcpumins+cpurunmins OR grptresmins + tresrunmins, so
256 #new_from_sshare_record handles specially.
257 670 my @sshare_fields_in_order = qw(
258 account
259 user
260 partition
261 raw_shares
262 normalized_shares
263 raw_usage
264 normalized_usage
265 effective_usage
266 fairshare
267 grpcpumins
268 cpurunmins
269 );
270  
271 670 my @ro_accessors = (@sshare_fields_in_order, 'cluster', 'grptresmins', 'tresrunmins' );
272  
273 670 __PACKAGE__->mk_accessors(@rw_accessors);
274 670 __PACKAGE__->mk_ro_accessors(@ro_accessors);
275  
276  
277 670 my @required_parms = qw(
278 );
279  
280 #-------------------------------------------------------------------
281 # Constructors, etc
282 #-------------------------------------------------------------------
283  
284 sub new($;@)
285 134741 ▶{ my $class = shift;
Subroutine new: called CC=2 SCAR=6.9
Pod documented
286 134741 ▶ $class = ref($class) if ref($class);
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 134741 134741
287 134741 my @args = @_;
288  
289 134741 my $obj = {};
290 134741 bless $obj, $class;
291  
292 134741 $obj->_parse_args(@args);
293 134741 $obj->_set_defaults;
294 134741 $obj->_init;
295  
296 134741 return $obj;
297 }
298  
299 sub _parse_args($@)
300 134741 ▶{ my $obj = shift;
Subroutine _parse_args: called CC=10 SCAR=27.2
301 134741 my %args = @_;
302  
303 134741 my ($arg, $meth, $val);
304 134741 RWARG: foreach $arg (@rw_accessors)
305 0 ▶ { next RWARG unless exists $args{$arg};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args{$arg} 0 0 0
306 0 $val = delete $args{$arg};
307 0 ▶ next RWARG unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 0 0
308 0 $meth = $arg;
309 0 $obj->$meth($val);
310 }
311  
312 134741 ROARG: foreach $arg (@ro_accessors)
313 1886374 ▶ { next ROARG unless exists $args{$arg};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args{$arg} 568839 1317535 1886374
314 1317535 $val = delete $args{$arg};
315 1317535 ▶ next ROARG unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 1317535 1317535
316 1317535 ▶ if ( $arg eq 'grptresmins' )
Branch: 2 branches
BranchTrueFalseTotal
if ($arg eq 'grptresmins') { } 12488 1305047 1317535
elsif ($arg eq 'tresrunmins') { } 35551 1269496 1305047
317 12488 { $obj->_set_grptresmins($val);
318 } elsif ( $arg eq 'tresrunmins' )
319 35551 { $obj->_set_tresrunmins($val);
320 } else
321 1269496 { $meth = $arg;
322 1269496 $obj->set($meth,$val);
323 }
324 }
325  
326  
327 #Warn about unknown arguments
328 134741 ▶ if ( scalar(keys %args) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %args) 0 134741 134741
329 0 { my $tmp = join ", ", (keys %args);
330 0 croak "Unrecognized arguments [ $tmp ] to constructor at ";
331 };
332 }
333  
334 sub _set_defaults($)
335 134741 ▶{ my $obj = shift;
Subroutine _set_defaults: called CC=9 SCAR=22.2
336  
337 #Duplicate GrpCPUMins/CPURunMins <=> GrpTRESMins/TRESRunMins
338 #Since all accessors are read-only, we can just do it here when instantiating object
339 #Otherwise, probably best to create private _grpcpumins, etc. accessor/mutators and have the
340 #public grpcpumin, etc. accessor/mutators set their partner appropriately when they are set.
341 134741 my ($tmp1, $tmp2, $val);
342  
343 134741 $tmp1 = $obj->grptresmins;
344 134741 $tmp2 = $obj->grpcpumins;
345 134741 ▶ if ( defined $tmp1 )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tmp1) { } 12488 122253 134741
346 12488 ▶ { unless ( defined $tmp2 )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $tmp2) 12488 0 12488
347 { #Set grpcpumins from grptresmins->{cpu}
348 12488 $val = $tmp1->{cpu};
349 12488 ▶ $obj->set('grpcpumins', $val) if defined $val;
Branch: 1 branch
BranchTrueFalseTotal
if defined $val 12488 0 12488
350 }
351 } else
352 122253 ▶ { if ( defined $tmp2 )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tmp2) 35457 86796 122253
353 { #Set grptresmins from grpcpumins
354 35457 $val = { cpu => $tmp2 };
355 35457 $obj->_set_grptresmins($val);
356 }
357 }
358  
359 134741 $tmp1 = $obj->tresrunmins;
360 134741 $tmp2 = $obj->cpurunmins;
361 134741 ▶ if ( defined $tmp1 )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tmp1) { } 35551 99190 134741
362 35551 ▶ { unless ( defined $tmp2 )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $tmp2) 35551 0 35551
363 { #Set cpurunmins from trerunsmins->{cpu}
364 35551 $val = $tmp1->{cpu};
365 35551 ▶ $obj->set('cpurunmins', $val) if defined $val;
Branch: 1 branch
BranchTrueFalseTotal
if defined $val 35551 0 35551
366 }
367 } else
368 99190 ▶ { if ( defined $tmp2 )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tmp2) 99190 0 99190
369 { #Set tresrunmins from cpurunmins
370 99190 $val = { cpu => $tmp2 };
371 99190 $obj->_set_tresrunmins($val);
372 }
373 }
374  
375  
376 134741 return;
377 }
378  
379 sub _init($)
380 134741 ▶{ my $obj = shift;
Subroutine _init: called CC=3 SCAR=17.3
381  
382 134741 my ($fld, $meth, $val);
383 134741 foreach $fld (@required_parms)
384 0 { $meth = $fld;
385 0 $val = $obj->$meth;
386 0 ▶ unless ( defined $val )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $val) 0 0 0
387 0 { croak "Missing required argument $fld";
388 }
389 }
390  
391 }
392  
393 #----- Special private mutators for tresrunmins/grptresmins
394 # Handle either string or hash ref
395  
396 sub _tres_string2hash($$)
397 #Converts tres string (fld=val, fld2=val2, etc) to hash ref ( {fld=>val, fld2=>val2} )
398 48039 ▶{ my $obj = shift;
Subroutine _tres_string2hash: called CC=5 SCAR=16.2
399 48039 my $string = shift;
400 48039 my $fldname = shift;
401 48039 my $me = __PACKAGE__ . '::new';
402  
403 48039 ▶ croak "$me: Illegal value $string for $fldname (expecting HASH ref or string) at "
Branch: 1 branch
BranchTrueFalseTotal
if ref $string 0 48039 48039
404 if ref($string);
405  
406 48039 my $href = {};
407  
408 #Strip leading/trailing spaces
409 48039 $string =~ s/^\s*//; $string =~ s/\s*$//;
410  
411 48039 my @records = split /\s*,\s*/, $string;
412 48039 foreach my $record (@records)
413 {
414 141389 ▶ croak "$me: Illegal value '$string' for $fldname: " .
Branch: 1 branch
BranchTrueFalseTotal
unless $record =~ /=/ 0 141389 141389
415 "No = in record '$record' at "
416 unless ( $record =~ /=/ );
417  
418 141389 my ( $fld, $val ) = split /\s*=\s*/, $record;
419 croak "$me: Illegal value '$string' for $fldname: " .
420 "Duplicate TRES value for $fld at "
421 141389 ▶ if exists $href->{$fld};
Branch: 1 branch
BranchTrueFalseTotal
if exists $href->{$fld} 0 141389 141389
422  
423 141389 $href->{$fld} = $val;
424 }
425  
426 48039 return $href;
427 }
428  
429
430 sub _set_grptresmins($$)
431 #Sets grptresmins either from string or hash ref
432 47945 ▶{ my $obj = shift;
Subroutine _set_grptresmins: called CC=3 SCAR=11.3
433 47945 my $new = shift;
434 47945 my $fld = 'grptresmins';
435 47945 my $me = __PACKAGE__ . '::new';
436  
437 47945 ▶ unless ( defined $new )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $new) 0 47945 47945
438 { #new = undef, so undefine it
439 0 $obj->set($fld, undef);
440 0 return;
441 }
442  
443 47945 ▶ unless ( ref($new) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $new eq "HASH") 12488 35457 47945
444 { #Should have a string
445 12488 $new = $obj->_tres_string2hash($new, $fld);
446 }
447  
448 47945 $obj->set($fld, $new);
449 }
450  
451 sub _set_tresrunmins($$)
452 #Sets tresrunmins either from string or hash ref
453 134741 ▶{ my $obj = shift;
Subroutine _set_tresrunmins: called CC=3 SCAR=11.3
454 134741 my $new = shift;
455 134741 my $fld = 'tresrunmins';
456 134741 my $me = __PACKAGE__ . '::new';
457  
458 134741 ▶ unless ( defined $new )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $new) 0 134741 134741
459 { #new = undef, so undefine it
460 0 $obj->set($fld, undef);
461 0 return;
462 }
463  
464 134741 ▶ unless ( ref($new) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $new eq "HASH") 35551 99190 134741
465 { #Should have a string
466 35551 $new = $obj->_tres_string2hash($new, $fld);
467 }
468  
469 134741 $obj->set($fld, $new);
470 }
471  
472
473 #-------------------------------------------------------------------
474 # Class methods to Run basic sshare commands
475 #-------------------------------------------------------------------
476  
477 sub _noshell_backticks($$@)
478 #Calls an external command using pipes and forks so no shell gets invoked
479 #Returns ($err, @out) where $err is the error is the exit status of
480 #the command, and @out is the list of output returned, line by line.
481 #If $mode is 0, only STDOUT is returned in @out,
482 #If $mode is non-zero, STDERR is dupped onto STDOUT and also returned.
483 27319 ▶{ my $class = shift;
Subroutine _noshell_backticks: called CC=8 SCAR=24.9
484 27319 my $mode = shift;
485 27319 my @cmd = @_;
486  
487 27319 my ($err, @out, $PIPE, $res);
488 27319 my $chd_excode=254;
489  
490 27319 ▶ if ( $res = open($PIPE, "-|" ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($res = open($PIPE, '-|')) { } 26735 584 27319
491 { #Parent
492 26735 ▶ if ( ! defined $res )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $res) 0 26735 26735
493 0 { my $tmp = join ' ', @cmd;
494 0 die "Pipe to '$tmp' failed: $!";
495 }
496 26735 @out = <$PIPE>;
497 26735 $res = close $PIPE;
498 26735 $err = $?;
499 26735 ▶ if ( $err && ( ($err >> 8) == $chd_excode ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($err and $err >> 8 == $chd_excode) 0 26735 26735
Condition33%1/3
$err and $err >> 8 == $chd_excode
!ll&&!rl&&r
2673500
MC/DC0%0/2
$err and $err >> 8 == $chd_excode
$err $err >> 8 == $chd_excode
Truth table33%1/3
A and B
A= $errB= $err >> 8 == $chd_excode
ABresult
0X0
100
111
500 { #We (probably?) got an exception running exec in child process
501 #Re-raise the exception
502 0 my $exc = join '', @out;
503 0 die $exc;
504 }
505 26735 return ($err, @out);
506 } else
507 { #Child
508 #Duplicate stderr onto stdout if so requested
509 584 ▶ if ( $mode )
Branch: 1 branch
BranchTrueFalseTotal
if ($mode) 584 0 584
510 584 ▶ { unless ( open(STDERR, '>&STDOUT') )
Branch: 1 branch
BranchTrueFalseTotal
unless (open STDERR, ">&STDOUT") 0 584 584
511 0 { print "Cannot dup stderr to stdout in child";
512 0 die "Cannot dup stderr to stdout in child";
513 }
514 }
515 #Wrap exec in an eval, and exit on error, not die.
516 #Otherwise, if _noshell_backticks_ is put in an eval block,
517 #an exception raised by exec (e.g. taint issues) will result in
518 #BOTH child and parent continuing from the user's eval block.
519 #See e.g http://www.perlmonks.org/?node_id=166538
520 584 eval { exec { $cmd[0] } @cmd; #Not subject to shell escapes
521 };
522 #We only reach here if exec raised an exception
523 0 ▶ warn "$@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
524 0 exit $chd_excode;
525 }
526 }
527  
528 sub _run_generic_sshare_cmd_always($@)
529 #Run a generic sshare cmd, returning results
530 #Does NOT honors dryrun.
531 #This should only be called directly for commands which do NOT
532 #modify the database
533 27319 ▶{ my $class = shift;
Subroutine _run_generic_sshare_cmd_always: called CC=2 SCAR=6.9
534 27319 my @args = @_;
535  
536 27319 my $cmd = $class->sshare;
537 27319 my $mode = 1;
538 27319 ▶ if ( $class->verbose )
Branch: 1 branch
BranchTrueFalseTotal
if ($class->verbose) 2 27317 27319
539 { #Verbose mode:
540 #Output command before executing it
541 2 my @tmp = ($class->sshare, @args);
542 2 my $tmpcmd = join ' ', @tmp;
543 2 print STDERR "[VERBOSE] $tmpcmd\n";
544 }
545 27319 my ($err, @out ) = $class->_noshell_backticks($mode, $cmd, @args);
546 26735 $_last_raw_output = [ @out ];
547 26735 return ($err, @out);
548 }
549  
550 sub run_generic_sshare_cmd($@)
551 #Run a generic sshare cmd, returning results
552 #No dryrun mode, as sshare is view only anyway. Also, no --readonly flag.
553 #
554 #Returns list ref of output, line by line on success.
555 #Returns non-ref error message on error.
556 27319 ▶{ my $class = shift;
Subroutine run_generic_sshare_cmd: called CC=3 SCAR=14.8
Pod undocumented
557 27319 my @args = @_;
558  
559 27319 my ($err, @out) = $class->_run_generic_sshare_cmd_always(@args);
560 26735 ▶ if ( $err )
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 26735 26735
561 0 { my $errstr = "Exit code: $err";
562 0 my $output = join "\n", @out;
563 0 ▶ $errstr .= "\n$output" if $output;
Branch: 1 branch
BranchTrueFalseTotal
if $output 0 0 0
564 0 return $errstr;
565 }
566 #return $err if $err;
567 26735 return [ @out ];
568
569 }
570  
571 sub run_generic_sshare_list_command($@)
572 #Runs a sshare list command, returns output as a list ref of list refs
573 #of the fields in order.
574 #(Tried using hash refs, but those get abbreviated. Ugh!)
575 #'list' should be included in the command spec
576 #
577 #The list of arguments to this method are passed as arguments to the sshare
578 #command.
579 #On error, returns non-ref error message/error code
580 #
581 #Appends --parsable2, --long and --noheader to the command
582 26687 ▶{ my $class = shift;
Subroutine run_generic_sshare_list_command: called CC=5 SCAR=16.3
Pod undocumented
583 26687 my @cmd = @_;
584  
585 26687 push @cmd, '--parsable2', '--noheader', '--long';
586 26687 my $lines = $class->run_generic_sshare_cmd(@cmd);
587  
588 26191 ▶ return $lines unless $lines && ref($lines) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless $lines and ref $lines eq "ARRAY" 0 26191 26191
Condition33%1/3
$lines and ref $lines eq "ARRAY"
!ll&&!rl&&r
0026191
MC/DC0%0/2
$lines and ref $lines eq "ARRAY"
$lines ref $lines eq "ARRAY"
Truth table33%1/3
A and B
A= $linesB= ref $lines eq "ARRAY"
ABresult
0X0
100
111
589  
590 26191 my $results = [];
591 26191 LINE: foreach my $line (@$lines)
592 136398 { chomp $line;
593 136398 ▶ next LINE unless $line =~ /\|/;
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ /\|/ 1666 134732 136398
594 134732 my @values = split /\|/, $line;
595 134732 push @$results, \@values;
596 }
597  
598 26191 return $results;
599 }
600  
601 #-------------------------------------------------------------------
602 # Class methods to generate Slurm::Sshare object from output of
603 # sshare command
604 #-------------------------------------------------------------------
605  
606 sub _sshare_fields_in_order($)
607 #Should return a list ref of field names in order sacctmgr will return them
608 134741 ▶{ my $class = shift;
Subroutine _sshare_fields_in_order: called CC=1 SCAR=0.0
609 134741 return [ @sshare_fields_in_order];
610 }
611  
612 sub new_from_sshare_record($$$)
613 #Generates a new instance from a list ref as obtained from the
614 #sshare command output
615 134741 ▶{ my $class = shift;
Subroutine new_from_sshare_record: called CC=27 SCAR=33.5
Pod undocumented
616 134741 my $record = shift;
617 134741 my $cluster = shift;
618  
619 134741 my $fields = $class->_sshare_fields_in_order;
620 134741 my @fields = @$fields;
621 134741 my @record = @$record;
622  
623 #Determine if we have partition info or not
624 #3rd field is either partition or raw_shares, so if not
625 #a number we have partition (unless undef (only for root?)
626 #in which case look at 4th field, either RawShare (if partition)
627 #NormShares (w/out part) or so check if integral.)
628 134741 my $have_partition_info;
629 134741 my $tmp = $record->[2];
630 134741 ▶ if ( defined $tmp && $tmp ne '' )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tmp and $tmp ne '') { } 118298 16443 134741
Condition66%2/3
defined $tmp and $tmp ne ""
!ll&&!rl&&r
016443118298
MC/DC50%1/2
defined $tmp and $tmp ne ""
defined $tmp $tmp ne ""
Truth table66%2/3
A and B
A= defined $tmpB= $tmp ne ""
ABresult
0X0
100
111
631 { #Have a value
632 #Is it an integer (for raw_shares)
633 118298 ▶ if ( $tmp =~ /^\s*\d+\s*$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($tmp =~ /^\s*\d+\s*$/) { } 112871 5427 118298
634 { #Looks like raw_shares, so no partinfo
635 112871 $have_partition_info = 0;
636 } else
637 { #Non-numeric, so must be a partition name
638 5427 $have_partition_info = 1;
639 }
640 } else
641 { #No value for raw shares/partition.
642 #Try next field and see if integral
643 16443 $tmp = $record->[3];
644 16443 ▶ if ( $tmp =~ /^\s*\d+\s*$/ )
Branch: 2 branches
BranchTrueFalseTotal
if ($tmp =~ /^\s*\d+\s*$/) { } 4400 12043 16443
elsif ($tmp ne '') { } 11209 834 12043
645 { #Integral, so is RawShares, so we have partition
646 4400 $have_partition_info = 1;
647 } elsif ( $tmp ne '' )
648 11209 { $have_partition_info = 0;
649 } else
650 { #Boths [2] and [3] are empty; i.e. either
651 #both raw and normshares are empty (and no partinfo)
652 #of both partition and rawshares are empty (w partinfo)
653 #[4] should either be rawusage (no partinfo) or normshares (w partinfo)
654 834 $tmp = $record->[4];
655 834 ▶ if ( $tmp =~ /^\s*\d+\s*$/ )
Branch: 2 branches
BranchTrueFalseTotal
if ($tmp =~ /^\s*\d+\s*$/) { } 0 834 834
elsif ($tmp =~ /\./) { } 834 0 834
656 { #Integer, so looks like rawusage
657 0 $have_partition_info = 0;
658 } elsif ( $tmp =~ /\./ )
659 { #Has decimal point, so looks like normshares
660 834 $have_partition_info = 1;
661 } else
662 { #I am about to give up. Count fields
663 #Will see one extra due to final |
664 0 ▶ $have_partition_info = (scalar(@$record) == scalar(@fields) +1)?1:0;
Branch: 1 branch
BranchTrueFalseTotal
scalar @$record == scalar(@fields) + 1 ? : 0 0 0
665 }
666 }
667 }
668 134741 ▶ if ( $have_partition_info )
Branch: 1 branch
BranchTrueFalseTotal
if ($have_partition_info) 10661 124080 134741
669 { #We should cache that we have a sshare which can give partition info
670 10661 $class->_set_sshare_caps_cache('can_display_partition', 1 );
671 }
672 #but not if $have_partition_info=0, as maybe sshare can do it but requested it not do so
673  
674 134741 my @newargs = ();
675 134741 ▶ @newargs = (cluster => $cluster) if $cluster;
Branch: 1 branch
BranchTrueFalseTotal
if $cluster 130236 4505 134741
676  
677 134741 FIELD: foreach my $fld (@fields)
678 1482151 ▶ { next FIELD if $fld eq 'partition' && ! $have_partition_info;
Branch: 1 branch
BranchTrueFalseTotal
if $fld eq "partition" and not $have_partition_info 124080 1358071 1482151
Condition100%3/3
$fld eq "partition" and not $have_partition_info
!ll&&!rl&&r
134741010661124080
MC/DC100%2/2
$fld eq "partition" and not $have_partition_info
$fld eq "partition" not $have_partition_info
Truth table100%3/3
A and not(B)
A= $fld eq "partition"B= not $have_partition_info
ABresult
0X0
100
111
679 1358071 my $val = shift @record;
680 1358071 ▶ $val =~ s/^ *// if defined $val;
Branch: 1 branch
BranchTrueFalseTotal
if defined $val 1358071 0 1358071
681 1358071 $fld = lc $fld;
682  
683 1358071 ▶ if ( $fld eq 'grpcpumins' )
Branch: 1 branch
BranchTrueFalseTotal
if ($fld eq "grpcpumins") 134741 1223330 1358071
684 { #Is this grpcpumins or grptresmins? Former is integral, latter is x=y
685 134741 ▶ $fld = 'grptresmins' if ( defined $val && $val !~ /^\s*\d+\s*$/ && $val !~ /^\s*$/ );
Branch: 1 branch
BranchTrueFalseTotal
if defined $val and not $val =~ /^\s*\d+\s*$/ and not $val =~ /^\s*$/ 12488 122253 134741
Condition83%5/6
defined $val and not $val =~ /^\s*\d+\s*$/ and not $val =~ /^\s*$/
!ll&&!rl&&r
354578679612488
defined $val and not $val =~ /^\s*\d+\s*$/
!ll&&!rl&&r
03545799284
MC/DC66%2/3
defined $val and not $val =~ /^\s*\d+\s*$/ and not $val =~ /^\s*$/
defined $val not $val =~ /^\s*\d+\s*$/ not $val =~ /^\s*$/
Truth table75%3/4
A and not(B) and not(C)
A= defined $valB= not $val =~ /^\s*\d+\s*$/C= not $val =~ /^\s*$/
ABCresult
0XX0
10X0
1100
1111
686 }
687 1358071 ▶ if ( $fld eq 'cpurunmins' )
Branch: 1 branch
BranchTrueFalseTotal
if ($fld eq "cpurunmins") 134741 1223330 1358071
688 { #Is this cpurunmins or tresrunmins? Former is integral, latter is x=y
689 134741 ▶ $fld = 'tresrunmins' if ( defined $val && $val !~ /^\s*\d+\s*$/ && $val !~ /^\s*$/ );
Branch: 1 branch
BranchTrueFalseTotal
if defined $val and not $val =~ /^\s*\d+\s*$/ and not $val =~ /^\s*$/ 35551 99190 134741
Condition66%4/6
defined $val and not $val =~ /^\s*\d+\s*$/ and not $val =~ /^\s*$/
!ll&&!rl&&r
99190035551
defined $val and not $val =~ /^\s*\d+\s*$/
!ll&&!rl&&r
09919035551
MC/DC33%1/3
defined $val and not $val =~ /^\s*\d+\s*$/ and not $val =~ /^\s*$/
defined $val not $val =~ /^\s*\d+\s*$/ not $val =~ /^\s*$/
Truth table50%2/4
A and not(B) and not(C)
A= defined $valB= not $val =~ /^\s*\d+\s*$/C= not $val =~ /^\s*$/
ABCresult
0XX0
10X0
1100
1111
690 }
691 1358071 ▶ if ( $fld eq 'grptresmins' || $fld eq 'tresrunmins' )
Branch: 1 branch
BranchTrueFalseTotal
if ($fld eq "grptresmins" or $fld eq "tresrunmins") 48039 1310032 1358071
Condition100%3/3
$fld eq "grptresmins" or $fld eq "tresrunmins"
l!l&&r!l&&!r
12488355511310032
MC/DC100%2/2
$fld eq "grptresmins" or $fld eq "tresrunmins"
$fld eq "grptresmins" $fld eq "tresrunmins"
Truth table100%3/3
A or B
A= $fld eq "grptresmins"B= $fld eq "tresrunmins"
ABresult
1X1
011
000
692 { #If we have TRES data, our sshare should be new enough to give partition info
693 48039 $class->_set_sshare_caps_cache('can_display_partition', 1 );
694 }
695  
696
697 1358071 ▶ push @newargs, $fld, $val if defined $val && $val ne '';
Branch: 1 branch
BranchTrueFalseTotal
if defined $val and $val ne "" 1187299 170772 1358071
Condition66%2/3
defined $val and $val ne ""
!ll&&!rl&&r
01707721187299
MC/DC50%1/2
defined $val and $val ne ""
defined $val $val ne ""
Truth table66%2/3
A and B
A= defined $valB= $val ne ""
ABresult
0X0
100
111
698 }
699  
700 134741 my $obj = $class->new(@newargs);
701 134741 return $obj;
702 }
703  
704 #-------------------------------------------------------------------
705 # High level commands
706 #-------------------------------------------------------------------
707  
708 sub sshare_list($@)
709 #Gets sshare output.
710 #Input parameters are key=>value pairs and can include:
711 # accounts: list of accounts to get information for
712 # clusters: list of clusters to get information for.
713 # users: list of users to get information for
714 # nopartinfo: boolean to determine whether we try to get partition information.
715 #
716 #List values can be either list refs or CSV strings. For users, if the single
717 #string 'ALL' is given (not part of a list), then all users will be listed.
718 #
719 #If nopartinfo flag is set, the sshare command will not include the '--partition'
720 #flag to get partition information. Default is unset (so include the '--partition'
721 #flag if the sshare command supports it). This of course is only useful when
722 #the sshare command supports the --partition flag (although can be used on older sshares
723 #to avoid attempting to discover if it is supported).
724 #
725 #On success, returns a list ref of Slurm::Sshare objects corresponding
726 #to the output of the sshare command. Possibly an empty list.
727 #
728 #On error, either aborts or returns non-ref true value (text describing
729 #the error)
730 23392 ▶{ my $class = shift;
Subroutine sshare_list: called CC=25 SCAR=32.7
Pod documented
731 23392 my %where = @_;
732  
733 23392 my $me = 'sshare_list';
734 23392 my @args = ();
735 23392 my $tmp;
736  
737 23392 my $accounts = delete $where{accounts};
738 23392 my $clusters = delete $where{clusters};
739 23392 my $users = delete $where{users};
740 23392 my $nopartinfo = delete $where{nopartinfo};
741 23392 ▶ croak "$me: Extraneous arguments [" . (join ', ', (keys %where) ) .
Branch: 1 branch
BranchTrueFalseTotal
if scalar %where 0 23392 23392
742 "] given, aborting at " if scalar(%where);
743  
744 23392 ▶ if ( scalar(keys %where) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %where) 0 23392 23392
745 0 { $tmp = join ", ", (keys %where);
746 0 croak "$me: Unrecognized arguments [ $tmp ], aborting.\n";
747 }
748  
749 23392 ▶ if ( $accounts )
Branch: 1 branch
BranchTrueFalseTotal
if ($accounts) 13066 10326 23392
750 13066 ▶ { unless ( ref($accounts) eq 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $accounts eq "ARRAY") 3482 9584 13066
751 3482 { $accounts = [ split /\s*,\s*/, $accounts ];
752 }
753 }
754 23392 ▶ if ( $accounts && scalar(@$accounts) )
Branch: 1 branch
BranchTrueFalseTotal
if ($accounts and scalar @$accounts) 13066 10326 23392
Condition100%2/2
$accounts and scalar @$accounts
!ll
1032613066
MC/DC100%1/1
$accounts and scalar @$accounts
$accounts
Truth table100%2/2
A
A= $accounts
Aresult
00
11
755 13066 { $tmp = join ",", @$accounts;
756 13066 push @args, "--accounts=$tmp";
757 }
758  
759 23392 ▶ if ( $clusters )
Branch: 1 branch
BranchTrueFalseTotal
if ($clusters) 21949 1443 23392
760 21949 ▶ { unless ( ref($clusters) eq 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $clusters eq "ARRAY") 17650 4299 21949
761 17650 { $clusters = [ split /\s*,\s*/, $clusters ];
762 }
763 }
764 #unless ( $clusters && scalar(@$clusters) )
765 #{ croak "$me: At least one cluster must be specified at ";
766 #}
767  
768 23392 ▶ if ( $users )
Branch: 1 branch
BranchTrueFalseTotal
if ($users) 18807 4585 23392
769 18807 ▶ { unless ( ref($users) eq 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $users eq "ARRAY") 4861 13946 18807
770 4861 { $users = [ split /\s*,\s*/, $users ];
771 }
772 }
773 23392 ▶ if ( $users && ref($users) eq 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
if ($users and ref $users eq "ARRAY") 18807 4585 23392
Condition66%2/3
$users and ref $users eq "ARRAY"
!ll&&!rl&&r
4585018807
MC/DC50%1/2
$users and ref $users eq "ARRAY"
$users ref $users eq "ARRAY"
Truth table66%2/3
A and B
A= $usersB= ref $users eq "ARRAY"
ABresult
0X0
100
111
774 18807 ▶ { if ( scalar(@$users) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$users) { } 15785 3022 18807
775 15785 ▶ { if ( $users->[0] eq 'ALL' )
Branch: 1 branch
BranchTrueFalseTotal
if ($users->[0] eq 'ALL') { } 3485 12300 15785
776 3485 { push @args, '--all';
777 } else
778 12300 { $tmp = join ",", @$users;
779 12300 push @args, "--users=$tmp";
780 }
781 } else
782 { #We were given an empty list ref of users
783 #Return only records with NO user field
784 #Can't actually do it, so set users to non-existant user
785 3022 push @args, "--users='NO SUCH USER'";
786 }
787 }
788  
789 #Include partition name in results if can and not explicitly requested not to
790 23392 ▶ unless ($nopartinfo)
Branch: 1 branch
BranchTrueFalseTotal
unless ($nopartinfo) 10639 12753 23392
791 10639 ▶ { if ( $class->sshare_cmd_supports('can_display_partition') )
Branch: 1 branch
BranchTrueFalseTotal
if ($class->sshare_cmd_supports("can_display_partition")) 2220 8338 10558
792 2220 { push @args, '--partition';
793 }
794 }
795  
796 #Save raw output for debugging purposes
797 23311 $_sslist_last_raw_output = [];
798  
799 23311 my @objects = ();
800  
801 23311 ▶ if ( $clusters )
Branch: 1 branch
BranchTrueFalseTotal
if ($clusters) { } 21888 1423 23311
802 { # One or more clusters specified; run sshare on each specified cluster
803 # and label results based on the cluster
804 21888 foreach my $cluster (@$clusters)
805 25264 { my $tmplist = $class->run_generic_sshare_list_command(
806 "--clusters=$cluster", @args);
807 24857 push @$_sslist_last_raw_output, @{$class->_sshare_last_raw_output};
808  
809 24857 ▶ unless ( $tmplist && ref($tmplist) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($tmplist and ref $tmplist) 0 24857 24857
Condition33%1/3
$tmplist and ref $tmplist
!ll&&!rl&&r
0024857
MC/DC0%0/2
$tmplist and ref $tmplist
$tmplist ref $tmplist
Truth table33%1/3
A and B
A= $tmplistB= ref $tmplist
ABresult
0X0
100
111
810 0 { return "Error in sshare cmd for $cluster: $tmplist";
811 }
812  
813 24857 foreach my $rec (@$tmplist)
814 {
815 130236 my $obj = $class->new_from_sshare_record($rec,$cluster);
816 130236 push @objects, $obj;
817 }
818 }
819 } else
820 { #No clusters specified
821 1423 my $tmplist = $class->run_generic_sshare_list_command(@args);
822 1334 push @$_sslist_last_raw_output, @{$class->_sshare_last_raw_output};
823  
824 1334 ▶ unless ( $tmplist && ref($tmplist) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($tmplist and ref $tmplist) 0 1334 1334
Condition33%1/3
$tmplist and ref $tmplist
!ll&&!rl&&r
001334
MC/DC0%0/2
$tmplist and ref $tmplist
$tmplist ref $tmplist
Truth table33%1/3
A and B
A= $tmplistB= ref $tmplist
ABresult
0X0
100
111
825 0 { return "Error in sshare cmd: $tmplist";
826 }
827  
828 1334 foreach my $rec (@$tmplist)
829 {
830 4496 my $obj = $class->new_from_sshare_record($rec);
831 4496 push @objects, $obj;
832 }
833 }
834
835 22815 return [@objects];
836 }
837  
838 sub combine_tres_hashes($$$)
839 #Given two hash refs representing TRES hashes, they will be combined.
840 #Either hash ref can be undef, which is treated essentially as an empty hash
841 #(except that if both are undef, this will return undef)
842 #If a field is common to both and defined value in both, the field will be
843 #in the combined hash with the sum of the values of the individual hashes.
844 #If a field is found in only one of the two, it will be passed unchanged into
845 #the combined hash
846 4290 ▶{ my $class = shift;
Subroutine combine_tres_hashes: called CC=14 SCAR=28.1
Pod documented
847 4290 my $thash1 = shift;
848 4290 my $thash2 = shift;
849 4290 my $me = __PACKAGE__ . '::combine_tres_hashes';
850  
851 4290 ▶ return unless $thash1 || $thash2;
Branch: 1 branch
BranchTrueFalseTotal
unless $thash1 or $thash2 0 4290 4290
Condition66%2/3
$thash1 or $thash2
l!l&&r!l&&!r
66036300
MC/DC0%0/2
$thash1 or $thash2
$thash1 $thash2
Truth table66%2/3
A or B
A= $thash1B= $thash2
ABresult
1X1
011
000
852 4290 ▶ croak "$me: Invalid tres1 ($thash1), expecting hash ref, at "
Branch: 1 branch
BranchTrueFalseTotal
if $thash1 and ref $thash1 ne "HASH" 0 4290 4290
Condition66%2/3
$thash1 and ref $thash1 ne "HASH"
!ll&&!rl&&r
36306600
MC/DC0%0/2
$thash1 and ref $thash1 ne "HASH"
$thash1 ref $thash1 ne "HASH"
Truth table66%2/3
A and B
A= $thash1B= ref $thash1 ne "HASH"
ABresult
0X0
100
111
853 if $thash1 && ref($thash1) ne 'HASH';
854 4290 ▶ croak "$me: Invalid tres2 ($thash2), expecting hash ref, at "
Branch: 1 branch
BranchTrueFalseTotal
if $thash2 and ref $thash2 ne "HASH" 0 4290 4290
Condition33%1/3
$thash2 and ref $thash2 ne "HASH"
!ll&&!rl&&r
042900
MC/DC0%0/2
$thash2 and ref $thash2 ne "HASH"
$thash2 ref $thash2 ne "HASH"
Truth table33%1/3
A and B
A= $thash2B= ref $thash2 ne "HASH"
ABresult
0X0
100
111
855 if $thash2 && ref($thash2) ne 'HASH';
856 4290 ▶ $thash1 = {} unless $thash1;
Branch: 1 branch
BranchTrueFalseTotal
unless $thash1 3630 660 4290
857 4290 ▶ $thash2 = {} unless $thash2;
Branch: 1 branch
BranchTrueFalseTotal
unless $thash2 0 4290 4290
858  
859 4290 my $chash = {};
860 4290 my @keys = keys %$thash1;
861 4290 push @keys, (keys %$thash2);
862 4290 my %temp = map { $_ => undef } @keys;
863 4290 @keys = keys %temp;
864  
865 4290 foreach my $key (@keys)
866 7400 { my $tres1 = $thash1->{$key};
867 7400 my $tres2 = $thash2->{$key};
868  
869 7400 ▶ if ( defined $tres1 && defined $tres2 )
Branch: 3 branches
BranchTrueFalseTotal
if (defined $tres1 and defined $tres2) { } 1184 6216 7400
elsif (defined $tres1) { } 0 6216 6216
elsif (defined $tres2) { } 6216 0 6216
Condition66%2/3
defined $tres1 and defined $tres2
!ll&&!rl&&r
621601184
MC/DC50%1/2
defined $tres1 and defined $tres2
defined $tres1 defined $tres2
Truth table66%2/3
A and B
A= defined $tres1B= defined $tres2
ABresult
0X0
100
111
870 { #Defined for both
871 1184 $chash->{$key} = $tres1 + $tres2;
872 } elsif ( defined $tres1 )
873 0 { $chash->{$key} = $tres1;
874 } elsif ( defined $tres2 )
875 6216 { $chash->{$key} = $tres2;
876 }
877 }
878 4290 return $chash;
879 }
880
881
882 sub combine_sshare_usage_records($$;$)
883 #Takes a list ref of Slurm::Sshare instances (e.g. filtered output of sshare_list
884 #command), and returns a hash ref containing the "sum" of the records.
885 #NOTE: no checks are made that it is sensible to combine the records given
886 #The resultant hash will have the following keys:
887 # raw_shares
888 # normalized_shares
889 # raw_usage
890 # normalized_usage
891 # effective_usage
892 # fairshare
893 # grpcpumins
894 # cpurunmins
895 #Fields will only exist if exist and have defined values in at least one element.
896 #All of the above are simply summed
897 #
898 #In addition, the hash valued fields
899 # grptresmins
900 # tresrunmins
901 #will be added key by key.
902 #
903 #Elements of the input list ref can also be a hash ref with the above fields instead
904 #of an actual Slurm::Sshare object.
905 2332 ▶{ my $class = shift;
Subroutine combine_sshare_usage_records: called CC=25 SCAR=35.5
Pod documented
906 2332 ▶ my $list = shift || [];
Condition50%1/2
shift() || []
l!l
23320
MC/DC0%0/1
shift() || []
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
907 2332 ▶ my $me = shift || __PACKAGE__ . '::combine_sshare_usage_records';
Condition50%1/2
shift() || 'Slurm::Sshare::combine_sshare_usage_records'
l!l
23320
MC/DC0%0/1
shift() || 'Slurm::Sshare::combine_sshare_usage_records'
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
908  
909 2332 my ($rshares, $nshares, $rusage, $nusage, $eusage, $fshare, $gcpumins, $crunmins);
910 2332 my ($grptresmins, $tresrunmins);
911 2332 foreach my $rec (@$list)
912 2992 { my ( $tmp_rshares, $tmp_nshares, $tmp_rusage, $tmp_nusage);
913 2992 my ( $tmp_eusage, $tmp_fshare, $tmp_gcmins, $tmp_crmins);
914 2992 my ( $tmp_grptresmins, $tmp_tresrunmins);
915 #Get values for this record
916 2992 ▶ if ( UNIVERSAL::isa($rec, 'Slurm::Sshare') || UNIVERSAL::can($rec,'raw_usage') )
Branch: 2 branches
BranchTrueFalseTotal
if (UNIVERSAL::isa($rec, 'Slurm::Sshare') or UNIVERSAL::can($rec, 'raw_usage')) { } 2992 0 2992
elsif (ref $rec eq 'HASH') { } 0 0 0
Condition33%1/3
UNIVERSAL::isa($rec, "Slurm::Sshare") or UNIVERSAL::can($rec, "raw_usage")
l!l&&r!l&&!r
299200
MC/DC0%0/2
UNIVERSAL::isa($rec, "Slurm::Sshare") or UNIVERSAL::can($rec, "raw_usage")
UNIVERSAL::isa($rec, "Slurm::Sshare") UNIVERSAL::can($rec, "raw_usage")
Truth table33%1/3
A or B
A= UNIVERSAL::isa($rec, "Slurm::Sshare")B= UNIVERSAL::can($rec, "raw_usage")
ABresult
1X1
011
000
917 { #Looks like a Slurm::Sshare instance
918 2992 $tmp_rshares = $rec->raw_shares;
919 2992 $tmp_nshares = $rec->normalized_shares;
920 2992 $tmp_rusage = $rec->raw_usage;
921 2992 $tmp_nusage = $rec->normalized_usage;
922 2992 $tmp_eusage = $rec->effective_usage;
923 2992 $tmp_fshare = $rec->fairshare;
924 2992 $tmp_gcmins = $rec->grpcpumins;
925 2992 $tmp_crmins = $rec->cpurunmins;
926 2992 $tmp_grptresmins = $rec->grptresmins;
927 2992 $tmp_tresrunmins = $rec->tresrunmins;
928 } elsif ( ref($rec) eq 'HASH' )
929 { #Simple hash ref
930 0 $tmp_rshares = $rec->{raw_shares};
931 0 $tmp_nshares = $rec->{normalized_shares};
932 0 $tmp_rusage = $rec->{raw_usage};
933 0 $tmp_nusage = $rec->{normalized_usage};
934 0 $tmp_eusage = $rec->{effective_usage};
935 0 $tmp_fshare = $rec->{fairshare};
936 0 $tmp_gcmins = $rec->{grpcpumins};
937 0 $tmp_crmins = $rec->{cpurunmins};
938 0 $tmp_grptresmins = $rec->{grptresmins};
939 0 $tmp_tresrunmins = $rec->{tresrunmins};
940 } else
941 0 { croak "$me: Illegal sshare usage record $rec, expecting Slurm::Sshare instance";
942 }
943  
944 2992 ▶ if ( defined $tmp_rshares )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tmp_rshares) 2992 0 2992
945 2992 ▶ { $rshares = 0 unless defined $rshares;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rshares 2332 660 2992
946 2992 $rshares += $tmp_rshares;
947 }
948 2992 ▶ if ( defined $tmp_nshares )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tmp_nshares) 2992 0 2992
949 2992 ▶ { $nshares = 0 unless defined $nshares;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $nshares 2332 660 2992
950 2992 $nshares += $tmp_nshares;
951 }
952 2992 ▶ if ( defined $tmp_rusage )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tmp_rusage) 2992 0 2992
953 2992 ▶ { $rusage = 0 unless defined $rusage;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rusage 2332 660 2992
954 2992 $rusage += $tmp_rusage;
955 }
956 2992 ▶ if ( defined $tmp_nusage )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tmp_nusage) 2992 0 2992
957 2992 ▶ { $nusage = 0 unless defined $nusage;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $nusage 2332 660 2992
958 2992 $nusage += $tmp_nusage;
959 }
960 2992 ▶ if ( defined $tmp_eusage )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tmp_eusage) 2992 0 2992
961 2992 ▶ { $eusage = 0 unless defined $eusage;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $eusage 2332 660 2992
962 2992 $eusage += $tmp_eusage;
963 }
964 2992 ▶ if ( defined $tmp_fshare )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tmp_fshare) 2992 0 2992
965 2992 ▶ { $fshare = 0 unless defined $fshare;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fshare 2332 660 2992
966 2992 $fshare += $tmp_fshare;
967 }
968 2992 ▶ if ( defined $tmp_gcmins )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tmp_gcmins) 1298 1694 2992
969 1298 ▶ { $gcpumins = 0 unless defined $gcpumins;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $gcpumins 1298 0 1298
970 1298 $gcpumins += $tmp_gcmins;
971 }
972 2992 ▶ if ( defined $tmp_crmins )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tmp_crmins) 2992 0 2992
973 2992 ▶ { $crunmins = 0 unless defined $crunmins;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $crunmins 2332 660 2992
974 2992 $crunmins += $tmp_crmins;
975 }
976  
977 #Handle TRES stuff
978 2992 ▶ if ( defined $tmp_grptresmins)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tmp_grptresmins) 1298 1694 2992
979 1298 { $grptresmins = $class->combine_tres_hashes(
980 $grptresmins, $tmp_grptresmins);
981 }
982 2992 ▶ if ( defined $tmp_tresrunmins)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tmp_tresrunmins) 2992 0 2992
983 2992 { $tresrunmins = $class->combine_tres_hashes(
984 $tresrunmins, $tmp_tresrunmins);
985 }
986 }
987  
988 2332 my $hash = {
989 raw_shares => $rshares,
990 normalized_shares => $nshares,
991 raw_usage => $rusage,
992 normalized_usage => $nusage,
993 effective_usage => $eusage,
994 fairshare => $fshare,
995 grpcpumins => $gcpumins,
996 cpurunmins => $crunmins,
997 grptresmins => $grptresmins,
998 tresrunmins => $tresrunmins,
999 };
1000 2332 return $hash;
1001 }
1002  
1003 sub collect_usage_records_by_account($@)
1004 #Takes a list ref of Slurm::Sshare instances (e.g. output of sshare_list)
1005 #and collects them by cluster, account, and user.
1006 #Input is key => value pairs, with the following keys recognized:
1007 # records: list ref of Slurm::Sshare instances REQUIRED
1008 # clusters: list ref of clusters to include in results.
1009 # If omitted, results will include data for all clusters
1010 # found in records. To get results for records with
1011 # cluster undef, use either 'DEFAULT' or undef in list ref.
1012 # accounts: list ref of accounts to include in results.
1013 # If omitted, results will include data for all accounts
1014 # found in results.
1015 # users: list ref of users to include results for. Defaults to
1016 # all users found in results.
1017 #The return value is a hash ref keyed on the cluster names (an undef cluster
1018 #name is converted to the string 'DEFAULT'). The value is another hash
1019 #ref, this time keyed on the account name. The value of the account name
1020 #key is yet another hash ref, this one containing usage information for
1021 #the specified account. It may have the following keys:
1022 # account: name of the account (always present)
1023 # cluster: name of the cluster (might be undef)
1024 # raw_shares
1025 # normalized_shares
1026 # raw_usage
1027 # normalized_usage
1028 # effective_usage
1029 # fairshare
1030 # grpcpumins
1031 # cpurunmins
1032 # grptresmins
1033 # tresrunmins
1034 # users_hash: a hash ref keyed on user name, containing usage data
1035 # for that user AND account. It has similar structure to
1036 # the account usage data, except no users_hash key, and instead
1037 # has an user key with the name of the user.
1038 #For both the account and user level usage hash, the usage fields may or may not
1039 #be present, depending on whether there was any data for them in the records.
1040 1688 ▶{ my $class = shift;
Subroutine collect_usage_records_by_account: called CC=40 SCAR=45.4
Pod documented
1041 1688 my %args = @_;
1042 1688 my $me = __PACKAGE__ . '::collect_usage_records_by_account';
1043  
1044 1688 my $records = delete $args{records};
1045 1688 my $only_clusters = delete $args{clusters};
1046 1688 my $only_accounts = delete $args{accounts};
1047 1688 my $only_users = delete $args{users};
1048  
1049 1688 ▶ croak "$me: Missing required parameter 'records' at " unless $records;
Branch: 1 branch
BranchTrueFalseTotal
unless $records 0 1688 1688
1050 1688 ▶ croak "$me: Invalid value '$records' for parameter records (expecting list ref) at "
Branch: 1 branch
BranchTrueFalseTotal
unless $records and ref $records eq "ARRAY" 0 1688 1688
Condition33%1/3
$records and ref $records eq "ARRAY"
!ll&&!rl&&r
001688
MC/DC0%0/2
$records and ref $records eq "ARRAY"
$records ref $records eq "ARRAY"
Truth table33%1/3
A and B
A= $recordsB= ref $records eq "ARRAY"
ABresult
0X0
100
111
1051 unless $records && ref($records) eq 'ARRAY';
1052 1688 ▶ if ( %args )
Branch: 1 branch
BranchTrueFalseTotal
if (%args) 0 1688 1688
1053 0 { my $tmp = join ', ', (keys %args);
1054 0 croak "$me: Extraneous parameters [ $tmp ], aborting at ";
1055 }
1056
1057 1688 ▶ $only_clusters = [ $only_clusters ]
Branch: 1 branch
BranchTrueFalseTotal
if $only_clusters and ref $only_clusters ne "ARRAY" 0 1688 1688
Condition33%1/3
$only_clusters and ref $only_clusters ne "ARRAY"
!ll&&!rl&&r
168800
MC/DC0%0/2
$only_clusters and ref $only_clusters ne "ARRAY"
$only_clusters ref $only_clusters ne "ARRAY"
Truth table33%1/3
A and B
A= $only_clustersB= ref $only_clusters ne "ARRAY"
ABresult
0X0
100
111
1058 if $only_clusters && ref($only_clusters) ne 'ARRAY';
1059 0 ▶ $only_clusters = [ map { (defined $_)?$_:'DEFAULT' } @$only_clusters ]
Branch: 2 branches
BranchTrueFalseTotal
if $only_clusters and ref $only_clusters eq "ARRAY" 0 1688 1688
defined $_ ? : 0 0 0
Condition33%1/3
$only_clusters and ref $only_clusters eq "ARRAY"
!ll&&!rl&&r
168800
MC/DC0%0/2
$only_clusters and ref $only_clusters eq "ARRAY"
$only_clusters ref $only_clusters eq "ARRAY"
Truth table33%1/3
A and B
A= $only_clustersB= ref $only_clusters eq "ARRAY"
ABresult
0X0
100
111
1060 if $only_clusters && ref($only_clusters) eq 'ARRAY';
1061 1688 ▶ $only_clusters = [ undef ]
Branch: 1 branch
BranchTrueFalseTotal
if $only_clusters and ref $only_clusters eq "ARRAY" and scalar @$only_clusters 0 1688 1688
Condition40%2/5
$only_clusters and ref $only_clusters eq "ARRAY" and scalar @$only_clusters
!ll
16880
$only_clusters and ref $only_clusters eq "ARRAY"
!ll&&!rl&&r
168800
MC/DC0%0/2
$only_clusters and ref $only_clusters eq "ARRAY" and scalar @$only_clusters
$only_clusters ref $only_clusters eq "ARRAY"
Truth table33%1/3
A and B
A= $only_clustersB= ref $only_clusters eq "ARRAY"
ABresult
0X0
100
111
1062 if $only_clusters && ref($only_clusters) eq 'ARRAY' && scalar(@$only_clusters);
1063 1688 ▶ $only_accounts = [ $only_accounts ]
Branch: 1 branch
BranchTrueFalseTotal
if $only_accounts and ref $only_accounts ne "ARRAY" 0 1688 1688
Condition33%1/3
$only_accounts and ref $only_accounts ne "ARRAY"
!ll&&!rl&&r
168800
MC/DC0%0/2
$only_accounts and ref $only_accounts ne "ARRAY"
$only_accounts ref $only_accounts ne "ARRAY"
Truth table33%1/3
A and B
A= $only_accountsB= ref $only_accounts ne "ARRAY"
ABresult
0X0
100
111
1064 if $only_accounts && ref($only_accounts) ne 'ARRAY';
1065 1688 ▶ $only_users = [ $only_users ]
Branch: 1 branch
BranchTrueFalseTotal
if $only_users and ref $only_users ne "ARRAY" 0 1688 1688
Condition33%1/3
$only_users and ref $only_users ne "ARRAY"
!ll&&!rl&&r
168800
MC/DC0%0/2
$only_users and ref $only_users ne "ARRAY"
$only_users ref $only_users ne "ARRAY"
Truth table33%1/3
A and B
A= $only_usersB= ref $only_users ne "ARRAY"
ABresult
0X0
100
111
1066 if $only_users && ref($only_users) ne 'ARRAY';
1067 1688 my %only_clusters = ();
1068 1688 my %only_accounts = ();
1069 1688 my %only_users = ();
1070 0 ▶ %only_clusters = map { $_ => undef } @$only_clusters
Branch: 1 branch
BranchTrueFalseTotal
if $only_clusters and ref $only_clusters eq "ARRAY" 0 1688 1688
Condition33%1/3
$only_clusters and ref $only_clusters eq "ARRAY"
!ll&&!rl&&r
168800
MC/DC0%0/2
$only_clusters and ref $only_clusters eq "ARRAY"
$only_clusters ref $only_clusters eq "ARRAY"
Truth table33%1/3
A and B
A= $only_clustersB= ref $only_clusters eq "ARRAY"
ABresult
0X0
100
111
1071 if $only_clusters && ref($only_clusters) eq 'ARRAY';
1072 0 ▶ %only_accounts = map { $_ => undef } @$only_accounts
Branch: 1 branch
BranchTrueFalseTotal
if $only_accounts and ref $only_accounts eq "ARRAY" 0 1688 1688
Condition33%1/3
$only_accounts and ref $only_accounts eq "ARRAY"
!ll&&!rl&&r
168800
MC/DC0%0/2
$only_accounts and ref $only_accounts eq "ARRAY"
$only_accounts ref $only_accounts eq "ARRAY"
Truth table33%1/3
A and B
A= $only_accountsB= ref $only_accounts eq "ARRAY"
ABresult
0X0
100
111
1073 if $only_accounts && ref($only_accounts) eq 'ARRAY';
1074 0 ▶ %only_users = map { $_ => undef } @$only_users
Branch: 1 branch
BranchTrueFalseTotal
if $only_users and ref $only_users eq "ARRAY" 0 1688 1688
Condition33%1/3
$only_users and ref $only_users eq "ARRAY"
!ll&&!rl&&r
168800
MC/DC0%0/2
$only_users and ref $only_users eq "ARRAY"
$only_users ref $only_users eq "ARRAY"
Truth table33%1/3
A and B
A= $only_usersB= ref $only_users eq "ARRAY"
ABresult
0X0
100
111
1075 if $only_users && ref($only_users) eq 'ARRAY';
1076  
1077 #Get all clusters referenced in our records
1078 1688 my @clusters = map { $_->cluster } @$records;
1079 1688 ▶ my %temp = map { (defined($_)?$_:'') => undef } @clusters;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 2728 264 2992
1080 1688 @clusters = keys %temp;
1081  
1082 1688 my $results = {};
1083  
1084 1688 CLUSTER: foreach my $cluster (@clusters)
1085 1204 { my $tmpclus = $cluster;
1086 1204 ▶ $tmpclus = 'DEFAULT' unless defined $cluster;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $cluster 0 1204 1204
1087 1204 ▶ $tmpclus = 'DEFAULT' if $cluster eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $cluster eq "" 68 1136 1204
1088 1204 ▶ next CLUSTER if $only_clusters && ! exists $only_clusters{$tmpclus};
Branch: 1 branch
BranchTrueFalseTotal
if $only_clusters and not exists $only_clusters{$tmpclus} 0 1204 1204
Condition33%1/3
$only_clusters and not exists $only_clusters{$tmpclus}
!ll&&!rl&&r
120400
MC/DC0%0/2
$only_clusters and not exists $only_clusters{$tmpclus}
$only_clusters not exists $only_clusters{$tmpclus}
Truth table33%1/3
A and not(B)
A= $only_clustersB= not exists $only_clusters{$tmpclus}
ABresult
0X0
100
111
1089 1204 my $cresults = {};
1090  
1091 #Get all records for this cluster
1092 1204 my @crecords;
1093 1204 ▶ if ( $tmpclus eq 'DEFAULT' )
Branch: 1 branch
BranchTrueFalseTotal
if ($tmpclus eq 'DEFAULT') { } 68 1136 1204
1094 68 { @crecords = grep { ! defined $_->cluster } @$records;
1095 } else
1096 1136 { @crecords = grep { $_->cluster eq $cluster } @$records;
1097 }
1098  
1099 #Get all accounts referenced in our records
1100 1204 my @accounts = map { $_->account } @crecords;
1101 1204 %temp = map { $_ => undef } @accounts;
1102 1204 @accounts = keys %temp;
1103  
1104 1204 ACCOUNT: foreach my $account (@accounts)
1105 1204 ▶ { next ACCOUNT if $only_accounts && ! exists $only_accounts{$account};
Branch: 1 branch
BranchTrueFalseTotal
if $only_accounts and not exists $only_accounts{$account} 0 1204 1204
Condition33%1/3
$only_accounts and not exists $only_accounts{$account}
!ll&&!rl&&r
120400
MC/DC0%0/2
$only_accounts and not exists $only_accounts{$account}
$only_accounts not exists $only_accounts{$account}
Truth table33%1/3
A and not(B)
A= $only_accountsB= not exists $only_accounts{$account}
ABresult
0X0
100
111
1106  
1107 #Get all records for this account
1108 1204 my @arecords = grep { $_->account eq $account } @crecords;
1109  
1110 #Get the data for the account as a whole (records with no user set)
1111 1204 my @nouser = grep { ! $_->user } @arecords;
1112 1204 my $ahash = $class->combine_sshare_usage_records(\@nouser, $me);
1113 1204 ▶ $ahash = {} unless $ahash && ref($ahash) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless $ahash and ref $ahash eq "HASH" 0 1204 1204
Condition33%1/3
$ahash and ref $ahash eq "HASH"
!ll&&!rl&&r
001204
MC/DC0%0/2
$ahash and ref $ahash eq "HASH"
$ahash ref $ahash eq "HASH"
Truth table33%1/3
A and B
A= $ahashB= ref $ahash eq "HASH"
ABresult
0X0
100
111
1114 1204 my $aresults = {
1115 cluster=> $cluster,
1116 account => $account,
1117 %$ahash,
1118 };
1119  
1120 #Get collect the data for individual users in the account
1121 1204 my @userrecs = grep { $_->user } @arecords;
1122 1204 my @allusers = map { $_->user } @userrecs;
1123 1204 %temp = map { $_ => undef } @allusers;
1124 1204 @allusers = keys %temp;
1125  
1126 1204 my $users_hash = {};
1127  
1128 1204 USER: foreach my $user (@allusers)
1129 1128 ▶ { next USER if $only_users && ! $only_users{$user};
Branch: 1 branch
BranchTrueFalseTotal
if $only_users and not $only_users{$user} 0 1128 1128
Condition33%1/3
$only_users and not $only_users{$user}
!ll&&!rl&&r
112800
MC/DC0%0/2
$only_users and not $only_users{$user}
$only_users not $only_users{$user}
Truth table33%1/3
A and not(B)
A= $only_usersB= not $only_users{$user}
ABresult
0X0
100
111
1130 1128 my @urecords = grep { $_->user eq $user } @userrecs;
1131 1128 my $uhash = $class->combine_sshare_usage_records(\@urecords, $me);
1132 1128 ▶ $uhash = {} unless $uhash && ref($uhash) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless $uhash and ref $uhash eq "HASH" 0 1128 1128
Condition33%1/3
$uhash and ref $uhash eq "HASH"
!ll&&!rl&&r
001128
MC/DC0%0/2
$uhash and ref $uhash eq "HASH"
$uhash ref $uhash eq "HASH"
Truth table33%1/3
A and B
A= $uhashB= ref $uhash eq "HASH"
ABresult
0X0
100
111
1133 1128 $uhash->{cluster} = $cluster;
1134 1128 $uhash->{account} = $account;
1135 1128 $uhash->{user} = $user;
1136  
1137 1128 $users_hash->{$user} = $uhash;
1138 }
1139  
1140 1204 $aresults->{users_hash} = $users_hash;
1141  
1142 1204 $cresults->{$account} = $aresults;
1143 }
1144  
1145 1204 $results->{$tmpclus} = $cresults;
1146 }
1147  
1148 1688 return $results;
1149 }
1150
1151 sub sshare_usage($@)
1152 #This takes arguments which are passed to sshare_list. The output from sshare_list
1153 #is then passed to collect_usage_records_by_account for parsing.
1154 #So see sshare_list for input specifications, and
1155 #collect_usage_records_by_account for output specifications.
1156 #On non-fatal errors, returns a non-ref error string;
1157 1905 ▶{ my $class = shift;
Subroutine sshare_usage: called CC=3 SCAR=11.4
Pod documented
1158 1905 my @args = @_;
1159 1905 my $me = __PACKAGE__ . '::sshare_usage';
1160  
1161 1905 my $records = $class->sshare_list(@args);
1162 1688 ▶ return "$me: $records at " unless $records && ref($records) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless $records and ref $records eq "ARRAY" 0 1688 1688
Condition33%1/3
$records and ref $records eq "ARRAY"
!ll&&!rl&&r
001688
MC/DC0%0/2
$records and ref $records eq "ARRAY"
$records ref $records eq "ARRAY"
Truth table33%1/3
A and B
A= $recordsB= ref $records eq "ARRAY"
ABresult
0X0
100
111
1163  
1164 1688 my $usage_hash = $class->collect_usage_records_by_account(records=>$records);
1165 1688 return $usage_hash;
1166 }
1167  
1168 sub sshare_usage_for_account($@)
1169 #Calls sshare_usage to get usage information for a specific cluster and account.
1170 #Takes key => value pairs as input, recognizing the following keys
1171 # cluster: name of cluster. If omitted, will use whatever cluster sshare defaults to
1172 # account: name of account to get usage info for. REQUIRED
1173 # users: a list ref of user names to return data for. If omitted, will return
1174 # data for all users associated with the account. Give an empty list
1175 # ref (i.e. []) to get no user information returned.
1176 # nowarnings: boolean. If true, suppress warnings about not finding any data for the account
1177 #
1178 #On non-fatal errors, returns a non-ref textual error string.
1179 #On success, returns an account usage hash ref, e.g. a hash ref with keys
1180 # account: name of the account (always present). Same as input
1181 # cluster: same as cluster for input
1182 # raw_shares
1183 # normalized_shares
1184 # raw_usage
1185 # normalized_usage
1186 # effective_usage
1187 # fairshare
1188 # grpcpumins
1189 # cpurunmins
1190 # grptresmins
1191 # tresrunmins
1192 # users_hash: a hash ref keyed on user name, containing usage data
1193 # for that user AND account. It has similar structure to
1194 # the account usage data, except no users_hash key, and instead
1195 # If users list was given. will be restricted to those users, otherwise will
1196 # contain all users who can access the account.
1197 #NOTE: not all of the above fields will be defined; only if they have values in one of the records
1198 #from sshare
1199 #If no information for cluster/account found, a warning will be generated (unless nowarnings)
1200 561 ▶{ my $class = shift;
Subroutine sshare_usage_for_account: called CC=15 SCAR=30.0
Pod documented
1201 561 my %args = @_;
1202 561 my $me = __PACKAGE__ . '::sshare_usage_for_account';
1203  
1204 #Get and validate input
1205 561 my $cluster = delete $args{cluster};
1206 561 my $account = delete $args{account};
1207 561 my $users = delete $args{users};
1208 561 my $nowarn = delete $args{nowarnings};
1209  
1210 561 ▶ croak "$me: Missing required parameter 'account' at " unless $account;
Branch: 1 branch
BranchTrueFalseTotal
unless $account 0 561 561
1211 561 ▶ if ( %args )
Branch: 1 branch
BranchTrueFalseTotal
if (%args) 0 561 561
1212 0 { my $tmp = join ', ', (keys %args);
1213 0 croak "$me: Extraneous arguments [$tmp] provided. Aborting at ";
1214 }
1215  
1216 #call sshare
1217 561 my $tmpusers = $users;
1218 561 ▶ $tmpusers = 'ALL' unless $tmpusers;
Branch: 1 branch
BranchTrueFalseTotal
unless $tmpusers 289 272 561
1219  
1220 561 my @sshare_args = ( accounts=>[$account], users=>$tmpusers);
1221 561 ▶ push @sshare_args, clusters => [$cluster] if $cluster && $cluster ne 'DEFAULT';
Branch: 1 branch
BranchTrueFalseTotal
if $cluster and $cluster ne "DEFAULT" 405 156 561
Condition66%2/3
$cluster and $cluster ne "DEFAULT"
!ll&&!rl&&r
1560405
MC/DC50%1/2
$cluster and $cluster ne "DEFAULT"
$cluster $cluster ne "DEFAULT"
Truth table66%2/3
A and B
A= $clusterB= $cluster ne "DEFAULT"
ABresult
0X0
100
111
1222  
1223 561 my $usage = $class->sshare_usage(@sshare_args);
1224 388 ▶ return $usage unless $usage && ref($usage) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless $usage and ref $usage eq "HASH" 0 388 388
Condition33%1/3
$usage and ref $usage eq "HASH"
!ll&&!rl&&r
00388
MC/DC0%0/2
$usage and ref $usage eq "HASH"
$usage ref $usage eq "HASH"
Truth table33%1/3
A and B
A= $usageB= ref $usage eq "HASH"
ABresult
0X0
100
111
1225  
1226 388 my $tmpclus = $cluster;
1227 388 ▶ $tmpclus = 'DEFAULT' unless defined $cluster;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $cluster 113 275 388
1228 #my $clusage = $usage->{$cluster};
1229 388 my $clusage = $usage->{$tmpclus};
1230 388 ▶ unless ( $clusage && defined $clusage )
Branch: 1 branch
BranchTrueFalseTotal
unless ($clusage and defined $clusage) 84 304 388
Condition66%2/3
$clusage and defined $clusage
!ll&&!rl&&r
840304
MC/DC50%1/2
$clusage and defined $clusage
$clusage defined $clusage
Truth table66%2/3
A and B
A= $clusageB= defined $clusage
ABresult
0X0
100
111
1231 { #No records for this cluster?
1232 84 ▶ carp "$me: Unable to find information for cluster $cluster in sshare output at " unless $nowarn;
Branch: 1 branch
BranchTrueFalseTotal
unless $nowarn 0 84 84
1233 84 return { cluster => $cluster, account=>$account };
1234 }
1235  
1236 304 my $ausage = $clusage->{$account};
1237 304 ▶ unless ( $ausage && defined $ausage )
Branch: 1 branch
BranchTrueFalseTotal
unless ($ausage and defined $ausage) 0 304 304
Condition33%1/3
$ausage and defined $ausage
!ll&&!rl&&r
00304
MC/DC0%0/2
$ausage and defined $ausage
$ausage defined $ausage
Truth table33%1/3
A and B
A= $ausageB= defined $ausage
ABresult
0X0
100
111
1238 { #No records for this account in cluster?
1239 0 ▶ carp "$me: Unable to find information for account $account in cluster $cluster in sshare output at " unless $nowarn;
Branch: 1 branch
BranchTrueFalseTotal
unless $nowarn 0 0 0
1240 0 return { cluster => $cluster, account=>$account };
1241 }
1242
1243 304 return $ausage;
1244 }
1245  
1246 sub sshare_usage_for_account_user($@)
1247 #Calls sshare_usage to get usage information for a specific user, cluster and account.
1248 #Takes key => value pairs as input, recognizing the following keys
1249 # cluster: name of cluster. If omitted, will use whatever cluster sshare defaults to
1250 # account: name of account to get usage info for. REQUIRED
1251 # user: name of user to get usage info for. REQUIRED.
1252 # nowarnings: boolean. If true, suppress warnings about not finding any data for the account
1253 #
1254 #On non-fatal errors, returns a non-ref textual error string.
1255 #On success, returns an account usage hash ref, e.g. a hash ref with keys
1256 # account: name of the account (always present). Same as input
1257 # user: name of user (always present). Same as input
1258 # cluster: same as cluster for input
1259 # raw_shares
1260 # normalized_shares
1261 # raw_usage
1262 # normalized_usage
1263 # effective_usage
1264 # fairshare
1265 # grpcpumins
1266 # cpurunmins
1267 # grptresmins
1268 # tresrunmins
1269 #NOTE: not all of the above fields will be defined; only if they have values in one of the records
1270 #from sshare
1271 #If no information for cluster/account/user found, a warning will be generated (unless nowarnings)
1272 1285 ▶{ my $class = shift;
Subroutine sshare_usage_for_account_user: called CC=21 SCAR=36.2
Pod documented
1273 1285 my %args = @_;
1274 1285 my $me = __PACKAGE__ . '::sshare_usage_for_account_user';
1275  
1276 #Get and validate input
1277 1285 my $cluster = delete $args{cluster};
1278 1285 my $account = delete $args{account};
1279 1285 my $user = delete $args{user};
1280 1285 my $nowarn = delete $args{nowarnings};
1281  
1282 1285 ▶ croak "$me: Missing required parameter 'account' at " unless $account;
Branch: 1 branch
BranchTrueFalseTotal
unless $account 0 1285 1285
1283 1285 ▶ croak "$me: Missing required parameter 'user' at " unless $user;
Branch: 1 branch
BranchTrueFalseTotal
unless $user 0 1285 1285
1284 1285 ▶ if ( %args )
Branch: 1 branch
BranchTrueFalseTotal
if (%args) 0 1285 1285
1285 0 { my $tmp = join ', ', (keys %args);
1286 0 croak "$me: Extraneous arguments [$tmp] provided. Aborting at ";
1287 }
1288  
1289 #call sshare
1290 1285 my @sshare_args = ( accounts=>[$account], users=>[$user] );
1291 1285 ▶ push @sshare_args, clusters => [$cluster] if $cluster && $cluster ne 'DEFAULT';
Branch: 1 branch
BranchTrueFalseTotal
if $cluster and $cluster ne "DEFAULT" 1282 3 1285
Condition66%2/3
$cluster and $cluster ne "DEFAULT"
!ll&&!rl&&r
301282
MC/DC50%1/2
$cluster and $cluster ne "DEFAULT"
$cluster $cluster ne "DEFAULT"
Truth table66%2/3
A and B
A= $clusterB= $cluster ne "DEFAULT"
ABresult
0X0
100
111
1292  
1293 1285 my $usage = $class->sshare_usage(@sshare_args);
1294 1246 ▶ return $usage unless $usage && ref($usage) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless $usage and ref $usage eq "HASH" 0 1246 1246
Condition33%1/3
$usage and ref $usage eq "HASH"
!ll&&!rl&&r
001246
MC/DC0%0/2
$usage and ref $usage eq "HASH"
$usage ref $usage eq "HASH"
Truth table33%1/3
A and B
A= $usageB= ref $usage eq "HASH"
ABresult
0X0
100
111
1295  
1296 1246 my $tmpclus = $cluster;
1297 1246 ▶ $tmpclus = 'DEFAULT' unless defined $cluster;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $cluster 2 1244 1246
1298 1246 my $clusage = $usage->{$tmpclus};
1299 1246 ▶ unless ( $clusage && defined $clusage )
Branch: 1 branch
BranchTrueFalseTotal
unless ($clusage and defined $clusage) 346 900 1246
Condition66%2/3
$clusage and defined $clusage
!ll&&!rl&&r
3460900
MC/DC50%1/2
$clusage and defined $clusage
$clusage defined $clusage
Truth table66%2/3
A and B
A= $clusageB= defined $clusage
ABresult
0X0
100
111
1300 { #No records for this cluster?
1301 346 ▶ carp "$me: Unable to find information for cluster $cluster in sshare output at " unless $nowarn;
Branch: 1 branch
BranchTrueFalseTotal
unless $nowarn 0 346 346
1302 346 return { cluster => $cluster, account=>$account, user=>$user };
1303 }
1304  
1305 900 my $ausage = $clusage->{$account};
1306 900 ▶ unless ( $ausage && defined $ausage )
Branch: 1 branch
BranchTrueFalseTotal
unless ($ausage and defined $ausage) 0 900 900
Condition33%1/3
$ausage and defined $ausage
!ll&&!rl&&r
00900
MC/DC0%0/2
$ausage and defined $ausage
$ausage defined $ausage
Truth table33%1/3
A and B
A= $ausageB= defined $ausage
ABresult
0X0
100
111
1307 { #No records for this account in cluster?
1308 0 ▶ carp "$me: Unable to find information for account $account in cluster $cluster in sshare output at " unless $nowarn;
Branch: 1 branch
BranchTrueFalseTotal
unless $nowarn 0 0 0
1309 0 return { cluster => $cluster, account=>$account, user=>$user };
1310 }
1311  
1312 900 my $users_hash = $ausage->{users_hash};
1313 900 ▶ unless ( $ausage && defined $ausage )
Branch: 1 branch
BranchTrueFalseTotal
unless ($ausage and defined $ausage) 0 900 900
Condition33%1/3
$ausage and defined $ausage
!ll&&!rl&&r
00900
MC/DC0%0/2
$ausage and defined $ausage
$ausage defined $ausage
Truth table33%1/3
A and B
A= $ausageB= defined $ausage
ABresult
0X0
100
111
1314 { #No records for users of this account
1315 0 ▶ carp "$me: Unable to find user usage information for account $account in cluster $cluster in sshare output at " unless $nowarn;
Branch: 1 branch
BranchTrueFalseTotal
unless $nowarn 0 0 0
1316 0 return { cluster => $cluster, account=>$account, user=>$user };
1317 }
1318
1319 900 my $uusage = $users_hash->{$user};
1320 900 ▶ unless ( $uusage && defined $uusage )
Branch: 1 branch
BranchTrueFalseTotal
unless ($uusage and defined $uusage) 286 614 900
Condition66%2/3
$uusage and defined $uusage
!ll&&!rl&&r
2860614
MC/DC50%1/2
$uusage and defined $uusage
$uusage defined $uusage
Truth table66%2/3
A and B
A= $uusageB= defined $uusage
ABresult
0X0
100
111
1321 { #No records for this user in this account
1322 286 ▶ carp "$me: Unable to find usage information for user $user, account $account, cluster $cluster in sshare output at " unless $nowarn;
Branch: 1 branch
BranchTrueFalseTotal
unless $nowarn 0 286 286
1323 286 return { cluster => $cluster, account=>$account, user=>$user };
1324 }
1325
1326 614 return $uusage;
1327 }
1328  
1329 sub usage_for_account_in_cluster($@)
1330 #******************************************************
1331 # This routine is DEPRECATED
1332 # Use sshare_usage_for_account instead.
1333 # This will be deleted in a future version
1334 #******************************************************
1335 #Input same as sshare_usage_for_account.
1336 #Output on success is
1337 # [ $cpusec_used, $cpumin_limit, $cpumin_unused, $userdata ]
1338 #where $userdata is hash ref with key=username, value=cpusecs used by user/account
1339 489 ▶{ my $class = shift;
Subroutine usage_for_account_in_cluster: called CC=11 SCAR=24.6
Pod documented
1340 489 my %args = @_;
1341 489 my $me = __PACKAGE__ . '::usage_for_account_in_cluster';
1342  
1343 #Get and validate input
1344 489 my $cluster = delete $args{cluster};
1345 489 my $account = delete $args{account};
1346 489 my $users = delete $args{users};
1347 489 my $nowarn = delete $args{nowarnings};
1348  
1349 489 my $usage_hash = $class->sshare_usage_for_account(
1350 cluster=>$cluster, account=>$account,
1351 users=>$users, nowarnings=>$nowarn);
1352 325 ▶ return $usage_hash unless $usage_hash && ref($usage_hash) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless $usage_hash and ref $usage_hash eq "HASH" 0 325 325
Condition33%1/3
$usage_hash and ref $usage_hash eq "HASH"
!ll&&!rl&&r
00325
MC/DC0%0/2
$usage_hash and ref $usage_hash eq "HASH"
$usage_hash ref $usage_hash eq "HASH"
Truth table33%1/3
A and B
A= $usage_hashB= ref $usage_hash eq "HASH"
ABresult
0X0
100
111
1353  
1354 #Convert to old style output
1355 325 my $users_hash = $usage_hash->{users_hash};
1356 325 my $userdata;
1357 325 ▶ if ( $users_hash && ref($users_hash) eq 'HASH' && scalar(%$users_hash) )
Branch: 1 branch
BranchTrueFalseTotal
if ($users_hash and ref $users_hash eq "HASH" and scalar %$users_hash) 274 51 325
Condition80%4/5
$users_hash and ref $users_hash eq "HASH" and scalar %$users_hash
!ll
21304
$users_hash and ref $users_hash eq "HASH"
!ll&&!rl&&r
210304
MC/DC50%1/2
$users_hash and ref $users_hash eq "HASH" and scalar %$users_hash
$users_hash ref $users_hash eq "HASH"
Truth table66%2/3
A and B
A= $users_hashB= ref $users_hash eq "HASH"
ABresult
0X0
100
111
1358 274 { $userdata = { map { $_ => $users_hash->{$_}->{raw_usage} } (keys %$users_hash) };
1359 }
1360 325 ▶ my $cpusec_used = $usage_hash->{raw_usage} || 0;
Condition100%2/2
$usage_hash->{'raw_usage'} || 0
l!l
30421
MC/DC100%1/1
$usage_hash->{'raw_usage'} || 0
$usage_hash->{'raw_usage'}
Truth table100%2/2
A
A= $usage_hash->{'raw_usage'}
Aresult
11
00
1361 325 ▶ my $cpumin_used = $cpusec_used/60 if defined $cpusec_used;
Branch: 1 branch
BranchTrueFalseTotal
if defined $cpusec_used 325 0 325
1362 325 ▶ my $cpumin_limit = $usage_hash->{grpcpumins} || 0;
Condition100%2/2
$usage_hash->{'grpcpumins'} || 0
l!l
30421
MC/DC100%1/1
$usage_hash->{'grpcpumins'} || 0
$usage_hash->{'grpcpumins'}
Truth table100%2/2
A
A= $usage_hash->{'grpcpumins'}
Aresult
11
00
1363 325 my $cpumin_unused;
1364 325 ▶ $cpumin_unused = $cpumin_limit - $cpumin_used if defined $cpumin_limit && defined $cpumin_used;
Branch: 1 branch
BranchTrueFalseTotal
if defined $cpumin_limit and defined $cpumin_used 325 0 325
Condition33%1/3
defined $cpumin_limit and defined $cpumin_used
!ll&&!rl&&r
00325
MC/DC0%0/2
defined $cpumin_limit and defined $cpumin_used
defined $cpumin_limit defined $cpumin_used
Truth table33%1/3
A and B
A= defined $cpumin_limitB= defined $cpumin_used
ABresult
0X0
100
111
1365  
1366 325 my $results = [ $cpusec_used, $cpumin_limit, $cpumin_unused, $userdata ];
1367 325 return $results;
1368 }
1369  
1370 sub usage_for_user_account_in_cluster($@)
1371 #Input same as sshare_usage_for_account_user.
1372 #Output on success is the number of cpusecs used by this user/account/cluster
1373 #If no record for user in account/cluster found, will generate warning (unless
1374 #nowarnings set) and return undef.
1375 1280 ▶{ my $class = shift;
Subroutine usage_for_user_account_in_cluster: called CC=5 SCAR=16.4
Pod documented
1376 1280 my %args = @_;
1377 1280 my $me = __PACKAGE__ . '::usage_for_user_account_in_cluster';
1378  
1379 #Get and validate input
1380 1280 my $cluster = delete $args{cluster};
1381 1280 my $account = delete $args{account};
1382 1280 my $user = delete $args{user};
1383 1280 my $nowarn = delete $args{nowarnings};
1384  
1385 1280 my $usage_hash = $class->sshare_usage_for_account_user(
1386 cluster=>$cluster, account=>$account,
1387 user=>$user, nowarnings=>$nowarn);
1388 1243 ▶ return unless defined $usage_hash;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $usage_hash 0 1243 1243
1389 1243 ▶ return $usage_hash unless $usage_hash && ref($usage_hash) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless $usage_hash and ref $usage_hash eq "HASH" 0 1243 1243
Condition33%1/3
$usage_hash and ref $usage_hash eq "HASH"
!ll&&!rl&&r
001243
MC/DC0%0/2
$usage_hash and ref $usage_hash eq "HASH"
$usage_hash ref $usage_hash eq "HASH"
Truth table33%1/3
A and B
A= $usage_hashB= ref $usage_hash eq "HASH"
ABresult
0X0
100
111
1390  
1391 1243 my $cpusecs_used = $usage_hash->{raw_usage};
1392 1243 ▶ return 0 unless defined $cpusecs_used;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $cpusecs_used 629 614 1243
1393 614 return $cpusecs_used;
1394 }
1395  
1396 #
1397 670 1;
1398 __END__
« bin/sbalance ↑ Summary