diff options
author | Robert Rothenberg <rrwo@cpan.org> | 2020-03-24 23:20:54 +0000 |
---|---|---|
committer | Robert Rothenberg <rrwo@cpan.org> | 2020-03-24 23:20:54 +0000 |
commit | 5e5f0ab7f9d5600a212d991b613cd5d5bb2ac782 (patch) | |
tree | 24535b21a16dcd032f063a7ba00ab0f92061084f | |
parent | ba22c4ab1b96f0ab1b8aae9e171a30b2bfa8127d (diff) |
Use getloadavg call in Linux
-rw-r--r-- | Changes | 4 | ||||
-rw-r--r-- | CpuLoad.xs | 2 | ||||
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | lib/Sys/CpuLoad.pm | 16 | ||||
-rw-r--r-- | t/01-basic.t | 4 |
5 files changed, 17 insertions, 11 deletions
@@ -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] @@ -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); @@ -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; |