| 1 | package Net::Tomcat::Connector::Scoreboard; | ||
| 2 | |||
| 3 | 2 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 2 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 2 | ▶ | use overload ( '""' => \&pretty_print ); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | 2 | ▶ | use Net::Tomcat::Connector::Scoreboard::Entry; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | |||
| 10 | 2 | our $VERSION = '0.01'; | |
| 11 | 2 | our %STATES = ( | |
| 12 | R => 'ready', | ||
| 13 | P => 'parse', | ||
| 14 | S => 'service', | ||
| 15 | F => 'finish', | ||
| 16 | K => 'keepalive' | ||
| 17 | ); | ||
| 18 | |||
| 19 | 2 | foreach my $state ( keys %STATES ) {{ | |
| 20 | 2 | ▶ | no strict 'refs'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 21 | 10 | *{ __PACKAGE__ . '::threads_' . $STATES{ $state } } = sub { | |
| 22 | 0 | ▶ | my $self = shift; |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||
| 23 | 0 | return grep { $_->{stage} eq $state } @{ $self->{__threads} } | |
| 24 | } | ||
| 25 | 10 | }} | |
| 26 | |||
| 27 | sub new { | ||
| 28 | 0 | ▶ | my ( $class, @args ) = @_; |
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
documented
| |||
| 29 | 0 | my $self = bless {}, $class; | |
| 30 | 0 | $self->{__timestamp} = time; | |
| 31 | 0 | my @h = @{ shift @args }; | |
| 32 | |||
| 33 | 0 | for ( @args ) { | |
| 34 | 0 | my %a; | |
| 35 | 0 | @a{ @h } = @{ $_ }; | |
| 36 | 0 | push @{ $self->{__threads} }, Net::Tomcat::Connector::Scoreboard::Entry->new( %a ); | |
| 37 | } | ||
| 38 | |||
| 39 | 0 | return $self; | |
| 40 | } | ||
| 41 | |||
| 42 | 0 | ▶ | sub threads { return @{ $_[0]->{__threads } } } |
|
Subroutine
threads: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 43 | |||
| 44 | 0 | ▶ | sub thread_count { return scalar @{ $_[0]->{__threads} } } |
|
Subroutine
thread_count: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 45 | |||
| 46 | sub threads_for_client { | ||
| 47 | 0 | ▶ | my ( $self, $client ) = @_; |
|
Subroutine
threads_for_client: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 48 | 0 | return grep { $_->{client} eq $client } @{ $self->{__threads} }; | |
| 49 | } | ||
| 50 | |||
| 51 | sub threads_for_vhost { | ||
| 52 | 0 | ▶ | my ( $self, $vhost ) = @_; |
|
Subroutine
threads_for_vhost: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 53 | 0 | return grep { $_->{vhost} eq $vhost } @{ $self->{__threads} }; | |
| 54 | } | ||
| 55 | |||
| 56 | 0 | ▶ | sub __timestamp { return $_[0]->{__timestamp} } |
|
Subroutine
__timestamp: not called CC=1 SCAR=6.9
| |||
| 57 | |||
| 58 | sub pretty_print { | ||
| 59 | 0 | ▶ | my $self = shift; |
|
Subroutine
pretty_print: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 60 | 0 | print <<PP; | |
| 61 | +----------+----------+----------+----------+--------------------+--------------------+----------------------------------------+ | ||
| 62 | | Stage | Time | B Sent | B Recv | Client | VHost | Request | | ||
| 63 | +----------+----------+----------+----------+--------------------+--------------------+----------------------------------------+ | ||
| 64 | PP | ||
| 65 | map { | ||
| 66 | 0 | printf( "|%9s |%9s |%9s |%9s |%19s |%19s |%39s |\n", | |
| 67 | $_->stage, | ||
| 68 | $_->time, | ||
| 69 | $_->bytes_sent, | ||
| 70 | $_->bytes_received, | ||
| 71 | $_->client, | ||
| 72 | $_->vhost, | ||
| 73 | $_->request | ||
| 74 | ) | ||
| 75 | } $self->threads; | ||
| 76 | |||
| 77 | 0 | print "+----------+----------+----------+----------+--------------------+--------------------+----------------------------------------+\n"; | |
| 78 | } | ||
| 79 | |||
| 80 | 2 | 1; | |
| 81 | |||
| 82 | __END__ | ||