line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTTP::LoadGen::Logger; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
24595
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
76
|
|
4
|
2
|
|
|
2
|
|
2032
|
use Coro; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
use Coro qw/:prio/; |
6
|
|
|
|
|
|
|
use Coro::Channel; |
7
|
|
|
|
|
|
|
use Coro::Handle; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub get { |
12
|
|
|
|
|
|
|
my ($fh, $fmt)=@_; |
13
|
|
|
|
|
|
|
my $queue=Coro::Channel->new; |
14
|
|
|
|
|
|
|
$fh=\*STDOUT unless $fh; |
15
|
|
|
|
|
|
|
unless( ref $fh ) { |
16
|
|
|
|
|
|
|
my $name=$fh; |
17
|
|
|
|
|
|
|
undef $fh; |
18
|
|
|
|
|
|
|
open $fh, '>>', $name or die "Cannot open logfile $name: $!\n"; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
$fh=unblock $fh; |
21
|
|
|
|
|
|
|
my $thr=async { |
22
|
|
|
|
|
|
|
my ($fh)=@_; |
23
|
|
|
|
|
|
|
$Coro::current->prio(PRIO_MIN); |
24
|
|
|
|
|
|
|
while(defined(my $l=$queue->get)) { |
25
|
|
|
|
|
|
|
$fh->syswrite($l); |
26
|
|
|
|
|
|
|
cede; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
} $fh; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
if($fmt) { |
31
|
|
|
|
|
|
|
return sub { |
32
|
|
|
|
|
|
|
if(@_) { |
33
|
|
|
|
|
|
|
$queue->put(scalar $fmt->(@_)); |
34
|
|
|
|
|
|
|
} else { |
35
|
|
|
|
|
|
|
$queue->shutdown; |
36
|
|
|
|
|
|
|
$thr->join; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
}; |
39
|
|
|
|
|
|
|
} else { |
40
|
|
|
|
|
|
|
return sub { |
41
|
|
|
|
|
|
|
if(@_) { |
42
|
|
|
|
|
|
|
$queue->put(join("\t", @_)."\n"); |
43
|
|
|
|
|
|
|
} else { |
44
|
|
|
|
|
|
|
$queue->shutdown; |
45
|
|
|
|
|
|
|
$thr->join; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
}; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
1; |
52
|
|
|
|
|
|
|
__END__ |