« blib/lib/HPC/Runner/Command/stats/Logger/JSON/Summary/TableOutput.pm
↑ Summary
blib/lib/HPC/Runner/Command/stats/Logger/JSON/Long/JSONOutput.pm »
| 1 | package HPC::Runner::Command::execute_job::Logger::JSON; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | with 'HPC::Runner::Command::execute_job::Logger::Lock'; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use JSON; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use File::Spec; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use DateTime; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use File::Path qw(make_path remove_tree); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use File::Slurp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Cwd; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use Time::HiRes; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 1 | has 'task_json' => ( | |||||||||||||||||||||||||||
| 18 | is => 'rw', | ||||||||||||||||||||||||||||
| 19 | isa => 'Str', | ||||||||||||||||||||||||||||
| 20 | default => '', | ||||||||||||||||||||||||||||
| 21 | required => 0, | ||||||||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 1 | has 'task_jobname' => ( | |||||||||||||||||||||||||||
| 25 | is => 'rw', | ||||||||||||||||||||||||||||
| 26 | isa => 'Str', | ||||||||||||||||||||||||||||
| 27 | required => 0, | ||||||||||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | sub parse_meta_str { | ||||||||||||||||||||||||||||
| 31 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
parse_meta_str: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 0 | my $job_meta = {}; | |||||||||||||||||||||||||||
| 34 | 0 | ▶ | if ( $self->metastr ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 0 | $job_meta = decode_json( $self->metastr ); | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | ▶ | if ( !$job_meta || !exists $job_meta->{jobname} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$job_meta and exists $job_meta->{"jobname"}
MC/DC0%0/2
$job_meta and exists $job_meta->{"jobname"}
$job_meta
exists $job_meta->{"jobname"}
Truth table0%0/3
A and B
A= $job_metaB= exists $job_meta->{"jobname"}
| |||||||||||||||||||||||||||||
| 39 | ##TO account for single_node mode | ||||||||||||||||||||||||||||
| 40 | 0 | $job_meta->{jobname} = $self->jobname; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 0 | $self->task_jobname( $job_meta->{jobname} ); | |||||||||||||||||||||||||||
| 44 | 0 | return $job_meta; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | sub create_json_task { | ||||||||||||||||||||||||||||
| 48 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
create_json_task: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 49 | 0 | my $cmdpid = shift; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 0 | my $job_meta = $self->parse_meta_str; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | my $task_obj = { | ||||||||||||||||||||||||||||
| 54 | pid => $cmdpid, | ||||||||||||||||||||||||||||
| 55 | start_time => $self->table_data->{start_time}, | ||||||||||||||||||||||||||||
| 56 | jobname => $job_meta->{jobname}, | ||||||||||||||||||||||||||||
| 57 | 0 | task_id => $self->counter, | |||||||||||||||||||||||||||
| 58 | }; | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | $task_obj->{scheduler_id} = $self->job_scheduler_id | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | if $self->can('scheduler_id'); | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 0 | my $data_dir = File::Spec->catdir( $self->data_dir, $self->task_jobname ); | |||||||||||||||||||||||||||
| 64 | 0 | make_path($data_dir); | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 0 | ▶ | if ( !$self->no_log_json ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 0 | $self->check_lock; | |||||||||||||||||||||||||||
| 68 | 0 | $self->write_lock; | |||||||||||||||||||||||||||
| 69 | 0 | $self->add_to_running( $data_dir, $task_obj ); | |||||||||||||||||||||||||||
| 70 | try { | ||||||||||||||||||||||||||||
| 71 | 0 | ▶ | $self->lock_file->remove; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 72 | 0 | }; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | return $task_obj; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | ##TODO Once we add to the complete | ||||||||||||||||||||||||||||
| 79 | ## Get all the for the tasks | ||||||||||||||||||||||||||||
| 80 | ## Compute mean, min, max of all tasks | ||||||||||||||||||||||||||||
| 81 | sub update_json_task { | ||||||||||||||||||||||||||||
| 82 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
update_json_task: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | # my @stats = ( 'vmpeak', 'vmrss', 'vmsize', 'vmhwm' ); | ||||||||||||||||||||||||||||
| 85 | # my $job_meta = $self->parse_meta_str; | ||||||||||||||||||||||||||||
| 86 | # my $basename = $self->data_tar->basename('.tar.gz'); | ||||||||||||||||||||||||||||
| 87 | # my $data_dir = File::Spec->catdir( $basename, $job_meta->{jobname} ); | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 0 | my $data_dir = File::Spec->catdir( $self->data_dir, $self->task_jobname ); | |||||||||||||||||||||||||||
| 90 | 0 | make_path($data_dir); | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 0 | my $tags = ""; | |||||||||||||||||||||||||||
| 93 | 0 | ▶ | if ( exists $self->table_data->{task_tags} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 0 | my $task_tags = $self->table_data->{task_tags}; | |||||||||||||||||||||||||||
| 95 | 0 | ▶ | if ($task_tags) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | 0 | $tags = $task_tags; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | # my $task_obj = $self->get_from_running($data_dir); | ||||||||||||||||||||||||||||
| 101 | 0 | my $task_obj = {}; | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 0 | $task_obj->{exit_time} = $self->table_data->{exit_time}; | |||||||||||||||||||||||||||
| 104 | 0 | $task_obj->{duration} = $self->table_data->{duration}; | |||||||||||||||||||||||||||
| 105 | 0 | $task_obj->{exit_code} = $self->table_data->{exitcode}; | |||||||||||||||||||||||||||
| 106 | 0 | $task_obj->{task_tags} = $tags; | |||||||||||||||||||||||||||
| 107 | 0 | $task_obj->{cmdpid} = $self->table_data->{cmdpid}; | |||||||||||||||||||||||||||
| 108 | 0 | $task_obj->{start_time} = $self->table_data->{start_time}; | |||||||||||||||||||||||||||
| 109 | 0 | $task_obj->{task_id} = $self->table_data->{task_id}; | |||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | # $task_obj->{memory_profile} = {}; | ||||||||||||||||||||||||||||
| 112 | # | ||||||||||||||||||||||||||||
| 113 | # foreach my $stat (@stats) { | ||||||||||||||||||||||||||||
| 114 | # $task_obj->{memory_profile}->{$stat}->{low} = | ||||||||||||||||||||||||||||
| 115 | # $self->task_mem_data->{low}->{$stat}; | ||||||||||||||||||||||||||||
| 116 | # $task_obj->{memory_profile}->{$stat}->{high} = | ||||||||||||||||||||||||||||
| 117 | # $self->task_mem_data->{high}->{$stat}; | ||||||||||||||||||||||||||||
| 118 | # $task_obj->{memory_profile}->{$stat}->{mean} = | ||||||||||||||||||||||||||||
| 119 | # $self->task_mem_data->{mean}->{$stat}; | ||||||||||||||||||||||||||||
| 120 | # $task_obj->{memory_profile}->{$stat}->{count} = | ||||||||||||||||||||||||||||
| 121 | # $self->task_mem_data->{count}->{$stat}; | ||||||||||||||||||||||||||||
| 122 | # } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 0 | ▶ | if ( !$self->no_log_json ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | 0 | $self->check_lock; | |||||||||||||||||||||||||||
| 126 | 0 | $self->write_lock; | |||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 0 | $self->remove_from_running($data_dir); | |||||||||||||||||||||||||||
| 129 | ##TODO Add in mem for job | ||||||||||||||||||||||||||||
| 130 | 0 | $self->add_to_complete( $data_dir, $task_obj ); | |||||||||||||||||||||||||||
| 131 | try { | ||||||||||||||||||||||||||||
| 132 | 0 | ▶ | $self->lock_file->remove; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 133 | 0 | }; | |||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 0 | $task_obj->{pid} = $self->table_data->{cmdpid}; | |||||||||||||||||||||||||||
| 137 | 0 | $task_obj->{start_time_dt} = $self->table_data->{start_time_dt}; | |||||||||||||||||||||||||||
| 138 | 0 | return $task_obj; | |||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | sub add_to_complete { | ||||||||||||||||||||||||||||
| 142 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
add_to_complete: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 143 | 0 | my $data_dir = shift; | |||||||||||||||||||||||||||
| 144 | 0 | my $task_data = shift; | |||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 0 | my $c_file = File::Spec->catfile( $data_dir, 'complete.json' ); | |||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 0 | my $json_obj = $self->read_json($c_file); | |||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 0 | $json_obj->{ $self->counter } = $task_data; | |||||||||||||||||||||||||||
| 151 | 0 | $self->write_json( $c_file, $json_obj ); | |||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 0 | return $json_obj; | |||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | ## keep this or no? | ||||||||||||||||||||||||||||
| 157 | ##TODO Create Mem profile file | ||||||||||||||||||||||||||||
| 158 | sub create_task_file { | ||||||||||||||||||||||||||||
| 159 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
create_task_file: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 160 | 0 | my $data_dir = shift; | |||||||||||||||||||||||||||
| 161 | 0 | my $json_obj = shift; | |||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 0 | my $t_file = File::Spec->catfile( $data_dir, $self->counter . '.json' ); | |||||||||||||||||||||||||||
| 164 | 0 | $self->write_json( $t_file, $json_obj, ); | |||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | sub add_to_running { | ||||||||||||||||||||||||||||
| 168 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
add_to_running: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 169 | 0 | my $data_dir = shift; | |||||||||||||||||||||||||||
| 170 | 0 | my $task_data = shift; | |||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 0 | my $r_file = File::Spec->catfile( $data_dir, 'running.json' ); | |||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 0 | my $json_obj = $self->read_json( $r_file, ); | |||||||||||||||||||||||||||
| 175 | 0 | $json_obj->{ $self->counter } = $task_data; | |||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 0 | $self->write_json( $r_file, $json_obj, ); | |||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | sub remove_from_running { | ||||||||||||||||||||||||||||
| 181 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
remove_from_running: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 182 | 0 | my $data_dir = shift; | |||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | 0 | my $r_file = File::Spec->catfile( $data_dir, 'running.json' ); | |||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | 0 | my $json_obj = $self->read_json( $r_file, ); | |||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | 0 | delete $json_obj->{ $self->table_data->{task_id} }; | |||||||||||||||||||||||||||
| 189 | 0 | $self->write_json( $r_file, $json_obj, ); | |||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | sub get_from_running { | ||||||||||||||||||||||||||||
| 193 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
get_from_running: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 194 | 0 | my $data_dir = shift; | |||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | 0 | my $r_file = File::Spec->catfile( $data_dir, 'running.json' ); | |||||||||||||||||||||||||||
| 197 | 0 | my $json_obj = $self->read_json( $r_file, ); | |||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | 0 | return $json_obj->{ $self->table_data->{task_id} }; | |||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | sub read_json { | ||||||||||||||||||||||||||||
| 203 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
read_json: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 204 | 0 | my $file = shift; | |||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | 0 | my $json_obj = {}; | |||||||||||||||||||||||||||
| 207 | 0 | my $text; | |||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | 0 | ▶ | if ( -e $file ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 210 | 0 | $text = read_file($file); | |||||||||||||||||||||||||||
| 211 | try { | ||||||||||||||||||||||||||||
| 212 | 0 | ▶ | $json_obj = decode_json($text) if $text; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 213 | 0 | }; | |||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | 0 | return $json_obj; | |||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | sub write_json { | ||||||||||||||||||||||||||||
| 220 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
write_json: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 221 | 0 | my $file = shift; | |||||||||||||||||||||||||||
| 222 | 0 | my $json_obj = shift; | |||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | 0 | ▶ | return unless $json_obj; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 225 | 0 | my $json_text = ''; | |||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | try { | ||||||||||||||||||||||||||||
| 228 | 0 | ▶ | $json_text = encode_json($json_obj); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||
| 230 | catch { | ||||||||||||||||||||||||||||
| 231 | 0 | ▶ | $json_text = ''; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 232 | 0 | }; | |||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | 0 | write_file($file, $json_text); | |||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | 1 | 1; | |||||||||||||||||||||||||||