--- hwCpu.pm 2003/09/01 15:22:42 1.1
+++ hwCpu.pm 2003/09/08 10:49:35 1.2
@@ -36,27 +36,70 @@
sub probe ($$) {
my ($self, $obj) = @_;
- if ($obj->{-name} =~ m|\.hwCpuNum$|) {
- if ($self->{-ctx}->{-platform}->id() =~ m/FreeBSD/i) {
- # query sysctl(8)
- my $out = $self->{-ctx}->{-sys}->run("/sbin/sysctl -n hw.ncpu", "forever");
- $obj->{-value} = $out->{-stdout};
- $obj->{-value} =~ s/^\s*(.+?)\s*$/$1/s;
+ if ($self->{-ctx}->{-platform}->id() =~ m/FreeBSD/i) {
+ # query sysctl(8)
+ my $out = $self->{-ctx}->{-sys}->run("/sbin/sysctl -n hw.ncpu", "forever");
+ $obj->{-value} = $out->{-stdout};
+ $obj->{-value} =~ s/^\s*(.+?)\s*$/$1/s;
+ }
+ elsif ($self->{-ctx}->{-platform}->id() =~ m/Linux/i) {
+ # query dmesg(8)
+ # FIXME: this works only within a reasonable time after booting
+ # but I don't know any alternative method for querying the speed!
+ my $out = $self->{-ctx}->{-sys}->run("/sbin/dmesg", "forever");
+ if ($out->{-stdout} =~ m|(\d+)(\.\d+)?[ -]*MHz|si) {
+ $obj->{-value} = $1;
}
}
- elsif ($obj->{-name} =~ m|\.hwCpuSpeed$|) {
- if ($self->{-ctx}->{-platform}->id() =~ m/FreeBSD/i) {
- # query dmesg(8)
- # FIXME: this works only within a reasonable time after booting
- # but I don't know any alternative method for querying the speed!
- my $out = $self->{-ctx}->{-sys}->run("/sbin/dmesg", "forever");
- if ($out->{-stdout} =~ m|(\d+)(\.\d+)?[ -]*MHz|si) {
- $obj->{-value} = $1;
+ elsif($self->{-ctx}->{-platform}->id() =~ m/SunOS/i) {
+ my $hwCpuNum = undef;
+ # $hwCpuSpeed see @dat[]->{hwCpuSpeed}
+ # $hwCpuTemp see @dat[]->{hwCpuTemp}
+
+ # local workspace
+ my $out; my $raw; my @dat; my $arch;
+
+ # initialize arch
+ $arch = $self->{-ctx}->{-platform}->arch();
+
+ # hwCpuSpeed
+ $out = $self->{-ctx}->{-sys}->run("/usr/platform/$arch/sbin/prtdiag -v", "1m");
+ $raw = $out->{-stdout};
+ if ($raw =~ m/\n=+ CPUs =+\n.*?\n---[ -]+\n(.*?)\n=+/s) {
+ $raw = $1;
+ foreach $line (split "\n", $raw) {
+ my ($brd,$cpu,$module,$mhz,$mb,$impl,$mask) = split(" ", $line);
+ if ($cpu =~ m/^\d+$/) {
+ @dat[$cpu] = {} if (not defined @dat[$cpu]);
+ @dat[$cpu]->{hwCpuSpeed} = $mhz;
+ }
}
}
- }
- elsif ($obj->{-name} =~ m|\.hwCpuTemp$|) {
- if ($self->{-ctx}->{-platform}->id() =~ m/FreeBSD/i) {
+
+ # hwCpuTemp
+ $out = $self->{-ctx}->{-sys}->run("/usr/platform/$arch/sbin/prtdiag -v", "1m");
+ $raw = $out->{-stdout};
+ if ($raw =~ m/\n=+ Environmental Status =+\n\nSystem Temperatures \(Celsius\):\n-+\n(.*?)\n=+/s) {
+ $raw = $1;
+ foreach $line (split "\n", $raw) {
+ my ($cpu,$temp) = split(" ", $line);
+ if ($cpu =~ m/CPU(\d+)/) {
+ $cpu = $1;
+ @dat[$cpu] = {} if (not defined @dat[$cpu]);
+ @dat[$cpu]->{hwCpuTemp} = $temp;
+ }
+ }
+ }
+
+ # hwCpuNum
+ $hwCpuNum = $#{@dat} + 1;
+
+ $obj->{-value} = $hwCpuNum if ($obj->{-name} =~ m/\.hwCpuNum$/);
+ if ($obj->{-name} =~ m/\.hwCpuInfoENTRY\.([^.]+)\.(\d+)$/) {
+ my $col = $1;
+ my $row = ($2 > 0 ? $2 - 1 : 0);
+ $self->{-ctx}->{-log}->printf(4, "col=%s row=%s", $col, $row);
+ $obj->{-value} = @dat[$row]->{$col} if (defined @dat[$row]->{$col});
}
}
return;
|