summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Rothenberg <rrwo@cpan.org>2020-03-24 23:20:54 +0000
committerRobert Rothenberg <rrwo@cpan.org>2020-03-24 23:20:54 +0000
commit5e5f0ab7f9d5600a212d991b613cd5d5bb2ac782 (patch)
tree24535b21a16dcd032f063a7ba00ab0f92061084f
parentba22c4ab1b96f0ab1b8aae9e171a30b2bfa8127d (diff)
Use getloadavg call in Linux
-rw-r--r--Changes4
-rw-r--r--CpuLoad.xs2
-rw-r--r--README.md2
-rw-r--r--lib/Sys/CpuLoad.pm16
-rw-r--r--t/01-basic.t4
5 files changed, 17 insertions, 11 deletions
diff --git a/Changes b/Changes
index 2df810f..7b76f94 100644
--- a/Changes
+++ b/Changes
@@ -1,6 +1,10 @@
Revision history for Perl extension {{$dist->name}}:
{{$NEXT}}
+ [Enhancements]
+ - Use getloadavg system call in Linux.
+
+ - Port changes for Cygwin from Sys::CpuLoadX.
0.11 2020-03-24 22:57:02+00:00 Europe/London
[Enhancements]
diff --git a/CpuLoad.xs b/CpuLoad.xs
index b82428c..d992234 100644
--- a/CpuLoad.xs
+++ b/CpuLoad.xs
@@ -18,7 +18,7 @@ _getbsdload()
PREINIT:
double loadavg[3];
PPCODE:
-#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
+#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__) || defined(__linux__)
getloadavg(loadavg, 3);
#endif
EXTEND(SP, 3);
diff --git a/README.md b/README.md
index 025b211..efcc741 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,7 @@ Sys::CpuLoad - retrieve system load averages
# VERSION
-version 0.11
+version 0.12
# SYNOPSIS
diff --git a/lib/Sys/CpuLoad.pm b/lib/Sys/CpuLoad.pm
index b79036f..bf15133 100644
--- a/lib/Sys/CpuLoad.pm
+++ b/lib/Sys/CpuLoad.pm
@@ -54,7 +54,14 @@ sub import {
my $this = __PACKAGE__;
my $os = lc $^O;
- if ( -r '/proc/loadavg' && $os eq 'linux' ) {
+ if ( $os =~ /^(darwin|freebsd|openbsd|linux)$/ ) {
+
+ no strict 'refs'; ## no critic (ProhibitNoStrict)
+
+ *{"${this}::load"} = \&_getbsdload;
+
+ }
+ elsif ( -r '/proc/loadavg' && $os ne 'cygwin' ) {
no strict 'refs'; ## no critic (ProhibitNoStrict)
@@ -71,13 +78,6 @@ sub import {
};
}
- elsif ( $os =~ /^(darwin|freebsd|openbsd)$/ ) {
-
- no strict 'refs'; ## no critic (ProhibitNoStrict)
-
- *{"${this}::load"} = \&_getbsdload;
-
- }
else {
no strict 'refs'; ## no critic (ProhibitNoStrict)
diff --git a/t/01-basic.t b/t/01-basic.t
index 7dc57bc..9e3f204 100644
--- a/t/01-basic.t
+++ b/t/01-basic.t
@@ -6,6 +6,8 @@ my @load = load();
cmp_deeply
\@load,
- [ (re(qr/^\d(\.\d+)?$/)) x 3 ], 'load';
+ [ (re(qr/^\d(\.\d+)?(e[\-\+]\d+)?$/)) x 3 ], 'load';
+
+diag "@load";
done_testing;