From: Vincent Pit Date: Sun, 29 Jun 2008 16:41:26 +0000 (+0200) Subject: Importing Linux-SysInfo-0.05.tar.gz X-Git-Tag: v0.05^0 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=11e5f2a7b384d99ffcc265c3f684983e47d6886c;p=perl%2Fmodules%2FLinux-SysInfo.git Importing Linux-SysInfo-0.05.tar.gz --- diff --git a/Changes b/Changes index 5665e24..578f6bd 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,12 @@ Revision history for Linux-SysInfo +0.05 2007-08-13 11:10 UTC + + Add : Kwalitee test. + + Chg : Makefile.PL overhaul. + + Chg : Hash keys are now shared. This new implementation doesn't like + 5.9.3, but seems to be somehow ok with 5.9.5. If you're using + 5.9.3, either upgrade or keep with the precedent module version. + 0.04 2007-05-03 09:35 UTC + Add : The samples/sysinfo.pl sample script. + Chg : Declare LS_HAS_EXTENDED with newCONSTSUB. diff --git a/MANIFEST b/MANIFEST index ad30d73..418a084 100644 --- a/MANIFEST +++ b/MANIFEST @@ -10,5 +10,6 @@ t/00-load.t t/10-standard.t t/20-extended.t t/boilerplate.t +t/kwalitee.t t/pod-coverage.t t/pod.t diff --git a/META.yml b/META.yml index 6dd7092..36293a4 100644 --- a/META.yml +++ b/META.yml @@ -1,12 +1,14 @@ --- #YAML:1.0 name: Linux-SysInfo -version: 0.04 +version: 0.05 abstract: Perl interface to the sysinfo(2) Linux system call. license: perl -generated_by: ExtUtils::MakeMaker version 6.32 +generated_by: ExtUtils::MakeMaker version 6.36 distribution_type: module requires: + Exporter: 0 Test::More: 0 + XSLoader: 0 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.2.html version: 1.2 diff --git a/Makefile.PL b/Makefile.PL index 979d78b..cf1da63 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -10,8 +10,13 @@ WriteMakefile( ABSTRACT_FROM => 'lib/Linux/SysInfo.pm', PL_FILES => {}, PREREQ_PM => { + 'Exporter' => 0, 'Test::More' => 0, + 'XSLoader' => 0, + }, + dist => { + PREOP => 'pod2text lib/Linux/SysInfo.pm > $(DISTVNAME)/README', + COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, - dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, clean => { FILES => 'Linux-SysInfo-*' }, ); diff --git a/README b/README index c138c40..3d0e626 100644 --- a/README +++ b/README @@ -2,7 +2,7 @@ NAME Linux::SysInfo - Perl interface to the sysinfo(2) Linux system call. VERSION - Version 0.04 + Version 0.05 SYNOPSIS use Linux::SysInfo qw/sysinfo/; @@ -94,6 +94,8 @@ SEE ALSO AUTHOR Vincent Pit, "" + You can contact me by mail or on #perl @ FreeNode (Prof_Vince). + BUGS Please report any bugs or feature requests to "bug-linux-sysinfo at rt.cpan.org", or through the web interface at diff --git a/SysInfo.xs b/SysInfo.xs index f7509c4..c2b268d 100644 --- a/SysInfo.xs +++ b/SysInfo.xs @@ -1,41 +1,65 @@ +/* This file is part of the Linux::SysInfo Perl module. + * See http://search.cpan.org/dist/Linux-SysInfo/ + * Vincent Pit - 2007 */ + +#include /* LINUX_VERSION_CODE, KERNEL_VERSION() */ +#include /* , sysinfo(), SI_LOAD_SHIFT */ + +#define PERL_NO_GET_CONTEXT #include "EXTERN.h" #include "perl.h" #include "XSUB.h" -#include /* LINUX_VERSION_CODE, KERNEL_VERSION() */ -#include /* , sysinfo(), SI_LOAD_SHIFT */ +#define __PACKAGE__ "Linux::SysInfo" + +/* --- Extended fields ----------------------------------------------------- */ #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 +# define LS_HAS_EXTENDED 1 +#else +# define LS_HAS_EXTENDED 0 +#endif + +/* --- Keys ---------------------------------------------------------------- */ + +#define LS_KEY(K) (ls_key_##K##_sv) +#if PERL_API_REVISION >= 5 && PERL_API_VERSION >= 9 && PERL_API_SUBVERSION >= 5 +/* From 5.9.5, newSVpvn_share doesn't seem to fill the UV field of the key SV + * properly (the SV actually doesn't even look like a UV). That's why we have + * to keep the hash in another variable. */ +# define LS_HASH(K) (ls_key_##K##_hash) +# define LS_KEY_DECLARE(K) STATIC SV *LS_KEY(K) = NULL; \ + STATIC U32 LS_HASH(K) = 0 +# define LS_KEY_DEFINE(K) PERL_HASH(LS_HASH(K), #K, sizeof(#K)-1); \ + LS_KEY(K) = newSVpvn_share(#K, sizeof(#K)-1, \ + LS_HASH(K)); +# define LS_KEY_STORE(H,K,V) hv_store_ent((H), LS_KEY(K), (V), LS_HASH(K)) #else -# define SYSINFO_EXTENDED 0 +/* This won't work for 5.9.3 (5.9.4 ?), neither will the previous one. + * If you want to bleed, upgrade your blead! */ +# define LS_KEY_DECLARE(K) STATIC SV *LS_KEY(K) = NULL +# define LS_KEY_DEFINE(K) LS_KEY(K) = newSVpvn_share(#K, sizeof(#K)-1, 0) +# define LS_KEY_STORE(H,K,V) hv_store_ent((H), LS_KEY(K), (V), SvUVX(LS_KEY(K))) #endif -typedef struct { - const char* key; - U32 klen; - U32 hash; -} sysinfo_key; - -#define SYSINFO_KEY_SET_HASH(S) PERL_HASH((S).hash, (S).key, (S).klen) -#define SYSINFO_KEY_STORE(H,S,V) hv_store((H), (S).key, (S).klen, (V), (S).hash) - -static sysinfo_key key_uptime = { "uptime", 6, 0 }; -static sysinfo_key key_load1 = { "load1", 5, 0 }; -static sysinfo_key key_load5 = { "load5", 5, 0 }; -static sysinfo_key key_load15 = { "load15", 6, 0 }; -static sysinfo_key key_totalram = { "totalram", 8, 0 }; -static sysinfo_key key_freeram = { "freeram", 7, 0 }; -static sysinfo_key key_sharedram = { "sharedram", 9, 0 }; -static sysinfo_key key_bufferram = { "bufferram", 9, 0 }; -static sysinfo_key key_totalswap = { "totalswap", 9, 0 }; -static sysinfo_key key_freeswap = { "freeswap", 8, 0 }; -static sysinfo_key key_procs = { "procs", 5, 0 }; -#if SYSINFO_EXTENDED -static sysinfo_key key_totalhigh = { "totalhigh", 9, 0 }; -static sysinfo_key key_freehigh = { "freehigh", 8, 0 }; -static sysinfo_key key_mem_unit = { "mem_unit", 8, 0 }; -#endif /* SYSINFO_EXTENDED */ +LS_KEY_DECLARE(uptime); +LS_KEY_DECLARE(load1); +LS_KEY_DECLARE(load5); +LS_KEY_DECLARE(load15); +LS_KEY_DECLARE(totalram); +LS_KEY_DECLARE(freeram); +LS_KEY_DECLARE(sharedram); +LS_KEY_DECLARE(bufferram); +LS_KEY_DECLARE(totalswap); +LS_KEY_DECLARE(freeswap); +LS_KEY_DECLARE(procs); +#if LS_HAS_EXTENDED +LS_KEY_DECLARE(totalhigh); +LS_KEY_DECLARE(freehigh); +LS_KEY_DECLARE(mem_unit); +#endif /* LS_HAS_EXTENDED */ + +/* --- XS ------------------------------------------------------------------ */ MODULE = Linux::SysInfo PACKAGE = Linux::SysInfo @@ -44,29 +68,28 @@ PROTOTYPES: ENABLE BOOT: { HV *stash; - stash = gv_stashpv("Linux::SysInfo", TRUE); - newCONSTSUB(stash, "LS_HAS_EXTENDED", newSViv(SYSINFO_EXTENDED)); - - SYSINFO_KEY_SET_HASH(key_uptime); - SYSINFO_KEY_SET_HASH(key_load1); - SYSINFO_KEY_SET_HASH(key_load5); - SYSINFO_KEY_SET_HASH(key_load15); - SYSINFO_KEY_SET_HASH(key_totalram); - SYSINFO_KEY_SET_HASH(key_freeram); - SYSINFO_KEY_SET_HASH(key_sharedram); - SYSINFO_KEY_SET_HASH(key_bufferram); - SYSINFO_KEY_SET_HASH(key_totalswap); - SYSINFO_KEY_SET_HASH(key_freeswap); - SYSINFO_KEY_SET_HASH(key_procs); -#if SYSINFO_EXTENDED - SYSINFO_KEY_SET_HASH(key_totalhigh); - SYSINFO_KEY_SET_HASH(key_freehigh); - SYSINFO_KEY_SET_HASH(key_mem_unit); -#endif /* SYSINFO_EXTENDED */ + stash = gv_stashpv(__PACKAGE__, TRUE); + newCONSTSUB(stash, "LS_HAS_EXTENDED", newSViv(LS_HAS_EXTENDED)); + + LS_KEY_DEFINE(uptime); + LS_KEY_DEFINE(load1); + LS_KEY_DEFINE(load5); + LS_KEY_DEFINE(load15); + LS_KEY_DEFINE(totalram); + LS_KEY_DEFINE(freeram); + LS_KEY_DEFINE(sharedram); + LS_KEY_DEFINE(bufferram); + LS_KEY_DEFINE(totalswap); + LS_KEY_DEFINE(freeswap); + LS_KEY_DEFINE(procs); +#if LS_HAS_EXTENDED + LS_KEY_DEFINE(totalhigh); + LS_KEY_DEFINE(freehigh); + LS_KEY_DEFINE(mem_unit); +#endif /* LS_HAS_EXTENDED */ } -SV * -sysinfo() +SV *sysinfo() PREINIT: struct sysinfo si; NV l; @@ -76,29 +99,29 @@ CODE: XSRETURN_UNDEF; } - h = newHV(); /* mortalized in RETVAL */ + h = newHV(); - SYSINFO_KEY_STORE(h, key_uptime, newSViv(si.uptime)); + LS_KEY_STORE(h, uptime, newSViv(si.uptime)); l = ((NV) si.loads[0]) / ((NV) (((U32) 1) << ((U32) SI_LOAD_SHIFT))); - SYSINFO_KEY_STORE(h, key_load1, newSVnv(l)); + LS_KEY_STORE(h, load1, newSVnv(l)); l = ((NV) si.loads[1]) / ((NV) (((U32) 1) << ((U32) SI_LOAD_SHIFT))); - SYSINFO_KEY_STORE(h, key_load5, newSVnv(l)); + LS_KEY_STORE(h, 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)); - SYSINFO_KEY_STORE(h, key_bufferram, newSVuv(si.bufferram)); - SYSINFO_KEY_STORE(h, key_totalswap, newSVuv(si.totalswap)); - SYSINFO_KEY_STORE(h, key_freeswap, newSVuv(si.freeswap)); - SYSINFO_KEY_STORE(h, key_procs, newSVuv(si.procs)); -#if SYSINFO_EXTENDED - SYSINFO_KEY_STORE(h, key_totalhigh, newSVuv(si.totalhigh)); - SYSINFO_KEY_STORE(h, key_freehigh, newSVuv(si.freehigh)); - SYSINFO_KEY_STORE(h, key_mem_unit, newSVuv(si.mem_unit)); -#endif /* SYSINFO_EXTENDED */ + LS_KEY_STORE(h, load15, newSVnv(l)); + + LS_KEY_STORE(h, totalram, newSVuv(si.totalram)); + LS_KEY_STORE(h, freeram, newSVuv(si.freeram)); + LS_KEY_STORE(h, sharedram, newSVuv(si.sharedram)); + LS_KEY_STORE(h, bufferram, newSVuv(si.bufferram)); + LS_KEY_STORE(h, totalswap, newSVuv(si.totalswap)); + LS_KEY_STORE(h, freeswap, newSVuv(si.freeswap)); + LS_KEY_STORE(h, procs, newSVuv(si.procs)); +#if LS_HAS_EXTENDED + LS_KEY_STORE(h, totalhigh, newSVuv(si.totalhigh)); + LS_KEY_STORE(h, freehigh, newSVuv(si.freehigh)); + LS_KEY_STORE(h, mem_unit, newSVuv(si.mem_unit)); +#endif /* LS_HAS_EXTENDED */ RETVAL = newRV_noinc((SV *) h); OUTPUT: diff --git a/lib/Linux/SysInfo.pm b/lib/Linux/SysInfo.pm index 9746646..b99e4d4 100644 --- a/lib/Linux/SysInfo.pm +++ b/lib/Linux/SysInfo.pm @@ -9,11 +9,11 @@ Linux::SysInfo - Perl interface to the sysinfo(2) Linux system call. =head1 VERSION -Version 0.04 +Version 0.05 =cut -our $VERSION = '0.04'; +our $VERSION = '0.05'; =head1 SYNOPSIS @@ -132,6 +132,8 @@ L : Wrapper to the C BSD system call. Vincent Pit, C<< >> +You can contact me by mail or on #perl @ FreeNode (Prof_Vince). + =head1 BUGS Please report any bugs or feature requests to diff --git a/t/10-standard.t b/t/10-standard.t index 69a0d6e..9952ac2 100644 --- a/t/10-standard.t +++ b/t/10-standard.t @@ -1,10 +1,12 @@ #!perl -T -use Test::More tests => 12; +use Test::More tests => 12 * 5; use Linux::SysInfo qw/sysinfo/; -my $si = sysinfo; -ok(defined $si); +for (1 .. 5) { + my $si = sysinfo; + ok(defined $si); -ok(exists $si->{$_}) for qw/uptime load1 load5 load15 totalram freeram sharedram bufferram totalswap freeswap procs/; + ok(exists $si->{$_}) for qw/uptime load1 load5 load15 totalram freeram sharedram bufferram totalswap freeswap procs/; +} diff --git a/t/20-extended.t b/t/20-extended.t index 28806a4..892a596 100644 --- a/t/20-extended.t +++ b/t/20-extended.t @@ -7,10 +7,12 @@ use Linux::SysInfo qw/sysinfo LS_HAS_EXTENDED/; unless (LS_HAS_EXTENDED) { plan skip_all => 'your kernel does not support extended sysinfo fields'; } else { - plan tests => 4; + plan tests => 4 * 5; - my $si = sysinfo; - ok(defined $si); + for (1 .. 5) { + my $si = sysinfo; + ok(defined $si); - ok(exists $si->{$_}) for qw/totalhigh freehigh mem_unit/; + ok(exists $si->{$_}) for qw/totalhigh freehigh mem_unit/; + } } diff --git a/t/kwalitee.t b/t/kwalitee.t new file mode 100644 index 0000000..1e95c3d --- /dev/null +++ b/t/kwalitee.t @@ -0,0 +1,6 @@ +#!perl + +use Test::More; + +eval { require Test::Kwalitee; Test::Kwalitee->import() }; +plan( skip_all => 'Test::Kwalitee not installed; skipping' ) if $@;