hatch coltraine
New member
I'm trying to teach myself perl, and I was given this canned script that runs a quasi-tkprof.
Here's my code:
use strict;
use warnings;
my $cid; # cursor id
my %ela; # $ela{event} contains sum of ela statistics for event
my $sum_ela = 0; # sum of all ela times across events
my $r = 0; # response time for database call
my $action = "(?
ARSE|EXEC|FETCH|UNMAP|SORT UNMAP)";
while (<>) {
if (/^WAIT #(\d+): nam='([^']*)' ela=\s*(\d+)/i) {
$ela{$2} += $3;
$sum_ela += $3;
}
elsif (/^$action #(\d+):c=(\d+),e=(\d+)/i) {
$ela{"total CPU"} += $2;
$r = $3;
}
else {
# ignore this line
}
if (!defined $cid) {
$cid = $1;
} else {
die "can't mix data across cursor ids $cid and $1" if $1 != $cid;
}
}
$ela{"unaccounted-for"} = $r - ($ela{"total CPU"} + $sum_ela);
printf "%9s %6s %-40s\n", "Duration", "Pct", "Oracle kernel event";
printf "%8s- %5s- %-40s\n", "-"x8, "-"x5, "-"x40;
printf "%8.2fs %5.1f%% %-40s\n", $ela{$_}/100, $ela{$_}/$r*100, $_ for sort { $ela{$b}<=> $ela{$a} } keys %ela;
printf "%8s- %5s- %-40s\n", "-"x8, "-"x5, "-"x40;
printf "%8.2fs %5.1f%% %-40s\n", $r/100, 100, "Total response time";
executed in the following way:
user$ tkprof.pl level12.trc
my output
Use of uninitialized value in numeric ne (!=) at tkprof.pl line 42, <> line 29.
Use of uninitialized value in concatenation (.) or string at tkprof.pl line 42, <> line 29.
can't mix data across cursor ids 2 and at tkprof.pl line 42, <> line 29.
my thought is that I need to supply something for $1 at the command line, but I'm not sure what.
Here's my code:
use strict;
use warnings;
my $cid; # cursor id
my %ela; # $ela{event} contains sum of ela statistics for event
my $sum_ela = 0; # sum of all ela times across events
my $r = 0; # response time for database call
my $action = "(?

while (<>) {
if (/^WAIT #(\d+): nam='([^']*)' ela=\s*(\d+)/i) {
$ela{$2} += $3;
$sum_ela += $3;
}
elsif (/^$action #(\d+):c=(\d+),e=(\d+)/i) {
$ela{"total CPU"} += $2;
$r = $3;
}
else {
# ignore this line
}
if (!defined $cid) {
$cid = $1;
} else {
die "can't mix data across cursor ids $cid and $1" if $1 != $cid;
}
}
$ela{"unaccounted-for"} = $r - ($ela{"total CPU"} + $sum_ela);
printf "%9s %6s %-40s\n", "Duration", "Pct", "Oracle kernel event";
printf "%8s- %5s- %-40s\n", "-"x8, "-"x5, "-"x40;
printf "%8.2fs %5.1f%% %-40s\n", $ela{$_}/100, $ela{$_}/$r*100, $_ for sort { $ela{$b}<=> $ela{$a} } keys %ela;
printf "%8s- %5s- %-40s\n", "-"x8, "-"x5, "-"x40;
printf "%8.2fs %5.1f%% %-40s\n", $r/100, 100, "Total response time";
executed in the following way:
user$ tkprof.pl level12.trc
my output
Use of uninitialized value in numeric ne (!=) at tkprof.pl line 42, <> line 29.
Use of uninitialized value in concatenation (.) or string at tkprof.pl line 42, <> line 29.
can't mix data across cursor ids 2 and at tkprof.pl line 42, <> line 29.
my thought is that I need to supply something for $1 at the command line, but I'm not sure what.