line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Harbinger::Client::Doom; |
2
|
|
|
|
|
|
|
$Harbinger::Client::Doom::VERSION = '0.001001'; |
3
|
1
|
|
|
1
|
|
3
|
use List::Util 'first'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
89
|
|
4
|
1
|
|
|
1
|
|
4
|
use Module::Runtime 'use_module'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
4
|
|
5
|
1
|
|
|
1
|
|
36
|
use Sereal::Encoder 'encode_sereal'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
51
|
|
6
|
1
|
|
|
1
|
|
4
|
use Try::Tiny; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
36
|
|
7
|
1
|
|
|
1
|
|
516
|
use Time::HiRes; |
|
1
|
|
|
|
|
1223
|
|
|
1
|
|
|
|
|
4
|
|
8
|
1
|
|
|
1
|
|
93
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
3
|
|
9
|
1
|
|
|
1
|
|
221
|
use warnings NONFATAL => 'all'; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
147
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub _measure_memory { |
12
|
|
|
|
|
|
|
my $pid = shift; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $ret = try { |
15
|
|
|
|
|
|
|
if ($^O eq 'MSWin32') { |
16
|
|
|
|
|
|
|
use_module('Win32::Process::Memory') |
17
|
|
|
|
|
|
|
->new({ pid => $pid }) |
18
|
|
|
|
|
|
|
->get_memtotal |
19
|
|
|
|
|
|
|
} else { |
20
|
|
|
|
|
|
|
( |
21
|
|
|
|
|
|
|
first { $_->pid == $pid } @{ |
22
|
|
|
|
|
|
|
use_module('Proc::ProcessTable') |
23
|
|
|
|
|
|
|
->new |
24
|
|
|
|
|
|
|
->table |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
)->rss |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
} catch { 0 }; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
int($ret / 1024) |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
1
|
|
|
1
|
|
435
|
use namespace::clean; |
|
1
|
|
|
|
|
7518
|
|
|
1
|
|
|
|
|
5
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
has pid => ( |
36
|
|
|
|
|
|
|
is => 'rw', |
37
|
|
|
|
|
|
|
default => sub { $$ }, |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
has [qw( |
41
|
|
|
|
|
|
|
server ident |
42
|
|
|
|
|
|
|
count port milliseconds_elapsed db_query_count memory_growth_in_kb |
43
|
|
|
|
|
|
|
_start_time _start_kb query_logger |
44
|
|
|
|
|
|
|
)] => ( is => 'rw' ); |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
0
|
0
|
0
|
0
|
sub bode_ill { $_[0]->count($_[0]->count||0 + 1) } |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub start { |
49
|
0
|
|
|
0
|
0
|
0
|
my ($self, @args) = @_; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
shift->new({ |
52
|
0
|
|
|
|
|
0
|
_start_time => [ Time::HiRes::gettimeofday ], |
53
|
|
|
|
|
|
|
_start_kb => _measure_memory($$), |
54
|
|
|
|
|
|
|
query_logger => use_module('DBIx::Class::QueryLog')->new, |
55
|
|
|
|
|
|
|
@args, |
56
|
|
|
|
|
|
|
}) |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub finish { |
60
|
0
|
|
|
0
|
0
|
0
|
my ($self, %args) = @_; |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
0
|
$self->milliseconds_elapsed( |
63
|
|
|
|
|
|
|
int(Time::HiRes::tv_interval($self->_start_time) * 1000) |
64
|
|
|
|
|
|
|
); |
65
|
0
|
|
|
|
|
0
|
$self->db_query_count($self->query_logger->count); |
66
|
0
|
|
|
|
|
0
|
$self->memory_growth_in_kb(_measure_memory($self->pid) - $self->_start_kb); |
67
|
0
|
|
|
|
|
0
|
$self->$_($args{$_}) for keys %args; |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
0
|
return $self |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
my %mapping = ( |
73
|
|
|
|
|
|
|
port => 'port', |
74
|
|
|
|
|
|
|
milliseconds_elapsed => 'ms', |
75
|
|
|
|
|
|
|
db_query_count => 'qc', |
76
|
|
|
|
|
|
|
memory_growth_in_kb => 'mg', |
77
|
|
|
|
|
|
|
count => 'c', |
78
|
|
|
|
|
|
|
); |
79
|
|
|
|
|
|
|
sub _as_sereal { |
80
|
3
|
|
|
3
|
|
20
|
my $self = shift; |
81
|
|
|
|
|
|
|
|
82
|
3
|
|
|
|
|
5
|
for my $thing (qw(server ident pid)) { |
83
|
6
|
100
|
|
|
|
31
|
unless ($self->$thing) { |
84
|
2
|
50
|
|
|
|
30
|
warn "$thing can't be blank" if $ENV{HARBINGER_WARNINGS}; |
85
|
|
|
|
|
|
|
return |
86
|
2
|
|
|
|
|
129
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
5
|
|
|
|
|
5
|
return encode_sereal({ |
90
|
|
|
|
|
|
|
server => $self->server, |
91
|
|
|
|
|
|
|
ident => $self->ident, |
92
|
|
|
|
|
|
|
pid => $self->pid, |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
map { |
95
|
1
|
|
|
|
|
9
|
my $m = $mapping{$_}; |
96
|
5
|
50
|
|
|
|
45
|
defined $self->$_ ? ( $m => 0 + $self->$_ ) : () |
97
|
|
|
|
|
|
|
} keys %mapping |
98
|
|
|
|
|
|
|
}) |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |