line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HPC::Runner::Command::submit_jobs::Utils::Scheduler::JobStats; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
#use Moose::Role; |
4
|
1
|
|
|
1
|
|
9
|
use Moose; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
9
|
|
5
|
1
|
|
|
1
|
|
10677
|
use JSON; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
13
|
|
6
|
1
|
|
|
1
|
|
192
|
use List::MoreUtils qw(firstidx); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
14
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 HPC::Runner::Command::submit_jobs::Utils::Scheduler::JobStats |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
This will be undergoing serious revision in the near future |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head2 Attributes |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Package Attributes |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=cut |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head3 job_stats |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
HashRef of job stats - total jobs submitted, total processes, etc |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=cut |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
has 'total_processes' => ( |
25
|
|
|
|
|
|
|
traits => ['Number'], |
26
|
|
|
|
|
|
|
is => 'rw', |
27
|
|
|
|
|
|
|
isa => 'Num', |
28
|
|
|
|
|
|
|
default => 0, |
29
|
|
|
|
|
|
|
handles => { |
30
|
|
|
|
|
|
|
set_total_processes => 'set', |
31
|
|
|
|
|
|
|
add_total_processes => 'add', |
32
|
|
|
|
|
|
|
}, |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
#has 'tally_commands' => ( |
36
|
|
|
|
|
|
|
#traits => ['Number'], |
37
|
|
|
|
|
|
|
#is => 'rw', |
38
|
|
|
|
|
|
|
#isa => 'Num', |
39
|
|
|
|
|
|
|
#default => 1, |
40
|
|
|
|
|
|
|
#handles => { add_tally_commands => 'add', }, |
41
|
|
|
|
|
|
|
#); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
has 'total_batches' => ( |
44
|
|
|
|
|
|
|
traits => ['Number'], |
45
|
|
|
|
|
|
|
is => 'rw', |
46
|
|
|
|
|
|
|
isa => 'Num', |
47
|
|
|
|
|
|
|
default => 0, |
48
|
|
|
|
|
|
|
handles => { |
49
|
|
|
|
|
|
|
set_total_batches => 'set', |
50
|
|
|
|
|
|
|
add_total_batches => 'add', |
51
|
|
|
|
|
|
|
}, |
52
|
|
|
|
|
|
|
); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
has batches => ( |
55
|
|
|
|
|
|
|
traits => ['Hash'], |
56
|
|
|
|
|
|
|
is => 'rw', |
57
|
|
|
|
|
|
|
isa => 'HashRef', |
58
|
|
|
|
|
|
|
default => sub { {} }, |
59
|
|
|
|
|
|
|
handles => { |
60
|
|
|
|
|
|
|
set_batches => 'set', |
61
|
|
|
|
|
|
|
defined_batches => 'defined', |
62
|
|
|
|
|
|
|
}, |
63
|
|
|
|
|
|
|
); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
has jobnames => ( |
66
|
|
|
|
|
|
|
traits => ['Hash'], |
67
|
|
|
|
|
|
|
is => 'rw', |
68
|
|
|
|
|
|
|
isa => 'HashRef', |
69
|
|
|
|
|
|
|
default => sub { {} }, |
70
|
|
|
|
|
|
|
handles => { |
71
|
|
|
|
|
|
|
keys_jobnames => 'keys', |
72
|
|
|
|
|
|
|
defined_jobnames => 'defined', |
73
|
|
|
|
|
|
|
set_jobnames => 'set', |
74
|
|
|
|
|
|
|
exists_jobnames => 'exists', |
75
|
|
|
|
|
|
|
}, |
76
|
|
|
|
|
|
|
); |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head2 Subroutines |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head3 create_meta_str |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=cut |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
#TODO This is a mess |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub create_meta_str { |
88
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
89
|
0
|
|
|
|
|
|
my $counter = shift; |
90
|
0
|
|
|
|
|
|
my $batch_counter = shift; |
91
|
0
|
|
|
|
|
|
my $current_job = shift; |
92
|
0
|
|
|
|
|
|
my $use_batches = shift; |
93
|
0
|
|
|
|
|
|
my $job = shift; |
94
|
0
|
|
|
|
|
|
my $cmd_count = shift; |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
my $batchname = $counter . "_" . $current_job; |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
my $batch = $self->{batches}->{$batchname}; |
99
|
0
|
|
|
|
|
|
$batch->{total_processes} = $self->total_processes; |
100
|
0
|
|
|
|
|
|
$batch->{total_batches} = $self->total_batches; |
101
|
0
|
|
|
|
|
|
$batch->{total_jobs} = $self->keys_jobnames; |
102
|
0
|
|
|
|
|
|
$batch->{jobname} = $current_job; |
103
|
0
|
|
|
|
|
|
$batch->{job_counter} = $counter; |
104
|
0
|
|
|
|
|
|
$batch->{job_tasks} = $job->cmd_counter; |
105
|
0
|
|
|
|
|
|
$batch->{job_cmd_start} = $job->{cmd_start}; |
106
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
$batch->{task_index_start} = $job->{cmd_start}; |
108
|
0
|
|
|
|
|
|
$batch->{task_index_end} = $job->{cmd_counter} + $job->{cmd_start} - 1; |
109
|
|
|
|
|
|
|
|
110
|
0
|
0
|
|
|
|
|
if ($use_batches) { |
111
|
0
|
|
|
|
|
|
$batch->{batch_index} = $batch_counter . "/" . $self->total_batches; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
else { |
114
|
0
|
|
|
|
|
|
$batch->{array_start} = $job->{batch_index_start}; |
115
|
0
|
|
|
|
|
|
$batch->{array_end} = $job->{batch_index_end}; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
|
my $json = JSON->new->allow_nonref; |
119
|
0
|
|
|
|
|
|
my $json_text = $json->encode($batch); |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
# $batch->{meta_str} = $json_text; |
122
|
|
|
|
|
|
|
# delete $batch->{meta_str}; |
123
|
0
|
|
|
|
|
|
$json_text = "--metastr \'$json_text\'"; |
124
|
0
|
|
|
|
|
|
return $json_text; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head3 collect_stats |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Collect job stats |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=cut |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub collect_stats { |
134
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
135
|
0
|
|
|
|
|
|
my $batch_counter = shift; |
136
|
0
|
|
|
|
|
|
my $cmd_counter = shift; |
137
|
0
|
|
|
|
|
|
my $current_job = shift; |
138
|
|
|
|
|
|
|
|
139
|
0
|
|
|
|
|
|
$batch_counter = sprintf( "%03d", $batch_counter ); |
140
|
|
|
|
|
|
|
|
141
|
0
|
|
|
|
|
|
$self->add_total_processes($cmd_counter); |
142
|
|
|
|
|
|
|
|
143
|
0
|
|
|
|
|
|
my $command_count = ( $self->total_processes - $cmd_counter ) + 1; |
144
|
|
|
|
|
|
|
|
145
|
0
|
|
|
|
|
|
$self->set_batches( |
146
|
|
|
|
|
|
|
$batch_counter . "_" . $current_job => { |
147
|
|
|
|
|
|
|
commands => $cmd_counter, |
148
|
|
|
|
|
|
|
jobname => $current_job, |
149
|
|
|
|
|
|
|
batch => $batch_counter, |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
); |
152
|
|
|
|
|
|
|
|
153
|
0
|
|
|
|
|
|
my $jobhref = {}; |
154
|
0
|
|
|
|
|
|
$jobhref->{$current_job} = []; |
155
|
|
|
|
|
|
|
|
156
|
0
|
0
|
|
|
|
|
if ( $self->exists_jobnames($current_job) ) { |
157
|
0
|
|
|
|
|
|
my $tarray = $self->jobnames->{$current_job}; |
158
|
0
|
|
|
|
|
|
push( @{$tarray}, $batch_counter . "_" . $current_job ); |
|
0
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
else { |
161
|
0
|
|
|
|
|
|
$self->set_jobnames( |
162
|
|
|
|
|
|
|
$current_job => [ $batch_counter . "_" . $current_job ] ); |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
0
|
|
|
|
|
|
$self->add_total_batches(1); |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head3 do_stats |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Do some stats on our job stats |
171
|
|
|
|
|
|
|
Foreach job name get the number of batches, and have a put that in batches->batch->job_batches |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=cut |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub do_stats { |
176
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
177
|
|
|
|
|
|
|
|
178
|
0
|
|
|
|
|
|
my @jobs = $self->keys_jobnames; |
179
|
|
|
|
|
|
|
|
180
|
0
|
|
|
|
|
|
foreach my $batch ( $self->keys_batches ) { |
181
|
0
|
|
|
|
|
|
my $href = $self->batches->{$batch}; |
182
|
0
|
|
|
|
|
|
my $jobname = $href->{jobname}; |
183
|
0
|
|
|
|
|
|
my @job_batches = @{ $self->jobnames->{$jobname} }; |
|
0
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
|
185
|
0
|
|
|
0
|
|
|
my $index = firstidx { $_ eq $batch } @job_batches; |
|
0
|
|
|
|
|
|
|
186
|
0
|
|
|
|
|
|
$index += 1; |
187
|
|
|
|
|
|
|
|
188
|
0
|
|
|
|
|
|
my $lenjobs = $#job_batches + 1; |
189
|
0
|
|
|
|
|
|
$self->batches->{$batch}->{job_batches} = $index . "/" . $lenjobs; |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
# print "Job batches are " |
192
|
|
|
|
|
|
|
# . $self->batches->{$batch}->{job_batches} . "\n"; |
193
|
|
|
|
|
|
|
|
194
|
0
|
|
|
|
|
|
$self->batches->{total_processes} = $self->total_processes; |
195
|
0
|
|
|
|
|
|
$self->batches->{total_batches} = $self->total_batches; |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
$self->batches->{batch_count} = |
198
|
0
|
|
|
|
|
|
$href->{batch} . "/" . $self->total_batches; |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
} |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
1; |