Oracle.pm untested

filter: Statementstmt 0.0% 0 / 62 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 91 CC 2 SCAR 10.0
CC
2
Cov
0%
new
6.0
harikari
2.0
run
2.0
CRAP 2.7
1 use strict;
2 use IO::File;
3 use DBI;
4 use vars qw($VERSION);
5 $VERSION='1.05';
6  
7 package StatsView::Oracle;
8 use vars qw ($Finished);
9  
10 ################################################################################
11  
12 sub harikari(@)
13 {
14 my $msg = "@_";
15 $msg =~ s/ at .*$//;
16 print($msg);
17 exit(1);
18 }
19  
20 ################################################################################
21  
22 sub new($$$$$$$;)
23 {
24 my ($class, $database, $username, $password,
25 $file, $rate, $skew, @monitors) = @_;
26 $class = ref($class) || $class;
27 my $self = { skew => $skew, rate => $rate };
28  
29 # Check rate and skew are valid
30 die("Invalid rate/skew combination\n") if ($rate < $skew * scalar(@monitors));
31  
32 # Connect to Oracle
33 local $SIG{__DIE__} = \&harikari;
34 $self->{db} = DBI->connect("dbi:Oracle:$database", $username, $password,
35 { AutoCommit => 0, RaiseError => 1 });
36  
37 # Open the output file
38 $self->{fh} = IO::File->new($file, "w") || die("Can't open $file: $!\n");
39  
40 # Write the header
41 my ($D, $M, $Y) = (localtime())[3,4,5]; $M++; $Y += 1900;
42 $self->{fh}->printf("Oracle Statistics File created on %.2d/%.2d/%.4d\n\n",
43 $D, $M, $Y);
44  
45 # Create the monitors
46 my $path = $class;
47 $path =~ s!::!/!g;
48 foreach my $monitor (@monitors)
49 {
50 require "$path/$monitor.pm";
51 push(@{$self->{monitors}},
52 "${class}::${monitor}"->new($self->{db}, $self->{fh}, $rate));
53 }
54  
55 # Start the data section
56 $self->{fh}->print("Data rate: $self->{rate}\n\n");
57  
58 return(bless($self, $class));
59 }
60  
61 ################################################################################
62  
63 sub run($$)
64 {
65 my ($self, $count) = @_;
66 my ($rate, $skew) = @$self{qw(rate skew)};
67 my $sleep = $rate - (scalar(@{$self->{monitors}}) * $skew);
68 local $SIG{__DIE__} = \&harikari;
69 while ($count-- != 0 && ! $StatsView::Oracle::Finished)
70 {
71 foreach my $monitor (@{$self->{monitors}})
72 {
73 my ($s, $m, $h, $D, $M, $Y) = localtime();
74 $M++; $Y += 1900;
75 my $ts = sprintf("%.2d/%.2d/%.4d %2d:%.2d:%.2d", $D, $M, $Y, $h, $m, $s);
76 $monitor->sample($ts);
77 sleep($skew);
78 }
79 sleep($sleep);
80 }
81 }
82  
83 ################################################################################
84  
85 sub DESTROY($)
86 {
87 my ($self) = @_;
88 undef($self->{monitors});
89 $self->{fh}->close();
90 local $SIG{__DIE__} = \&harikari;
91 $self->{db}->disconnect();
92 }
93  
94 ################################################################################
95 1;