| 1 | #!/usr/bin/env perl | ||||||||||||||||||||||||||||||||||||||||||
| 2 | #ABSTRACT: Summarise Slurm workload by combining sinfo node states with squeue job pressure | ||||||||||||||||||||||||||||||||||||||||||
| 3 | #PODNAME: slurm-load | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use v5.12; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Getopt::Long; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use FindBin qw($RealBin); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Term::ANSIColor qw(:constants); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | if (-e "$RealBin/../dist.ini") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | say STDERR "[dev mode] Using local lib" if ($ENV{"DEBUG"}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use lib "$RealBin/../lib"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use NBI::Slurm; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 2 | my $opt_tab = 0; | |||||||||||||||||||||||||||||||||||||||||
| 19 | 2 | my $opt_user; | |||||||||||||||||||||||||||||||||||||||||
| 20 | 2 | my $opt_help = 0; | |||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | GetOptions( | ||||||||||||||||||||||||||||||||||||||||||
| 23 | 't|tab' => \$opt_tab, | ||||||||||||||||||||||||||||||||||||||||||
| 24 | 'u|user=s' => \$opt_user, | ||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | 'version' => sub { say "slurm-load v", $NBI::Slurm::VERSION; exit 0 }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 2 | ▶ | 'h|help' => \$opt_help, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | ) or usage(1); | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 2 | ▶ | usage(0) if $opt_help; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 1 | for my $cmd (qw(sinfo squeue)) { | |||||||||||||||||||||||||||||||||||||||||
| 32 | 2 | ▶ | unless (_has_command($cmd)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | say STDERR RED, "Error: ", RESET, "$cmd not found in PATH. Are you in a Slurm cluster?"; | |||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | exit 1; | |||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 1 | my $partitions = load_sinfo(); | |||||||||||||||||||||||||||||||||||||||||
| 39 | 1 | my $jobs = load_squeue($opt_user); | |||||||||||||||||||||||||||||||||||||||||
| 40 | 1 | my $rows = build_rows($partitions, $jobs); | |||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 1 | ▶ | if ($opt_tab) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 1 | print_tsv($rows); | |||||||||||||||||||||||||||||||||||||||||
| 44 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | print_table($rows); | |||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 1 | exit 0; | |||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 1 | ▶ | sub load_sinfo { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
load_sinfo: called CC=7 SCAR=21.1
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 1 | my %partitions; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 1 | my ($ok, @lines) = _command_output('sinfo', '--noheader', '--format=%P|%D|%T'); | |||||||||||||||||||||||||||||||||||||||||
| 53 | 1 | ▶ | if (!$ok) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | die "ERROR slurm-load: sinfo failed\n"; | |||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 1 | for my $line (@lines) { | |||||||||||||||||||||||||||||||||||||||||
| 58 | 5 | chomp $line; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 5 | ▶ | next unless $line =~ /\S/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 5 | my ($partition, $nodes, $state) = split /\|/, $line, 3; | |||||||||||||||||||||||||||||||||||||||||
| 61 | 5 | ▶ | next unless defined $partition && defined $nodes && defined $state; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $partition and defined $nodes and defined $state
defined $partition and defined $nodes
MC/DC0%0/3
defined $partition and defined $nodes and defined $state
defined $partition
defined $nodes
defined $state
Truth table25%1/4
A and B and C
A= defined $partitionB= defined $nodesC= defined $state
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 5 | $partition =~ s/\*$//; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 5 | my $bucket = normalise_node_state($state); | |||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 5 | $partitions{$partition}{partition} = $partition; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 5 | $partitions{$partition}{total} += $nodes; | |||||||||||||||||||||||||||||||||||||||||
| 68 | 5 | $partitions{$partition}{$bucket} += $nodes; | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 1 | return \%partitions; | |||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 1 | ▶ | sub load_squeue { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
load_squeue: called CC=8 SCAR=22.4
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 1 | my ($user) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 75 | 1 | my %jobs; | |||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 1 | my @cmd = ('squeue', '--noheader', '--format=%P|%t|%D'); | |||||||||||||||||||||||||||||||||||||||||
| 78 | 1 | ▶ | push @cmd, "--user=$user" if defined $user; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 1 | my ($ok, @lines) = _command_output(@cmd); | |||||||||||||||||||||||||||||||||||||||||
| 80 | 1 | ▶ | if (!$ok) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | die "ERROR slurm-load: squeue failed\n"; | |||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 1 | for my $line (@lines) { | |||||||||||||||||||||||||||||||||||||||||
| 85 | 3 | chomp $line; | |||||||||||||||||||||||||||||||||||||||||
| 86 | 3 | ▶ | next unless $line =~ /\S/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 3 | my ($partition, $state, $nodes) = split /\|/, $line, 3; | |||||||||||||||||||||||||||||||||||||||||
| 88 | 3 | ▶ | next unless defined $partition && defined $state && defined $nodes; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $partition and defined $state and defined $nodes
defined $partition and defined $state
MC/DC0%0/3
defined $partition and defined $state and defined $nodes
defined $partition
defined $state
defined $nodes
Truth table25%1/4
A and B and C
A= defined $partitionB= defined $stateC= defined $nodes
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | 3 | $partition =~ s/\*$//; | |||||||||||||||||||||||||||||||||||||||||
| 91 | 3 | my $bucket = normalise_job_state($state); | |||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 3 | $jobs{$partition}{partition} = $partition; | |||||||||||||||||||||||||||||||||||||||||
| 94 | 3 | $jobs{$partition}{"jobs_$bucket"}++; | |||||||||||||||||||||||||||||||||||||||||
| 95 | 3 | $jobs{$partition}{"nodes_$bucket"} += $nodes; | |||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | 1 | return \%jobs; | |||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 1 | ▶ | sub build_rows { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
build_rows: called CC=15 SCAR=27.6
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 1 | my ($partitions, $jobs) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 103 | 1 | my @header = qw(Partition Total Up Idle Mix Alloc Down JobsR JobsPD RunNodes PendNodes Load); | |||||||||||||||||||||||||||||||||||||||||
| 104 | 1 | my @rows = (\@header); | |||||||||||||||||||||||||||||||||||||||||
| 105 | 1 | my %totals = ( | |||||||||||||||||||||||||||||||||||||||||
| 106 | partition => 'TOTAL', | ||||||||||||||||||||||||||||||||||||||||||
| 107 | total => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 108 | up => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 109 | idle => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 110 | mix => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 111 | alloc => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 112 | down => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 113 | jobs_running => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 114 | jobs_pending => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 115 | nodes_running => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 116 | nodes_pending => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 117 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | 1 | for my $partition (sort { | |||||||||||||||||||||||||||||||||||||||||
| 120 | 1 | ▶ | load_pct($partitions->{$b}) <=> load_pct($partitions->{$a}) || $a cmp $b | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
load_pct($partitions->{$b}) <=> load_pct($partitions->{$a}) || $a cmp $b
MC/DC0%0/2
load_pct($partitions->{$b}) <=> load_pct($partitions->{$a}) || $a cmp $b
load_pct($partitions->{$b}) <=> load_pct($partitions->{$a})
$a cmp $b
Truth table33%1/3
A || B
A= load_pct($partitions->{$b}) <=> load_pct($partitions->{$a})B= $a cmp $b
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 1 | } keys %{$partitions}) { | |||||||||||||||||||||||||||||||||||||||||
| 122 | 2 | ▶ | my $node = $partitions->{$partition} || {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$partitions->{$partition} || {}
MC/DC0%0/1
$partitions->{$partition} || {}
$partitions->{$partition}
Truth table50%1/2
A
A= $partitions->{$partition}
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 2 | ▶ | my $job = $jobs->{$partition} || {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$jobs->{$partition} || {}
MC/DC0%0/1
$jobs->{$partition} || {}
$jobs->{$partition}
Truth table50%1/2
A
A= $jobs->{$partition}
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 2 | ▶ | my $total = $node->{total} || 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$node->{'total'} || 0
MC/DC0%0/1
$node->{'total'} || 0
$node->{'total'}
Truth table50%1/2
A
A= $node->{'total'}
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 2 | ▶ | my $down = $node->{down} || 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$node->{'down'} || 0
MC/DC100%1/1
$node->{'down'} || 0
$node->{'down'}
Truth table100%2/2
A
A= $node->{'down'}
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | 2 | ▶ | my $idle = $node->{idle} || 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$node->{'idle'} || 0
MC/DC0%0/1
$node->{'idle'} || 0
$node->{'idle'}
Truth table50%1/2
A
A= $node->{'idle'}
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | 2 | ▶ | my $mix = $node->{mix} || 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$node->{'mix'} || 0
MC/DC100%1/1
$node->{'mix'} || 0
$node->{'mix'}
Truth table100%2/2
A
A= $node->{'mix'}
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | 2 | ▶ | my $alloc = $node->{alloc} || 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$node->{'alloc'} || 0
MC/DC100%1/1
$node->{'alloc'} || 0
$node->{'alloc'}
Truth table100%2/2
A
A= $node->{'alloc'}
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 2 | my $up = $total - $down; | |||||||||||||||||||||||||||||||||||||||||
| 131 | 2 | ▶ | my $jobs_running = $job->{jobs_running} || 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$job->{'jobs_running'} || 0
MC/DC0%0/1
$job->{'jobs_running'} || 0
$job->{'jobs_running'}
Truth table50%1/2
A
A= $job->{'jobs_running'}
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | 2 | ▶ | my $jobs_pending = $job->{jobs_pending} || 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$job->{'jobs_pending'} || 0
MC/DC100%1/1
$job->{'jobs_pending'} || 0
$job->{'jobs_pending'}
Truth table100%2/2
A
A= $job->{'jobs_pending'}
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | 2 | ▶ | my $nodes_running = $job->{nodes_running} || 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$job->{'nodes_running'} || 0
MC/DC0%0/1
$job->{'nodes_running'} || 0
$job->{'nodes_running'}
Truth table50%1/2
A
A= $job->{'nodes_running'}
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | 2 | ▶ | my $nodes_pending = $job->{nodes_pending} || 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$job->{'nodes_pending'} || 0
MC/DC100%1/1
$job->{'nodes_pending'} || 0
$job->{'nodes_pending'}
Truth table100%2/2
A
A= $job->{'nodes_pending'}
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | 2 | my $load = sprintf('%d%%', load_pct($node)); | |||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | 2 | push @rows, [ | |||||||||||||||||||||||||||||||||||||||||
| 138 | $partition, | ||||||||||||||||||||||||||||||||||||||||||
| 139 | $total, | ||||||||||||||||||||||||||||||||||||||||||
| 140 | $up, | ||||||||||||||||||||||||||||||||||||||||||
| 141 | $idle, | ||||||||||||||||||||||||||||||||||||||||||
| 142 | $mix, | ||||||||||||||||||||||||||||||||||||||||||
| 143 | $alloc, | ||||||||||||||||||||||||||||||||||||||||||
| 144 | $down, | ||||||||||||||||||||||||||||||||||||||||||
| 145 | $jobs_running, | ||||||||||||||||||||||||||||||||||||||||||
| 146 | $jobs_pending, | ||||||||||||||||||||||||||||||||||||||||||
| 147 | $nodes_running, | ||||||||||||||||||||||||||||||||||||||||||
| 148 | $nodes_pending, | ||||||||||||||||||||||||||||||||||||||||||
| 149 | $load, | ||||||||||||||||||||||||||||||||||||||||||
| 150 | ]; | ||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | 2 | $totals{total} += $total; | |||||||||||||||||||||||||||||||||||||||||
| 153 | 2 | $totals{up} += $up; | |||||||||||||||||||||||||||||||||||||||||
| 154 | 2 | $totals{idle} += $idle; | |||||||||||||||||||||||||||||||||||||||||
| 155 | 2 | $totals{mix} += $mix; | |||||||||||||||||||||||||||||||||||||||||
| 156 | 2 | $totals{alloc} += $alloc; | |||||||||||||||||||||||||||||||||||||||||
| 157 | 2 | $totals{down} += $down; | |||||||||||||||||||||||||||||||||||||||||
| 158 | 2 | $totals{jobs_running} += $jobs_running; | |||||||||||||||||||||||||||||||||||||||||
| 159 | 2 | $totals{jobs_pending} += $jobs_pending; | |||||||||||||||||||||||||||||||||||||||||
| 160 | 2 | $totals{nodes_running} += $nodes_running; | |||||||||||||||||||||||||||||||||||||||||
| 161 | 2 | $totals{nodes_pending} += $nodes_pending; | |||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | 1 | ▶ | if (@rows > 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | push @rows, [ | ||||||||||||||||||||||||||||||||||||||||||
| 166 | $totals{partition}, | ||||||||||||||||||||||||||||||||||||||||||
| 167 | $totals{total}, | ||||||||||||||||||||||||||||||||||||||||||
| 168 | $totals{up}, | ||||||||||||||||||||||||||||||||||||||||||
| 169 | $totals{idle}, | ||||||||||||||||||||||||||||||||||||||||||
| 170 | $totals{mix}, | ||||||||||||||||||||||||||||||||||||||||||
| 171 | $totals{alloc}, | ||||||||||||||||||||||||||||||||||||||||||
| 172 | $totals{down}, | ||||||||||||||||||||||||||||||||||||||||||
| 173 | $totals{jobs_running}, | ||||||||||||||||||||||||||||||||||||||||||
| 174 | $totals{jobs_pending}, | ||||||||||||||||||||||||||||||||||||||||||
| 175 | $totals{nodes_running}, | ||||||||||||||||||||||||||||||||||||||||||
| 176 | $totals{nodes_pending}, | ||||||||||||||||||||||||||||||||||||||||||
| 177 | 1 | sprintf('%d%%', load_pct(\%totals)), | |||||||||||||||||||||||||||||||||||||||||
| 178 | ]; | ||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | 1 | return \@rows; | |||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | 5 | ▶ | sub load_pct { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
load_pct: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||||||||||||
| 185 | 5 | my ($row) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 186 | 5 | ▶ | my $total = $row->{total} || 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$row->{'total'} || 0
MC/DC0%0/1
$row->{'total'} || 0
$row->{'total'}
Truth table50%1/2
A
A= $row->{'total'}
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | 5 | ▶ | my $down = $row->{down} || 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$row->{'down'} || 0
MC/DC100%1/1
$row->{'down'} || 0
$row->{'down'}
Truth table100%2/2
A
A= $row->{'down'}
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | 5 | my $up = $total - $down; | |||||||||||||||||||||||||||||||||||||||||
| 189 | 5 | ▶ | return 0 if $up <= 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 5 | ▶ | my $busy = ($row->{mix} || 0) + ($row->{alloc} || 0); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%4/4
$row->{'mix'} || 0
$row->{'alloc'} || 0
MC/DC100%1/1
$row->{'mix'} || 0
$row->{'mix'}
MC/DC100%1/1
$row->{'alloc'} || 0
$row->{'alloc'}
Truth table100%2/2
A
A= $row->{'mix'}
Truth table100%2/2
A
A= $row->{'alloc'}
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | 5 | return ($busy / $up) * 100; | |||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | 5 | ▶ | sub normalise_node_state { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
normalise_node_state: called CC=6 SCAR=18.2
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | 5 | my ($state) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 196 | 5 | ▶ | $state = lc($state // ''); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$state // ""
MC/DC0%0/1
$state // ""
$state
Truth table50%1/2
A
A= $state
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | 5 | $state =~ s/[^a-z].*$//; | |||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | 5 | ▶ | return 'idle' if $state =~ /^idle/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | 3 | ▶ | return 'mix' if $state =~ /^mix/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | 2 | ▶ | return 'alloc' if $state =~ /^alloc/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | 1 | ▶ | return 'down' if $state =~ /^(down|drain|drng|drained|fail)/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | return 'alloc'; | |||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | 3 | ▶ | sub normalise_job_state { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
normalise_job_state: called CC=4 SCAR=14.6
| |||||||||||||||||||||||||||||||||||||||||||
| 207 | 3 | my ($state) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 208 | 3 | ▶ | $state = uc($state // ''); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$state // ""
MC/DC0%0/1
$state // ""
$state
Truth table50%1/2
A
A= $state
| |||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | 3 | ▶ | return 'pending' if $state eq 'PD'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | 2 | ▶ | return 'running' if $state =~ /^(R|CG|CF|SI|SO|ST)$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | return 'running'; | |||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||
| 215 | 1 | ▶ | sub print_tsv { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
print_tsv: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 216 | 1 | my ($rows) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 217 | 1 | for my $row (@{$rows}) { | |||||||||||||||||||||||||||||||||||||||||
| 218 | 4 | say join("\t", @{$row}); | |||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | ▶ | sub print_table { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
print_table: not called CC=11 SCAR=48.8
| |||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | my ($rows) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | my @widths; | |||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | for my $row (@{$rows}) { | |||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | for my $i (0 .. $#{$row}) { | |||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | ▶ | my $len = length($row->[$i] // ''); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$row->[$i] // ""
MC/DC0%0/1
$row->[$i] // ""
$row->[$i]
Truth table0%0/2
A
A= $row->[$i]
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | ▶ | $widths[$i] = $len if !defined $widths[$i] || $len > $widths[$i]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $widths[$i] or $len > $widths[$i]
MC/DC0%0/2
not defined $widths[$i] or $len > $widths[$i]
not defined $widths[$i]
$len > $widths[$i]
Truth table0%0/3
not(A) or B
A= not defined $widths[$i]B= $len > $widths[$i]
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | for my $idx (0 .. $#{$rows}) { | |||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | my $row = $rows->[$idx]; | |||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | my @parts; | |||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | for my $i (0 .. $#{$row}) { | |||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | ▶ | my $fmt = $i == 0 ? "%-*s" : "%*s"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | push @parts, sprintf($fmt, $widths[$i], $row->[$i]); | |||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | if ($idx == 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | say BOLD, join(" ", @parts), RESET; | |||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | my @rule = map { '-' x $_ } @widths; | |||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | say join(" ", @rule); | |||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | ▶ | if ($row->[0] eq 'TOTAL') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | say BOLD, join(" ", @parts), RESET; | |||||||||||||||||||||||||||||||||||||||||
| 249 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | say join(" ", @parts); | |||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||
| 255 | 2 | ▶ | sub _has_command { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_has_command: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||||||||||||||||
| 256 | 2 | my ($cmd) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 257 | 2 | ▶ | if ($^O eq 'MSWin32') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | return system("where $cmd >nul 2>nul") == 0; | |||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||
| 260 | 2 | return system("command -v $cmd >/dev/null 2>&1") == 0; | |||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||
| 263 | 2 | ▶ | sub _command_output { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_command_output: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 264 | 2 | my (@cmd) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 265 | 2 | ▶ | open(my $fh, '-|', @cmd) or die "ERROR slurm-load: cannot execute $cmd[0]: $!\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 266 | 2 | my @lines = <$fh>; | |||||||||||||||||||||||||||||||||||||||||
| 267 | 2 | close $fh; | |||||||||||||||||||||||||||||||||||||||||
| 268 | 2 | return ($? == 0, @lines); | |||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | 1 | ▶ | sub usage { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
usage: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 272 | 1 | my ($exit_code) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 273 | 1 | print STDERR <<'END'; | |||||||||||||||||||||||||||||||||||||||||
| 274 | slurm-load - Summarise Slurm workload by partition | ||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||
| 276 | Usage: | ||||||||||||||||||||||||||||||||||||||||||
| 277 | slurm-load [options] | ||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||
| 279 | Options: | ||||||||||||||||||||||||||||||||||||||||||
| 280 | -t, --tab Print TSV instead of aligned text | ||||||||||||||||||||||||||||||||||||||||||
| 281 | -u, --user USER Restrict squeue job counts to one user | ||||||||||||||||||||||||||||||||||||||||||
| 282 | --version Show version and exit | ||||||||||||||||||||||||||||||||||||||||||
| 283 | -h, --help Show this help and exit | ||||||||||||||||||||||||||||||||||||||||||
| 284 | END | ||||||||||||||||||||||||||||||||||||||||||
| 285 | 1 | exit $exit_code; | |||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||
| 288 | __END__ | ||||||||||||||||||||||||||||||||||||||||||