File Coverage

blib/lib/Test2/Plugin/Times.pm
Criterion Covered Total %
statement 24 24 100.0
branch 1 2 50.0
condition n/a
subroutine 7 7 100.0
pod 0 1 0.0
total 32 34 94.1


line stmt bran cond sub pod time code
1             package Test2::Plugin::Times;
2 1     1   656 use strict;
  1         3  
  1         29  
3 1     1   5 use warnings;
  1         2  
  1         28  
4              
5 1     1   435 use Test2::Util::Times qw/render_bench render_duration/;
  1         6  
  1         61  
6              
7 1         40 use Test2::API qw{
8             test2_add_callback_exit
9 1     1   7 };
  1         2  
10              
11 1     1   5 use Time::HiRes qw/time/;
  1         2  
  1         9  
12              
13             our $VERSION = '0.000156';
14              
15             my $ADDED_HOOK = 0;
16             my $START;
17             sub import {
18 1 50   1   9 return if $ADDED_HOOK++;
19              
20 1         8 $START = time;
21 1         3 test2_add_callback_exit(\&send_time_event);
22             }
23              
24             sub send_time_event {
25 1     1 0 504 my ($ctx, $real, $new) = @_;
26 1         5 my $stop = time;
27 1         16 my @times = times();
28              
29 1         8 my $summary = render_bench($START, $stop, @times);
30 1         13 my $duration = render_duration($START, $stop);
31              
32 1         27 my $e = $ctx->send_ev2(
33             about => {package => __PACKAGE__, details => $summary},
34             info => [{tag => 'TIME', details => $summary}],
35             times => {
36             details => $summary,
37             start => $START,
38             stop => $stop,
39             user => $times[0],
40             sys => $times[1],
41             cuser => $times[2],
42             csys => $times[3],
43             },
44             harness_job_fields => [
45             {name => "time_duration", details => $duration},
46             {name => "time_user", details => $times[0]},
47             {name => "time_sys", details => $times[1]},
48             {name => "time_cuser", details => $times[2]},
49             {name => "time_csys", details => $times[3]},
50             ],
51             );
52             }
53              
54             1;
55              
56             __END__