Graph/Oracle.pm untested

filter: Statementstmt 0.0% 0 / 82 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 26 MC/DCmcdc 0.0% 0 / 16 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 147 CC 8 SCAR 29.1
CC
8
Cov
0%
read
30.0
new
20.0
get_data_type
2.0
CRAP 18.3
1 ################################################################################
2  
3 use strict;
4 use POSIX qw(mktime);
5 use StatsView::Graph;
6 package StatsView::Graph::Oracle;
7 @StatsView::Graph::Oracle::ISA = qw(StatsView::Graph);
8
9 ################################################################################
10  
11 sub new()
12 {
13 my ($class, $file, $fh) = @_;
14 $class = ref($class) || $class;
15  
16 # Look for the header line
17 my $line;
18 while (defined($line = $fh->getline()) && $line =~ /^\s*$/) { }
19 $line =~ /Oracle Statistics File/ || return(undef);
20  
21 # Read in all the categories
22 my $title;
23 my $self = $class->SUPER::init($file);
24 while (defined($line = $fh->getline()) && $line !~ /^\s*Data\s+/)
25 {
26 if ($line =~ /^Title:\s*(.*)/)
27 {
28 $title = $1;
29 $line = $fh->getline();
30 my ($tag, $type) = $line =~ /Statistics:\s*(\w+)\s+(\w+)/;
31 $type = ($type eq 'singlerow') ? '2d' : '3d';
32 $self->{info}->{$title} = { tag => qr/^$tag\s+(.*)/, type => $type};
33 push(@{$self->{category}}, $title)
34 }
35 }
36  
37 # Check the data tag line
38 die("$file is not a Oracle Statistics file (1)\n")
39 if ($line !~ /^\s*Data\s+rate:\s+\d+/);
40  
41 return($self);
42 }
43  
44 ################################################################################
45  
46 sub read($$)
47 {
48 my ($self, $category) = @_;
49 $self->SUPER::read($category);
50  
51 # Open the file
52 my $oracle = IO::File->new($self->{file}, "r")
53 || die("Can't open $self->{file}: $!\n");
54 $self->{title} = "Oracle $category";
55  
56 # Look for the banner line
57 my $line;
58 while (defined($line = $oracle->getline()) && $line =~ /^\s*$/) { }
59 $line =~ /Oracle Statistics File created on (\d\d\/\d\d\/\d\d(?:\d\d)?)/
60 || die("$self->{file} is not a Oracle Statistics file (2)\n");
61  
62 # Look for the header for the category
63 my ($tag, $type) = @{$self->{info}->{$category}}{qw(tag type)};
64 my ($headings, $formats);
65 while (defined($line = $oracle->getline()) && $line !~ /^\s*Data\s+/)
66 {
67 if ($line =~ /Title:\s*$category/)
68 {
69 $line = $oracle->getline(); # Skip Statistics: line
70 $line = $oracle->getline();
71 ($headings) = $line =~ /Headings:\s*(.*)/;
72 $line = $oracle->getline();
73 ($formats) = $line =~ /Formats:\s*(.*)/;
74 }
75 }
76  
77 # Define the column types - N = numeric, % = percentage
78 my @colname = split(',', $headings);
79 my @coltype = split('', $formats);
80 $self->define_cols(\@colname, \@coltype);
81  
82 # Store the interval information
83 $line =~ /^\s*Data\s+rate:\s+(\d+)\s*$/
84 || die("$self->{file} is not a Oracle Statistics file (3)\n");
85 $self->{interval} = $1;
86  
87 # Read in the data values
88 my $tstamp;
89 my $first_ts = 1;
90 while (defined($line = $oracle->getline()))
91 {
92 chomp($line);
93 if ($line =~ $tag)
94 {
95 my ($D, $M, $Y, $h, $m, $s) = split(/[\/: ]/, $1);
96 $M--; $Y -= 1900;
97 $tstamp = POSIX::mktime($s, $m, $h, $D, $M, $Y, 0, 0, -1);
98 push(@{$self->{tstamps}}, $tstamp);
99 if ($first_ts) { $self->{start} = $tstamp; $first_ts = 0; }
100 if ($type eq '2d')
101 {
102 $line = $oracle->getline(); chomp($line);
103 my @value = split(',', $line);
104 push(@{$self->{data}}, { tstamp => $tstamp, value => [ @value ] });
105 }
106 else
107 {
108 while (defined($line = $oracle->getline()) && $line !~ /^\s*$/)
109 {
110 chomp($line);
111 my ($inst, @value) = split(',', $line);
112 $self->define_inst($inst);
113 push(@{$self->{data}{$inst}},
114 { tstamp => $tstamp, value => [ @value ] });
115 }
116 }
117 }
118 }
119  
120 # Save the finish time
121 $self->{finish} = $tstamp;
122  
123 $oracle->close();
124 }
125  
126 ################################################################################
127  
128 sub get_data_type($;$)
129 {
130 my($self, $category) = @_;
131 return($self->{info}->{$category}->{type});
132 }
133  
134 ################################################################################
135 1;