Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

djberg96 (2603)

djberg96
  (email not shown publicly)

Journal of djberg96 (2603)

Monday February 03, 2003
12:05 AM

sys-cpu - Linux issues

[ #10351 ]
One of my co-workers wanted a Ruby module that provided cpu information. So, I took a look at Sys::CPU, Unix::Processors and Linux::Cpuinfo (since I'll want to support Linux as well) for guidance. I start with Linux...

Seems easy enough - just read out of /proc/cpuinfo and assign values to the appropriate attributes, right?. The problem, as Jonathan Stowe apparently learned the hard way, is that the information stored in this file varies slightly from one chip architecture to the next. You can't hard code the attributes.

My next idea was to dynamically generate the class during the configuration process. Seems logical and it's not that difficult to do. The problem with *that* approach is that the hardware could be upgraded at some point, and if the chip is changed (from, say, Intel to Athlon), we suddenly have a module returning bogus information.

What about dynamically generating the information each time a method is called? Seems horribly inefficient, since the probability of a cpu upgrade is rather low (relatively speaking).

The best compromise solution I can think of is to dynamically generate the class *once*, when the module is require'd. The file is small enough that the one time read should be negligable from a performance standpoint.

PS - I wouldn't have known about the differences in /proc/cpuinfo if I hadn't read the README file for Linux::Cpuinfo. :)

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.