bin/lsjobs

filter: Statementstmt 11.0% 59 / 532 Branchbran 0.7% 2 / 252 Conditioncond 0.8% 1 / 112 MC/DCmcdc 0.0% 0 / 66 Subroutinesub 33.3% 13 / 39 Podpod n/a totaltotal 7.4% 75 / 1001 CC 139 SCAR 54.1
CC
139
Cov
7%
fit_columns_to_terminal
930.0
getjobs
210.0
print_summary
182.0
CRAP 224.5
« blib/lib/NBI/Queue.pm ↑ Summary bin/waitjobs »
1 #!/usr/bin/env perl
2 #ABSTRACT: List your jobs (or others), and delete them if you wish
3 #PODNAME: lsjobs
4  
5 1 ▶use v5.12;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use FindBin qw($RealBin);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Term::ANSIColor qw(:constants);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Text::ASCIITable;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 $Data::Dumper::Sortkeys = 1;
15  
16 # Enable UTF-8 output
17 1 binmode(STDOUT, ':utf8');
18 1 binmode(STDERR, ':utf8');
19  
20 # Box drawing characters for modern table rendering
21 1 my $BOX = {
22 tl => '┌', tr => '┐', bl => '└', br => '┘', # corners
23 h => '─', v => '│', # lines
24 t => '┬', b => '┴', l => '├', r => '┤', # T-junctions
25 c => '┼', # cross
26 };
27  
28 1 ▶if (-e "$RealBin/../dist.ini") {
Branch: 1 branch
BranchTrueFalseTotal
if (-e "$main::RealBin/../dist.ini") 1 0 1
29 1 ▶ say STDERR "[dev mode] Using local lib" if ($ENV{"DEBUG"});
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"DEBUG"} 0 1 1
30 1 ▶ use lib "$RealBin/../lib";
Subroutine BEGIN: called CC=1 SCAR=0.0
31 }
32  
33 1 ▶use NBI::Slurm;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 1 ▶use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36  
37  
38  
39 1 ▶my $current_slurm_jobid = $ENV{SLURM_JOBID} // -1;
Condition50%1/2
$ENV{"SLURM_JOBID"} // -1
l!l
01
MC/DC0%0/1
$ENV{"SLURM_JOBID"} // -1
$ENV{"SLURM_JOBID"}
Truth table50%1/2
A
A= $ENV{"SLURM_JOBID"}
Aresult
11
00
40 1 my $unix_username = $ENV{USER};
41 1 my $user_home_dir = $ENV{HOME};
42  
43 1 my $opt_user = $unix_username;
44 1 my $opt_status = '.+';
45 1 my $opt_running_bool = 0;
46 1 my $opt_pending_bool = 0;
47 1 my $opt_delete_bool = 0;
48 1 my $opt_verbose_bool = 0;
49 1 my $opt_queue = '.+';
50 1 my $opt_name = '.+';
51 1 my $opt_tab = 0;
52 1 my $opt_summary = 0;
53 1 my @opt_hide = ();
54 1 my $opt_exclude = undef;
55 GetOptions(
56 'u|user=s' => \$opt_user,
57 'n|name=s' => \$opt_name,
58 'x|exclude=s' => \$opt_exclude,
59 's|status=s' => \$opt_status,
60 'r|running' => \$opt_running_bool,
61 'p|pending' => \$opt_pending_bool,
62 'd|delete' => \$opt_delete_bool,
63 't|tab' => \$opt_tab,
64 'summary' => \$opt_summary,
65 'hide=s' => \@opt_hide,
66 'verbose' => \$opt_verbose_bool,
67 1 ▶ 'version' => sub { say "lsjobs v", $NBI::Slurm::VERSION; exit },
Subroutine __ANON__: called CC=1 SCAR=0.0
68 0 ▶ 'help' => sub { usage() },
Subroutine __ANON__: not called CC=1 SCAR=6.9
69 1 );
70  
71 0 ▶if (not NBI::Slurm::has_squeue()) {
Branch: 1 branch
BranchTrueFalseTotal
unless (NBI::Slurm::has_squeue()) 0 0 0
72 0 say STDERR RED, "Error: ", RESET, "squeue not found in PATH. Are you in the cluster?";
73 0 exit 1;
74 }
75  
76 0 my $jobs = getjobs();
77  
78 # Check if we got any data
79 0 ▶if (not defined $jobs or ref($jobs) ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $jobs or ref $jobs ne "HASH") 0 0 0
Condition0%0/3
not defined $jobs or ref $jobs ne "HASH"
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $jobs or ref $jobs ne "HASH"
not defined $jobs ref $jobs ne "HASH"
Truth table0%0/3
not(A) or B
A= not defined $jobsB= ref $jobs ne "HASH"
ABresult
1X1
011
000
80 0 say STDERR RED, "Error: ", RESET, "Failed to retrieve job information";
81 0 exit 1;
82 }
83 0 my @ids = ();
84 0 for my $positional (@ARGV) {
85 0 ▶ if ($positional =~ /^(\d+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($positional =~ /^(\d+)$/u) { } 0 0 0
86 0 push(@ids, $1);
87 } else {
88 0 ▶ if ($opt_name eq '.+') {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt_name eq '.+') { } 0 0 0
89 0 $opt_name = $positional;
90 } else {
91 0 say STDERR "Error: unknown positional argument: $positional";
92 0 usage();
93 }
94 }
95 }
96  
97 0 ▶if ($opt_user eq 'ALL' or $opt_user eq 'all') {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt_user eq "ALL" or $opt_user eq "all") 0 0 0
Condition0%0/3
$opt_user eq "ALL" or $opt_user eq "all"
l!l&&r!l&&!r
000
MC/DC0%0/2
$opt_user eq "ALL" or $opt_user eq "all"
$opt_user eq "ALL" $opt_user eq "all"
Truth table0%0/3
A or B
A= $opt_user eq "ALL"B= $opt_user eq "all"
ABresult
1X1
011
000
98 0 $opt_user = '.+';
99 }
100 0 ▶if ($opt_verbose_bool) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt_verbose_bool) 0 0 0
101 0 say STDERR "User: $opt_user";
102 0 say STDERR "Jobs: ", scalar(keys %{$jobs});
103 }
104  
105 0 ▶if ($opt_summary) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt_summary) 0 0 0
106 0 print_state_summary_table($jobs, \@ids, $opt_user);
107 0 exit 0;
108 }
109  
110 0 my $selected_jobs = {};
111 0 my $selected_arrays = [['JobID', 'User', 'Queue', 'Name', 'State', 'Time', 'TotalTime', 'NodeList', 'CPUS', 'Memory', 'Reason']];
112  
113 0 ▶if ($opt_tab) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt_tab) 0 0 0
114 # Add "#" prefix for TSV mode
115 0 $selected_arrays->[0]->[0] = "#" . $selected_arrays->[0]->[0];
116 }
117  
118 0 for my $job (sort keys %{$jobs}) {
119 # Check user (full match)
120 0 ▶ if ($jobs->{$job}->{USER} !~ /^$opt_user$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($jobs->{$job}{"USER"} =~ /^$opt_user$/u) 0 0 0
121 0 next;
122 }
123 # Check queue (partial match ok)
124 0 ▶ if ($jobs->{$job}->{PARTITION} !~ /$opt_queue/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($jobs->{$job}{"PARTITION"} =~ /$opt_queue/u) 0 0 0
125 0 next;
126 }
127  
128 # Check name
129 0 ▶ if ($jobs->{$job}->{NAME} !~ /$opt_name/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($jobs->{$job}{"NAME"} =~ /$opt_name/u) 0 0 0
130 0 next;
131 }
132 # Exclude jobs matching pattern
133 0 ▶ if (defined $opt_exclude && $jobs->{$job}->{NAME} =~ /$opt_exclude/) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt_exclude and $jobs->{$job}{"NAME"} =~ /$opt_exclude/u) 0 0 0
Condition0%0/3
defined $opt_exclude and $jobs->{$job}{"NAME"} =~ /$opt_exclude/u
!ll&&!rl&&r
000
MC/DC0%0/2
defined $opt_exclude and $jobs->{$job}{"NAME"} =~ /$opt_exclude/u
defined $opt_exclude $jobs->{$job}{"NAME"} =~ /$opt_exclude/u
Truth table0%0/3
A and B
A= defined $opt_excludeB= $jobs->{$job}{"NAME"} =~ /$opt_exclude/u
ABresult
0X0
100
111
134 0 next;
135 }
136 # Check status (general pattern match)
137 0 ▶ if ($jobs->{$job}->{STATE} !~ /$opt_status/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($jobs->{$job}{"STATE"} =~ /$opt_status/u) 0 0 0
138 0 next;
139 }
140 # Check specific status flags (these override general status pattern)
141 0 ▶ if ($opt_pending_bool and $jobs->{$job}->{STATE} ne 'PENDING') {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt_pending_bool and $jobs->{$job}{"STATE"} ne "PENDING") 0 0 0
Condition0%0/3
$opt_pending_bool and $jobs->{$job}{"STATE"} ne "PENDING"
!ll&&!rl&&r
000
MC/DC0%0/2
$opt_pending_bool and $jobs->{$job}{"STATE"} ne "PENDING"
$opt_pending_bool $jobs->{$job}{"STATE"} ne "PENDING"
Truth table0%0/3
A and B
A= $opt_pending_boolB= $jobs->{$job}{"STATE"} ne "PENDING"
ABresult
0X0
100
111
142 0 next;
143 }
144 0 ▶ if ($opt_running_bool and $jobs->{$job}->{STATE} ne 'RUNNING') {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt_running_bool and $jobs->{$job}{"STATE"} ne "RUNNING") 0 0 0
Condition0%0/3
$opt_running_bool and $jobs->{$job}{"STATE"} ne "RUNNING"
!ll&&!rl&&r
000
MC/DC0%0/2
$opt_running_bool and $jobs->{$job}{"STATE"} ne "RUNNING"
$opt_running_bool $jobs->{$job}{"STATE"} ne "RUNNING"
Truth table0%0/3
A and B
A= $opt_running_boolB= $jobs->{$job}{"STATE"} ne "RUNNING"
ABresult
0X0
100
111
145 0 next;
146 }
147 0 ▶ if (scalar @ids > 0 and not grep {$_ eq $job} @ids) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @ids > 0 and not grep({$_ eq $job;} @ids)) 0 0 0
Condition0%0/3
scalar @ids > 0 and not grep({$_ eq $job;} @ids)
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @ids > 0 and not grep({$_ eq $job;} @ids)
scalar @ids > 0 not grep({$_ eq $job;} @ids)
Truth table0%0/3
A and not(B)
A= scalar @ids > 0B= not grep({$_ eq $job;} @ids)
ABresult
0X0
100
111
148 0 next;
149 }
150  
151 # Format job ID for display (handle array jobs)
152 0 my $display_jobid = $jobs->{$job}->{JOBID};
153 0 ▶ if (defined $display_jobid && $display_jobid =~ /_/) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $display_jobid and $display_jobid =~ /_/u) 0 0 0
Condition0%0/3
defined $display_jobid and $display_jobid =~ /_/u
!ll&&!rl&&r
000
MC/DC0%0/2
defined $display_jobid and $display_jobid =~ /_/u
defined $display_jobid $display_jobid =~ /_/u
Truth table0%0/3
A and B
A= defined $display_jobidB= $display_jobid =~ /_/u
ABresult
0X0
100
111
154 # Array job format: convert "12345_1" to "12345#"
155 0 $display_jobid =~ s/_.*/#/;
156 }
157  
158 my $array = [$display_jobid // 'N/A',
159 $jobs->{$job}->{USER} // 'N/A',
160 $jobs->{$job}->{PARTITION} // 'N/A',
161 $jobs->{$job}->{NAME} // 'N/A',
162 $opt_tab ? ($jobs->{$job}->{STATE} // 'N/A') : state_string($jobs->{$job}->{STATE} // 'UNKNOWN'),
163 $jobs->{$job}->{TIME} // '0:00',
164 $jobs->{$job}->{TIME_LIMIT} // 'N/A',
165 $jobs->{$job}->{NODELIST} // 'N/A',
166 $jobs->{$job}->{"CPUS"} // 'N/A',
167 $jobs->{$job}->{"MIN_MEMORY"} // 'N/A',
168 0 ▶ $opt_tab ? ($jobs->{$job}->{"REASON"} // 'N/A') : reason_string($jobs->{$job}->{"REASON"} // 'None')
Branch: 2 branches
BranchTrueFalseTotal
$opt_tab ? : 0 0 0
$opt_tab ? : 0 0 0
Condition0%0/26
$display_jobid // "N/A"
l!l
00
$jobs->{$job}{"USER"} // "N/A"
l!l
00
$jobs->{$job}{"PARTITION"} // "N/A"
l!l
00
$jobs->{$job}{"NAME"} // "N/A"
l!l
00
$jobs->{$job}{"STATE"} // "N/A"
l!l
00
$jobs->{$job}{"STATE"} // "UNKNOWN"
l!l
00
$jobs->{$job}{"TIME"} // "0:00"
l!l
00
$jobs->{$job}{"TIME_LIMIT"} // "N/A"
l!l
00
$jobs->{$job}{"NODELIST"} // "N/A"
l!l
00
$jobs->{$job}{"CPUS"} // "N/A"
l!l
00
$jobs->{$job}{"MIN_MEMORY"} // "N/A"
l!l
00
$jobs->{$job}{"REASON"} // "N/A"
l!l
00
$jobs->{$job}{"REASON"} // "None"
l!l
00
MC/DC0%0/1
$display_jobid // "N/A"
$display_jobid
MC/DC0%0/1
$jobs->{$job}{"USER"} // "N/A"
$jobs->{$job}{"USER"}
MC/DC0%0/1
$jobs->{$job}{"PARTITION"} // "N/A"
$jobs->{$job}{"PARTITION"}
MC/DC0%0/1
$jobs->{$job}{"NAME"} // "N/A"
$jobs->{$job}{"NAME"}
MC/DC0%0/1
$jobs->{$job}{"STATE"} // "N/A"
$jobs->{$job}{"STATE"}
MC/DC0%0/1
$jobs->{$job}{"STATE"} // "UNKNOWN"
$jobs->{$job}{"STATE"}
MC/DC0%0/1
$jobs->{$job}{"TIME"} // "0:00"
$jobs->{$job}{"TIME"}
MC/DC0%0/1
$jobs->{$job}{"TIME_LIMIT"} // "N/A"
$jobs->{$job}{"TIME_LIMIT"}
MC/DC0%0/1
$jobs->{$job}{"NODELIST"} // "N/A"
$jobs->{$job}{"NODELIST"}
MC/DC0%0/1
$jobs->{$job}{"CPUS"} // "N/A"
$jobs->{$job}{"CPUS"}
MC/DC0%0/1
$jobs->{$job}{"MIN_MEMORY"} // "N/A"
$jobs->{$job}{"MIN_MEMORY"}
MC/DC0%0/1
$jobs->{$job}{"REASON"} // "N/A"
$jobs->{$job}{"REASON"}
MC/DC0%0/1
$jobs->{$job}{"REASON"} // "None"
$jobs->{$job}{"REASON"}
Truth table0%0/2
A
A= $display_jobid
Aresult
11
00
Truth table0%0/2
A
A= $jobs->{$job}{"USER"}
Aresult
11
00
Truth table0%0/2
A
A= $jobs->{$job}{"PARTITION"}
Aresult
11
00
Truth table0%0/2
A
A= $jobs->{$job}{"NAME"}
Aresult
11
00
Truth table0%0/2
A
A= $jobs->{$job}{"STATE"}
Aresult
11
00
Truth table0%0/2
A
A= $jobs->{$job}{"STATE"}
Aresult
11
00
Truth table0%0/2
A
A= $jobs->{$job}{"TIME"}
Aresult
11
00
Truth table0%0/2
A
A= $jobs->{$job}{"TIME_LIMIT"}
Aresult
11
00
Truth table0%0/2
A
A= $jobs->{$job}{"NODELIST"}
Aresult
11
00
Truth table0%0/2
A
A= $jobs->{$job}{"CPUS"}
Aresult
11
00
Truth table0%0/2
A
A= $jobs->{$job}{"MIN_MEMORY"}
Aresult
11
00
Truth table0%0/2
A
A= $jobs->{$job}{"REASON"}
Aresult
11
00
Truth table0%0/2
A
A= $jobs->{$job}{"REASON"}
Aresult
11
00
169 ];
170 0 push(@{$selected_arrays}, $array);
171  
172  
173 }
174 # Apply column hiding if requested
175 0 ▶if (@opt_hide && !$opt_tab) {
Branch: 1 branch
BranchTrueFalseTotal
if (@opt_hide and not $opt_tab) 0 0 0
Condition0%0/3
@opt_hide and not $opt_tab
!ll&&!rl&&r
000
MC/DC0%0/2
@opt_hide and not $opt_tab
@opt_hide not $opt_tab
Truth table0%0/3
A and not(B)
A= @opt_hideB= not $opt_tab
ABresult
0X0
100
111
176 0 $selected_arrays = hide_columns($selected_arrays, \@opt_hide);
177 }
178  
179 # Print summary header (not in tab mode)
180 0 ▶if (!$opt_tab) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opt_tab) 0 0 0
181 0 print_summary($jobs, $selected_arrays);
182 }
183  
184 0 ▶if ($opt_tab) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt_tab) { } 0 0 0
185 0 for my $array (@{$selected_arrays}) {
186 0 say join("\t", @{$array});
187 }
188 } else {
189 # Render modern table with Unicode box drawing
190 0 render_table_modern(@{$selected_arrays});
191 0 print RESET, "\n";
192 }
193  
194 ## Print single job
195 0 ▶if ($opt_verbose_bool and scalar @{$selected_arrays} == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt_verbose_bool and scalar @{$selected_arrays;} == 3) 0 0 0
Condition0%0/3
$opt_verbose_bool and scalar @{$selected_arrays;} == 3
!ll&&!rl&&r
000
MC/DC0%0/2
$opt_verbose_bool and scalar @{$selected_arrays;} == 3
$opt_verbose_bool scalar @{$selected_arrays;} == 3
Truth table0%0/3
A and B
A= $opt_verbose_boolB= scalar @{$selected_arrays;} == 3
ABresult
0X0
100
111
196 0 my $job = extractJobByID($jobs, $selected_arrays->[2]->[0]);
197 0 for my $key (sort keys %{$job}) {
198 # Filter useless values
199 0 ▶ if ($job->{$key} =~ /^$/ or $job->{$key} =~ /^(\(null\)|\*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($job->{$key} =~ /^$/u or $job->{$key} =~ /^(\(null\)|\*)$/u) 0 0 0
Condition0%0/3
$job->{$key} =~ /^$/u or $job->{$key} =~ /^(\(null\)|\*)$/u
l!l&&r!l&&!r
000
MC/DC0%0/2
$job->{$key} =~ /^$/u or $job->{$key} =~ /^(\(null\)|\*)$/u
$job->{$key} =~ /^$/u $job->{$key} =~ /^(\(null\)|\*)$/u
Truth table0%0/3
A or B
A= $job->{$key} =~ /^$/uB= $job->{$key} =~ /^(\(null\)|\*)$/u
ABresult
1X1
011
000
200 0 next;
201 }
202 0 ▶ if ($key =~/(S_C_T|USER|ACCOUNT)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /(S_C_T|USER|ACCOUNT)/u) 0 0 0
203 0 next;
204 }
205 0 say YELLOW, sprintf("%-20s", $key), RESET, $job->{$key};
206 }
207 }
208  
209 0 my @selected_ids = joblist_to_ids(@{$selected_arrays});
210  
211  
212 0 ▶if ($opt_delete_bool and (scalar @selected_ids)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($opt_delete_bool and scalar @selected_ids) { } 0 0 0
elsif ($opt_delete_bool) { } 0 0 0
Condition0%0/2
$opt_delete_bool and scalar @selected_ids
!ll
00
MC/DC0%0/1
$opt_delete_bool and scalar @selected_ids
$opt_delete_bool
Truth table0%0/2
A
A= $opt_delete_bool
Aresult
00
11
213 0 say RED "\nDELETE JOBS:", RESET;
214 0 ▶ if (prompt("Delete " . scalar(@selected_ids) . " jobs?", 'n') =~ /^(y|Y|yes|YES)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (prompt('Delete ' . scalar(@selected_ids) . ' jobs?', 'n') =~ /^(y|Y|yes|YES)$/u) { } 0 0 0
215 0 my $command = "scancel " . join(" ", @selected_ids);
216 0 my $result = system($command);
217 0 ▶ if ($result == -1) {
Branch: 3 branches
BranchTrueFalseTotal
if ($result == -1) { } 0 0 0
elsif ($result & 127) { } 0 0 0
elsif (my $exit_code = $result >> 8) { } 0 0 0
218 0 say RED, "ERROR", RESET, ": Failed to execute scancel: $!";
219 } elsif ($result & 127) {
220 0 say RED, "ERROR", RESET, ": scancel died with signal ", ($result & 127);
221 } elsif (my $exit_code = $result >> 8) {
222 0 say RED, "ERROR", RESET, ": scancel exited with status $exit_code";
223 } else {
224 0 say GREEN, "Success", RESET, ": Deleted ", scalar(@selected_ids), " job(s)";
225 }
226 } else {
227 0 say "Deletion cancelled.";
228 }
229  
230 } elsif ($opt_delete_bool) {
231 0 say STDERR YELLOW, "Warning: ", RESET, "No jobs selected for deletion";
232 }
233  
234 0 ▶sub state_string {
Subroutine state_string: not called CC=7 SCAR=40.3
235 0 ▶ my $s = shift // 'UNKNOWN';
Condition0%0/2
shift() // "UNKNOWN"
l!l
00
MC/DC0%0/1
shift() // "UNKNOWN"
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
236 0 my ($icon, $color, $text);
237  
238 0 ▶ if ($s =~ /^R/i) {
Branch: 5 branches
BranchTrueFalseTotal
if ($s =~ /^R/iu) { } 0 0 0
elsif ($s =~ /^P/iu) { } 0 0 0
elsif ($s =~ /^C/iu) { } 0 0 0
elsif ($s =~ /^F/iu) { } 0 0 0
elsif ($s =~ /^S/iu) { } 0 0 0
239 0 $icon = '▶';
240 0 $color = GREEN . BOLD;
241 0 $text = 'RUN';
242 } elsif ($s =~ /^P/i) {
243 0 $icon = '◷';
244 0 $color = YELLOW . BOLD;
245 0 $text = 'PND';
246 } elsif ($s =~ /^C/i) {
247 0 $icon = '✓';
248 0 $color = CYAN . BOLD;
249 0 $text = 'CMP';
250 } elsif ($s =~ /^F/i) {
251 0 $icon = '✗';
252 0 $color = RED . BOLD;
253 0 $text = 'FLD';
254 } elsif ($s =~ /^S/i) {
255 0 $icon = '■';
256 0 $color = RED . BOLD;
257 0 $text = 'STP';
258 } else {
259 0 $icon = '?';
260 0 $color = WHITE;
261 0 $text = substr($s, 0, 3);
262 }
263  
264 0 return $color . $icon . ' ' . $text . RESET;
265 }
266 0 ▶sub reason_string {
Subroutine reason_string: not called CC=8 SCAR=42.8
267 0 ▶ my $s = shift // 'None';
Condition0%0/2
shift() // "None"
l!l
00
MC/DC0%0/1
shift() // "None"
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
268 0 my ($icon, $color);
269  
270 0 ▶ if ($s =~ /^None/i) {
Branch: 6 branches
BranchTrueFalseTotal
if ($s =~ /^None/iu) { } 0 0 0
elsif ($s =~ /^Priority/iu) { } 0 0 0
elsif ($s =~ /^Resources/iu) { } 0 0 0
elsif ($s =~ /^Dependency/iu) { } 0 0 0
elsif ($s =~ /^(Bad|Error|Invalid)/iu) { } 0 0 0
elsif ($s =~ /^QOS/iu) { } 0 0 0
271 0 $icon = '✓';
272 0 $color = CYAN;
273 0 return $color . $icon . ' ' . $s . RESET;
274 } elsif ($s =~ /^Priority/i) {
275 0 $icon = '↑'; # was ⏳ — 2-wide emoji on modern terminals
276 0 $color = YELLOW;
277 } elsif ($s =~ /^Resources/i) {
278 0 $icon = '↯'; # was ⚡ — 2-wide emoji on modern terminals
279 0 $color = YELLOW;
280 } elsif ($s =~ /^Dependency/i) {
281 0 $icon = '→'; # was ⛓ — 2-wide emoji on modern terminals
282 0 $color = BLUE;
283 } elsif ($s =~ /^(Bad|Error|Invalid)/i) {
284 0 $icon = '✗';
285 0 $color = RED . BOLD;
286 } elsif ($s =~ /^QOS/i) {
287 0 $icon = '!'; # was ⚠ — ambiguous-width on modern terminals
288 0 $color = YELLOW;
289 } else {
290 0 $icon = '•';
291 0 $color = WHITE;
292 }
293  
294 0 return $color . $icon . ' ' . $s . RESET;
295 }
296 0 ▶sub joblist_to_ids {
Subroutine joblist_to_ids: not called CC=3 SCAR=24.8
297 # Receive a list of lists (all same length) and returns a list of jobids
298 0 my @rows = @_;
299 0 my @ids = ();
300 # remove first two rows
301
302 0 for my $row (@rows) {
303 # Skip non numeric values
304
305 0 ▶ next if ($row->[0] !~ /^\d+$/);
Branch: 1 branch
BranchTrueFalseTotal
unless $row->[0] =~ /^\d+$/u 0 0 0
306  
307 0 push @ids, $row->[0];
308
309
310 }
311  
312 0 return @ids;
313
314 }
315 0 ▶sub short_job {
Subroutine short_job: not called CC=1 SCAR=6.9
316 # Print a line of minimal information about a job
317 0 my $line_width = get_terminal_width();
318 0 my $job = shift;
319 0 my $jobid = $job->{JOBID};
320 0 my $name = $job->{NAME};
321 0 my $state = $job->{STATE};
322 0 my $user = $job->{USER};
323 0 my $queue = $job->{PARTITION};
324 0 my $time = $job->{TIME};
325 # Return a string sorther than $line_width
326 0 my $line = sprintf("%-10s %-10s %-10s %-10s %-10s %-10s", $jobid, $name, $state, $user, $queue, $time);
327 0 return $line;
328 }
329  
330 0 ▶sub print_summary {
Subroutine print_summary: not called CC=13 SCAR=52.0
331 0 my ($jobs, $selected_arrays) = @_;
332 0 my %stats = (running => 0, pending => 0, completed => 0, failed => 0, other => 0);
333  
334 # Count job states
335 0 for my $job (values %$jobs) {
336 0 ▶ my $state = $job->{STATE} // '';
Condition0%0/2
$job->{"STATE"} // ""
l!l
00
MC/DC0%0/1
$job->{"STATE"} // ""
$job->{"STATE"}
Truth table0%0/2
A
A= $job->{"STATE"}
Aresult
11
00
337 0 ▶ if ($state =~ /^R/i) {
Branch: 4 branches
BranchTrueFalseTotal
if ($state =~ /^R/iu) { } 0 0 0
elsif ($state =~ /^P/iu) { } 0 0 0
elsif ($state =~ /^C/iu) { } 0 0 0
elsif ($state =~ /^F/iu) { } 0 0 0
338 0 $stats{running}++;
339 } elsif ($state =~ /^P/i) {
340 0 $stats{pending}++;
341 } elsif ($state =~ /^C/i) {
342 0 $stats{completed}++;
343 } elsif ($state =~ /^F/i) {
344 0 $stats{failed}++;
345 } else {
346 0 $stats{other}++;
347 }
348 }
349  
350 0 my $total = scalar(keys %$jobs);
351 0 my $showing = scalar(@$selected_arrays) - 1; # -1 for header row
352  
353 0 say '';
354 0 say BOLD . CYAN . '╔════════════════════════════════════════════════════════════════╗' . RESET;
355 0 say BOLD . CYAN . '║' . RESET . ' ' . BOLD . 'SLURM Job Queue Summary' . RESET . ' ' x 39 . BOLD . CYAN . '║' . RESET;
356 0 say BOLD . CYAN . '╚════════════════════════════════════════════════════════════════╝' . RESET;
357 0 say '';
358  
359 # Stats line
360 0 my @stat_parts;
361 push @stat_parts, sprintf('%s %-9s %s%3d%s',
362 0 ▶ GREEN . BOLD . '▶' . RESET, 'Running:', GREEN . BOLD, $stats{running}, RESET) if $stats{running};
Branch: 1 branch
BranchTrueFalseTotal
if $stats{"running"} 0 0 0
363 push @stat_parts, sprintf('%s %-9s %s%3d%s',
364 0 ▶ YELLOW . BOLD . '◷' . RESET, 'Pending:', YELLOW . BOLD, $stats{pending}, RESET) if $stats{pending};
Branch: 1 branch
BranchTrueFalseTotal
if $stats{"pending"} 0 0 0
365 push @stat_parts, sprintf('%s %-9s %s%3d%s',
366 0 ▶ CYAN . '✓' . RESET, 'Complete:', CYAN, $stats{completed}, RESET) if $stats{completed};
Branch: 1 branch
BranchTrueFalseTotal
if $stats{"completed"} 0 0 0
367 push @stat_parts, sprintf('%s %-9s %s%3d%s',
368 0 ▶ RED . BOLD . '✗' . RESET, 'Failed:', RED . BOLD, $stats{failed}, RESET) if $stats{failed};
Branch: 1 branch
BranchTrueFalseTotal
if $stats{"failed"} 0 0 0
369 push @stat_parts, sprintf('%s %-9s %s%3d%s',
370 0 ▶ WHITE . '•' . RESET, 'Other:', WHITE, $stats{other}, RESET) if $stats{other};
Branch: 1 branch
BranchTrueFalseTotal
if $stats{"other"} 0 0 0
371  
372 0 ▶ if (@stat_parts) {
Branch: 1 branch
BranchTrueFalseTotal
if (@stat_parts) 0 0 0
373 0 say ' ' . join(' ', @stat_parts);
374 }
375  
376 0 say '';
377 0 say sprintf(' %s Showing: %s%d%s of %s%d%s total jobs',
378 CYAN . BOLD . '→' . RESET,
379 BOLD . CYAN, $showing, RESET,
380 BOLD, $total, RESET
381 );
382 0 say '';
383 }
384  
385 0 ▶sub summary_bucket_for_state {
Subroutine summary_bucket_for_state: not called CC=6 SCAR=37.4
386 0 ▶ my $state = shift // '';
Condition0%0/2
shift() // ""
l!l
00
MC/DC0%0/1
shift() // ""
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
387  
388 0 ▶ return 'running' if $state =~ /^RUNNING$/i;
Branch: 1 branch
BranchTrueFalseTotal
if $state =~ /^RUNNING$/iu 0 0 0
389 0 ▶ return 'pending' if $state =~ /^PENDING$/i;
Branch: 1 branch
BranchTrueFalseTotal
if $state =~ /^PENDING$/iu 0 0 0
390 0 ▶ return 'completed' if $state =~ /^COMPLETED$/i;
Branch: 1 branch
BranchTrueFalseTotal
if $state =~ /^COMPLETED$/iu 0 0 0
391 0 ▶ return 'errors' if $state =~ /^(?:FAILED|CANCELLED|TIMEOUT|NODE_FAIL|OUT_OF_MEMORY|BOOT_FAIL|DEADLINE|PREEMPTED)$/i;
Branch: 1 branch
BranchTrueFalseTotal
if $state =~ /^(?:FAILED|CANCELLED|TIMEOUT|NODE_FAIL|OUT_OF_MEMORY|BOOT_FAIL|DEADLINE|PREEMPTED)$/iu 0 0 0
392 0 return 'other';
393 }
394  
395 0 ▶sub summary_color {
Subroutine summary_color: not called CC=5 SCAR=34.0
396 0 my $bucket = shift;
397  
398 0 ▶ return GREEN . BOLD if $bucket eq 'running';
Branch: 1 branch
BranchTrueFalseTotal
if $bucket eq "running" 0 0 0
399 0 ▶ return YELLOW . BOLD if $bucket eq 'pending';
Branch: 1 branch
BranchTrueFalseTotal
if $bucket eq "pending" 0 0 0
400 0 ▶ return BLUE if $bucket eq 'completed';
Branch: 1 branch
BranchTrueFalseTotal
if $bucket eq "completed" 0 0 0
401 0 ▶ return RED if $bucket eq 'errors';
Branch: 1 branch
BranchTrueFalseTotal
if $bucket eq "errors" 0 0 0
402 0 return BLACK;
403 }
404  
405 0 ▶sub summary_user_label {
Subroutine summary_user_label: not called CC=3 SCAR=24.8
406 0 my $user = shift;
407 0 ▶ return 'All users' if !defined $user || $user eq '.+';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $user or $user eq ".+" 0 0 0
Condition0%0/3
not defined $user or $user eq ".+"
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $user or $user eq ".+"
not defined $user $user eq ".+"
Truth table0%0/3
not(A) or B
A= not defined $userB= $user eq ".+"
ABresult
1X1
011
000
408 0 return $user;
409 }
410  
411 0 ▶sub job_matches_summary_scope {
Subroutine job_matches_summary_scope: not called CC=5 SCAR=34.0
412 0 my ($jobid, $job, $ids_ref) = @_;
413  
414 0 ▶ return 0 if $job->{PARTITION} !~ /$opt_queue/;
Branch: 1 branch
BranchTrueFalseTotal
unless $job->{"PARTITION"} =~ /$opt_queue/u 0 0 0
415 0 ▶ return 0 if $job->{NAME} !~ /$opt_name/;
Branch: 1 branch
BranchTrueFalseTotal
unless $job->{"NAME"} =~ /$opt_name/u 0 0 0
416 0 ▶ return 0 if @$ids_ref && !grep { $_ eq $jobid } @$ids_ref;
Branch: 1 branch
BranchTrueFalseTotal
if @$ids_ref and not grep({$_ eq $jobid;} @$ids_ref) 0 0 0
Condition0%0/3
@$ids_ref and not grep({$_ eq $jobid;} @$ids_ref)
!ll&&!rl&&r
000
MC/DC0%0/2
@$ids_ref and not grep({$_ eq $jobid;} @$ids_ref)
@$ids_ref not grep({$_ eq $jobid;} @$ids_ref)
Truth table0%0/3
A and not(B)
A= @$ids_refB= not grep({$_ eq $jobid;} @$ids_ref)
ABresult
0X0
100
111
417 0 return 1;
418 }
419  
420 0 ▶sub print_state_summary_table {
Subroutine print_state_summary_table: not called CC=12 SCAR=50.5
421 0 my ($jobs, $ids_ref, $user_pattern) = @_;
422  
423 0 my @order = qw(running pending completed errors other);
424 0 my %labels = (
425 running => 'Running jobs',
426 pending => 'Pending jobs',
427 completed => 'Completed',
428 errors => 'Errors',
429 other => 'Other',
430 );
431 0 my %counts = map { $_ => { user => 0, total => 0 } } @order;
432  
433 0 for my $jobid (sort keys %$jobs) {
434 0 my $job = $jobs->{$jobid};
435 0 ▶ next unless job_matches_summary_scope($jobid, $job, $ids_ref);
Branch: 1 branch
BranchTrueFalseTotal
unless job_matches_summary_scope($jobid, $job, $ids_ref) 0 0 0
436  
437 0 my $bucket = summary_bucket_for_state($job->{STATE});
438 0 $counts{$bucket}{total}++;
439 0 ▶ if (($job->{USER} // '') =~ /^$user_pattern$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (($job->{"USER"} // "") =~ /^$user_pattern$/u) 0 0 0
Condition0%0/2
$job->{"USER"} // ""
l!l
00
MC/DC0%0/1
$job->{"USER"} // ""
$job->{"USER"}
Truth table0%0/2
A
A= $job->{"USER"}
Aresult
11
00
440 0 $counts{$bucket}{user}++;
441 }
442 }
443  
444 0 my $user_label = summary_user_label($user_pattern);
445 0 my $label_w = length('Pending jobs');
446 0 my $user_w = length($user_label);
447 0 my $total_w = length('Total');
448 0 my $user_total = 0;
449 0 my $grand_total = 0;
450  
451 0 for my $bucket (@order) {
452 0 my $user_count = $counts{$bucket}{user};
453 0 my $total_count = $counts{$bucket}{total};
454 0 $user_total += $user_count;
455 0 $grand_total += $total_count;
456 0 ▶ $user_w = length($user_count) if length($user_count) > $user_w;
Branch: 1 branch
BranchTrueFalseTotal
if length $user_count > $user_w 0 0 0
457 0 ▶ $total_w = length($total_count) if length($total_count) > $total_w;
Branch: 1 branch
BranchTrueFalseTotal
if length $total_count > $total_w 0 0 0
458 }
459 0 ▶ $label_w = length('Total') if length('Total') > $label_w;
Branch: 1 branch
BranchTrueFalseTotal
if 5 > $label_w 0 0 0
460 0 ▶ $user_w = length($user_total) if length($user_total) > $user_w;
Branch: 1 branch
BranchTrueFalseTotal
if length $user_total > $user_w 0 0 0
461 0 ▶ $total_w = length($grand_total) if length($grand_total) > $total_w;
Branch: 1 branch
BranchTrueFalseTotal
if length $grand_total > $total_w 0 0 0
462  
463 0 say '';
464 0 say sprintf(" %-*s | %*s | %*s", $label_w, '', $user_w, $user_label, $total_w, 'Total');
465 0 say sprintf(" %s-+-%s-+-%s", '-' x $label_w, '-' x $user_w, '-' x $total_w);
466  
467 0 for my $bucket (@order) {
468 my $line = sprintf(
469 " %-*s | %*d | %*d",
470 $label_w, $labels{$bucket},
471 $user_w, $counts{$bucket}{user},
472 $total_w, $counts{$bucket}{total},
473 0 );
474 0 say summary_color($bucket) . $line . RESET;
475 }
476 0 say sprintf(" %s-+-%s-+-%s", '-' x $label_w, '-' x $user_w, '-' x $total_w);
477 0 say BOLD . sprintf(
478 " %-*s | %*d | %*d",
479 $label_w, 'Total',
480 $user_w, $user_total,
481 $total_w, $grand_total,
482 ) . RESET;
483  
484 0 say '';
485 }
486  
487 0 ▶sub hide_columns {
Subroutine hide_columns: not called CC=10 SCAR=47.0
488 0 my ($arrays_ref, $hide_patterns) = @_;
489 0 ▶ return $arrays_ref unless @$hide_patterns;
Branch: 1 branch
BranchTrueFalseTotal
unless @$hide_patterns 0 0 0
490  
491 0 my @arrays = @$arrays_ref;
492 0 ▶ return \@arrays unless @arrays;
Branch: 1 branch
BranchTrueFalseTotal
unless @arrays 0 0 0
493  
494 0 my $header = $arrays[0];
495 0 my @keep_indices;
496  
497 # Determine which columns to keep
498 0 for my $i (0..$#{$header}) {
499 0 my $col_name = $header->[$i];
500 0 my $should_hide = 0;
501  
502 0 for my $pattern (@$hide_patterns) {
503 # Case insensitive substring match (minimum 3 chars)
504 0 ▶ if (length($pattern) >= 3 && $col_name =~ /\Q$pattern\E/i) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $pattern >= 3 and $col_name =~ /\Q$pattern\E/iu) 0 0 0
Condition0%0/3
length $pattern >= 3 and $col_name =~ /\Q$pattern\E/iu
!ll&&!rl&&r
000
MC/DC0%0/2
length $pattern >= 3 and $col_name =~ /\Q$pattern\E/iu
length $pattern >= 3 $col_name =~ /\Q$pattern\E/iu
Truth table0%0/3
A and B
A= length $pattern >= 3B= $col_name =~ /\Q$pattern\E/iu
ABresult
0X0
100
111
505 0 $should_hide = 1;
506 0 last;
507 }
508 }
509  
510 0 ▶ push @keep_indices, $i unless $should_hide;
Branch: 1 branch
BranchTrueFalseTotal
unless $should_hide 0 0 0
511 }
512  
513 # If all columns would be hidden, keep them all
514 0 ▶ return \@arrays unless @keep_indices;
Branch: 1 branch
BranchTrueFalseTotal
unless @keep_indices 0 0 0
515  
516 # Filter each row to keep only non-hidden columns
517 0 my @filtered_arrays;
518 0 for my $row (@arrays) {
519 0 my @filtered_row = map { $row->[$_] } @keep_indices;
520 0 push @filtered_arrays, \@filtered_row;
521 }
522  
523 0 return \@filtered_arrays;
524 }
525  
526 0 ▶sub ansi_first_char {
Subroutine ansi_first_char: not called CC=2 SCAR=17.9
527 # Return the first visible glyph of an ANSI-coloured string,
528 # preserving any leading colour escape sequences.
529 0 my $s = shift;
530 0 my $prefix = '';
531 0 ▶ while ($s =~ s/^(\e\[[0-9;]*m)//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ s/^(\e\[[0-9;]*m)//u) 0 0 0
532 0 $prefix .= $1;
533 }
534 0 return $prefix . substr($s, 0, 1) . RESET;
535 }
536  
537 0 ▶sub fit_columns_to_terminal {
Subroutine fit_columns_to_terminal: not called CC=30 SCAR=68.4
538 # Given natural column widths and the header row, return:
539 # ($fitted_widths_ref, $hidden_hashref, $icon_only_hashref)
540 # Strategy (in order):
541 # 1. Shrink flexible cols (name, nodelist, reason) down to their minimums
542 # 2. Hide NodeList entirely (optional column, first to go)
543 # 3. Hide Reason entirely (optional column, second to go)
544 # 4. Collapse State to icon-only glyph
545 # 5. Last-resort: truncate whatever is still widest
546 0 my ($widths, $header) = @_;
547 0 my $terminal_width = get_terminal_width();
548  
549 0 my @fitted = @$widths;
550 0 my %hidden = ();
551 0 my %icon_only = ();
552  
553 # Map normalised column name -> index
554 0 my %col_idx;
555 0 for my $i (0..$#$header) {
556 0 my $name = lc($header->[$i]);
557 0 $name =~ s/[^a-z0-9]//g;
558 0 $col_idx{$name} = $i;
559 }
560  
561 # Rendered width: left border + each visible col (content + 2 spaces + right border)
562 0 ▶ my $calc_width = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
563 0 my $w = 1;
564 0 for my $i (0..$#fitted) {
565 0 ▶ next if $hidden{$i};
Branch: 1 branch
BranchTrueFalseTotal
if $hidden{$i} 0 0 0
566 0 $w += $fitted[$i] + 3;
567 }
568 0 return $w;
569 0 };
570  
571 0 ▶ return (\@fitted, \%hidden, \%icon_only) if $calc_width->() <= $terminal_width;
Branch: 1 branch
BranchTrueFalseTotal
if &$calc_width() <= $terminal_width 0 0 0
572  
573 # Step 1: Shrink Name/NodeList/Reason down to minimums
574 0 my %min_widths = (name => 10, nodelist => 8, reason => 8);
575 0 my $progress = 1;
576 0 ▶ while ($calc_width->() > $terminal_width && $progress) {
Branch: 1 branch
BranchTrueFalseTotal
if (&$calc_width() > $terminal_width and $progress) 0 0 0
Condition0%0/3
&$calc_width() > $terminal_width and $progress
!ll&&!rl&&r
000
MC/DC0%0/2
&$calc_width() > $terminal_width and $progress
&$calc_width() > $terminal_width $progress
Truth table0%0/3
A and B
A= &$calc_width() > $terminal_widthB= $progress
ABresult
0X0
100
111
577 0 $progress = 0;
578 0 my ($best, $best_w) = (undef, 0);
579 0 for my $name (qw(name nodelist reason)) {
580 0 my $i = $col_idx{$name};
581 0 ▶ next unless defined $i;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $i 0 0 0
582 0 ▶ next if $hidden{$i};
Branch: 1 branch
BranchTrueFalseTotal
if $hidden{$i} 0 0 0
583 0 my $min = $min_widths{$name};
584 0 ▶ if ($fitted[$i] > $min && $fitted[$i] > $best_w) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fitted[$i] > $min and $fitted[$i] > $best_w) 0 0 0
Condition0%0/3
$fitted[$i] > $min and $fitted[$i] > $best_w
!ll&&!rl&&r
000
MC/DC0%0/2
$fitted[$i] > $min and $fitted[$i] > $best_w
$fitted[$i] > $min $fitted[$i] > $best_w
Truth table0%0/3
A and B
A= $fitted[$i] > $minB= $fitted[$i] > $best_w
ABresult
0X0
100
111
585 0 $best = $name;
586 0 $best_w = $fitted[$i];
587 }
588 }
589 0 ▶ if (defined $best) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $best) 0 0 0
590 0 my $i = $col_idx{$best};
591 0 my $min = $min_widths{$best};
592 0 my $excess = $calc_width->() - $terminal_width;
593 0 my $cut = $fitted[$i] - $min;
594 0 ▶ $cut = $excess if $excess < $cut;
Branch: 1 branch
BranchTrueFalseTotal
if $excess < $cut 0 0 0
595 0 $fitted[$i] -= $cut;
596 0 ▶ $progress = 1 if $cut > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $cut > 0 0 0 0
597 }
598 }
599  
600 # Step 2: Hide NodeList (optional, first to go)
601 0 ▶ if ($calc_width->() > $terminal_width) {
Branch: 1 branch
BranchTrueFalseTotal
if (&$calc_width() > $terminal_width) 0 0 0
602 0 my $i = $col_idx{nodelist};
603 0 ▶ $hidden{$i} = 1 if defined $i;
Branch: 1 branch
BranchTrueFalseTotal
if defined $i 0 0 0
604 }
605  
606 # Step 3: Hide Reason (optional, second to go)
607 0 ▶ if ($calc_width->() > $terminal_width) {
Branch: 1 branch
BranchTrueFalseTotal
if (&$calc_width() > $terminal_width) 0 0 0
608 0 my $i = $col_idx{reason};
609 0 ▶ $hidden{$i} = 1 if defined $i;
Branch: 1 branch
BranchTrueFalseTotal
if defined $i 0 0 0
610 }
611  
612 # Step 4: Collapse State to a single icon glyph
613 0 ▶ if ($calc_width->() > $terminal_width) {
Branch: 1 branch
BranchTrueFalseTotal
if (&$calc_width() > $terminal_width) 0 0 0
614 0 my $i = $col_idx{state};
615 0 ▶ if (defined $i && !$hidden{$i}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $i and not $hidden{$i}) 0 0 0
Condition0%0/3
defined $i and not $hidden{$i}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $i and not $hidden{$i}
defined $i not $hidden{$i}
Truth table0%0/3
A and not(B)
A= defined $iB= not $hidden{$i}
ABresult
0X0
100
111
616 0 $icon_only{$i} = 1;
617 0 $fitted[$i] = 1;
618 }
619 }
620  
621 # Step 5: Last-resort generic truncation of whatever is still widest
622 0 $progress = 1;
623 0 ▶ while ($calc_width->() > $terminal_width && $progress) {
Branch: 1 branch
BranchTrueFalseTotal
if (&$calc_width() > $terminal_width and $progress) 0 0 0
Condition0%0/3
&$calc_width() > $terminal_width and $progress
!ll&&!rl&&r
000
MC/DC0%0/2
&$calc_width() > $terminal_width and $progress
&$calc_width() > $terminal_width $progress
Truth table0%0/3
A and B
A= &$calc_width() > $terminal_widthB= $progress
ABresult
0X0
100
111
624 0 $progress = 0;
625 0 my ($best_i, $best_w) = (-1, 0);
626 0 for my $i (0..$#fitted) {
627 0 ▶ next if $hidden{$i} || $icon_only{$i};
Branch: 1 branch
BranchTrueFalseTotal
if $hidden{$i} or $icon_only{$i} 0 0 0
Condition0%0/3
$hidden{$i} or $icon_only{$i}
l!l&&r!l&&!r
000
MC/DC0%0/2
$hidden{$i} or $icon_only{$i}
$hidden{$i} $icon_only{$i}
Truth table0%0/3
A or B
A= $hidden{$i}B= $icon_only{$i}
ABresult
1X1
011
000
628 0 ▶ if ($fitted[$i] > 4 && $fitted[$i] > $best_w) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fitted[$i] > 4 and $fitted[$i] > $best_w) 0 0 0
Condition0%0/3
$fitted[$i] > 4 and $fitted[$i] > $best_w
!ll&&!rl&&r
000
MC/DC0%0/2
$fitted[$i] > 4 and $fitted[$i] > $best_w
$fitted[$i] > 4 $fitted[$i] > $best_w
Truth table0%0/3
A and B
A= $fitted[$i] > 4B= $fitted[$i] > $best_w
ABresult
0X0
100
111
629 0 $best_i = $i;
630 0 $best_w = $fitted[$i];
631 }
632 }
633 0 ▶ if ($best_i >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($best_i >= 0) 0 0 0
634 0 my $excess = $calc_width->() - $terminal_width;
635 0 my $cut = $fitted[$best_i] - 4;
636 0 ▶ $cut = $excess if $excess < $cut;
Branch: 1 branch
BranchTrueFalseTotal
if $excess < $cut 0 0 0
637 0 $fitted[$best_i] -= $cut;
638 0 ▶ $progress = 1 if $cut > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $cut > 0 0 0 0
639 }
640 }
641  
642 0 return (\@fitted, \%hidden, \%icon_only);
643 }
644  
645 0 ▶sub render_table_modern {
Subroutine render_table_modern: not called CC=7 SCAR=40.3
646 # Receive a list of lists (all same length) and print a modern table with Unicode borders
647 0 my @rows = @_;
648 0 ▶ return unless @rows;
Branch: 1 branch
BranchTrueFalseTotal
unless @rows 0 0 0
649  
650 0 my $n_cols = scalar(@{$rows[0]});
651  
652 # Calculate maximum widths for each column
653 0 my @max_widths = ();
654 0 for my $col (0..$n_cols-1) {
655 0 my $max_width = 0;
656 0 for my $row (@rows) {
657 0 my $width = ascii_len($row->[$col]);
658 0 ▶ $max_width = $width if ($width > $max_width);
Branch: 1 branch
BranchTrueFalseTotal
if $width > $max_width 0 0 0
659 }
660 0 push(@max_widths, $max_width);
661 }
662  
663 # Fit columns to terminal: truncate, hide optional cols, collapse State to icon
664 0 my ($fitted_widths, $hidden_cols, $icon_only_cols) =
665 fit_columns_to_terminal(\@max_widths, $rows[0]);
666  
667 # Print top border
668 0 print_border_line('top', $fitted_widths, $hidden_cols);
669  
670 # Print header row (first row)
671 0 ▶ if (@rows > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@rows > 0) 0 0 0
672 0 print_table_row($rows[0], $fitted_widths, 'header', $hidden_cols, $icon_only_cols);
673 0 print_border_line('middle', $fitted_widths, $hidden_cols);
674 }
675  
676 # Print data rows
677 0 for my $i (1..$#rows) {
678 0 print_table_row($rows[$i], $fitted_widths, 'data', $hidden_cols, $icon_only_cols);
679 }
680  
681 # Print bottom border
682 0 print_border_line('bottom', $fitted_widths, $hidden_cols);
683 }
684  
685 0 ▶sub print_border_line {
Subroutine print_border_line: not called CC=6 SCAR=37.4
686 0 my ($type, $widths, $hidden) = @_;
687 0 ▶ $hidden //= {};
Condition0%0/2
$hidden //= {}
l!l
00
MC/DC0%0/1
$hidden //= {}
$hidden
Truth table0%0/2
A
A= $hidden
Aresult
11
00
688 0 my ($left, $mid, $right, $fill);
689  
690 0 ▶ if ($type eq 'top') {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'top') { } 0 0 0
elsif ($type eq 'middle') { } 0 0 0
691 0 ($left, $mid, $right, $fill) = ($BOX->{tl}, $BOX->{t}, $BOX->{tr}, $BOX->{h});
692 } elsif ($type eq 'middle') {
693 0 ($left, $mid, $right, $fill) = ($BOX->{l}, $BOX->{c}, $BOX->{r}, $BOX->{h});
694 } else { # bottom
695 0 ($left, $mid, $right, $fill) = ($BOX->{bl}, $BOX->{b}, $BOX->{br}, $BOX->{h});
696 }
697  
698 0 my @visible = grep { !$hidden->{$_} } 0..$#{$widths};
699 0 print CYAN . $left . RESET;
700 0 for my $j (0..$#visible) {
701 0 my $i = $visible[$j];
702 0 print CYAN . ($fill x ($widths->[$i] + 2)) . RESET;
703 0 ▶ print CYAN . ($j == $#visible ? $right : $mid) . RESET;
Branch: 1 branch
BranchTrueFalseTotal
$j == $#visible ? : 0 0 0
704 }
705 0 say '';
706 }
707  
708 0 ▶sub print_table_row {
Subroutine print_table_row: not called CC=9 SCAR=45.0
709 0 my ($row, $widths, $style, $hidden, $icon_only) = @_;
710 0 ▶ $hidden //= {};
Condition0%0/2
$hidden //= {}
l!l
00
MC/DC0%0/1
$hidden //= {}
$hidden
Truth table0%0/2
A
A= $hidden
Aresult
11
00
711 0 ▶ $icon_only //= {};
Condition0%0/2
$icon_only //= {}
l!l
00
MC/DC0%0/1
$icon_only //= {}
$icon_only
Truth table0%0/2
A
A= $icon_only
Aresult
11
00
712  
713 0 print CYAN . $BOX->{v} . RESET;
714 0 for my $i (0..$#{$row}) {
715 0 ▶ next if $hidden->{$i};
Branch: 1 branch
BranchTrueFalseTotal
if $hidden->{$i} 0 0 0
716  
717 0 my $cell = $row->[$i];
718 0 my $width = $widths->[$i];
719  
720 # Icon-only mode: show just the leading glyph (used for State when space is tight)
721 0 ▶ if ($icon_only->{$i}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($icon_only->{$i}) 0 0 0
722 0 my $icon = ansi_first_char($cell);
723 0 print " $icon " . RESET;
724 0 print CYAN . $BOX->{v} . RESET;
725 0 next;
726 }
727  
728 0 my $stripped = $cell;
729 0 $stripped =~ s/\e\[[0-9;]*m//g; # Strip ANSI codes
730  
731 0 ▶ my $prefix = ($style eq 'header') ? BOLD . WHITE : '';
Branch: 1 branch
BranchTrueFalseTotal
$style eq 'header' ? : 0 0 0
732  
733 0 ▶ if (length($stripped) > $width) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $stripped > $width) { } 0 0 0
734 # Truncate and mark with a coloured '>' ellipsis
735 0 my $visible = substr($stripped, 0, $width - 1);
736 0 print " $prefix$visible" . YELLOW . BOLD . '>' . RESET . ' ';
737 } else {
738 # Normal padded cell — preserve ANSI codes in the original value
739 0 my $tmpline = sprintf(" %s%-*s ", $prefix, $width, $stripped);
740 0 my $index = index($tmpline, $stripped);
741 0 ▶ if ($index >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($index >= 0) 0 0 0
742 0 substr($tmpline, $index, length($stripped), $cell);
743 }
744 0 print $tmpline . RESET;
745 }
746 0 print CYAN . $BOX->{v} . RESET;
747 }
748 0 say '';
749 }
750  
751 0 ▶sub render_table {
Subroutine render_table: not called CC=6 SCAR=37.4
752 # Receive a list of lists (all same length) and print a table not larger than $line_width
753
754 # @_ is an array of array references
755 0 my @rows = @_;
756 0 my $n_cols = scalar(@{$rows[0]});
757 0 my $line_width = get_terminal_width() - $n_cols - 1;
758 # For each column, evaluate the maximum string contained in that column
759 0 my @max_widths = ();
760 0 for my $col (0..$n_cols-1) {
761 0 my $max_width = 0;
762 0 for my $row (@rows) {
763 0 my $width = ascii_len($row->[$col]);
764 0 ▶ $max_width = $width if ($width > $max_width);
Branch: 1 branch
BranchTrueFalseTotal
if $width > $max_width 0 0 0
765 }
766 0 push(@max_widths, $max_width);
767 }
768 # Now print the table
769 0 for my $row (@rows) {
770 0 my $line = WHITE . ON_BLACK;
771 0 for my $col (0..$n_cols-1) {
772 0 my $width = $max_widths[$col];
773 0 my $cell = $row->[$col];
774 0 my $stripped = $cell;
775 0 $stripped =~ s/\e\[[0-9;]*m//g;
776 0 my $tmpline = sprintf("|%-${width}s ", $stripped);
777 # In tmpline replace $stripped with $cell, without using regex
778 0 my $index = index($tmpline, $stripped);
779 0 substr($tmpline, $index, length($stripped), $cell);
780 0 $line .= $tmpline;
781 }
782 0 say $line, "|";
783 }
784 0 print RESET;
785 }
786  
787 0 ▶sub ascii_len {
Subroutine ascii_len: not called CC=1 SCAR=6.9
788 0 my $string = shift;
789 # Return legnth excluding ANSI escape sequences
790 0 $string =~ s/\e\[[0-9;]*m//g;
791 0 return length($string);
792 }
793  
794 0 ▶sub extractJobByID {
Subroutine extractJobByID: not called CC=3 SCAR=24.8
795 0 my ($jobs, $id) = @_;
796 0 my $job = {};
797 0 for my $jobid (keys %{$jobs}) {
798 0 ▶ if ($jobid eq $id) {
Branch: 1 branch
BranchTrueFalseTotal
if ($jobid eq $id) 0 0 0
799 0 $job = $jobs->{$jobid};
800 0 last;
801 }
802 }
803 0 return $job;
804 }
805 0 ▶sub getjobs {
Subroutine getjobs: not called CC=14 SCAR=53.5
806 # Create an anonymous hash, and return it
807 0 my $jobs = {};
808 # Use ASCII record separator (chr 30) as delimiter — safe against job names
809 # that contain '|' (e.g. Nextflow workflow names).
810 0 my $sep = chr(30);
811 0 my $fmt = join($sep, qw(%i %u %P %j %T %M %l %N %C %m %r));
812 0 $fmt =~ s/ //g; # remove spaces between format codes
813 0 my $cmd = "squeue --format='$fmt'";
814 0 my @output = `$cmd 2>&1`;
815  
816 # Check if command failed
817 0 ▶ if ($? != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0) 0 0 0
818 0 say STDERR RED, "Error: ", RESET, "Failed to execute squeue command";
819 0 ▶ say STDERR "Output: ", join("\n", @output) if @output;
Branch: 1 branch
BranchTrueFalseTotal
if @output 0 0 0
820 0 return $jobs;
821 }
822  
823 0 my $c = 0;
824 0 my @header = ();
825 0 for my $line (@output) {
826 0 chomp $line;
827 0 ▶ next if $line =~ /^\s*$/; # Skip empty lines
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*$/u 0 0 0
828  
829 0 my @fields = split(/\x1e/, $line);
830 0 $c++;
831 0 ▶ if ($c == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c == 1) { } 0 0 0
832 # Field names
833 0 for my $field (@fields) {
834 0 push(@header, stripchars($field));
835 }
836 } else {
837 # Job info
838 0 my $job = {};
839 0 ▶ if (scalar(@fields) != scalar(@header)) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @fields != scalar @header) 0 0 0
840 0 say STDERR YELLOW, "Warning: ", RESET, "Skipping malformed line (field count mismatch)";
841 0 ▶ if ($ENV{DEBUG}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"DEBUG"}) 0 0 0
842 0 say STDERR " Expected: ", scalar(@header), " fields";
843 0 say STDERR " Got: ", scalar(@fields), " fields";
844 0 say STDERR " Line: $line";
845 }
846 0 next; # Skip this line instead of exiting
847 }
848 0 for my $i (0..$#header) {
849 0 ▶ $job->{"$header[$i]"} = $fields[$i] if (not defined $job->{"$header[$i]"});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$job{"$header[$i]"} 0 0 0
850 }
851  
852 # Ensure we have a valid JOBID before adding
853 0 ▶ if (defined $job->{JOBID} && $job->{JOBID} ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $job->{'JOBID'} and $job->{'JOBID'} ne '') { } 0 0 0
Condition0%0/3
defined $job->{"JOBID"} and $job->{"JOBID"} ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
defined $job->{"JOBID"} and $job->{"JOBID"} ne ""
defined $job->{"JOBID"} $job->{"JOBID"} ne ""
Truth table0%0/3
A and B
A= defined $job->{"JOBID"}B= $job->{"JOBID"} ne ""
ABresult
0X0
100
111
854 0 $jobs->{$job->{JOBID}} = $job;
855 } else {
856 0 ▶ say STDERR YELLOW, "Warning: ", RESET, "Skipping job with missing JOBID" if $ENV{DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"DEBUG"} 0 0 0
857 }
858  
859 }
860  
861 }
862  
863 0 return $jobs;
864 }
865  
866  
867 0 ▶sub get_terminal_width {
Subroutine get_terminal_width: not called CC=5 SCAR=34.0
868 0 my $terminal_width = `tput cols 2>/dev/null`;
869 0 ▶ chomp($terminal_width) if defined $terminal_width;
Branch: 1 branch
BranchTrueFalseTotal
if defined $terminal_width 0 0 0
870  
871 # Validate that we got a positive integer
872 0 ▶ if (defined $terminal_width && $terminal_width =~ /^\d+$/ && $terminal_width > 20) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $terminal_width and $terminal_width =~ /^\d+$/u and $terminal_width > 20) 0 0 0
Condition0%0/6
defined $terminal_width and $terminal_width =~ /^\d+$/u and $terminal_width > 20
!ll&&!rl&&r
000
defined $terminal_width and $terminal_width =~ /^\d+$/u
!ll&&!rl&&r
000
MC/DC0%0/3
defined $terminal_width and $terminal_width =~ /^\d+$/u and $terminal_width > 20
defined $terminal_width $terminal_width =~ /^\d+$/u $terminal_width > 20
Truth table0%0/4
A and B and C
A= defined $terminal_widthB= $terminal_width =~ /^\d+$/uC= $terminal_width > 20
ABCresult
0XX0
10X0
1100
1111
873 0 return $terminal_width;
874 }
875  
876 # Fallback to default width
877 0 return 80;
878 }
879  
880 0 ▶sub stripchars {
Subroutine stripchars: not called CC=1 SCAR=6.9
881 0 my $string = shift;
882 # replace non alphanumeric characters with _
883 0 $string =~ s/[^A-Za-z0-9]/_/g;
884 0 return $string;
885 }
886  
887 0 ▶sub prompt {
Subroutine prompt: not called CC=2 SCAR=17.9
888 0 my ($message, $default) = @_;
889 0 my $prompt = "$message [$default]: ";
890 0 print $prompt;
891 0 my $answer = <STDIN>;
892 0 chomp $answer;
893 0 ▶ $answer = $default if ($answer eq '');
Branch: 1 branch
BranchTrueFalseTotal
if $answer eq "" 0 0 0
894 0 return $answer;
895 }
896  
897 0 ▶sub usage {
Subroutine usage: not called CC=1 SCAR=6.9
898 0 say <<END;
899 Usage: lsjobs [options] [jobid ... | pattern ]
900 ----------------------------------------------
901 Options:
902 -u, --user <username> Show only jobs from this user [default: $unix_username]
903 Type 'all' to show all users
904  
905 -n, --name <pattern> Show only jobs with this name (regex) [default: .+]
906 -x, --exclude <pattern> Exclude jobs whose name matches this pattern (regex)
907  
908 -s, --status <pattern> Show only jobs matching this status (regex) [default: .+]
909 -r, --running Show only running jobs
910 -p, --pending Show only pending jobs
911 -t, --tab Output in simple TSV format (pipe to vd for interactive table)
912 --summary Print per-state counts for the selected user vs total jobs
913  
914 --hide <column> Hide column from display (case insensitive substring match,
915 minimum 3 characters). Can be specified multiple times.
916 Examples: --hide time --hide memory --hide nodelist
917  
918 -d, --delete Delete the selected jobs (with confirmation prompt)
919 --verbose Show verbose output
920 --version Show version and exit
921 --help Show this help message
922 END
923 0 exit;
924  
925 }
926  
927 __END__
« blib/lib/NBI/Queue.pm ↑ Summary bin/waitjobs »