line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HPC::Runner::Command::Utils::Base; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
404288
|
use Cwd; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
66
|
|
4
|
1
|
|
|
1
|
|
6
|
use File::Path qw(make_path remove_tree); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
44
|
|
5
|
1
|
|
|
1
|
|
288
|
use List::Uniq ':all'; |
|
1
|
|
|
|
|
511
|
|
|
1
|
|
|
|
|
98
|
|
6
|
1
|
|
|
1
|
|
5
|
use File::Spec; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
21
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
4
|
use MooseX::App::Role; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
10
|
|
9
|
1
|
|
|
1
|
|
6809
|
use MooseX::Types::Path::Tiny qw/Path Paths AbsPath AbsFile/; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
13
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 HPC::Runner::Command::Utils::Base |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Base class for HPC::Runner::Command libraries. |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
This is a Moose Role. To use in any another applications or plugins call as |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
package MyApp; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
use Moose; |
20
|
|
|
|
|
|
|
with 'HPC::Runner::Command::Utils::Base'; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head2 Command Line Options |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head3 infile |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
File of commands separated by newline. The command 'wait' indicates all previous commands should finish before starting the next one. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=cut |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
option 'infile' => ( |
32
|
|
|
|
|
|
|
is => 'rw', |
33
|
|
|
|
|
|
|
required => 1, |
34
|
|
|
|
|
|
|
documentation => |
35
|
|
|
|
|
|
|
q{File of commands separated by newline. The command 'wait' indicates all previous commands should finish before starting the next one.}, |
36
|
|
|
|
|
|
|
isa => AbsFile, |
37
|
|
|
|
|
|
|
coerce => 1, |
38
|
|
|
|
|
|
|
cmd_aliases => ['i'], |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head3 outdir |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Directory to write out files and optionally, logs. |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=cut |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
option 'outdir' => ( |
48
|
|
|
|
|
|
|
is => 'rw', |
49
|
|
|
|
|
|
|
isa => AbsPath, |
50
|
|
|
|
|
|
|
lazy => 1, |
51
|
|
|
|
|
|
|
coerce => 1, |
52
|
|
|
|
|
|
|
required => 1, |
53
|
|
|
|
|
|
|
default => \&set_outdir, |
54
|
|
|
|
|
|
|
documentation => q{Directory to write out files.}, |
55
|
|
|
|
|
|
|
trigger => \&_make_the_dirs, |
56
|
|
|
|
|
|
|
predicate => 'has_outdir', |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
option 'basedir' => ( |
60
|
|
|
|
|
|
|
is => 'rw', |
61
|
|
|
|
|
|
|
isa => AbsPath, |
62
|
|
|
|
|
|
|
lazy => 1, |
63
|
|
|
|
|
|
|
coerce => 1, |
64
|
|
|
|
|
|
|
required => 1, |
65
|
|
|
|
|
|
|
default => \&set_basedir, |
66
|
|
|
|
|
|
|
documentation => q{Base directory to write out files.}, |
67
|
|
|
|
|
|
|
trigger => \&_make_the_dirs, |
68
|
|
|
|
|
|
|
predicate => 'has_basedir', |
69
|
|
|
|
|
|
|
); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
#These two should both be in execute_jobs |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head3 procs |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Total number of concurrent running tasks. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Analagous to parallel --jobs i |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=cut |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
option 'procs' => ( |
82
|
|
|
|
|
|
|
is => 'rw', |
83
|
|
|
|
|
|
|
isa => 'Int', |
84
|
|
|
|
|
|
|
default => 1, |
85
|
|
|
|
|
|
|
required => 0, |
86
|
|
|
|
|
|
|
documentation => |
87
|
|
|
|
|
|
|
q{Total number of concurrently running jobs allowed at any time.} |
88
|
|
|
|
|
|
|
); |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
option 'poll_time' => ( |
91
|
|
|
|
|
|
|
is => 'rw', |
92
|
|
|
|
|
|
|
isa => 'Num', |
93
|
|
|
|
|
|
|
documentation => |
94
|
|
|
|
|
|
|
'Time in seconds to poll the process for memory profiling.', |
95
|
|
|
|
|
|
|
default => 5, |
96
|
|
|
|
|
|
|
cmd_aliases => ['pt'], |
97
|
|
|
|
|
|
|
); |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
option 'memory_diff' => ( |
100
|
|
|
|
|
|
|
is => 'rw', |
101
|
|
|
|
|
|
|
isa => 'Num', |
102
|
|
|
|
|
|
|
documentation => 'Difference from last memory profile in order to record.', |
103
|
|
|
|
|
|
|
default => 0.10, |
104
|
|
|
|
|
|
|
cmd_aliases => ['md'], |
105
|
|
|
|
|
|
|
); |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head2 Attributes |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=cut |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
has 'cmd' => ( |
112
|
|
|
|
|
|
|
traits => ['String'], |
113
|
|
|
|
|
|
|
is => 'rw', |
114
|
|
|
|
|
|
|
isa => 'Str', |
115
|
|
|
|
|
|
|
required => 0, |
116
|
|
|
|
|
|
|
handles => { |
117
|
|
|
|
|
|
|
add_cmd => 'append', |
118
|
|
|
|
|
|
|
match_cmd => 'match', |
119
|
|
|
|
|
|
|
}, |
120
|
|
|
|
|
|
|
predicate => 'has_cmd', |
121
|
|
|
|
|
|
|
clearer => 'clear_cmd', |
122
|
|
|
|
|
|
|
); |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head3 set_basedir |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=cut |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub set_basedir { |
129
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
130
|
|
|
|
|
|
|
|
131
|
1
|
50
|
|
|
|
34
|
if ( $self->has_basedir ) { |
132
|
0
|
|
|
|
|
0
|
make_path( $self->basedir ); |
133
|
0
|
|
|
|
|
0
|
return; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
1
|
|
|
|
|
29
|
my $dt = $self->dt; |
137
|
1
|
|
|
|
|
6
|
$dt = "$dt"; |
138
|
1
|
|
|
|
|
50
|
$dt =~ s/:/-/g; |
139
|
|
|
|
|
|
|
|
140
|
1
|
|
|
|
|
3
|
my $outdir; |
141
|
1
|
50
|
33
|
|
|
41
|
if ( $self->has_version && $self->has_git ) { |
142
|
0
|
0
|
|
|
|
0
|
if ( $self->has_project ) { |
143
|
0
|
|
|
|
|
0
|
$outdir = |
144
|
|
|
|
|
|
|
File::Spec->catdir( 'hpc-runner', $self->project, $dt, |
145
|
|
|
|
|
|
|
$self->version, ); |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
else { |
148
|
0
|
|
|
|
|
0
|
$outdir = File::Spec->catdir( 'hpc-runner', $dt, $self->version, ); |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
else { |
152
|
1
|
50
|
|
|
|
43
|
if ( $self->has_project ) { |
153
|
0
|
|
|
|
|
0
|
$outdir = File::Spec->catdir( 'hpc-runner', $dt, $self->project, ); |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
else { |
156
|
1
|
|
|
|
|
11
|
$outdir = File::Spec->catdir( 'hpc-runner', $dt ); |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
1
|
|
|
|
|
256
|
make_path($outdir); |
161
|
|
|
|
|
|
|
|
162
|
1
|
|
|
|
|
34
|
return $outdir; |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head3 set_outdir |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Internal variable |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=cut |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
##Why is this different from set logdir? |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
sub set_outdir { |
174
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
175
|
|
|
|
|
|
|
|
176
|
0
|
0
|
|
|
|
0
|
if ( $self->has_outdir ) { |
177
|
0
|
|
|
|
|
0
|
$self->_make_the_dirs( $self->outdir ); |
178
|
0
|
|
|
|
|
0
|
return; |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
|
181
|
0
|
|
|
|
|
0
|
my $outdir = File::Spec->catdir($self->basedir, 'scratch'); |
182
|
|
|
|
|
|
|
|
183
|
0
|
|
|
|
|
0
|
make_path($outdir); |
184
|
|
|
|
|
|
|
|
185
|
0
|
|
|
|
|
0
|
return $outdir; |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head3 make_the_dirs |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
Make any necessary directories |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=cut |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
sub _make_the_dirs { |
195
|
3
|
|
|
3
|
|
54
|
my ( $self, $outdir ) = @_; |
196
|
|
|
|
|
|
|
|
197
|
3
|
100
|
|
|
|
32
|
make_path($outdir) unless -d $outdir; |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=head3 datetime_now |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=cut |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
sub datetime_now { |
205
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
206
|
|
|
|
|
|
|
|
207
|
0
|
|
|
|
|
|
my $dt = DateTime->now( time_zone => 'local' ); |
208
|
|
|
|
|
|
|
|
209
|
0
|
|
|
|
|
|
my $ymd = $dt->ymd(); |
210
|
0
|
|
|
|
|
|
my $hms = $dt->hms(); |
211
|
|
|
|
|
|
|
|
212
|
0
|
|
|
|
|
|
return ( $dt, $ymd, $hms ); |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=head3 git_things |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
Get git versions, branch, and tags |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=cut |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
sub git_things { |
222
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
223
|
|
|
|
|
|
|
|
224
|
0
|
|
|
|
|
|
$self->init_git; |
225
|
0
|
|
|
|
|
|
$self->dirty_run; |
226
|
0
|
|
|
|
|
|
$self->git_info; |
227
|
|
|
|
|
|
|
|
228
|
0
|
0
|
|
|
|
|
return unless $self->has_git; |
229
|
|
|
|
|
|
|
|
230
|
0
|
0
|
|
|
|
|
return unless $self->has_version; |
231
|
|
|
|
|
|
|
|
232
|
0
|
0
|
|
|
|
|
if ( $self->tags ) { |
233
|
0
|
0
|
|
|
|
|
push( @{ $self->tags }, "$self->{version}" ) if $self->has_version; |
|
0
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
} |
235
|
|
|
|
|
|
|
else { |
236
|
0
|
|
|
|
|
|
$self->tags( [ $self->version ] ); |
237
|
|
|
|
|
|
|
} |
238
|
0
|
|
|
|
|
|
my @tmp = uniq( @{ $self->tags } ); |
|
0
|
|
|
|
|
|
|
239
|
0
|
|
|
|
|
|
$self->tags( \@tmp ); |
240
|
|
|
|
|
|
|
} |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
1; |