Apoptosis/GTop.pm untested

filter: Statementstmt 0.0% 0 / 29 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 52 CC 5 SCAR 20.8
CC
5
Cov
0%
BEGIN
12.0
check_apoptosis_condition
12.0
setup
2.0
CRAP 8.0
1 # $Id: /mirror/perl/Catalyst-Plugin-Apoptosis/trunk/lib/Catalyst/Plugin/Apoptosis/GTop.pm 2552 2007-09-18T08:36:57.555445Z daisuke $
2 #
3 # Copyright (c) 2007 Daisuke Maki <daisuke@endeworks.jp>
4 # All rights reserved.
5  
6 package Catalyst::Plugin::Apoptosis::GTop;
7 use strict;
8 use base qw(Catalyst::Plugin::Apoptosis Class::Data::Inheritable);
9 use GTop;
10 BEGIN
11 {
12 if (my $code = GTop->can('THREADED')) {
13 if (! $code->()) {
14 delete $INC{'threads.pm'};
15 }
16 }
17 }
18  
19 __PACKAGE__->mk_classdata($_) for qw(gtop);
20  
21 sub setup
22 {
23 my ($class, @arguments) = @_;
24  
25 $class->NEXT::setup(@arguments);
26 $class->gtop(GTop->new);
27  
28 $class->config->{apoptosis}{gtop} ||= {};
29 }
30  
31 sub check_apoptosis_condition
32 {
33 my $class = shift;
34 my $pm = $class->gtop->proc_mem($$);
35  
36 my $config = $class->config->{apoptosis}{gtop};
37 foreach my $field qw(size vsize resident share rss) {
38 my $limit = $config->{$field};
39 defined $limit or next;
40 my $value = $pm->$field;
41 if ($value > $limit) {
42 $class->log->info("Apoptosis condition reached. Bailing out")
43 if $class->log->is_info;
44 Catalyst::Exception::Apoptosis->throw(message => "Apoptosis condition reached ($field [$value] > $limit)");
45 }
46 }
47 }
48  
49 1;
50  
51 __END__