| 1 | package Test2::Plugin::Times; | ||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 1 | ▶ | use Test2::Util::Times qw/render_bench render_duration/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 1 | ▶ | use Test2::API qw{ | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | test2_add_callback_exit | ||||||||||
| 9 | 1 | }; | |||||||||
| 10 | |||||||||||
| 11 | 1 | ▶ | use Time::HiRes qw/time/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 1 | our $VERSION = '1.302226'; | |||||||||
| 14 | |||||||||||
| 15 | 1 | my $ADDED_HOOK = 0; | |||||||||
| 16 | 1 | my $START; | |||||||||
| 17 | 1 | ▶ | sub import { | ||||||||
|
Subroutine
import: called CC=2 SCAR=7.1
| |||||||||||
| 18 | 1 | ▶ | return if $ADDED_HOOK++; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 19 | |||||||||||
| 20 | 1 | $START = time; | |||||||||
| 21 | 1 | test2_add_callback_exit(\&send_time_event); | |||||||||
| 22 | } | ||||||||||
| 23 | |||||||||||
| 24 | 1 | ▶ | sub send_time_event { | ||||||||
|
Subroutine
send_time_event: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 25 | 1 | my ($ctx, $real, $new) = @_; | |||||||||
| 26 | 1 | my $stop = time; | |||||||||
| 27 | 1 | my @times = times(); | |||||||||
| 28 | |||||||||||
| 29 | 1 | my $summary = render_bench($START, $stop, @times); | |||||||||
| 30 | 1 | my $duration = render_duration($START, $stop); | |||||||||
| 31 | |||||||||||
| 32 | 1 | 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 | 1; | |||||||||
| 55 | |||||||||||
| 56 | __END__ | ||||||||||