Trace.pm

filter: Statementstmt 95.6% 110 / 115 Branchbran 60.0% 24 / 40 Conditioncond 53.8% 7 / 13 MC/DCmcdc 14.2% 1 / 7 Subroutinesub 94.7% 18 / 19 Podpod 90.0% 9 / 10 totaltotal 82.8% 169 / 204 CC 27 SCAR 14.9
CC
27
Cov
84%
parse
9.2
mini_report
5.1
test_report
4.7
CRAP 4.4
« Trace/Footer.pm ↑ Summary Trace/Utils.pm »
1 #
2 # $Id: Trace.pm,v 1.6 2003/12/24 20:38:54 oratrc Exp $
3 #
4 package Oracle::Trace;
5  
6 1 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use FileHandle;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Oracle::Trace::Header;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Oracle::Trace::Entry;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Oracle::Trace::Footer;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Oracle::Trace::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 our @ISA = qw(Oracle::Trace::Utils);
17  
18 1 our $VERSION = do { my @r = (q$Revision: 1.8 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
19  
20 1 ▶my $DEBUG = $ENV{Oracle_Trace_DEBUG} || 0;
Condition50%1/2
$ENV{'Oracle_Trace_DEBUG'} || 0
l!l
01
MC/DC0%0/1
$ENV{'Oracle_Trace_DEBUG'} || 0
$ENV{'Oracle_Trace_DEBUG'}
Truth table50%1/2
A
A= $ENV{'Oracle_Trace_DEBUG'}
Aresult
11
00
21 1 ▶my $EXTENDED = $ENV{Oracle_Trace_EXTENDED} || 0;
Condition50%1/2
$ENV{'Oracle_Trace_EXTENDED'} || 0
l!l
01
MC/DC0%0/1
$ENV{'Oracle_Trace_EXTENDED'} || 0
$ENV{'Oracle_Trace_EXTENDED'}
Truth table50%1/2
A
A= $ENV{'Oracle_Trace_EXTENDED'}
Aresult
11
00
22 1 ▶my $RECURSE = $ENV{Oracle_Trace_RECURSE} || 0;
Condition50%1/2
$ENV{'Oracle_Trace_RECURSE'} || 0
l!l
01
MC/DC0%0/1
$ENV{'Oracle_Trace_RECURSE'} || 0
$ENV{'Oracle_Trace_RECURSE'}
Truth table50%1/2
A
A= $ENV{'Oracle_Trace_RECURSE'}
Aresult
11
00
23 1 my $RESOLUTION = 1000000;
24  
25 =item new
26  
27 Create a new object for a given Orace Trace file.
28  
29 my $o_trc = Oracle::Trace->new($tracefile);
30  
31 =cut
32  
33 1 ▶sub new {
Subroutine new: called CC=3 SCAR=11.3
Pod documented
34 1 my $proto = shift;
35 1 ▶ my $class = ref($proto) ? ref($proto) : $proto;
Branch: 1 branch
BranchTrueFalseTotal
ref $proto ? : 0 1 1
36 1 my $self = bless({
37 _entries => [],
38 _filehandle => undef,
39 _footer => undef,
40 _header => undef,
41 _stats => {},
42 _tracefile => shift,
43 }, $class)->init;
44 1 ▶ $self->debug(Dumper($self)) if $DEBUG >= 2;
Branch: 1 branch
BranchTrueFalseTotal
if $DEBUG >= 2 0 1 1
45 1 return $self;
46 }
47  
48 =item init
49  
50 Initialise the object (check the tracefile).
51  
52 $o_trc->init.
53  
54 =cut
55  
56 1 ▶sub init {
Subroutine init: called CC=4 SCAR=14.5
Pod documented
57 1 my $self = shift;
58 1 my $s_file = $self->{_tracefile};
59 1 ▶ $self->fatal("non-existent trace file($s_file)") unless -f $s_file;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $s_file 0 1 1
60 1 ▶ $self->fatal("non-readable trace file($s_file)") unless -r _;
Branch: 1 branch
BranchTrueFalseTotal
unless -r _ 0 1 1
61 1 ▶ $self->fatal("no-data in trace file($s_file)") unless -s _;
Branch: 1 branch
BranchTrueFalseTotal
unless -s _ 0 1 1
62 1 return $self;
63 }
64  
65 =item opentracefile
66  
67 Perform basic exists/read/etc. checks on given tracefile.
68  
69 Returns object or undef.
70  
71 $o_trc = $o_trc->checkfile($tfile);
72  
73 =cut
74  
75 # user_dump_dest or background_dump_dest
76  
77 1 ▶sub opentracefile {
Subroutine opentracefile: called CC=4 SCAR=14.6
Pod documented
78 1 my $self = shift;
79 1 ▶ my $s_file = shift || '';
Condition50%1/2
shift() || ''
l!l
10
MC/DC0%0/1
shift() || ''
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
80 1 ▶ my $FH = FileHandle->new($s_file) or $self->fatal("failed to open trace file($s_file) $!");
Branch: 1 branch
BranchTrueFalseTotal
my $FH = "FileHandle"->new($s_file) or $self->fatal("failed to open trace file($s_file) $!") 1 0 1
81 1 ▶ $self->debug("incoming trace file($s_file) => FH($FH)") if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $DEBUG 0 1 1
82 1 return $FH;
83 }
84  
85 # Chunk
86  
87 1 ▶sub parse {
Subroutine parse: called CC=9 SCAR=22.2
Pod undocumented
88 1 my $self = shift;
89 1 my $FH = $self->opentracefile($self->{_tracefile});
90 1 my $i_ent = 0;
91 1 my %args = ('_extended'=>$EXTENDED, '_recurse'=>$RECURSE);
92 1 local $/ = "=====================\n";
93 1 ▶ while (<$FH>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $FH)) 26 1 27
94 26 my $entry = $_;
95 26 $entry =~ s#$/$##;
96 26 ▶ $self->debug("entry[$.]") if $DEBUG >= 2;
Branch: 1 branch
BranchTrueFalseTotal
if $DEBUG >= 2 0 26 26
97 26 ▶ if ($self->{_header}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'_header'}) { } 25 1 26
98 25 my $e = Oracle::Trace::Entry->new(%args)->parse($entry);
99 25 ▶ if ($RECURSE || !$e->{_child}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($RECURSE or not $e->{"_child"}) 4 21 25
Condition66%2/3
$RECURSE or not $e->{"_child"}
l!l&&r!l&&!r
0421
MC/DC50%1/2
$RECURSE or not $e->{"_child"}
$RECURSE not $e->{"_child"}
Truth table66%2/3
A or not(B)
A= $RECURSEB= not $e->{"_child"}
ABresult
1X1
011
000
100 4 push @{$self->{_entries}}, $e;
101 4 $i_ent++;
102 }
103 } else {
104 1 $self->{_header} = Oracle::Trace::Header->new(%args)->parse($entry);
105 1 my $release = join('',$self->header->keys('Oracle\d+.+?Release'));
106 1 ▶ $RESOLUTION = 100 if $release =~ /Oracle[678]/;
Branch: 1 branch
BranchTrueFalseTotal
if $release =~ /Oracle[678]/ 0 1 1
107 }
108 }
109 1 ▶ $self->debug("entries read: $. and retained: $i_ent") if $DEBUG >= 1;
Branch: 1 branch
BranchTrueFalseTotal
if $DEBUG >= 1 0 1 1
110 1 $self->{_footer} = Oracle::Trace::Footer->new(%args)->parse();
111 1 ▶ return $self->{_header} ? $self : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'_header'} ? : 1 0 1
112 };
113  
114 =item header
115  
116 Return the C<Header> object.
117  
118 my $o_hdr = $o_trc->header;
119  
120 =cut
121  
122 7 ▶sub header { my $self = shift; return $self->{_header}; }
Subroutine header: called CC=1 SCAR=0.0
Pod documented
123  
124 =item entries
125  
126 Return Entry objects which comply with given regex criteria.
127  
128 my @o_ents = $o_trc->entries('type'=>'EXEC #\d+', 'key'=>dep, 'value'=>0);
129  
130 =cut
131  
132 7 ▶sub entries {
Subroutine entries: called CC=4 SCAR=13.9
Pod documented
133 7 my $self = shift;
134 7 my %crit = @_;
135 7 ▶ if (keys %crit) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %crit) { } 4 3 7
136 4 my @entries = ();
137 ENTRY:
138 4 foreach my $e (@{$self->{_entries}}) {
139 16 my $i_vals = my @vals = $e->values(%crit);
140 16 ▶ push(@entries, $e) if $i_vals;
Branch: 1 branch
BranchTrueFalseTotal
if $i_vals 12 4 16
141 }
142 4 return @entries;
143 } else {
144 3 return @{$self->{_entries}};
145 }
146 }
147  
148 =item oids
149  
150 Return the unique object ids for the currently known C<Entry>ies
151  
152 my @oids = $o_trc->oids;
153  
154 =cut
155  
156 0 ▶sub oids { return map { $_->oid } $_[0]->entries(@_); }
Subroutine oids: not called CC=1 SCAR=6.9
Pod documented
157  
158 =item footer
159  
160 Return the C<Footer> object
161  
162 my $o_ftr = $o_trc->footer;
163  
164 =cut
165  
166 2 ▶sub footer { return $_[0]->{_footer}; }
Subroutine footer: called CC=1 SCAR=0.0
Pod documented
167  
168 =item test_report
169  
170 Return a B<simple> test_report of the current object.
171  
172 print $o_trc->test_report('string');
173  
174 =cut
175  
176 1 ▶sub test_report {
Subroutine test_report: called CC=4 SCAR=15.5
Pod documented
177 1 my $self = shift;
178 1 ▶ my $type = shift || 'string';
Condition50%1/2
shift() || 'string'
l!l
10
MC/DC0%0/1
shift() || 'string'
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
179 1 my $report = '';
180 1 ▶ if ($type eq 'string') {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'string') { } 1 0 1
elsif ($type eq 'html') { } 0 0 0
181 1 my $i_rep = my @rep = $self->entries('type'=>'other'); #, 'value' => 'select');
182 1 my $x_rep = my @xep = $self->entries('type'=>'other','key'=>'.*','value'=>'.*'); #, 'value' => 'select');
183 1 my $rep = $self->mini_report('10', @rep);
184 1 $report = join("\n",
185 ' instance name: '.join('',$self->header->value('Instance name')),
186 ' release: '.join('',$self->header->keys('Oracle.+?Release')),
187 ' info: '.join("\n", $self->header->value('other')),
188 ' header lines: '.$self->header->keys.' oid: '.$self->header->oid,
189 ' entries: '.$self->entries,
190 ' root statements: '.$self->entries('type'=>'PARSING IN CURSOR #\d+','key'=>'dep','value'=>'0'),
191 ' parse errors: '.$self->entries('type'=>'PARSE ERROR #\d+','key'=>'dep','value'=>'0'),
192 # ' select oids: '.join(', ', map{$_->oid} @sel),
193 sprintf('%5d', $i_rep).' reports (top ten): '.$rep,
194 ' footer lines: '.$self->footer->keys,
195 '',
196 );
197 } elsif ($type eq 'html') {
198 0 $report = 'html unsupported yet...<br>';
199 } else {
200 0 $self->error("unsupported report type($type)");
201 }
202 1 return $report;
203 };
204  
205 =item mini_report
206  
207 Return a B<simple> string of descending order timings for the statements
208 retrieved from the given objects.
209  
210 my $s_str = $o_trc->mini_report($i_max, @o_objs);
211  
212 Note that we use microsecond resolution for Oracle 9i and above and
213 centisecond resolution otherwise
214  
215 =cut
216  
217 1 ▶sub mini_report {
Subroutine mini_report: called CC=5 SCAR=16.3
Pod documented
218 1 my $self = shift;
219 1 my $i_max = shift;
220 1 my @objs = @_;
221  
222 1 my %rep = ();
223 STMT:
224 1 foreach my $o (@objs) {
225 4 ($rep{$o->elapsed}) = $o->statement;
226 4 ▶ if ($EXTENDED) {
Branch: 1 branch
BranchTrueFalseTotal
if ($EXTENDED) 0 4 4
227 0 $rep{$o->elapsed} .= "\n\t\t".join("\n\t\t", $o->stats);
228 }
229 }
230 1 my $rep = "\n";
231 1 my $i_rep = 0;
232 REP:
233 1 foreach my $k (reverse sort {$a <=> $b} keys %rep) {
234 4 $i_rep++;
235 4 $rep .= sprintf('%15.3f', $k/$RESOLUTION)." secs <- $rep{$k}\n";
236 4 ▶ last REP if $i_rep >= 10;
Branch: 1 branch
BranchTrueFalseTotal
if $i_rep >= 10 0 4 4
237 }
238  
239 1 return $rep;
240 }
241
242 1 1;
243  
244 __END__
« Trace/Footer.pm ↑ Summary Trace/Utils.pm »