File Coverage

blib/lib/HPC/Runner/Command/submit_jobs/Utils/Log.pm
Criterion Covered Total %
statement 18 89 20.2
branch 0 2 0.0
condition 0 2 0.0
subroutine 6 10 60.0
pod 1 4 25.0
total 25 107 23.3


line stmt bran cond sub pod time code
1             package HPC::Runner::Command::submit_jobs::Utils::Log;
2              
3 1     1   1188 use Moose::Role;
  1         3  
  1         9  
4 1     1   5348 use namespace::autoclean;
  1         3  
  1         10  
5             with 'HPC::Runner::Command::Utils::Log';
6              
7 1     1   538 use Text::ASCIITable;
  1         5766  
  1         50  
8 1     1   7 use File::Spec;
  1         2  
  1         22  
9 1     1   4 use File::Slurp;
  1         3  
  1         62  
10 1     1   6 use Log::Log4perl qw(:easy);
  1         2  
  1         10  
11              
12             sub print_table_schedule_info {
13 0     0 0   my $self = shift;
14 0           my $t = Text::ASCIITable->new();
15              
16 0           my @rows = ();
17 0           foreach my $job ( $self->all_schedules ) {
18 0           my $row = [];
19 0           my $ref = $self->graph_job_deps->{$job};
20              
21 0           push( @$row, $job );
22              
23 0           my $depstring = join( ", ", @{$ref} );
  0            
24 0           push( @$row, $depstring );
25              
26 0           my $count_cmd = $self->jobs->{$job}->cmd_counter;
27 0           push( @$row, $count_cmd );
28              
29 0           my $mem = $self->jobs->{$job}->mem;
30 0           push( @$row, $mem );
31              
32 0           my $cpus = $self->jobs->{$job}->cpus_per_task;
33 0           push( @$row, $cpus );
34              
35 0           $self->assign_num_max_array($job);
36 0           my $array_count = $self->jobs->{$job}->{num_job_arrays};
37              
38 0           push( @$row, $array_count );
39              
40 0           push( @rows, $row );
41             }
42              
43             $t->setCols(
44 0           [ "JobName", "Deps", "Task Count", "Mem", "Cpu", "Num Arrays" ] );
45 0           map { $t->addRow($_) } @rows;
  0            
46 0           $self->app_log->info(
47             "Here is your tabular dependency list in submission order");
48 0           $self->app_log->info( "\n\n" . $t );
49             }
50              
51             =head3 summarize_jobs
52              
53             =cut
54              
55             #TODO Update this!
56              
57             sub summarize_jobs {
58 0     0 1   my $self = shift;
59              
60 0           my $t = Text::ASCIITable->new();
61 0           my $x = 0;
62 0           my @rows = ();
63              
64             #SIGHS
65             #cmd_start is zero indexes
66             #But batches are 1 indexes
67             #WHY DO I DO THIS TO MYSELF
68 0           foreach my $job ( $self->all_schedules ) {
69              
70 0           my $cmd_start = $self->jobs->{$job}->{cmd_start};
71 0           my $commands_per_node = $self->jobs->{$job}->commands_per_node;
72              
73 0           for ( my $x = 0 ; $x < $self->jobs->{$job}->{num_job_arrays} ; $x++ ) {
74 0           my $row = [];
75              
76 0 0         next unless $self->jobs->{$job}->batch_indexes->[$x];
77              
78 0           my $batch_indexes = $self->jobs->{$job}->batch_indexes->[$x];
79              
80 0           my $batch_index_start = $batch_indexes->{batch_index_start} - 1;
81 0           my $batch_index_end = $batch_indexes->{batch_index_end} - 1;
82              
83             my $start_array =
84             $self->jobs->{$job}->batches->[$batch_index_start]->{cmd_start} +
85 0           $cmd_start;
86              
87             my $end_array =
88             $self->jobs->{$job}->batches->[$batch_index_end]->{cmd_start} +
89             $cmd_start - 1 +
90 0           $self->jobs->{$job}->commands_per_node;
91              
92 0           my $len = $end_array - $start_array + 1;
93              
94 0           push( @{$row}, $job );
  0            
95 0   0       push( @{$row}, $self->jobs->{$job}->scheduler_ids->[$x] || '0' );
  0            
96 0           push( @{$row}, "$start_array-$end_array" );
  0            
97 0           push( @{$row}, $len );
  0            
98 0           push( @rows, $row );
99             }
100             }
101              
102             $t->setCols(
103 0           [ "Job Name", "Scheduler ID", "Task Indices", "Total Tasks" ] );
104 0           map { $t->addRow($_) } @rows;
  0            
105 0           $self->app_log->info("Job Summary");
106 0           $self->app_log->info( "\n" . $t );
107              
108 0           return \@rows;
109             }
110              
111             sub write_job_project_table {
112 0     0 0   my $self = shift;
113              
114 0           my $job_file = File::Spec->catdir( $self->logdir, 'project_job_table.md' );
115 0           write_file( $job_file, '| Job | Status | Notes |'."\n" );
116 0           foreach my $job ( $self->all_schedules ) {
117 0           write_file($job_file, {append => 1}, '| '.$job.' | | |'."\n");
118             }
119 0           $self->app_log->info('Project table per job: '.$job_file);
120             }
121              
122             sub write_task_project_table {
123 0     0 0   my $self = shift;
124              
125 0           my $task_file = File::Spec->catdir( $self->logdir, 'project_task_table.md' );
126 0           write_file( $task_file, '| Job | TaskID | Status | Notes |'."\n" );
127 0           foreach my $job ( $self->all_schedules ) {
128 0           my $cmd_start = $self->jobs->{$job}->{cmd_start} + 1;
129 0           my $cmd_end = $self->jobs->{$job}->cmd_counter + $cmd_start - 1;
130 0           for(my $x=$cmd_start; $x<=$cmd_end; $x++){
131 0           write_file($task_file, {append => 1}, '| '.$job.' | '.$x.' | | |'."\n");
132             }
133             }
134              
135 0           $self->app_log->info('Project table per task: '.$task_file);
136             }
137              
138             1;