| 1 | package Git::Deploy::Timing; | ||||||||||
| 2 | 20 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 20 | ▶ | use warnings FATAL => "all"; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 20 | ▶ | use Exporter 'import'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 20 | ▶ | use Time::HiRes; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 20 | our @EXPORT = qw( | |||||||||
| 8 | push_timings | ||||||||||
| 9 | should_write_timings | ||||||||||
| 10 | write_timings | ||||||||||
| 11 | ); | ||||||||||
| 12 | |||||||||||
| 13 | 20 | our (@timings, $write_timings, @real_argv); | |||||||||
| 14 | 20 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | # @timings is a set of 4-tuples: [ $tag, $time_stamp, $time_since_last_step, $time_since_start_tag ] | ||||||||||
| 16 | 20 | @timings= ( | |||||||||
| 17 | [ | ||||||||||
| 18 | 'gdt_start', # tagname | ||||||||||
| 19 | $^T, # process start time (set by Perl at perl startup) | ||||||||||
| 20 | -1, # time since last step (-1 == Not Applicable) | ||||||||||
| 21 | -1, # time since start tag - only relevant on _end tags (-1 == Not Applicable) | ||||||||||
| 22 | ] | ||||||||||
| 23 | ); | ||||||||||
| 24 | # if this is true then we will write a timings file at process conclusion | ||||||||||
| 25 | 20 | $write_timings= 0; | |||||||||
| 26 | 20 | @real_argv= @ARGV; | |||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | 0 | ▶ | sub should_write_timings { | ||||||||
|
Subroutine
should_write_timings: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 30 | 0 | $write_timings= 1; | |||||||||
| 31 | } | ||||||||||
| 32 | |||||||||||
| 33 | 18 | ▶ | sub push_timings { | ||||||||
|
Subroutine
push_timings: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||
| 34 | 18 | my $tag= shift; | |||||||||
| 35 | 18 | $tag =~ s/[^a-zA-Z0-9_]+/_/g; # strip any bogosity from the tag | |||||||||
| 36 | 18 | my $time= Time::HiRes::time(); | |||||||||
| 37 | 18 | my $elapsed= -1; | |||||||||
| 38 | 18 | ▶ | if ($tag=~/_end\z/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | 14 | (my $start= $tag)=~s/_end\z/_start/; | |||||||||
| 40 | 14 | foreach my $timing (@timings) { | |||||||||
| 41 | 18 | ▶ | next unless $timing->[0] eq $start; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 42 | 14 | $elapsed= $time - $timing->[1]; | |||||||||
| 43 | 14 | last; | |||||||||
| 44 | } | ||||||||||
| 45 | } | ||||||||||
| 46 | 18 | push @timings, [ $tag, $time, $time - $timings[-1][1], $elapsed ]; | |||||||||
| 47 | } | ||||||||||
| 48 | |||||||||||
| 49 | 12 | ▶ | sub write_timings { | ||||||||
|
Subroutine
write_timings: called CC=6 SCAR=35.1
Pod
undocumented
| |||||||||||
| 50 | 12 | ▶ | return unless $write_timings; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | # Do we even have to write the timing data? | ||||||||||
| 52 | 0 | require Git::Deploy; | |||||||||
| 53 | 0 | ▶ | return unless Git::Deploy::get_config_bool("log-timing-data",'false'); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | # Where do we write it? | ||||||||||
| 55 | 0 | my $log_directory; | |||||||||
| 56 | 0 | ▶ | unless ( $log_directory = Git::Deploy::log_directory() ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | 0 | warn "Not writing timing data: 'log_directory' has not been configured."; | |||||||||
| 58 | 0 | return; | |||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | 0 | my $timing_file= "$log_directory/timing_gdt-$timings[0][1].txt"; | |||||||||
| 62 | open my $fh, '>', $timing_file | ||||||||||
| 63 | 0 | ▶ | or do { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | 0 | warn "Not writing timing data: failed to open timing file '$timing_file': $!"; | |||||||||
| 65 | 0 | return; | |||||||||
| 66 | }; | ||||||||||
| 67 | 0 | print $fh "# ". join("\t",$0,@real_argv),"\n"; | |||||||||
| 68 | 0 | for my $timing (@timings) { | |||||||||
| 69 | 0 | print $fh join("\t",@$timing),"\n"; | |||||||||
| 70 | } | ||||||||||
| 71 | 0 | close $fh; | |||||||||
| 72 | } | ||||||||||
| 73 | |||||||||||
| 74 | 20 | 1; | |||||||||