Oracle/BufferCache.pm untested

filter: Statementstmt 0.0% 0 / 35 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 21 MC/DCmcdc 0.0% 0 / 14 Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 78 CC 2 SCAR 12.8
CC
2
Cov
0%
sample
6.0
new
2.0
BEGIN
2.0
CRAP 3.6
1 ################################################################################
2 # Monitor the Buffer Cache
3  
4 use strict;
5 use StatsView::Oracle::Monitor;
6 package StatsView::Oracle::BufferCache;
7 @StatsView::Oracle::BufferCache::ISA = qw(StatsView::Oracle::Monitor);
8  
9 ################################################################################
10  
11 sub new($$$$)
12 {
13 my ($class, $db, $fh, $rate) = @_;
14 $class = ref($class) || $class;
15 my $self = $class->SUPER::new($db, $fh, $rate);
16 my $query = q(select /*+ rule */ name, value from v$sysstat where
17 name in ('db block gets', 'consistent gets', 'physical reads'));
18 $self->{cursor} = $db->prepare($query);
19 $self->header("singlerow", "Buffer Cache activity",
20 "I/O Requests/Sec,Physical I/Os/Sec,Hit Ratio", "NN%");
21 $self->{cursor}->execute();
22 my ($io_req, $phys_io) = (0, 0);
23 while (my ($k, $v) = $self->{cursor}->fetchrow())
24 {
25 $k eq 'db block gets' && ($io_req += $v);
26 $k eq 'consistent gets' && ($io_req += $v);
27 $k eq 'physical reads' && ($phys_io = $v);
28 }
29 @$self{qw(io_req phys_io)} = ($io_req, $phys_io);
30 return($self);
31 }
32  
33 ##############################################################################
34  
35 sub sample($$)
36 {
37 my ($self, $ts) = @_;
38 $self->{cursor}->execute();
39 my ($io_req, $phys_io) = (0, 0);
40 while (my ($k, $v) = $self->{cursor}->fetchrow())
41 {
42 $k eq 'db block gets' && ($io_req += $v);
43 $k eq 'consistent gets' && ($io_req += $v);
44 $k eq 'physical reads' && ($phys_io = $v);
45 }
46 my $d_io_req = ($io_req - $self->{io_req}) / $self->{rate};
47 my $d_phys_io = ($phys_io - $self->{phys_io}) / $self->{rate};
48 @$self{qw(io_req phys_io)} = ($io_req, $phys_io);
49 my $ratio = $d_io_req ? (1 - $d_phys_io / $d_io_req) * 100 : 100;
50 $self->data($ts, "$d_io_req,$d_phys_io,$ratio");
51 }
52  
53 ################################################################################
54 1;