« blib/lib/HPC/Runner/Command/submit_jobs/Utils/Scheduler/Directives.pm
↑ Summary
blib/lib/HPC/Runner/Command/execute_job/Utils/Plugin.pm »
| 1 | package HPC::Runner::Command::submit_jobs::Utils::Scheduler::JobStats; | ||||||||||
| 2 | |||||||||||
| 3 | #use Moose::Role; | ||||||||||
| 4 | 1 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use JSON; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use List::MoreUtils qw(firstidx); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 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 | 1 | 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 | 1 | 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 | 0 | ▶ | default => sub { {} }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 59 | 1 | 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 | 0 | ▶ | default => sub { {} }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 70 | 1 | 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 | ▶ | my $self = shift; | ||||||||
|
Subroutine
create_meta_str: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 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 | ▶ | if ($use_batches) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | ▶ | my $self = shift; | ||||||||
|
Subroutine
collect_stats: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 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 | ▶ | if ( $self->exists_jobnames($current_job) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 157 | 0 | my $tarray = $self->jobnames->{$current_job}; | |||||||||
| 158 | 0 | push( @{$tarray}, $batch_counter . "_" . $current_job ); | |||||||||
| 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 | ▶ | my $self = shift; | ||||||||
|
Subroutine
do_stats: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 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} }; | |||||||||
| 184 | |||||||||||
| 185 | 0 | ▶ | my $index = firstidx { $_ eq $batch } @job_batches; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 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 | 1; | |||||||||