Monday, July 16, 2007

Inconsistency in prtdiag output

I've been doing a lot of work recently writing Perl scripts to mine data from local Explorer repositories. It's a phenominal resource as a sort of RAW input to a configuration DB, and with Perl it's a snap to pull out data. My latest excecise was pretty trivial. I need to yank out the memory size field from prtdiag for each system, then dump it into an XML feed that serves one of our databases.

The information resides in the prtdiag-v.out file, and looks something like this:

fooserver{sysconfig}$ more ./prtdiag-v.out
System Configuration: Sun Microsystems sun4u Sun Fire E20K
System clock frequency: 150 MHz
Memory size: 65536 Megabytes


So, we throw together a little Perl script that does this:

sub get_memory_size {
my $explodir=shift();
my $prtdiagfile="$explodir/sysconfig/prtdiag-v.out";
my $line;
my $memsize;

if ( -e "$prtdiagfile" ) {
open(PRTDIAG,$prtdiagfile);
while () {
chomp;
last if ( $_ =~ /^Memory size:\s/ );
};
close(PRTDIAG);
s/Memory size:\s//g; # Kill the label
s/\s+$//; # Remove any trailing whitespace
return $_;
} else {
# We did noit find the prtdiag file.
return 0;
} #end if

} #end get_memory_size


No problem!

Then I put together a simple loop to check what I'd found... Now help me understand why this can't be simple and consistent? Here's some of the variety:

[2GB]
[6144 Megabytes]
[512MB]


Can't we just agree to use either MB or GB? Or if we're in a verbose frame of mind, Megabytes or Gigabytes. My response is to normalize the exceptions I can locate so that it comes out consistently with GB or MB, but I wonder whether this will remain a stable interface?

What I find even more entertaining is a daydream of an engineering team sitting around a table having a serious debate about changing the output from Megabytes to MB. With such a controversial topic, I'd imagine the debate was heated.

No comments: