faster finderr
Posted in 1993
If you have perl, and you have the informix errmsg.txt file, you
might be interested in this perl version of finderr, which is *much* faster,
by virtue of doing a binary search on errmsg.txt, rather than a linear
search. consider:
$ tail -4 $INFORMIXDIR/msg/errmsg.txt -26352 API error: Not enough memory for script file.
Memory allocation error. Exit OpenView and retry the option.
so -26352 is the last error code in the file.
$ time $INFORMIXDIR/bin/finderr -26352 -26352 API error: Not enough memory for script file.
Memory allocation error. Exit OpenView and retry the option.
real 28.0
user 25.2
sys 2.2
So on average the informix supplied finderr takes (on my system)
roughly 28 / 2 = 14 seconds to lookup an error message. Now how about
this:
$ time /usr/local/bin/finderr -26352 -26352 API error: Not enough memory for script file.
Memory allocation error. Exit OpenView and retry the option.
real 0.7
user 0.2
sys 0.2
Not bad huh? :-)
Anyway here it is:
8<---8<---8<---8<---8<---8<---8<---8<---8<---8<---8<---8<---8<---8<---8<---
#!/usr/local/bin/perl
# $Id: finderr,v 1.1 1993/12/08 17:14:53 bill Exp $
($progname = $0) =~ s#.*/##;
$SIG{PIPE} = IGNORE;
sub finderr {
local($errmsg) = @_;
local($errno) = (int($errmsg));
local($errtxt) = ('');
local($INFORMIXDIR);
$INFORMIXDIR = $ENV{INFORMIXDIR} || '/usr/informix';
if (open(ERRMSGTXT, "$INFORMIXDIR/msg/errmsg.txt")) {
local($/) = ("\\n\\n");
local($max,$min,$mid,$_);
$max = (stat(ERRMSGTXT))[7];
SEEK: while ($max - $min > 1) {
$mid = int(($max + $min) / 2);
seek(ERRMSGTXT, $mid, 0);
$_ = <ERRMSGTXT> if $mid;
while (<ERRMSGTXT>) {
($num) = split("\\t");
if ($num =~ /^(-?\\d+)$/) {
if ($errno < $1) {
$min = $mid;
next SEEK;
} elsif ($errno > $1) {
$max = $mid;
next SEEK;
} else {
$errtxt .= $_;
while (<ERRMSGTXT>) {
last if /^-?\\d+\\t/;
$errtxt .= $_;
}
last SEEK;
}
}
}
}
close(ERRMSGTXT);
}
$errtxt = "$errmsg\\n\\nError number $errno not found\\n" unless $errtxt;
$errtxt;
}
$err = shift || die "use $progname errorcode\\n";
open(MORE, "| more") || die "can't pipe to more: $!";
print MORE &finderr("$err");
close(MORE);
8<---8<---8<---8<---8<---8<---8<---8<---8<---8<---8<---8<---8<---8<---8<---
--
Cheers
Bill
===========================================================================
| Bill Hails <bill@tardis.co.uk> | Reisner's rule of conceptual inertia: |
| C.L.I. Connect Ltd. | |
| 19, Quarry St., Guildford, Surrey | If you think big enough, you'll never |
| GU1 3UY. Tel (UK) 0483 300 200 | have to do it. |
===========================================================================