Skip Menu |

This queue is for tickets about the Sys-CpuLoad CPAN distribution.

Report information
The Basics
Id: 14034
Status: resolved
Priority: 0/
Queue: Sys-CpuLoad

People
Owner: Nobody in particular
Requestors: vincent [...] vinc17.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in:
  • 0.03
  • 0.01
  • 0.02
Fixed in: 0.21



Subject: Mac OS X support
The patch adds support for Mac OS X, where "uptime" outputs the results in a slightly different format (there are no commas between the load averages).
--- /opt/local/lib/perl5/site_perl/5.8.7/darwin-2level/Sys/CpuLoad.pm 2002-03-18 23:41:39.000000000 +0000 +++ /Users/vinc17/lib/site_perl/Sys/CpuLoad.pm 2005-08-04 22:22:51.000000000 +0000 @@ -83,7 +83,7 @@ if (defined $fh) { my $line = <$fh>; $fh->close(); - if ($line =~ /(\d+\.\d+)\s*,\s+(\d+\.\d+)\s*,\s+(\d+\.\d+)\s*$/) { + if ($line =~ /(\d+\.\d+)\s*,?\s+(\d+\.\d+)\s*,?\s+(\d+\.\d+)\s*$/) { return ($1, $2, $3); } # if we can parse the output of /usr/bin/uptime } # if we could run /usr/bin/uptime
From: vincent [...] vinc17.net
Le Sam 06 Aoû 2005 10:45:08, guest a écrit : Show quoted text
> The patch adds support for Mac OS X, where "uptime" outputs the > results in a slightly different format (there are no commas between > the load averages).
Also, it is preferable to use the getloadavg() function like on other BSD systems. I've attached a new patch.
Subject: CpuLoad.diff
--- CpuLoad.pm~ 2002-03-19 00:41:39.000000000 +0100 +++ CpuLoad.pm 2011-08-04 15:05:07.000000000 +0200 @@ -55,7 +55,7 @@ sub load { # handle bsd getloadavg(). Read the README about why it is freebsd/openbsd. - if ($cache eq 'getloadavg()' or lc $^O eq 'freebsd' or lc $^O eq 'openbsd' ) { + if ($cache eq 'getloadavg()' or lc $^O eq 'freebsd' or lc $^O eq 'openbsd' or lc $^O eq 'darwin') { $cache = 'getloadavg()'; return getbsdload() } @@ -83,7 +83,7 @@ if (defined $fh) { my $line = <$fh>; $fh->close(); - if ($line =~ /(\d+\.\d+)\s*,\s+(\d+\.\d+)\s*,\s+(\d+\.\d+)\s*$/) { + if ($line =~ /(\d+\.\d+)\s*,?\s+(\d+\.\d+)\s*,?\s+(\d+\.\d+)\s*$/) { return ($1, $2, $3); } # if we can parse the output of /usr/bin/uptime } # if we could run /usr/bin/uptime --- CpuLoad.xs~ 2002-03-19 00:16:14.000000000 +0100 +++ CpuLoad.xs 2011-08-04 14:52:12.000000000 +0200 @@ -18,7 +18,7 @@ PREINIT: double loadavg[3]; PPCODE: -#if defined(__FreeBSD__) || defined(__OpenBSD__) +#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__) getloadavg(loadavg, 3); #endif EXTEND(SP, 3);
Any progress? This bug has been outstanding for a number of years.
RT-Send-CC: vincent [...] vinc17.net
On Wed Jan 31 17:20:55 2018, NHORNE wrote: Show quoted text
> Any progress? This bug has been outstanding for a number of years.
I have taken over maintenance. This should be fixed in v0.11 which has just been u[loaded to CPAN. There is now a git repo at https://github.com/robrwo/Sys-CpuLoad - please add issues or PRs as needed.