AIX-Perfstat
view release on metacpan or search on metacpan
strncpy(cpu_name.name, name, IDENTIFIER_LENGTH);
my_cpu_t* cpu = (my_cpu_t*)safemalloc(sizeof(my_cpu_t));
if (cpu == NULL)
{
die("cpu: malloc failed for cpu");
}
cpu->size = 0;
cpu->data = (perfstat_cpu_t*)safemalloc(desired_number * sizeof(perfstat_cpu_t));
if (cpu->data == NULL)
{
safefree(cpu);
die("cpu: malloc failed for cpu->data");
}
if ((cpu->size = perfstat_cpu(&cpu_name, cpu->data, sizeof(perfstat_cpu_t), desired_number)) == -1 || (cpu->size == 0))
{
safefree(cpu->data);
safefree(cpu);
cpu = NULL;
}
if (update_name)
{
int name_len = strlen(name);
int cpu_name_len = strlen(cpu_name.name);
if (cpu_name_len > name_len)
/* pack a number of (struct perfstat_cpu_t) into an array of hashes
* and put a reference to this array onto Perl stack
*/
void XS_pack_my_cpu_tPtr(SV *st, my_cpu_t *q)
{
AV *av = newAV();
SV *sv;
perfstat_cpu_t *p;
int i;
for (i = 0, p = q->data; i < (q->size); i++, p++)
{
HV *hv = newHV();
PACK_PV(name,0);
PACK_UV(user);
PACK_UV(sys);
PACK_UV(idle);
PACK_UV(wait);
PACK_UV(pswitch);
PACK_UV(syscall);
#include <libperfstat.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct my_cpu_t
{
int size;
perfstat_cpu_t *data;
} my_cpu_t;
extern my_cpu_t* cpu_impl(int desired_number, char* name, int update_name);
extern int cpu_count_impl();
extern perfstat_cpu_total_t* cpu_total_impl();
extern void XS_pack_my_cpu_tPtr(SV *, my_cpu_t *);
extern void XS_pack_perfstat_cpu_total_tPtr(SV *, perfstat_cpu_total_t *);
#ifdef __cplusplus
XSRETURN_UNDEF;
}
if ((items == 2) && (!SvREADONLY((SV*)ST(1))))
{
sv_setpv((SV*)ST(1), name);
SvSETMAGIC(ST(1));
}
OUTPUT:
RETVAL
CLEANUP:
safefree(RETVAL->data);
safefree(RETVAL);
disk/disk.c view on Meta::CPAN
strncpy(disk_name.name, name, IDENTIFIER_LENGTH);
my_disk_t* disk = (my_disk_t*)safemalloc(sizeof(my_disk_t));
if (disk == NULL)
{
die("disk: malloc failed for disk");
}
disk->size = 0;
disk->data = (perfstat_disk_t*)safemalloc(desired_number * sizeof(perfstat_disk_t));
if (disk->data == NULL)
{
safefree(disk);
die("disk: malloc failed for disk->data");
}
if ((disk->size = perfstat_disk(&disk_name, disk->data, sizeof(perfstat_disk_t), desired_number)) == -1 || (disk->size == 0))
{
safefree(disk->data);
safefree(disk);
disk = NULL;
}
if (update_name)
{
int name_len = strlen(name);
int disk_name_len = strlen(disk_name.name);
if (disk_name_len > name_len)
disk/disk.c view on Meta::CPAN
/* pack a number of (struct perfstat_disk_t) into an array of hashes
* and put a reference to this array onto Perl stack
*/
void XS_pack_my_disk_tPtr(SV *st, my_disk_t *q)
{
AV *av = newAV();
SV *sv;
perfstat_disk_t *p;
int i;
for (i = 0, p = q->data; i < (q->size); i++, p++)
{
HV *hv = newHV();
PACK_PV(name,0);
PACK_PV(description,0);
PACK_PV(vgname,0);
PACK_UV(size);
PACK_UV(free);
PACK_UV(bsize);
PACK_UV(xrate);
disk/disk.h view on Meta::CPAN
#include <libperfstat.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct my_disk_t
{
int size;
perfstat_disk_t *data;
} my_disk_t;
extern my_disk_t* disk_impl(int desired_number, char * name, int update_name);
extern int disk_count_impl();
extern perfstat_disk_total_t* disk_total_impl();
// Functions called by XSUB to pack the C datastructures into perl structures. */
extern void XS_pack_my_disk_tPtr(SV *, my_disk_t *);
extern void XS_pack_perfstat_disk_total_tPtr(SV *, perfstat_disk_total_t *);
#ifdef __cplusplus
}
#endif
#endif /* undef DISK_H_INCLUDE_GUARD */
disk/disk_xs view on Meta::CPAN
XSRETURN_UNDEF;
}
if ((items == 2) && (!SvREADONLY((SV*)ST(1))))
{
sv_setpv((SV*)ST(1), name);
SvSETMAGIC(ST(1));
}
OUTPUT:
RETVAL
CLEANUP:
safefree(RETVAL->data);
safefree(RETVAL);
example1.pl view on Meta::CPAN
my $num_cpus = AIX::Perfstat::cpu_count();
print "cpu_count() $num_cpus\n";
my $num_disks = AIX::Perfstat::disk_count();
print "disk_count() $num_disks\n";
my $num_netifs = AIX::Perfstat::netinterface_count();
print "netinterface_count() $num_netifs\n";
my $cpu_data = AIX::Perfstat::cpu($num_cpus);
print "cpu($num_cpus) ", Dumper($cpu_data);
my $disk_data = AIX::Perfstat::disk($num_disks);
print "disk($num_disks) ", Dumper($disk_data);
my $netif_data = AIX::Perfstat::netinterface($num_netifs);
print "netinterface($num_netifs) ", Dumper($netif_data);
lib/AIX/Perfstat.pm view on Meta::CPAN
$netift = AIX::Perfstat::netinterface_total();
$memoryt = AIX::Perfstat::memory_total();
$num_cpus = AIX::Perfstat::cpu_count();
$num_disks = AIX::Perfstat::disk_count();
$num_netifs = AIX::Perfstat::netinterface_count();
$cpu_data = AIX::Perfstat::cpu(desired_number = 1, name = "");
$disk_data = AIX::Perfstat::disk(desired_number = 1, name = "");
$netif_data = AIX::Perfstat::netinterface(desired_number = 1, name = "");
=head1 DESCRIPTION
This Perl module lets you call all of the perfstat functions defined on
AIX 5.1 and returns system data in Perl data structures.
The C<AIX::Perfstat::cpu_total>, C<AIX::Perfstat::disk_total>,
C<AIX::Perfstat::netinterface_total>, and C<AIX::Perfstat::memory_total>
functions each return a hashref containing all of the respective C
structures.
The C<AIX::Perfstat::cpu_count>, C<AIX::Perfstat::disk_count>, and
C<AIX::Perfstat::netinterface_count> functions each return a count
of how many structures are available from the C<AIX::Perfstat::cpu>,
C<AIX::Perfstat::disk>, and C<AIX::Perfstat::netinterface> functions
respectively.
The C<AIX::Perfstat::cpu>, C<AIX::Perfstat::disk>, and
C<AIX::Perfstat::netinterface> functions each take up to
two arguments and return a reference to an array of hashes. The
arguments specify the number of records to return, and the name
of the record to start with. These arguments are equivalent to the
C<desired_number> and C<name> parameters to the C<perfstat> functions.
Only valid data is returned (Example: If you call
C<AIX::Perfstat::netinterface(5)> on a machine with only 2 network
interfaces, the returned array will only contain two entries.) When
these functions are called with a variable for the name parameter
the variable will be modified in place to contain the name of the next
available record, or "" if no more records are available.
=head2 EXPORT
None by default.
netinterface/netinterface.c view on Meta::CPAN
strncpy(netinterface_name.name, name, IDENTIFIER_LENGTH);
my_netinterface_t* netinterface = (my_netinterface_t*)safemalloc(sizeof(my_netinterface_t));
if (netinterface == NULL)
{
die("netinterface: malloc failed for netinterface");
}
netinterface->size = 0;
netinterface->data = (perfstat_netinterface_t*)safemalloc(desired_number * sizeof(perfstat_netinterface_t));
if (netinterface->data == NULL)
{
safefree(netinterface);
die("netinterface: malloc failed for netinterface->data");
}
if ((netinterface->size = perfstat_netinterface(&netinterface_name, netinterface->data, sizeof(perfstat_netinterface_t), desired_number)) == -1 || (netinterface->size == 0))
{
safefree(netinterface->data);
safefree(netinterface);
netinterface = NULL;
}
if (update_name)
{
int name_len = strlen(name);
int netinterface_name_len = strlen(netinterface_name.name);
if (netinterface_name_len > name_len)
netinterface/netinterface.c view on Meta::CPAN
/* pack a number of (struct perfstat_netinterface_t) into an array of hashes
* and put a reference to this array onto Perl stack
*/
void XS_pack_my_netinterface_tPtr(SV *st, my_netinterface_t *q)
{
AV *av = newAV();
SV *sv;
perfstat_netinterface_t *p;
int i;
for (i = 0, p = q->data; i < (q->size); i++, p++)
{
HV *hv = newHV();
PACK_PV(name,0);
PACK_PV(description,0);
PACK_UV(type);
PACK_UV(mtu);
PACK_UV(ipackets);
PACK_UV(ibytes);
PACK_UV(ierrors);
netinterface/netinterface.h view on Meta::CPAN
#include <libperfstat.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct my_netinterface_t
{
int size;
perfstat_netinterface_t *data;
} my_netinterface_t;
extern my_netinterface_t* netinterface_impl(int desired_number, char* name, int update_name);
extern int netinterface_count_impl();
extern perfstat_netinterface_total_t* netinterface_total_impl();
extern void XS_pack_my_netinterface_tPtr(SV *, my_netinterface_t *);
extern void XS_pack_perfstat_netinterface_total_tPtr(SV *, perfstat_netinterface_total_t *);
#ifdef __cplusplus
netinterface/netinterface_xs view on Meta::CPAN
XSRETURN_UNDEF;
}
if ((items == 2) && (!SvREADONLY((SV*)ST(1))))
{
sv_setpv((SV*)ST(1), name);
SvSETMAGIC(ST(1));
}
OUTPUT:
RETVAL
CLEANUP:
safefree(RETVAL->data);
safefree(RETVAL);
PERL_MAGIC_glob|5.007002||p
PERL_MAGIC_isaelem|5.007002||p
PERL_MAGIC_isa|5.007002||p
PERL_MAGIC_mutex|5.007002||p
PERL_MAGIC_nkeys|5.007002||p
PERL_MAGIC_overload_elem|5.007002||p
PERL_MAGIC_overload_table|5.007002||p
PERL_MAGIC_overload|5.007002||p
PERL_MAGIC_pos|5.007002||p
PERL_MAGIC_qr|5.007002||p
PERL_MAGIC_regdata|5.007002||p
PERL_MAGIC_regdatum|5.007002||p
PERL_MAGIC_regex_global|5.007002||p
PERL_MAGIC_shared_scalar|5.007003||p
PERL_MAGIC_shared|5.007003||p
PERL_MAGIC_sigelem|5.007002||p
PERL_MAGIC_sig|5.007002||p
PERL_MAGIC_substr|5.007002||p
PERL_MAGIC_sv|5.007002||p
PERL_MAGIC_taint|5.007002||p
PERL_MAGIC_tiedelem|5.007002||p
XS_VERSION|||
XS|||
ZeroD|5.009002||p
Zero|||
_aMY_CXT|5.007003||p
_pMY_CXT|5.007003||p
aMY_CXT_|5.007003||p
aMY_CXT|5.007003||p
aTHX_|5.006000||p
aTHX|5.006000||p
add_data|||
allocmy|||
amagic_call|||
any_dup|||
ao|||
append_elem|||
append_list|||
apply_attrs_my|||
apply_attrs_string||5.006001|
apply_attrs|||
apply|||
magic_getsubstr|||
magic_gettaint|||
magic_getuvar|||
magic_getvec|||
magic_get|||
magic_killbackrefs|||
magic_len|||
magic_methcall|||
magic_methpack|||
magic_nextpack|||
magic_regdata_cnt|||
magic_regdatum_get|||
magic_regdatum_set|||
magic_scalarpack|||
magic_set_all_env|||
magic_setamagic|||
magic_setarylen|||
magic_setbm|||
magic_setcollxfrm|||
magic_setdbline|||
magic_setdefelem|||
#endif
/* Older perls (<=5.003) lack AvFILLp */
#ifndef AvFILLp
# define AvFILLp AvFILL
#endif
#ifndef ERRSV
# define ERRSV get_sv("@",FALSE)
#endif
#ifndef newSVpvn
# define newSVpvn(data,len) ((data) \
? ((len) ? newSVpv((data), (len)) : newSVpv("", 0)) \
: newSV(0))
#endif
/* Hint: gv_stashpvn
* This function's backport doesn't support the length parameter, but
* rather ignores it. Portability can only be ensured if the length
* parameter is used for speed reasons, but the length can always be
* correctly computed from the string argument.
*/
#ifndef gv_stashpvn
PL_hints = oldhints;
PL_curcop->cop_stash = old_cop_stash;
PL_curstash = old_curstash;
PL_curcop->cop_line = oldline;
}
#endif
#endif
/*
* Boilerplate macros for initializing and accessing interpreter-local
* data from C. All statics in extensions should be reworked to use
* this, if you want to make the extension thread-safe. See ext/re/re.xs
* for an example of the use of these macros.
*
* Code that uses these macros is responsible for the following:
* 1. #define MY_CXT_KEY to a unique string, e.g. "DynaLoader_guts"
* 2. Declare a typedef named my_cxt_t that is a structure that contains
* all the data that needs to be interpreter-local.
* 3. Use the START_MY_CXT macro after the declaration of my_cxt_t.
* 4. Use the MY_CXT_INIT macro such that it is called exactly once
* (typically put in the BOOT: section).
* 5. Use the members of the my_cxt_t structure everywhere as
* MY_CXT.member.
* 6. Use the dMY_CXT macro (a declaration) in all the functions that
* access MY_CXT.
*/
#if defined(MULTIPLICITY) || defined(PERL_OBJECT) || \
defined(PERL_CAPI) || defined(PERL_IMPLICIT_CONTEXT)
#ifndef START_MY_CXT
/* This must appear in all extensions that define a my_cxt_t structure,
* right after the definition (i.e. at file scope). The non-threads
* case below uses it to declare the data as static. */
#define START_MY_CXT
#if (PERL_VERSION < 4 || (PERL_VERSION == 4 && PERL_SUBVERSION < 68 ))
/* Fetches the SV that keeps the per-interpreter data. */
#define dMY_CXT_SV \
SV *my_cxt_sv = get_sv(MY_CXT_KEY, FALSE)
#else /* >= perl5.004_68 */
#define dMY_CXT_SV \
SV *my_cxt_sv = *hv_fetch(PL_modglobal, MY_CXT_KEY, \
sizeof(MY_CXT_KEY)-1, TRUE)
#endif /* < perl5.004_68 */
/* This declaration should be used within all functions that use the
* interpreter-local data. */
#define dMY_CXT \
dMY_CXT_SV; \
my_cxt_t *my_cxtp = INT2PTR(my_cxt_t*,SvUV(my_cxt_sv))
/* Creates and zeroes the per-interpreter data.
* (We allocate my_cxtp in a Perl SV so that it will be released when
* the interpreter goes away.) */
#define MY_CXT_INIT \
dMY_CXT_SV; \
/* newSV() allocates one more than needed */ \
my_cxt_t *my_cxtp = (my_cxt_t*)SvPVX(newSV(sizeof(my_cxt_t)-1));\
Zero(my_cxtp, 1, my_cxt_t); \
sv_setuv(my_cxt_sv, PTR2UV(my_cxtp))
/* This macro must be used to access members of the my_cxt_t structure.
* e.g. MYCXT.some_data */
#define MY_CXT (*my_cxtp)
/* Judicious use of these macros can reduce the number of times dMY_CXT
* is used. Use is similar to pTHX, aTHX etc. */
#define pMY_CXT my_cxt_t *my_cxtp
#define pMY_CXT_ pMY_CXT,
#define _pMY_CXT ,pMY_CXT
#define aMY_CXT my_cxtp
#define aMY_CXT_ aMY_CXT,
#define _aMY_CXT ,aMY_CXT
#endif /* START_MY_CXT */
#ifndef MY_CXT_CLONE
/* Clones the per-interpreter data. */
#define MY_CXT_CLONE \
dMY_CXT_SV; \
my_cxt_t *my_cxtp = (my_cxt_t*)SvPVX(newSV(sizeof(my_cxt_t)-1));\
Copy(INT2PTR(my_cxt_t*, SvUV(my_cxt_sv)), my_cxtp, 1, my_cxt_t);\
sv_setuv(my_cxt_sv, PTR2UV(my_cxtp))
#endif
#else /* single interpreter */
#ifndef START_MY_CXT
#endif
#ifndef PERL_MAGIC_overload_table
# define PERL_MAGIC_overload_table 'c'
#endif
#ifndef PERL_MAGIC_bm
# define PERL_MAGIC_bm 'B'
#endif
#ifndef PERL_MAGIC_regdata
# define PERL_MAGIC_regdata 'D'
#endif
#ifndef PERL_MAGIC_regdatum
# define PERL_MAGIC_regdatum 'd'
#endif
#ifndef PERL_MAGIC_env
# define PERL_MAGIC_env 'E'
#endif
if (radix && IN_LOCALE) {
STRLEN len = strlen(radix);
if (*sp + len <= send && memEQ(*sp, radix, len)) {
*sp += len;
return TRUE;
}
}
#endif /* PERL_VERSION */
#endif /* USE_LOCALE_NUMERIC */
/* always try "." if numeric radix didn't match because
* we may have data from different locales mixed */
if (*sp < send && **sp == '.') {
++*sp;
return TRUE;
}
return FALSE;
}
#endif
#endif
/* grok_number depends on grok_numeric_radix */
( run in 0.428 second using v1.01-cache-2.11-cpan-8d75d55dd25 )