Revision history for Linux-SysInfo
+0.02 2007-04-18 10:18 UTC
+ + Fix : Load average raw values have to be shifted on a platform
+ dependant way. They are now correctly reported.
+ + Fix : Missing META.yml
+ + Doc : Information about binary compatibility.
+
0.01 2007-04-11 12:45 UTC
- First version, released on an unsuspecting world.
+ * First version, released on an unsuspecting world.
Linux::SysInfo - Perl interface to the sysinfo(2) Linux system call.
VERSION
- Version 0.01
+ Version 0.02
SYNOPSIS
use Linux::SysInfo qw/sysinfo/;
This constant is set to 1 if your kernel supports the three extended
fields "totalhigh", "freehigh" and "mem_unit" ; and to 0 otherwise.
+BINARY COMPATIBILITY
+ If you upgrade your kernel to a greater version than 2.3.23 on i386 or
+ 2.3.48 on any other platform, you will need to rebuild the module to
+ access the extended fields.
+
+ Moreover, since the perl hash function has changed after the 5.6
+ version, you will also need to recompile the module if you upgrade your
+ perl from a version earlier than 5.6.
+
SEE ALSO
The sysinfo(2) man page.
#include "perl.h"
#include "XSUB.h"
-#include <linux/version.h>
-#include <sys/sysinfo.h>
+#include <linux/version.h> /* LINUX_VERSION_CODE, KERNEL_VERSION() */
+#include <sys/sysinfo.h> /* <struct sysinfo>, sysinfo(), SI_LOAD_SHIFT */
#if ((defined(__i386__) || defined(__x86_64__)) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 3, 23))) || (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 3, 48))
# define SYSINFO_EXTENDED 1
sysinfo()
PREINIT:
struct sysinfo si;
+ NV l;
HV* h;
CODE:
if (sysinfo(&si) == -1) {
XSRETURN_UNDEF;
}
- h = newHV();
-/* sv_2mortal((SV *) h); */
+ h = newHV(); /* mortalized in RETVAL */
SYSINFO_KEY_STORE(h, key_uptime, newSViv(si.uptime));
- SYSINFO_KEY_STORE(h, key_load1, newSVuv(si.loads[0]));
- SYSINFO_KEY_STORE(h, key_load5, newSVuv(si.loads[1]));
- SYSINFO_KEY_STORE(h, key_load15, newSVuv(si.loads[2]));
+
+ l = ((NV) si.loads[0]) / ((NV) (((U32) 1) << ((U32) SI_LOAD_SHIFT)));
+ SYSINFO_KEY_STORE(h, key_load1, newSVnv(l));
+ l = ((NV) si.loads[1]) / ((NV) (((U32) 1) << ((U32) SI_LOAD_SHIFT)));
+ SYSINFO_KEY_STORE(h, key_load5, newSVnv(l));
+ l = ((NV) si.loads[2]) / ((NV) (((U32) 1) << ((U32) SI_LOAD_SHIFT)));
+ SYSINFO_KEY_STORE(h, key_load15, newSVnv(l));
+
SYSINFO_KEY_STORE(h, key_totalram, newSVuv(si.totalram));
SYSINFO_KEY_STORE(h, key_freeram, newSVuv(si.freeram));
SYSINFO_KEY_STORE(h, key_sharedram, newSVuv(si.sharedram));
SV *
LS_HAS_EXTENDED()
CODE:
- RETVAL = newSViv(SYSINFO_EXTENDED);
+ RETVAL = newSViv(SYSINFO_EXTENDED); /* mortalized in RETVAL */
OUTPUT:
RETVAL
=head1 VERSION
-Version 0.01
+Version 0.02
=cut
-our $VERSION = '0.01';
+our $VERSION = '0.02';
=head1 SYNOPSIS
This constant is set to 1 if your kernel supports the three extended fields C<totalhigh>, C<freehigh> and C<mem_unit> ; and to 0 otherwise.
+=head1 BINARY COMPATIBILITY
+
+If you upgrade your kernel to a greater version than 2.3.23 on i386 or 2.3.48 on any other platform, you will need to rebuild the module to access the extended fields.
+
+Moreover, since the perl hash function has changed after the 5.6 version, you will also need to recompile the module if you upgrade your perl from a version earlier than 5.6.
+
=head1 SEE ALSO
The C<sysinfo(2)> man page.