#include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include "sigar.h" #include "sigar_fileinfo.h" #include "sigar_format.h" typedef sigar_t * Sigar; typedef sigar_net_address_t Sigar__NetAddress; /* generated list */ typedef sigar_uptime_t * Sigar__Uptime; typedef sigar_mem_t * Sigar__Mem; typedef sigar_proc_cred_t * Sigar__ProcCred; typedef sigar_proc_fd_t * Sigar__ProcFd; typedef sigar_dir_stat_t * Sigar__DirStat; typedef sigar_proc_cred_name_t * Sigar__ProcCredName; typedef sigar_file_attrs_t * Sigar__FileAttrs; typedef sigar_cpu_t * Sigar__Cpu; typedef sigar_cpu_info_t * Sigar__CpuInfo; typedef sigar_net_interface_config_t * Sigar__NetInterfaceConfig; typedef sigar_swap_t * Sigar__Swap; typedef sigar_proc_state_t * Sigar__ProcState; typedef sigar_net_connection_t * Sigar__NetConnection; typedef sigar_proc_exe_t * Sigar__ProcExe; typedef sigar_proc_time_t * Sigar__ProcTime; typedef sigar_proc_cpu_t * Sigar__ProcCpu; typedef sigar_proc_mem_t * Sigar__ProcMem; typedef sigar_file_system_t * Sigar__FileSystem; typedef sigar_file_system_usage_t * Sigar__FileSystemUsage; typedef sigar_proc_stat_t * Sigar__ProcStat; typedef sigar_net_route_t * Sigar__NetRoute; typedef sigar_net_interface_stat_t * Sigar__NetInterfaceStat; typedef sigar_who_t * Sigar__Who; typedef sigar_thread_cpu_t * Sigar__ThreadCpu; typedef sigar_resource_limit_t * Sigar__ResourceLimit; typedef sigar_net_info_t * Sigar__NetInfo; typedef sigar_dir_usage_t * Sigar__DirUsage; typedef sigar_sys_info_t * Sigar__SysInfo; typedef sigar_net_stat_t * Sigar__NetStat; typedef sigar_tcp_t * Sigar__Tcp; typedef sigar_nfs_client_v2_t * Sigar__NfsClientV2; typedef sigar_nfs_server_v2_t * Sigar__NfsServerV2; typedef sigar_nfs_client_v3_t * Sigar__NfsClientV3; typedef sigar_nfs_server_v3_t * Sigar__NfsServerV3; /* Perl < 5.6 */ #ifndef aTHX_ #define aTHX_ #endif #define SIGAR_CROAK(sigar, msg) \ Perl_croak(aTHX_ msg " %s", sigar_strerror(sigar, status)) static SV *convert_2svav(char *data, unsigned long number, int size, const char *classname) { AV *av = newAV(); unsigned long i; for (i=0; iklen == klen) && (strEQ(get->key, key))) { get->val = newSVpv(val, vlen); return !SIGAR_OK; /* foundit; stop iterating */ } return SIGAR_OK; } MODULE = Sigar PACKAGE = Sigar PROTOTYPES: disable INCLUDE: Sigar_generated.xs MODULE = Sigar PACKAGE = Sigar PREFIX = sigar_ Sigar new(classname) char *classname PREINIT: int status; CODE: if ((status = sigar_open(&RETVAL)) != SIGAR_OK) { classname = classname; /* -Wall */ SIGAR_CROAK(RETVAL, "open"); } OUTPUT: RETVAL void DESTROY(sigar) Sigar sigar CODE: (void)sigar_close(sigar); char * format_size(size) UV size PREINIT: char buffer[56]; CODE: RETVAL = sigar_format_size(size, buffer); OUTPUT: RETVAL char * sigar_fqdn(sigar) Sigar sigar PREINIT: char fqdn[SIGAR_FQDN_LEN]; CODE: sigar_fqdn_get(sigar, fqdn, sizeof(fqdn)); RETVAL = fqdn; OUTPUT: RETVAL SV * loadavg(sigar) Sigar sigar PREINIT: sigar_loadavg_t loadavg; int status; unsigned long i; AV *av; CODE: status = sigar_loadavg_get(sigar, &loadavg); if (status != SIGAR_OK) { SIGAR_CROAK(sigar, "loadavg"); } av = newAV(); av_extend(av, 2); for (i=0; i<3; i++) { av_push(av, newSVnv(loadavg.loadavg[i])); } RETVAL = newRV_noinc((SV*)av); OUTPUT: RETVAL SV * file_system_list(sigar) Sigar sigar PREINIT: sigar_file_system_list_t fslist; int status; CODE: status = sigar_file_system_list_get(sigar, &fslist); if (status != SIGAR_OK) { SIGAR_CROAK(sigar, "fslist"); } RETVAL = convert_2svav((char *)&fslist.data[0], fslist.number, sizeof(*fslist.data), "Sigar::FileSystem"); sigar_file_system_list_destroy(sigar, &fslist); OUTPUT: RETVAL SV * cpu_info_list(sigar) Sigar sigar PREINIT: sigar_cpu_info_list_t cpu_infos; int status; CODE: status = sigar_cpu_info_list_get(sigar, &cpu_infos); if (status != SIGAR_OK) { SIGAR_CROAK(sigar, "cpu_infos"); } RETVAL = convert_2svav((char *)&cpu_infos.data[0], cpu_infos.number, sizeof(*cpu_infos.data), "Sigar::CpuInfo"); sigar_cpu_info_list_destroy(sigar, &cpu_infos); OUTPUT: RETVAL SV * cpu_list(sigar) Sigar sigar PREINIT: sigar_cpu_list_t cpus; int status; CODE: status = sigar_cpu_list_get(sigar, &cpus); if (status != SIGAR_OK) { SIGAR_CROAK(sigar, "cpu_list"); } RETVAL = convert_2svav((char *)&cpus.data[0], cpus.number, sizeof(*cpus.data), "Sigar::Cpu"); sigar_cpu_list_destroy(sigar, &cpus); OUTPUT: RETVAL SV * proc_list(sigar) Sigar sigar PREINIT: sigar_proc_list_t proclist; int status; unsigned long i; AV *av; CODE: status = sigar_proc_list_get(sigar, &proclist); if (status != SIGAR_OK) { SIGAR_CROAK(sigar, "proc_list"); } av = newAV(); av_extend(av, proclist.number - 1); for (i=0; i