NAME

Sys::Info::CPU - CPU information.

SYNOPSIS

use Sys::Info;
my $info = Sys::Info->new;
my $cpu  = $info->cpu(%options);

or

use Sys::Info::CPU;
my $cpu = Sys::Info::CPU->new(%options);

Example:

printf "CPU: %s\n", scalar($cpu->identify)  || 'N/A';
printf "CPU speed is %s MHz\n", $cpu->speed || 'N/A';
printf "There are %d CPUs\n"  , $cpu->count || 1;
printf "CPU load: %s\n"       , $cpu->load  || 0;

DESCRIPTION

Collects and returns information about the Central Processing Unit (CPU) on the host machine.

Some platforms can limit the available information under some user accounts and this will affect the accessible amount of data. When this happens, some methods will not return anything usable.

METHODS

new

Acceps parameters in key => value format.

cache

If has a true value, internal cache will be enabled. Cache timeout can be controlled via cache_timeout parameter.

On some platforms, some methods can take a long time to be completed (i.e.: WMI access on Windows platform). If cache is enabled, all gathered data will be saved in an internal in-memory cache and, the related method will serve from cache until the cache expires.

Cache only has a meaning, if you call the related method continiously (in a loop, under persistent environments like GUI, mod_perl, PerlEx, etc.). It will not have any effect if you are calling it only once.

cache_timeout

Must be used together with cache parameter. If cache is enabled, and this is not set, it will take the default value: 10.

Timeout value is in seconds.

disable_si

If has a true value, slow interfaces like Windows WMI will be disabled. Such interfaces may be slow, but returns more detailed information.

identify

If called in a list context; returns an AoH filled with CPU metadata. If called in a scalar context, returns the name of the CPU (if CPU is multi-core or there are multiple CPUs, it'll also include the number of CPUs).

Returns undef upon failure.

speed

Returns the CPU clock speed in MHz if successful. Returns undef otherwise.

count

Returns the number of CPUs (or number of total cores).

load [, LEVEL]

Returns the CPU load percentage if successful. Returns undef otherwise.

The average CPU load average in the last minute. If you pass a level argument, it'll return the related CPU load.

LEVEL   MEANING
-----   -------------------------------
  0     CPU Load in the last  1 minute
  1     CPU Load in the last  5 minutes
  2     CPU Load in the last 10 minutes

LEVEL defaults to 0 and currently only implemented under Linux.

SEE ALSO

Sys::Info, Sys::Info::OS.

AUTHOR

Burak Gürsoy, <burak@cpan.org>

COPYRIGHT

Copyright 2006 Burak Gürsoy. All rights reserved.

LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 176:

Non-ASCII character seen before =encoding in 'Gürsoy,'. Assuming CP1252