Initial revision
This commit is contained in:
1 parent
1a7957fb1e
commit
dffe0da855
207 files changed
+34390
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,49 @@
|
||||
#ifndef SIGAR_OS_H
|
||||
#define SIGAR_OS_H
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <dlfcn.h>
|
||||
#include <procinfo.h>
|
||||
|
||||
enum {
|
||||
KOFFSET_LOADAVG,
|
||||
KOFFSET_VAR,
|
||||
KOFFSET_SYSINFO,
|
||||
KOFFSET_IFNET,
|
||||
KOFFSET_VMINFO,
|
||||
KOFFSET_CPUINFO,
|
||||
KOFFSET_MAX
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
time_t mtime;
|
||||
int num;
|
||||
char **devs;
|
||||
} swaps_t;
|
||||
|
||||
typedef int (*vminfo_func_t) (void *, int, int);
|
||||
|
||||
typedef int (*proc_fd_func_t) (sigar_t *, sigar_pid_t, sigar_proc_fd_t *);
|
||||
|
||||
struct sigar_t {
|
||||
SIGAR_T_BASE;
|
||||
int kmem;
|
||||
/* offsets for seeking on kmem */
|
||||
long koffsets[KOFFSET_MAX];
|
||||
vminfo_func_t getvminfo;
|
||||
proc_fd_func_t getprocfd;
|
||||
int pagesize;
|
||||
swaps_t swaps;
|
||||
time_t last_getprocs;
|
||||
sigar_pid_t last_pid;
|
||||
struct procsinfo *pinfo;
|
||||
struct cpuinfo *cpuinfo;
|
||||
int cpuinfo_size;
|
||||
};
|
||||
|
||||
#define HAVE_STRERROR_R
|
||||
|
||||
#define SIGAR_EPERM_KMEM (SIGAR_OS_START_ERROR+1)
|
||||
|
||||
#endif /* SIGAR_OS_H */
|
||||
@@ -0,0 +1,312 @@
|
||||
/*
|
||||
* struct user is not binary compatible
|
||||
* between 4.3 and 5.x
|
||||
* this structure is taken from 5.1 sys/user.h
|
||||
* and defines from sys/user.h and sys/types.h
|
||||
* we compile this on v5.
|
||||
* XXX: will not compile 5.x if we want to compile
|
||||
* on 5.x would need to create a struct user_v4
|
||||
* to maintain bincompt.
|
||||
*/
|
||||
|
||||
#define V5_NISIG 3 /* v4 == 2 */
|
||||
|
||||
#define SIGMAX64 255
|
||||
#define SIGMAX32 63
|
||||
#ifdef __64BIT__
|
||||
#define V5_SIGMAX SIGMAX64
|
||||
#else
|
||||
#define V5_SIGMAX SIGMAX32
|
||||
#endif
|
||||
|
||||
#define NSIG64 (SIGMAX64+1)
|
||||
#define NSIG32 (SIGMAX32+1)
|
||||
#ifdef __64BIT__
|
||||
#define V5_NSIG NSIG64
|
||||
#else
|
||||
#define V5_NSIG NSIG32
|
||||
#endif
|
||||
|
||||
#define WLM_TAG_LENGTH 30
|
||||
#define U_FD_LCK_CNT 16
|
||||
|
||||
typedef vmhandle_t vmlpghandle_t;
|
||||
|
||||
typedef struct {
|
||||
#ifdef _ALL_SOURCE
|
||||
unsigned int losigs, hisigs;
|
||||
#else
|
||||
unsigned int __losigs, __hisigs;
|
||||
#endif
|
||||
} sigset32_t;
|
||||
|
||||
struct user_v5 {
|
||||
|
||||
/* swappable process context */
|
||||
unsigned long long U_chk_paddr; /* address of checkpnt_pending var */
|
||||
struct saioq_head *U_saioq_head;/* anchor for async socket queue */
|
||||
uid_t U_sv_sgid; /* set group identifier at exec time */
|
||||
int U_num_pmsegs;/* number of PM segments */
|
||||
vmhandle_t *U_pm_segs; /* PM segments */
|
||||
vmhandle_t U_pm_space; /* space for first PM segment */
|
||||
vmhandle_t U_text_vmh; /* text seg vmhandle for memusage */
|
||||
unsigned long long U_cancel_func;/* cancelation user entry point */
|
||||
unsigned long long U_cancel_toc;/* cancelation user entry point */
|
||||
struct proc *U_procp; /* pointer to proc structure */
|
||||
Simple_lock U_handy_lock; /* self preservation lock */
|
||||
|
||||
#ifdef __64BIT_KERNEL
|
||||
#ifdef _POWER
|
||||
/* U_segs32 must be pinned and must not cross a page boundary */
|
||||
void *U_segs32_raddr; /* real addr of U_segs32 */
|
||||
vmhandle_t U_segs32[NSEGS]; /* shadow of first 4Gb for resume() */
|
||||
#endif /* _POWER */
|
||||
#endif /* __64BIT_KERNEL */
|
||||
|
||||
/* signal management */
|
||||
void (*U_signal[NSIG32+V5_NISIG])(int);/* disposition of sigs */
|
||||
sigset32_t U_sigmask[NSIG32+V5_NISIG]; /* sig's to be blocked */
|
||||
#ifdef __64BIT_KERNEL
|
||||
uint U_sigflags[V5_NSIG+V5_NISIG];
|
||||
#else
|
||||
ushort U_sigflags[NSIG64+V5_NISIG];/* ushort-save space for now*/
|
||||
#endif /* __64BIT_KERNEL */
|
||||
|
||||
/* user-mode address space mapping */
|
||||
#ifndef __64BIT_KERNEL
|
||||
adspace_t U_adspace; /* user-mode address space */
|
||||
struct segstate U_segst[NSEGS]; /* info on use of each segment */
|
||||
#else
|
||||
#ifdef _POWER
|
||||
void * U_uastrtp; /* strt addr for V_USERACC */
|
||||
vmsize_t U_uasize; /* size of the V_USERACC buf */
|
||||
#endif /* _POWER */
|
||||
struct asalloc U_snode; /* segment node allocation */
|
||||
struct asalloc U_unode; /* uadspace node allocation */
|
||||
struct uadnode U_adspace32[NADNODES]; /* usr adspace 32bit process */
|
||||
struct segnode U_segnode[NSEGNODES]; /* segnode for 32bit processes */
|
||||
#endif /* __64BIT_KERNEL */
|
||||
struct vmmlock U_adspace_lock;
|
||||
int U_vmmflags; /* vmm process state flags */
|
||||
|
||||
/* auditing stuff */
|
||||
int U_auditstatus; /* auditing RESUME or SUSPEND */
|
||||
|
||||
/* address map (mmap) */
|
||||
char *U_map;
|
||||
|
||||
/* current exec file information */
|
||||
char U_comm[MAXCOMLEN+1]; /* basename of exec file */
|
||||
|
||||
int U_ncargs; /* ARGMAX value during exec */
|
||||
|
||||
/*
|
||||
* Program model information, 64bit and 32bit, small and large data.
|
||||
* The 'max' values are the maximums allowed by the model, which
|
||||
* may be smaller than the current resource limits.
|
||||
* These fields are filled in during exec.
|
||||
*
|
||||
* There is no U_stksize field. The stack is allowed whatever it can
|
||||
* get, subject to resource limits, model limits (possibly set from
|
||||
* the a.out header during exec), and, in 32-bit mode, the PRIVSEG
|
||||
* data break address. The get_stack_size routine will return the
|
||||
* current maximum effective size of the stack.
|
||||
*
|
||||
* Other fields:
|
||||
* U_breakhiwater: the high water mark for the break value
|
||||
* U_minbreak: the smallest permitted break value
|
||||
* U_min_mmap: If non-zero, smallest address allowed for mmap()
|
||||
* or shmat() at a user-specified address.
|
||||
*/
|
||||
unsigned long long U_tstart; /* start of text */
|
||||
unsigned long long U_tsize; /* text size (bytes) */
|
||||
unsigned long long U_datastart; /* start of data */
|
||||
unsigned long long U_datasize; /* Current data size (bytes) */
|
||||
|
||||
/* DABR watchpoint information */
|
||||
unsigned long long U_wp_dabr; /* DABR value for ptrace watchpoint */
|
||||
unsigned long long U_wp_value; /* current value at watched address */
|
||||
|
||||
/* System call table information */
|
||||
void *U_svc_table; /* svc table address */
|
||||
int U_max_svcnum; /* max allowed svc number for process */
|
||||
|
||||
/* CHANGES FROM HERE ON DO NOT AFFECT ASSEMBLER CODE
|
||||
(see ml/POWER/32user.m4) */
|
||||
|
||||
char U_pad2[32];
|
||||
|
||||
unsigned long long U_datamax; /* Maximum data size (bytes) */
|
||||
unsigned long long U_minbreak; /* minimum/initial break address */
|
||||
unsigned long long U_breakhiwater; /* Largest break address so far */
|
||||
unsigned long long U_min_mmap; /* Minimum shmat/mmap address allowed */
|
||||
|
||||
uint U_brkseg; /* segment number of U_breakhiwater */
|
||||
uint U_stkseg; /* Lowest segment number of stack */
|
||||
|
||||
unsigned long long U_stkstart; /* stack start (grows downwards) */
|
||||
unsigned long long U_stkmax; /* stack max (bytes) */
|
||||
|
||||
/*
|
||||
* The following macros compute some commonly required values
|
||||
* about the addressing model.
|
||||
*
|
||||
* U_BIGDATA Tells you whether the 32-bit large data model
|
||||
* is in effect.
|
||||
* U_PDATASIZE Is the current data size for a 32-bit process
|
||||
* in the private segment (hence the P).
|
||||
* Note - this is always the PRIVSEG data size; with
|
||||
* the large data model, the general data size is
|
||||
* separate, as data begins in the BDATASEG.
|
||||
* U_PDATABRK Is the current data break address of a 32-bit process
|
||||
* in the private segment (see above).
|
||||
* U_DATABRK Is the general data break address in all cases.
|
||||
* U_DSIZE Is for compatibility only. Use it to fill in fields
|
||||
* that previously were copies of U_dsize, which is now
|
||||
* obsolete.
|
||||
*/
|
||||
|
||||
unsigned int U_sdsize; /* Size of data for privately loaded
|
||||
modules, if the bigdata model is
|
||||
being used. */
|
||||
short U_lock; /* process/text locking flags */
|
||||
char U_64bit; /* 0 if 32-bit process, 0x1 if 64-bit */
|
||||
char U_emul; /* emulation type (UW7, etc.) */
|
||||
|
||||
/* user identification and authorization */
|
||||
Simple_lock U_cr_lock; /* credentials lock */
|
||||
struct ucred * volatile U_cred; /* user credentials (uid, gid, etc) */
|
||||
|
||||
uinfo_t U_uinfo; /* usrinfo() buffer */
|
||||
int U_compatibility;/* compatibility/user mode bit masks */
|
||||
|
||||
/* defines for u.u_compatibility bit mask */
|
||||
|
||||
struct sem_undo *U_semundo; /* semaphore undo struct pointer */
|
||||
|
||||
/* accounting and profiling data */
|
||||
time_t U_start;
|
||||
time_t U_ticks;
|
||||
struct profdata U_prof;
|
||||
short U_acflag; /* accounting flag */
|
||||
struct trusage64 U_ru; /* this process resource usage value */
|
||||
struct trusage64 U_cru; /* accumulated children's resources */
|
||||
/*
|
||||
* The kernel uses U_ru & U_cru to keep track of the time used by
|
||||
* the process and its children.
|
||||
* Even though the ru_utime & ru_stime fields within U_ru & U_cru are
|
||||
* struct timeval, their granularity within the kernel is nanoseconds,
|
||||
* not microseconds. This is the granularity returned by getprocs().
|
||||
* Other syscalls and library functions convert this to microseconds.
|
||||
*/
|
||||
|
||||
char U_pthru; /* pthread rusage tracking */
|
||||
|
||||
/* virtualized resource usage values */
|
||||
struct trusage64 U_vru;
|
||||
struct trusage64 U_vcru;
|
||||
|
||||
/* resource limits and counters */
|
||||
unsigned long U_fsblimit; /* fs limit in 512 byte-blks */
|
||||
|
||||
#if defined(_KERNSYS) || defined(__64BIT_KERNEL)
|
||||
/* rlimit32 structure is exposed to only 32/64 kernel
|
||||
* and 64bit kernel extensions
|
||||
*/
|
||||
struct rlimit32 U_rlimit[RLIM_NLIMITS]; /* 32-bit resource limits */
|
||||
#else
|
||||
struct rlimit U_rlimit[RLIM_NLIMITS]; /* 32-bit resource limits */
|
||||
#endif
|
||||
struct rlimit64 U_saved_rlimit[RLIM_NLIMITS]; /* saved 64-bit limits */
|
||||
/*
|
||||
* To maximize compatibility with old kernel code, a 32-bit
|
||||
* representation of each resource limit is maintained in U_rlimit.
|
||||
* Should the limit require a 64-bit representation, the U_rlimit
|
||||
* value is set to RLIM_INFINITY, with actual 64-bit limit being
|
||||
* stored in U_saved_rlimit. These flags indicate what
|
||||
* the real situation is:
|
||||
*
|
||||
* RLFLAG_SML => limit correctly represented in 32-bit U_rlimit
|
||||
* RLFLAG_INF => limit is infinite
|
||||
* RLFLAG_MAX => limit is in 64_bit U_saved_rlimit.rlim_max
|
||||
* RLFLAG_CUR => limit is in 64_bit U_saved_rlimit.rlim_cur
|
||||
*
|
||||
* These flags are for use by the getrlimit/setrlimit routines only.
|
||||
* Kernel code desiring a 64-bit limit must go through kgetrlimit.
|
||||
*/
|
||||
struct {
|
||||
uchar rlim_cur; /* how to determine rlim_cur */
|
||||
uchar rlim_max; /* how to determine rlim_max */
|
||||
} U_rlimit_flag[RLIM_NLIMITS];
|
||||
|
||||
unsigned long long U_ioch; /* I/O character count */
|
||||
|
||||
/* timers */
|
||||
Simple_lock U_timer_lock;
|
||||
struct trb *U_timer[NTIMERS]; /* per process timers */
|
||||
|
||||
/* controlling tty info */
|
||||
pid_t *U_ttysid; /* ptr to session leader id in tty */
|
||||
pid_t *U_ttyp; /* ptr to controlling tty pgrp field */
|
||||
dev_t U_ttyd; /* controlling tty dev */
|
||||
long U_ttympx; /* mpx value for controlling tty */
|
||||
unsigned *U_ttys; /* pointer to t_state in tty struct */
|
||||
int32long64_t U_ttyid; /* tty id */
|
||||
int (*U_ttyf)(); /* tty query function pointer */
|
||||
|
||||
struct upfbuf *U_message; /* uprintf buffer pointer */
|
||||
struct trb * U_trb; /* trb for user scheduler */
|
||||
struct pvthread *U_chktv; /* pointer to adv handler pvthread */
|
||||
|
||||
/* file system state */
|
||||
vmid_t U_pn_segno; /* sid of chkpt/restart pathname seg*/
|
||||
Simple_lock U_pnseg_lock; /* lock of chkpt/restart pathname seg*/
|
||||
struct vnode *U_cdir; /* current directory of process */
|
||||
struct vnode *U_rdir; /* root directory of process */
|
||||
short U_cmask; /* mask for file creation */
|
||||
Simple_lock U_fso_lock; /* other file system fields lock */
|
||||
long U_lockflag; /* process has done file locks */
|
||||
long U_fdevent; /* fd lock event list */
|
||||
|
||||
long long U_irss; /* accumulator for memory integral */
|
||||
struct pinu_block *U_pinu_block;/* list of control structs for pinu */
|
||||
tid_t U_ulocks; /* event list for user locks */
|
||||
int32long64_t U_rmmap; /* anchor of rmmap list */
|
||||
|
||||
unsigned long long U_loader[84]; /* loader area */
|
||||
Simple_lock U_aio_susp_lock; /* aio lock used in aio_suspend */
|
||||
unsigned int U_fdfree[2]; /* file descriptor management */
|
||||
|
||||
unsigned int U_cannot_chpt; /* process unable to checkpoint */
|
||||
unsigned int U_maxofile; /* maximum u_ofile index in use */
|
||||
unsigned int U_freefile; /* first available u_ofile index */
|
||||
|
||||
/* WLM data */
|
||||
dev64_t U_dev; /* device of exec'ed file */
|
||||
ino64_t U_ino; /* inode */
|
||||
uint_t U_gen; /* generation number */
|
||||
|
||||
char U_tag[WLM_TAG_LENGTH+1]; /* WLM tag: user settable string */
|
||||
|
||||
/* structures added for VMM checkpoint/restart support */
|
||||
struct ckpt_ipcid *U_ckptshm; /* ptr to shmid blocks for checkpoint */
|
||||
struct ckpt_ipcid *U_ckptsem; /* ptr to semid blocks for checkpoint */
|
||||
struct ckpt_ipcid *U_ckptmsg; /* ptr to msgid blocks for checkpoint */
|
||||
struct _mmapent *U_mapent; /* ptr to mmap entry structure used for restart */
|
||||
ut_error_t U_ckpterr; /* u_error saved during ckpt processing */
|
||||
|
||||
#ifdef __64BIT_KERNEL
|
||||
char cacheline_pad[128]; /* keep 1st cacheline alligned */
|
||||
#else
|
||||
vmlpghandle_t U_lpgsegs32[NSEGS]; /* lgpg handles for 32bit processes */
|
||||
char cacheline_pad[64]; /* keep 1st cacheline alligned */
|
||||
#endif /* __64BIT_KERNEL */
|
||||
struct { /* file descriptor lock cacheline */
|
||||
Simple_lock u_fd_slock;
|
||||
char cache_pad[128 - sizeof(Simple_lock)];
|
||||
} U_fd_slcks[U_FD_LCK_CNT];
|
||||
|
||||
/* from here on the data is pageable. */
|
||||
|
||||
struct ufd U_ufd[OPEN_MAX];/* User's file descriptor table */
|
||||
};
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* struct utmp is not binary compatible
|
||||
* between 4.3 and 5.x
|
||||
* this structure is taken from 5.1 utmp.h
|
||||
* we compile this on v4.3.
|
||||
* XXX: will not compile 5.x if we want to compile
|
||||
* on 5.x would need to create a struct user_v4
|
||||
* to maintain bincompt.
|
||||
*/
|
||||
|
||||
struct utmp_v5 {
|
||||
char ut_user[256] ; /* User login name */
|
||||
char ut_id[14] ; /* /etc/inittab id */
|
||||
char ut_line[64] ; /* device name (console, lnxx) */
|
||||
pid_t ut_pid ; /* process id */
|
||||
short ut_type ; /* type of entry */
|
||||
#if !defined(__64BIT__) && !defined(__ia64)
|
||||
int __time_t_space; /* for 32vs64-bit time_t PPC */
|
||||
#endif
|
||||
time_t ut_time ; /* time entry was made */
|
||||
#if !defined(__64BIT__) && defined(__ia64)
|
||||
int __time_t_space; /* for 32vs64-bit time_t IA64 */
|
||||
#endif
|
||||
struct exit_status_v5
|
||||
{
|
||||
short e_termination ; /* Process termination status */
|
||||
short e_exit ; /* Process exit status */
|
||||
}
|
||||
ut_exit ; /* The exit status of a process
|
||||
* marked as DEAD_PROCESS.
|
||||
*/
|
||||
char ut_host[256] ; /* host name */
|
||||
int __dbl_word_pad; /* for double word alignment */
|
||||
int __reservedA[2];
|
||||
int __reservedV[6];
|
||||
};
|
||||
@@ -0,0 +1,854 @@
|
||||
#include "sigar.h"
|
||||
#include "sigar_private.h"
|
||||
#include "sigar_util.h"
|
||||
#include "sigar_os.h"
|
||||
|
||||
#ifdef DARWIN
|
||||
#include <mach/mach_init.h>
|
||||
#include <mach/message.h>
|
||||
#include <mach/kern_return.h>
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/user.h>
|
||||
#endif
|
||||
|
||||
#include <sys/mount.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/sockio.h>
|
||||
|
||||
#include <net/if.h>
|
||||
#include <net/if_dl.h>
|
||||
#include <net/if_types.h>
|
||||
#include <net/route.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
|
||||
#define NMIB(mib) (sizeof(mib)/sizeof(mib[0]))
|
||||
|
||||
int sigar_os_open(sigar_t **sigar)
|
||||
{
|
||||
int mib[2];
|
||||
int ncpu;
|
||||
size_t len;
|
||||
struct timeval boottime;
|
||||
|
||||
len = sizeof(ncpu);
|
||||
mib[0] = CTL_HW;
|
||||
mib[1] = HW_NCPU;
|
||||
if (sysctl(mib, NMIB(mib), &ncpu, &len, NULL, 0) < 0) {
|
||||
return errno;
|
||||
}
|
||||
|
||||
len = sizeof(boottime);
|
||||
mib[0] = CTL_KERN;
|
||||
mib[1] = KERN_BOOTTIME;
|
||||
if (sysctl(mib, NMIB(mib), &boottime, &len, NULL, 0) < 0) {
|
||||
return errno;
|
||||
}
|
||||
|
||||
*sigar = malloc(sizeof(**sigar));
|
||||
|
||||
#ifdef DARWIN
|
||||
(*sigar)->mach_port = mach_host_self();
|
||||
#endif
|
||||
|
||||
(*sigar)->ncpu = ncpu;
|
||||
|
||||
(*sigar)->boot_time = boottime.tv_sec; /* XXX seems off a bit */
|
||||
|
||||
(*sigar)->last_pid = -1;
|
||||
|
||||
(*sigar)->pinfo = NULL;
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
int sigar_os_close(sigar_t *sigar)
|
||||
{
|
||||
if (sigar->pinfo) {
|
||||
free(sigar->pinfo);
|
||||
}
|
||||
free(sigar);
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
char *sigar_os_error_string(int err)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int sigar_mem_get(sigar_t *sigar, sigar_mem_t *mem)
|
||||
{
|
||||
#ifdef DARWIN
|
||||
vm_statistics_data_t vmstat;
|
||||
kern_return_t status;
|
||||
mach_msg_type_number_t count = sizeof(vmstat) / sizeof(integer_t);
|
||||
#endif
|
||||
int mib[2];
|
||||
int totmem;
|
||||
size_t len = sizeof(totmem);
|
||||
|
||||
mib[0] = CTL_HW;
|
||||
|
||||
mib[1] = HW_PAGESIZE;
|
||||
if (sysctl(mib, NMIB(mib), &sigar->pagesize, &len, NULL, 0) < 0) {
|
||||
return errno;
|
||||
}
|
||||
|
||||
mib[1] = HW_PHYSMEM;
|
||||
if (sysctl(mib, NMIB(mib), &totmem, &len, NULL, 0) < 0) {
|
||||
return errno;
|
||||
}
|
||||
|
||||
mem->total = totmem;
|
||||
|
||||
sigar_mem_calc_ram(sigar, mem);
|
||||
|
||||
#ifdef DARWIN
|
||||
status = host_statistics(sigar->mach_port, HOST_VM_INFO,
|
||||
(host_info_t)&vmstat, &count);
|
||||
|
||||
if (status != KERN_SUCCESS) {
|
||||
return errno;
|
||||
}
|
||||
|
||||
mem->free = vmstat.free_count * sigar->pagesize;
|
||||
#else
|
||||
mem->free = 1; /*XXX*/
|
||||
#endif
|
||||
|
||||
mem->used = mem->total - mem->free;
|
||||
mem->shared = -1; /*XXX*/
|
||||
mem->buffer = -1;
|
||||
mem->cached = -1;
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
#define SIGAR_FS_BLOCKS_TO_BYTES(buf, f) \
|
||||
((buf.f * (buf.f_bsize / 512)) >> 1)
|
||||
|
||||
#define VM_DIR "/private/var/vm"
|
||||
#define SWAPFILE "swapfile"
|
||||
|
||||
int sigar_swap_get(sigar_t *sigar, sigar_swap_t *swap)
|
||||
{
|
||||
#ifdef DARWIN
|
||||
DIR *dirp;
|
||||
struct dirent *ent;
|
||||
char swapfile[SSTRLEN(VM_DIR) + SSTRLEN("/") + SSTRLEN(SWAPFILE) + 12];
|
||||
struct stat swapstat;
|
||||
struct statfs vmfs;
|
||||
|
||||
swap->used = swap->total = swap->free = 0;
|
||||
|
||||
if (!(dirp = opendir(VM_DIR))) {
|
||||
return errno;
|
||||
}
|
||||
|
||||
/* looking for "swapfile0", "swapfile1", etc. */
|
||||
while ((ent = readdir(dirp))) {
|
||||
char *ptr = swapfile;
|
||||
|
||||
if ((ent->d_namlen < SSTRLEN(SWAPFILE)+1) || /* n/a, see comment above */
|
||||
(ent->d_namlen > SSTRLEN(SWAPFILE)+11)) /* ensure no overflow */
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!strnEQ(ent->d_name, SWAPFILE, SSTRLEN(SWAPFILE))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* sprintf(swapfile, "%s/%s", VM_DIR, ent->d_name) */
|
||||
|
||||
memcpy(ptr, VM_DIR, SSTRLEN(VM_DIR));
|
||||
ptr += SSTRLEN(VM_DIR);
|
||||
|
||||
*ptr++ = '/';
|
||||
|
||||
memcpy(ptr, ent->d_name, ent->d_namlen+1);
|
||||
|
||||
if (stat(swapfile, &swapstat) < 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
swap->used += swapstat.st_size;
|
||||
}
|
||||
|
||||
closedir(dirp);
|
||||
|
||||
if (statfs(VM_DIR, &vmfs) < 0) {
|
||||
return errno;
|
||||
}
|
||||
|
||||
swap->total = SIGAR_FS_BLOCKS_TO_BYTES(vmfs, f_bfree) + swap->used;
|
||||
|
||||
swap->free = swap->total - swap->used;
|
||||
|
||||
#else
|
||||
/*XXX*/
|
||||
swap->total = 0;
|
||||
swap->used = 0;
|
||||
swap->free = 0;
|
||||
#endif
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
int sigar_cpu_get(sigar_t *sigar, sigar_cpu_t *cpu)
|
||||
{
|
||||
#ifdef DARWIN
|
||||
kern_return_t status;
|
||||
mach_msg_type_number_t count = HOST_CPU_LOAD_INFO_COUNT;
|
||||
host_cpu_load_info_data_t cpuload;
|
||||
|
||||
status = host_statistics(sigar->mach_port, HOST_CPU_LOAD_INFO,
|
||||
(host_info_t)&cpuload, &count);
|
||||
|
||||
if (status != KERN_SUCCESS) {
|
||||
return errno;
|
||||
}
|
||||
|
||||
cpu->user = cpuload.cpu_ticks[CPU_STATE_USER];
|
||||
cpu->sys = cpuload.cpu_ticks[CPU_STATE_SYSTEM];
|
||||
cpu->idle = cpuload.cpu_ticks[CPU_STATE_IDLE];
|
||||
cpu->nice = cpuload.cpu_ticks[CPU_STATE_NICE];
|
||||
|
||||
cpu->total = cpu->user + cpu->nice + cpu->sys + cpu->idle;
|
||||
|
||||
|
||||
#else
|
||||
/*XXX*/
|
||||
cpu->user = 0;
|
||||
cpu->nice = 0;
|
||||
cpu->sys = 0;
|
||||
cpu->idle = 0;
|
||||
|
||||
cpu->total = cpu->user + cpu->nice + cpu->sys + cpu->idle;
|
||||
#endif
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
int sigar_cpu_list_get(sigar_t *sigar, sigar_cpu_list_t *cpulist)
|
||||
{
|
||||
return SIGAR_ENOTIMPL;
|
||||
}
|
||||
|
||||
int sigar_uptime_get(sigar_t *sigar,
|
||||
sigar_uptime_t *uptime)
|
||||
{
|
||||
uptime->uptime = time(NULL) - sigar->boot_time;
|
||||
|
||||
uptime->idletime = -1;
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
int sigar_loadavg_get(sigar_t *sigar,
|
||||
sigar_loadavg_t *loadavg)
|
||||
{
|
||||
getloadavg(loadavg->loadavg, 3);
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
int sigar_proc_list_get(sigar_t *sigar,
|
||||
sigar_proc_list_t *proclist)
|
||||
{
|
||||
#ifdef DARWIN
|
||||
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0 };
|
||||
int i, num;
|
||||
size_t len;
|
||||
struct kinfo_proc *proc;
|
||||
|
||||
if (sysctl(mib, NMIB(mib), NULL, &len, NULL, 0) < 0) {
|
||||
return errno;
|
||||
}
|
||||
|
||||
proc = malloc(len);
|
||||
|
||||
if (sysctl(mib, NMIB(mib), proc, &len, NULL, 0) < 0) {
|
||||
free(proc);
|
||||
return errno;
|
||||
}
|
||||
|
||||
num = len/sizeof(*proc);
|
||||
proclist->number = 0;
|
||||
proclist->size = num;
|
||||
proclist->data = malloc(sizeof(*(proclist->data)) * num);
|
||||
|
||||
for (i=0; i<num; i++) {
|
||||
proclist->data[proclist->number++] = proc[i].kp_proc.p_pid;
|
||||
}
|
||||
|
||||
free(proc);
|
||||
|
||||
return SIGAR_OK;
|
||||
#else
|
||||
/*XXX above compiles on freebsd but no workie */
|
||||
return sigar_proc_list_procfs_get(sigar, proclist);
|
||||
#endif
|
||||
}
|
||||
|
||||
int sigar_proc_stat_get(sigar_t *sigar,
|
||||
sigar_proc_stat_t *procstat)
|
||||
{
|
||||
int status = /* XXX optimize */
|
||||
sigar_proc_count(sigar, &procstat->total);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
static int sigar_get_pinfo(sigar_t *sigar, sigar_pid_t pid)
|
||||
{
|
||||
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, 0 };
|
||||
size_t len = sizeof(*sigar->pinfo);
|
||||
time_t timenow = time(NULL);
|
||||
mib[3] = pid;
|
||||
|
||||
if (sigar->pinfo == NULL) {
|
||||
sigar->pinfo = malloc(len);
|
||||
}
|
||||
|
||||
if (sigar->last_pid == pid) {
|
||||
if ((timenow - sigar->last_getprocs) < SIGAR_LAST_PROC_EXPIRE) {
|
||||
return SIGAR_OK;
|
||||
}
|
||||
}
|
||||
|
||||
sigar->last_pid = pid;
|
||||
sigar->last_getprocs = timenow;
|
||||
|
||||
if (sysctl(mib, NMIB(mib), sigar->pinfo, &len, NULL, 0) < 0) {
|
||||
return errno;
|
||||
}
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
int sigar_proc_mem_get(sigar_t *sigar, sigar_pid_t pid,
|
||||
sigar_proc_mem_t *procmem)
|
||||
{
|
||||
mach_port_t task, self = mach_task_self();
|
||||
kern_return_t status;
|
||||
task_basic_info_data_t info;
|
||||
mach_msg_type_number_t type = TASK_BASIC_INFO_COUNT;
|
||||
|
||||
status = task_for_pid(self, pid, &task);
|
||||
|
||||
if (status != KERN_SUCCESS) {
|
||||
return errno;
|
||||
}
|
||||
|
||||
status = task_info(task, TASK_BASIC_INFO, &info, &type);
|
||||
|
||||
if (task != self) {
|
||||
mach_port_deallocate(self, task);
|
||||
}
|
||||
|
||||
procmem->vsize = info.virtual_size;
|
||||
procmem->resident = info.resident_size;
|
||||
|
||||
/*XXX*/
|
||||
procmem->size = 1; /* 1 == let ant test pass for now */
|
||||
procmem->rss = -1;
|
||||
procmem->share = -1;
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
int sigar_proc_cred_get(sigar_t *sigar, sigar_pid_t pid,
|
||||
sigar_proc_cred_t *proccred)
|
||||
{
|
||||
int status = sigar_get_pinfo(sigar, pid);
|
||||
struct kinfo_proc *pinfo = sigar->pinfo;
|
||||
|
||||
if (status != SIGAR_OK) {
|
||||
return status;
|
||||
}
|
||||
|
||||
proccred->uid = pinfo->kp_eproc.e_pcred.p_ruid;
|
||||
proccred->gid = pinfo->kp_eproc.e_pcred.p_rgid;
|
||||
proccred->euid = pinfo->kp_eproc.e_pcred.p_svuid;
|
||||
proccred->egid = pinfo->kp_eproc.e_pcred.p_svgid;
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
static int get_proc_times(sigar_pid_t pid, sigar_proc_time_t *time)
|
||||
{
|
||||
unsigned int count;
|
||||
time_value_t utime = {0, 0}, stime = {0, 0};
|
||||
task_basic_info_data_t ti;
|
||||
task_thread_times_info_data_t tti;
|
||||
task_port_t task, self = mach_task_self();
|
||||
kern_return_t status;
|
||||
|
||||
status = task_for_pid(self, pid, &task);
|
||||
if (status != KERN_SUCCESS) {
|
||||
return errno;
|
||||
}
|
||||
|
||||
count = TASK_BASIC_INFO_COUNT;
|
||||
status = task_info(task, TASK_BASIC_INFO,
|
||||
(task_info_t)&ti, &count);
|
||||
if (status != KERN_SUCCESS) {
|
||||
if (task != self) {
|
||||
mach_port_deallocate(self, task);
|
||||
}
|
||||
return errno;
|
||||
}
|
||||
|
||||
count = TASK_THREAD_TIMES_INFO_COUNT;
|
||||
status = task_info(task, TASK_THREAD_TIMES_INFO,
|
||||
(task_info_t)&tti, &count);
|
||||
if (status != KERN_SUCCESS) {
|
||||
if (task != self) {
|
||||
mach_port_deallocate(self, task);
|
||||
}
|
||||
return errno;
|
||||
}
|
||||
|
||||
time_value_add(&utime, &ti.user_time);
|
||||
time_value_add(&stime, &ti.system_time);
|
||||
time_value_add(&utime, &tti.user_time);
|
||||
time_value_add(&stime, &tti.system_time);
|
||||
|
||||
time->utime = utime.seconds;
|
||||
time->stime = stime.seconds;
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
int sigar_proc_time_get(sigar_t *sigar, sigar_pid_t pid,
|
||||
sigar_proc_time_t *proctime)
|
||||
{
|
||||
int status = sigar_get_pinfo(sigar, pid);
|
||||
struct kinfo_proc *pinfo = sigar->pinfo;
|
||||
|
||||
if (status != SIGAR_OK) {
|
||||
return status;
|
||||
}
|
||||
|
||||
if ((status = get_proc_times(pid, proctime)) != SIGAR_OK) {
|
||||
return status;
|
||||
}
|
||||
|
||||
#ifdef DARWIN
|
||||
proctime->start_time = pinfo->kp_proc.p_starttime.tv_sec;
|
||||
#else
|
||||
proctime->start_time = 1;/*XXX*/
|
||||
#endif
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
int sigar_proc_state_get(sigar_t *sigar, sigar_pid_t pid,
|
||||
sigar_proc_state_t *procstate)
|
||||
{
|
||||
int status = sigar_get_pinfo(sigar, pid);
|
||||
struct kinfo_proc *pinfo = sigar->pinfo;
|
||||
|
||||
if (status != SIGAR_OK) {
|
||||
return status;
|
||||
}
|
||||
|
||||
SIGAR_SSTRCPY(procstate->name, pinfo->kp_proc.p_comm);
|
||||
procstate->ppid = pinfo->kp_eproc.e_ppid;
|
||||
procstate->priority = pinfo->kp_proc.p_priority;
|
||||
procstate->nice = pinfo->kp_proc.p_nice;
|
||||
procstate->tty = -1; /*XXX*/
|
||||
|
||||
switch (pinfo->kp_proc.p_stat) {
|
||||
case SIDL:
|
||||
procstate->state = 'D';
|
||||
break;
|
||||
case SRUN:
|
||||
procstate->state = 'R';
|
||||
break;
|
||||
case SSLEEP:
|
||||
procstate->state = 'S';
|
||||
break;
|
||||
case SSTOP:
|
||||
procstate->state = 'T';
|
||||
break;
|
||||
case SZOMB:
|
||||
procstate->state = 'Z';
|
||||
break;
|
||||
}
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
int sigar_proc_args_get(sigar_t *sigar, sigar_pid_t pid,
|
||||
sigar_proc_args_t *procargs)
|
||||
{
|
||||
return SIGAR_ENOTIMPL;
|
||||
}
|
||||
|
||||
int sigar_proc_env_get(sigar_t *sigar, sigar_pid_t pid,
|
||||
sigar_proc_env_t *procenv)
|
||||
{
|
||||
return SIGAR_ENOTIMPL;
|
||||
}
|
||||
|
||||
int sigar_proc_fd_get(sigar_t *sigar, sigar_pid_t pid,
|
||||
sigar_proc_fd_t *procfd)
|
||||
{
|
||||
return SIGAR_ENOTIMPL;
|
||||
}
|
||||
|
||||
int sigar_proc_exe_get(sigar_t *sigar, sigar_pid_t pid,
|
||||
sigar_proc_exe_t *procexe)
|
||||
{
|
||||
return SIGAR_ENOTIMPL;
|
||||
}
|
||||
|
||||
int sigar_os_fs_type_get(sigar_file_system_t *fsp)
|
||||
{
|
||||
char *type = fsp->sys_type_name;
|
||||
|
||||
/* see sys/disklabel.h */
|
||||
switch (*type) {
|
||||
case 'h':
|
||||
if (strEQ(type, "hfs")) {
|
||||
fsp->type = SIGAR_FSTYPE_LOCAL_DISK;
|
||||
}
|
||||
break;
|
||||
case 'u':
|
||||
if (strEQ(type, "ufs")) {
|
||||
fsp->type = SIGAR_FSTYPE_LOCAL_DISK;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return fsp->type;
|
||||
}
|
||||
|
||||
int sigar_file_system_list_get(sigar_t *sigar,
|
||||
sigar_file_system_list_t *fslist)
|
||||
{
|
||||
struct statfs *fs;
|
||||
int num, i;
|
||||
long len;
|
||||
|
||||
if ((num = getfsstat(NULL, 0, MNT_NOWAIT)) < 0) {
|
||||
return errno;
|
||||
}
|
||||
|
||||
len = sizeof(*fs) * num;
|
||||
fs = malloc(len);
|
||||
|
||||
if ((num = getfsstat(fs, len, MNT_NOWAIT)) < 0) {
|
||||
return errno;
|
||||
}
|
||||
|
||||
sigar_file_system_list_create(fslist);
|
||||
|
||||
for (i=0; i<num; i++) {
|
||||
sigar_file_system_t *fsp;
|
||||
|
||||
SIGAR_FILE_SYSTEM_LIST_GROW(fslist);
|
||||
|
||||
fsp = &fslist->data[fslist->number++];
|
||||
|
||||
SIGAR_SSTRCPY(fsp->dir_name, fs[i].f_mntonname);
|
||||
SIGAR_SSTRCPY(fsp->dev_name, fs[i].f_mntfromname);
|
||||
SIGAR_SSTRCPY(fsp->sys_type_name, fs[i].f_fstypename);
|
||||
sigar_fs_type_init(fsp);
|
||||
}
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
int sigar_file_system_usage_get(sigar_t *sigar,
|
||||
const char *dirname,
|
||||
sigar_file_system_usage_t *fsusage)
|
||||
{
|
||||
struct statfs buf;
|
||||
|
||||
if (statfs(dirname, &buf) < 0) {
|
||||
return errno;
|
||||
}
|
||||
|
||||
fsusage->total = SIGAR_FS_BLOCKS_TO_BYTES(buf, f_blocks);
|
||||
fsusage->free = SIGAR_FS_BLOCKS_TO_BYTES(buf, f_bfree);
|
||||
fsusage->avail = SIGAR_FS_BLOCKS_TO_BYTES(buf, f_bavail);
|
||||
fsusage->files = buf.f_files;
|
||||
fsusage->free_files = buf.f_files;
|
||||
fsusage->use_percent = sigar_file_system_usage_calc_used(sigar, fsusage);
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
int sigar_cpu_infos_get(sigar_t *sigar,
|
||||
sigar_cpu_infos_t *cpu_infos)
|
||||
{
|
||||
int i;
|
||||
|
||||
sigar_cpu_infos_create(cpu_infos);
|
||||
|
||||
for (i=0; i<sigar->ncpu; i++) {
|
||||
sigar_cpu_info_t *info;
|
||||
|
||||
SIGAR_CPU_INFOS_GROW(cpu_infos);
|
||||
|
||||
info = &cpu_infos->data[cpu_infos->number++];
|
||||
|
||||
SIGAR_SSTRCPY(info->vendor, "Apple");
|
||||
SIGAR_SSTRCPY(info->model, "powerpc");
|
||||
|
||||
info->mhz = -1; /*XXX*/
|
||||
info->cache_size = -1;
|
||||
}
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
int sigar_net_route_list_get(sigar_t *sigar,
|
||||
sigar_net_route_list_t *routelist)
|
||||
{
|
||||
sigar_net_route_t *route;
|
||||
|
||||
sigar_net_route_list_create(routelist);
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
typedef enum {
|
||||
IFMSG_ITER_LIST,
|
||||
IFMSG_ITER_GET
|
||||
} ifmsg_iter_e;
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
ifmsg_iter_e type;
|
||||
union {
|
||||
sigar_net_interface_list_t *iflist;
|
||||
struct if_msghdr *ifm;
|
||||
} data;
|
||||
} ifmsg_iter_t;
|
||||
|
||||
static int sigar_ifmsg_init(sigar_t *sigar)
|
||||
{
|
||||
int mib[] = { CTL_NET, PF_ROUTE, 0, AF_INET, NET_RT_IFLIST, 0 };
|
||||
size_t len;
|
||||
|
||||
if (sysctl(mib, NMIB(mib), NULL, &len, NULL, 0) < 0) {
|
||||
return errno;
|
||||
}
|
||||
|
||||
if (sigar->ifconf_len < len) {
|
||||
sigar->ifconf_buf = realloc(sigar->ifconf_buf, len);
|
||||
sigar->ifconf_len = len;
|
||||
}
|
||||
|
||||
if (sysctl(mib, NMIB(mib), sigar->ifconf_buf, &len, NULL, 0) < 0) {
|
||||
return errno;
|
||||
}
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
static int sigar_ifmsg_iter(sigar_t *sigar, ifmsg_iter_t *iter)
|
||||
{
|
||||
char *end = sigar->ifconf_buf + sigar->ifconf_len;
|
||||
char *ptr = sigar->ifconf_buf;
|
||||
|
||||
if (iter->type == IFMSG_ITER_LIST) {
|
||||
sigar_net_interface_list_create(iter->data.iflist);
|
||||
}
|
||||
|
||||
while (ptr < end) {
|
||||
char *name;
|
||||
struct sockaddr_dl *sdl;
|
||||
struct if_msghdr *ifm = (struct if_msghdr *)ptr;
|
||||
|
||||
if (ifm->ifm_type != RTM_IFINFO) {
|
||||
break;
|
||||
}
|
||||
|
||||
ptr += ifm->ifm_msglen;
|
||||
|
||||
while (ptr < end) {
|
||||
struct if_msghdr *next = (struct if_msghdr *)ptr;
|
||||
|
||||
if (next->ifm_type != RTM_NEWADDR) {
|
||||
break;
|
||||
}
|
||||
|
||||
ptr += next->ifm_msglen;
|
||||
}
|
||||
|
||||
sdl = (struct sockaddr_dl *)(ifm + 1);
|
||||
if (sdl->sdl_family != AF_LINK) {
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (iter->type) {
|
||||
case IFMSG_ITER_LIST:
|
||||
SIGAR_NET_IFLIST_GROW(iter->data.iflist);
|
||||
|
||||
name = malloc(sdl->sdl_nlen+1);
|
||||
memcpy(name, sdl->sdl_data, sdl->sdl_nlen+1);
|
||||
|
||||
iter->data.iflist->data[iter->data.iflist->number++] = name;
|
||||
break;
|
||||
|
||||
case IFMSG_ITER_GET:
|
||||
if (strEQ(iter->name, sdl->sdl_data)) {
|
||||
iter->data.ifm = ifm;
|
||||
return SIGAR_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch (iter->type) {
|
||||
case IFMSG_ITER_LIST:
|
||||
return SIGAR_OK;
|
||||
|
||||
case IFMSG_ITER_GET:
|
||||
default:
|
||||
return ENXIO;
|
||||
}
|
||||
}
|
||||
|
||||
int sigar_net_interface_list_get(sigar_t *sigar,
|
||||
sigar_net_interface_list_t *iflist)
|
||||
{
|
||||
int status;
|
||||
ifmsg_iter_t iter;
|
||||
|
||||
if ((status = sigar_ifmsg_init(sigar)) != SIGAR_OK) {
|
||||
return status;
|
||||
}
|
||||
|
||||
iter.type = IFMSG_ITER_LIST;
|
||||
iter.data.iflist = iflist;
|
||||
|
||||
return sigar_ifmsg_iter(sigar, &iter);
|
||||
}
|
||||
|
||||
int sigar_net_interface_config_get(sigar_t *sigar, const char *name,
|
||||
sigar_net_interface_config_t *ifconfig)
|
||||
{
|
||||
int sock;
|
||||
int status;
|
||||
ifmsg_iter_t iter;
|
||||
struct if_msghdr *ifm;
|
||||
struct sockaddr_dl *sdl;
|
||||
struct ifreq ifr;
|
||||
|
||||
if (sigar->ifconf_len == 0) {
|
||||
if ((status = sigar_ifmsg_init(sigar)) != SIGAR_OK) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
iter.type = IFMSG_ITER_GET;
|
||||
iter.name = name;
|
||||
|
||||
if ((status = sigar_ifmsg_iter(sigar, &iter)) != SIGAR_OK) {
|
||||
return status;
|
||||
}
|
||||
|
||||
if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
|
||||
return errno;
|
||||
}
|
||||
|
||||
ifm = iter.data.ifm;
|
||||
|
||||
SIGAR_SSTRCPY(ifconfig->name, name);
|
||||
|
||||
sdl = (struct sockaddr_dl *)(ifm + 1);
|
||||
sigar_hwaddr_format(ifconfig->hwaddr,
|
||||
(unsigned char *)LLADDR(sdl));
|
||||
|
||||
ifconfig->flags = ifm->ifm_flags;
|
||||
ifconfig->mtu = ifm->ifm_data.ifi_mtu;
|
||||
ifconfig->metric = ifm->ifm_data.ifi_metric;
|
||||
|
||||
SIGAR_SSTRCPY(ifr.ifr_name, name);
|
||||
|
||||
#define ifr_s_addr(ifr) \
|
||||
((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr
|
||||
|
||||
if (!ioctl(sock, SIOCGIFADDR, &ifr)) {
|
||||
ifconfig->address = ifr_s_addr(ifr);
|
||||
}
|
||||
|
||||
if (!ioctl(sock, SIOCGIFNETMASK, &ifr)) {
|
||||
ifconfig->netmask = ifr_s_addr(ifr);
|
||||
}
|
||||
|
||||
if (ifconfig->flags & IFF_LOOPBACK) {
|
||||
ifconfig->destination = ifconfig->address;
|
||||
ifconfig->broadcast = 0;
|
||||
}
|
||||
else {
|
||||
if (!ioctl(sock, SIOCGIFDSTADDR, &ifr)) {
|
||||
ifconfig->destination = ifr_s_addr(ifr);
|
||||
}
|
||||
|
||||
if (!ioctl(sock, SIOCGIFBRDADDR, &ifr)) {
|
||||
ifconfig->broadcast = ifr_s_addr(ifr);
|
||||
}
|
||||
}
|
||||
|
||||
close(sock);
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
int sigar_net_interface_stat_get(sigar_t *sigar, const char *name,
|
||||
sigar_net_interface_stat_t *ifstat)
|
||||
{
|
||||
int status;
|
||||
ifmsg_iter_t iter;
|
||||
struct if_msghdr *ifm;
|
||||
|
||||
if (sigar->ifconf_len == 0) {
|
||||
if ((status = sigar_ifmsg_init(sigar)) != SIGAR_OK) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
iter.type = IFMSG_ITER_GET;
|
||||
iter.name = name;
|
||||
|
||||
if ((status = sigar_ifmsg_iter(sigar, &iter)) != SIGAR_OK) {
|
||||
return status;
|
||||
}
|
||||
|
||||
ifm = iter.data.ifm;
|
||||
|
||||
ifstat->rx_bytes = ifm->ifm_data.ifi_ibytes;
|
||||
ifstat->rx_packets = ifm->ifm_data.ifi_ipackets;
|
||||
ifstat->rx_errors = ifm->ifm_data.ifi_ierrors;
|
||||
ifstat->rx_dropped = ifm->ifm_data.ifi_iqdrops;
|
||||
ifstat->rx_overruns = -1;
|
||||
ifstat->rx_frame = -1;
|
||||
|
||||
ifstat->tx_bytes = ifm->ifm_data.ifi_obytes;
|
||||
ifstat->tx_packets = ifm->ifm_data.ifi_opackets;
|
||||
ifstat->tx_errors = ifm->ifm_data.ifi_oerrors;
|
||||
ifstat->tx_collisions = ifm->ifm_data.ifi_collisions;
|
||||
ifstat->tx_dropped = -1;
|
||||
ifstat->tx_overruns = -1;
|
||||
ifstat->tx_carrier = -1;
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
int sigar_net_connection_list_get(sigar_t *sigar,
|
||||
sigar_net_connection_list_t *connlist,
|
||||
int flags)
|
||||
{
|
||||
return SIGAR_ENOTIMPL;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#ifndef SIGAR_OS_H
|
||||
#define SIGAR_OS_H
|
||||
|
||||
#ifdef DARWIN
|
||||
#include <mach/port.h>
|
||||
#include <mach/host_info.h>
|
||||
#endif
|
||||
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
struct sigar_t {
|
||||
SIGAR_T_BASE;
|
||||
int pagesize;
|
||||
time_t last_getprocs;
|
||||
sigar_pid_t last_pid;
|
||||
struct kinfo_proc *pinfo;
|
||||
#ifdef DARWIN
|
||||
mach_port_t mach_port;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif /* SIGAR_OS_H */
|
||||
@@ -0,0 +1,3 @@
|
||||
see ../darwin/
|
||||
yes, darwin/macosx is based on freebsd (or something like that), but
|
||||
sigar was ported to darwin/macosx first so the sources live there.
|
||||
@@ -0,0 +1,266 @@
|
||||
/*
|
||||
* talk to Data Link Provider Interface aka /dev/dlpi
|
||||
* see: http://docs.hp.com/hpux/onlinedocs/B2355-90139/B2355-90139.html
|
||||
*/
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <memory.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/dlpi.h>
|
||||
#include <sys/dlpi_ext.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/stream.h>
|
||||
#include <sys/stropts.h>
|
||||
#include <sys/mib.h>
|
||||
|
||||
#define DLBUF_SIZE 8192
|
||||
|
||||
#define ERRBUF_SIZE 1024
|
||||
|
||||
static int send_req(int fd, char *ptr, int len, char *what, char *ebuf)
|
||||
{
|
||||
struct strbuf ctl;
|
||||
int flags = 0;
|
||||
|
||||
ctl.maxlen = 0;
|
||||
ctl.len = len;
|
||||
ctl.buf = ptr;
|
||||
|
||||
if (putmsg(fd, &ctl, (struct strbuf *) NULL, flags) < 0) {
|
||||
snprintf(ebuf, ERRBUF_SIZE, "send_req: putmsg \"%s\": %s",
|
||||
what, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int recv_ack(int fd, int size, const char *what, char *bufp, char *ebuf)
|
||||
{
|
||||
union DL_primitives *dlp;
|
||||
struct strbuf ctl;
|
||||
int flags = 0;
|
||||
|
||||
ctl.maxlen = DLBUF_SIZE;
|
||||
ctl.len = 0;
|
||||
ctl.buf = bufp;
|
||||
|
||||
if (getmsg(fd, &ctl, (struct strbuf*)NULL, &flags) < 0) {
|
||||
snprintf(ebuf, ERRBUF_SIZE, "recv_ack: %s getmsg: %s",
|
||||
what, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
dlp = (union DL_primitives *)ctl.buf;
|
||||
switch (dlp->dl_primitive) {
|
||||
case DL_INFO_ACK:
|
||||
case DL_BIND_ACK:
|
||||
case DL_OK_ACK:
|
||||
case DL_HP_PPA_ACK:
|
||||
case DL_HP_INFO_ACK:
|
||||
case DL_GET_STATISTICS_ACK:
|
||||
break;
|
||||
|
||||
case DL_ERROR_ACK:
|
||||
switch (dlp->error_ack.dl_errno) {
|
||||
|
||||
case DL_SYSERR:
|
||||
snprintf(ebuf, ERRBUF_SIZE, "recv_ack: %s: system error - %s",
|
||||
what, strerror(dlp->error_ack.dl_unix_errno));
|
||||
break;
|
||||
|
||||
default:
|
||||
snprintf(ebuf, ERRBUF_SIZE, "recv_ack: %s: dl error - %d",
|
||||
what, dlp->error_ack.dl_errno);
|
||||
break;
|
||||
}
|
||||
return -1;
|
||||
default:
|
||||
snprintf(ebuf, ERRBUF_SIZE,
|
||||
"recv_ack: %s: unexpected primitive ack %d",
|
||||
what, dlp->dl_primitive);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ctl.len < size) {
|
||||
snprintf(ebuf, ERRBUF_SIZE,
|
||||
"recv_ack: %s: ack too small (%d < %d)",
|
||||
what, ctl.len, size);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ctl.len;
|
||||
}
|
||||
|
||||
static int dl_attach_req(int fd, uint32_t ppa, char *ebuf)
|
||||
{
|
||||
dl_attach_req_t req;
|
||||
|
||||
req.dl_primitive = DL_ATTACH_REQ;
|
||||
req.dl_ppa = ppa;
|
||||
|
||||
return send_req(fd, (char *)&req, sizeof(req), "attach", ebuf);
|
||||
}
|
||||
|
||||
static int dl_bind_req(int fd, uint32_t sap, char *ebuf)
|
||||
{
|
||||
dl_bind_req_t req;
|
||||
|
||||
memset((char *)&req, 0, sizeof(req));
|
||||
req.dl_primitive = DL_BIND_REQ;
|
||||
|
||||
req.dl_max_conind = 1;
|
||||
/* 22 == INSAP, see HP-UX DLPI Programmer's Guide */
|
||||
req.dl_sap = 22;
|
||||
req.dl_service_mode = DL_HP_RAWDLS;
|
||||
req.dl_service_mode = DL_CODLS;
|
||||
|
||||
return send_req(fd, (char *)&req, sizeof(req), "bind", ebuf);
|
||||
}
|
||||
|
||||
static int dl_bind_ack(int fd, char *bufp, char *ebuf)
|
||||
{
|
||||
return recv_ack(fd, DL_BIND_ACK_SIZE, "bind", bufp, ebuf);
|
||||
}
|
||||
|
||||
static int dl_ok_ack(int fd, const char *what, char *bufp, char *ebuf)
|
||||
{
|
||||
return recv_ack(fd, DL_OK_ACK_SIZE, what, bufp, ebuf);
|
||||
}
|
||||
|
||||
static int dl_info_req(int fd, char *ebuf)
|
||||
{
|
||||
dl_info_req_t req;
|
||||
|
||||
req.dl_primitive = DL_INFO_REQ;
|
||||
|
||||
return send_req(fd, (char *)&req, sizeof(req), "info", ebuf);
|
||||
}
|
||||
|
||||
static int dl_info_ack(int fd, char *bufp, char *ebuf)
|
||||
{
|
||||
return recv_ack(fd, DL_INFO_ACK_SIZE, "info", bufp, ebuf);
|
||||
}
|
||||
|
||||
static int dl_hp_info_req(int fd, char *ebuf)
|
||||
{
|
||||
dl_hp_info_req_t req;
|
||||
|
||||
req.dl_primitive = DL_HP_INFO_REQ;
|
||||
|
||||
return send_req(fd, (char *)&req, sizeof(req), "hpinfo", ebuf);
|
||||
}
|
||||
|
||||
static int dl_hp_info_ack(int fd, char *bufp, char *ebuf)
|
||||
{
|
||||
return recv_ack(fd, DL_HP_INFO_ACK_SIZE, "hpinfo", bufp, ebuf);
|
||||
}
|
||||
|
||||
static int dl_stats_req(int fd, char *ebuf)
|
||||
{
|
||||
dl_get_statistics_req_t req;
|
||||
|
||||
req.dl_primitive = DL_GET_STATISTICS_REQ;
|
||||
|
||||
return send_req(fd, (char *)&req, sizeof(req), "stats", ebuf);
|
||||
}
|
||||
|
||||
static int dl_stats_ack(int fd, char *bufp, char *ebuf)
|
||||
{
|
||||
return recv_ack(fd, DL_GET_STATISTICS_ACK_SIZE, "stats", bufp, ebuf);
|
||||
}
|
||||
|
||||
static int dl_open(int ppa, char *ebuf)
|
||||
{
|
||||
char *dev = "/dev/dlpi";
|
||||
int fd = -1;
|
||||
dl_info_ack_t *infop;
|
||||
uint32_t buf[DLBUF_SIZE];
|
||||
char dname[128];
|
||||
|
||||
if ((fd = open(dev, O_RDWR)) < 0) {
|
||||
snprintf(ebuf, sizeof(ebuf),
|
||||
"failed to open %s: %s", dev, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dl_info_req(fd, ebuf) < 0 ||
|
||||
dl_info_ack(fd, (char *)buf, ebuf) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
infop = &((union DL_primitives *)buf)->info_ack;
|
||||
|
||||
if (infop->dl_provider_style == DL_STYLE2 &&
|
||||
(dl_attach_req(fd, ppa, ebuf) < 0 ||
|
||||
dl_ok_ack(fd, "attach", (char *)buf, ebuf) < 0))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dl_bind_req(fd, 0, ebuf) < 0 ||
|
||||
dl_bind_ack(fd, (char *)buf, ebuf) < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
static int dl_get_hp_info(int fd, char *bufp, char *ebuf)
|
||||
{
|
||||
dl_hp_info_ack_t *ip;
|
||||
|
||||
if ((dl_hp_info_req(fd, ebuf) < 0) ||
|
||||
(dl_hp_info_ack(fd, bufp, ebuf) < 0)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ip = (dl_hp_info_ack_t *)bufp;
|
||||
if (ip->dl_primitive != DL_HP_INFO_ACK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int dl_get_stats(int fd, char *bufp, char *ebuf)
|
||||
{
|
||||
dl_get_statistics_ack_t *ip;
|
||||
|
||||
if ((dl_stats_req(fd, ebuf) < 0) ||
|
||||
(dl_stats_ack(fd, bufp, ebuf) < 0)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ip = (dl_get_statistics_ack_t *)bufp;
|
||||
if (ip->dl_primitive != DL_GET_STATISTICS_ACK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hpux_get_mib_ifentry(int ppa, mib_ifEntry *mib)
|
||||
{
|
||||
int fd, status=0;
|
||||
char ebuf[ERRBUF_SIZE];
|
||||
uint32_t buf[DLBUF_SIZE];
|
||||
|
||||
if ((fd = dl_open(ppa, ebuf)) < 0) {
|
||||
return errno;
|
||||
}
|
||||
|
||||
if (dl_get_stats(fd, (char *)buf, ebuf) >= 0) {
|
||||
dl_get_statistics_ack_t *st = (dl_get_statistics_ack_t *)buf;
|
||||
memcpy(mib, (u_char *)buf + st->dl_stat_offset, sizeof(*mib));
|
||||
}
|
||||
else {
|
||||
status = errno;
|
||||
}
|
||||
|
||||
close(fd);
|
||||
return status;
|
||||
}
|
||||
@@ -0,0 +1,709 @@
|
||||
#include "sigar.h"
|
||||
#include "sigar_private.h"
|
||||
#include "sigar_os.h"
|
||||
#include "sigar_util.h"
|
||||
|
||||
#include <sys/dk.h>
|
||||
#include <errno.h>
|
||||
|
||||
int sigar_os_open(sigar_t **sigar)
|
||||
{
|
||||
*sigar = malloc(sizeof(**sigar));
|
||||
|
||||
/* does not change while system is running */
|
||||
pstat_getstatic(&(*sigar)->pstatic,
|
||||
sizeof((*sigar)->pstatic),
|
||||
1, 0);
|
||||
|
||||
(*sigar)->proctab = NULL;
|
||||
|
||||
(*sigar)->ticks = sysconf(_SC_CLK_TCK);
|
||||
|
||||
(*sigar)->last_pid = -1;
|
||||
|
||||
(*sigar)->pinfo = NULL;
|
||||
|
||||
return SIGAR_OK;
|
||||
|
||||
}
|
||||
|
||||
int sigar_os_close(sigar_t *sigar)
|
||||
{
|
||||
if (sigar->proctab) {
|
||||
free(sigar->proctab);
|
||||
}
|
||||
if (sigar->pinfo) {
|
||||
free(sigar->pinfo);
|
||||
}
|
||||
free(sigar);
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
char *sigar_os_error_string(int err)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int sigar_mem_get(sigar_t *sigar, sigar_mem_t *mem)
|
||||
{
|
||||
struct pst_dynamic stats;
|
||||
sigar_uint64_t pagesize = sigar->pstatic.page_size;
|
||||
|
||||
mem->total = sigar->pstatic.physical_memory * pagesize;
|
||||
|
||||
sigar_mem_calc_ram(sigar, mem);
|
||||
|
||||
pstat_getdynamic(&stats, sizeof(stats), 1, 0);
|
||||
|
||||
mem->free = stats.psd_free * pagesize;
|
||||
mem->used = mem->total - mem->free;
|
||||
|
||||
/*XXX*/
|
||||
mem->shared = mem->buffer = mem->cached = 0;
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
int sigar_swap_get(sigar_t *sigar, sigar_swap_t *swap)
|
||||
{
|
||||
struct pst_swapinfo swapinfo;
|
||||
int i=0;
|
||||
|
||||
swap->total = swap->free = 0;
|
||||
|
||||
while (pstat_getswap(&swapinfo, sizeof(swapinfo), 1, i++) > 0) {
|
||||
swapinfo.pss_nfpgs *= 4; /* nfpgs is in 512 byte blocks */
|
||||
|
||||
if (swapinfo.pss_nblksenabled == 0) {
|
||||
swapinfo.pss_nblksenabled = swapinfo.pss_nfpgs;
|
||||
}
|
||||
|
||||
swap->total += swapinfo.pss_nblksenabled;
|
||||
swap->free += swapinfo.pss_nfpgs;
|
||||
}
|
||||
|
||||
swap->used = swap->total - swap->free;
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
int sigar_cpu_get(sigar_t *sigar, sigar_cpu_t *cpu)
|
||||
{
|
||||
int i;
|
||||
struct pst_dynamic stats;
|
||||
|
||||
pstat_getdynamic(&stats, sizeof(stats), 1, 0);
|
||||
sigar->ncpu = stats.psd_proc_cnt;
|
||||
|
||||
cpu->user = stats.psd_cpu_time[CP_USER];
|
||||
cpu->sys = stats.psd_cpu_time[CP_SYS] + stats.psd_cpu_time[CP_SSYS];
|
||||
cpu->nice = stats.psd_cpu_time[CP_NICE];
|
||||
cpu->idle = stats.psd_cpu_time[CP_IDLE];
|
||||
|
||||
cpu->total = 0;
|
||||
|
||||
/* states above plus CP_BLOCK, CP_SWAIT, etc. (see sys/dk.h) */
|
||||
for (i=0; i<CPUSTATES; i++) {
|
||||
cpu->total += stats.psd_cpu_time[i];
|
||||
}
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
int sigar_cpu_list_get(sigar_t *sigar, sigar_cpu_list_t *cpulist)
|
||||
{
|
||||
int i;
|
||||
struct pst_dynamic stats;
|
||||
|
||||
pstat_getdynamic(&stats, sizeof(stats), 1, 0);
|
||||
sigar->ncpu = stats.psd_proc_cnt;
|
||||
|
||||
sigar_cpu_list_create(cpulist);
|
||||
|
||||
for (i=0; i<sigar->ncpu; i++) {
|
||||
int j;
|
||||
sigar_cpu_t *cpu;
|
||||
struct pst_processor proc;
|
||||
|
||||
if (pstat_getprocessor(&proc, sizeof(proc), 1, i) < 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
SIGAR_CPU_LIST_GROW(cpulist);
|
||||
|
||||
cpu = &cpulist->data[cpulist->number++];
|
||||
|
||||
cpu->user = proc.psp_cpu_time[CP_USER];
|
||||
cpu->sys = proc.psp_cpu_time[CP_SYS] + proc.psp_cpu_time[CP_SSYS];
|
||||
cpu->nice = proc.psp_cpu_time[CP_NICE];
|
||||
cpu->idle = proc.psp_cpu_time[CP_IDLE];
|
||||
|
||||
cpu->total = 0;
|
||||
|
||||
for (j=0; j<CPUSTATES; j++) {
|
||||
cpu->total += proc.psp_cpu_time[j];
|
||||
}
|
||||
}
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
int sigar_uptime_get(sigar_t *sigar,
|
||||
sigar_uptime_t *uptime)
|
||||
{
|
||||
uptime->uptime = time(NULL) - sigar->pstatic.boot_time;
|
||||
uptime->idletime = 0; /*XXX*/;
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
int sigar_loadavg_get(sigar_t *sigar,
|
||||
sigar_loadavg_t *loadavg)
|
||||
{
|
||||
struct pst_dynamic stats;
|
||||
|
||||
pstat_getdynamic(&stats, sizeof(stats), 1, 0);
|
||||
|
||||
loadavg->loadavg[0] = stats.psd_avg_1_min;
|
||||
loadavg->loadavg[1] = stats.psd_avg_5_min;
|
||||
loadavg->loadavg[2] = stats.psd_avg_15_min;
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
int sigar_proc_list_get(sigar_t *sigar,
|
||||
sigar_proc_list_t *proclist)
|
||||
{
|
||||
int n;
|
||||
|
||||
if (!sigar->proctab) {
|
||||
/* malloc this only once per-sigar_t as the size will not change */
|
||||
sigar->proctab = malloc(sizeof(*sigar->proctab) *
|
||||
sigar->pstatic.max_proc);
|
||||
}
|
||||
|
||||
n = pstat_getproc(sigar->proctab, sizeof(*sigar->proctab),
|
||||
sigar->pstatic.max_proc, 0);
|
||||
|
||||
proclist->number = 0;
|
||||
proclist->size = n;
|
||||
proclist->data = malloc(sizeof(*(proclist->data)) * n);
|
||||
|
||||
for (n=0; n<proclist->size; n++) {
|
||||
proclist->data[proclist->number++] =
|
||||
sigar->proctab[n].pst_pid;
|
||||
}
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
int sigar_proc_stat_get(sigar_t *sigar,
|
||||
sigar_proc_stat_t *procstat)
|
||||
{
|
||||
int status = /* XXX optimize */
|
||||
sigar_proc_count(sigar, &procstat->total);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
static int sigar_pstat_getproc(sigar_t *sigar, sigar_pid_t pid)
|
||||
{
|
||||
int status, num;
|
||||
time_t timenow = time(NULL);
|
||||
|
||||
if (sigar->pinfo == NULL) {
|
||||
sigar->pinfo = malloc(sizeof(*sigar->pinfo));
|
||||
}
|
||||
|
||||
if (sigar->last_pid == pid) {
|
||||
if ((timenow - sigar->last_getprocs) < SIGAR_LAST_PROC_EXPIRE) {
|
||||
return SIGAR_OK;
|
||||
}
|
||||
}
|
||||
|
||||
sigar->last_pid = pid;
|
||||
sigar->last_getprocs = timenow;
|
||||
|
||||
if (pstat_getproc(sigar->pinfo,
|
||||
sizeof(*sigar->pinfo),
|
||||
0, pid) == -1)
|
||||
{
|
||||
return ESRCH;
|
||||
}
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
int sigar_proc_mem_get(sigar_t *sigar, sigar_pid_t pid,
|
||||
sigar_proc_mem_t *procmem)
|
||||
{
|
||||
int pagesize = sigar->pstatic.page_size;
|
||||
int status = sigar_pstat_getproc(sigar, pid);
|
||||
struct pst_status *pinfo = sigar->pinfo;
|
||||
|
||||
if (status != SIGAR_OK) {
|
||||
return status;
|
||||
}
|
||||
|
||||
procmem->size =
|
||||
pinfo->pst_tsize + /* text */
|
||||
pinfo->pst_dsize + /* data */
|
||||
pinfo->pst_ssize; /* stack */
|
||||
|
||||
procmem->size *= pagesize;
|
||||
|
||||
procmem->vsize =
|
||||
pinfo->pst_vtsize + /* text */
|
||||
pinfo->pst_vdsize + /* data */
|
||||
pinfo->pst_vssize; /* stack */
|
||||
|
||||
procmem->vsize *= pagesize;
|
||||
|
||||
procmem->rss = pinfo->pst_rssize * pagesize;
|
||||
|
||||
procmem->share = pinfo->pst_shmsize * pagesize;
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
int sigar_proc_cred_get(sigar_t *sigar, sigar_pid_t pid,
|
||||
sigar_proc_cred_t *proccred)
|
||||
{
|
||||
int status = sigar_pstat_getproc(sigar, pid);
|
||||
struct pst_status *pinfo = sigar->pinfo;
|
||||
|
||||
if (status != SIGAR_OK) {
|
||||
return status;
|
||||
}
|
||||
|
||||
proccred->uid = pinfo->pst_uid;
|
||||
proccred->gid = pinfo->pst_gid;
|
||||
proccred->euid = pinfo->pst_euid;
|
||||
proccred->egid = pinfo->pst_egid;
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
int sigar_proc_time_get(sigar_t *sigar, sigar_pid_t pid,
|
||||
sigar_proc_time_t *proctime)
|
||||
{
|
||||
int status = sigar_pstat_getproc(sigar, pid);
|
||||
struct pst_status *pinfo = sigar->pinfo;
|
||||
|
||||
if (status != SIGAR_OK) {
|
||||
return status;
|
||||
}
|
||||
|
||||
proctime->start_time = pinfo->pst_start;
|
||||
proctime->start_time *= 1000;
|
||||
proctime->utime = pinfo->pst_utime;
|
||||
proctime->stime = pinfo->pst_stime;
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
int sigar_proc_state_get(sigar_t *sigar, sigar_pid_t pid,
|
||||
sigar_proc_state_t *procstate)
|
||||
{
|
||||
int status = sigar_pstat_getproc(sigar, pid);
|
||||
struct pst_status *pinfo = sigar->pinfo;
|
||||
|
||||
if (status != SIGAR_OK) {
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
SIGAR_SSTRCPY(procstate->name, pinfo->pst_ucomm);
|
||||
procstate->ppid = pinfo->pst_ppid;
|
||||
procstate->tty = makedev(pinfo->pst_term.psd_major,
|
||||
pinfo->pst_term.psd_minor);
|
||||
procstate->priority = pinfo->pst_pri;
|
||||
procstate->nice = pinfo->pst_nice;
|
||||
|
||||
switch (pinfo->pst_stat) {
|
||||
case PS_SLEEP:
|
||||
procstate->state = 'S';
|
||||
break;
|
||||
case PS_RUN:
|
||||
procstate->state = 'R';
|
||||
break;
|
||||
case PS_STOP:
|
||||
procstate->state = 'T';
|
||||
break;
|
||||
case PS_ZOMBIE:
|
||||
procstate->state = 'Z';
|
||||
break;
|
||||
case PS_IDLE:
|
||||
procstate->state = 'D';
|
||||
break;
|
||||
}
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
/* XXX: could be useful elsewhere */
|
||||
static char *sigar_getword(char **line, char stop)
|
||||
{
|
||||
char *pos = *line;
|
||||
int len;
|
||||
char *res;
|
||||
|
||||
while ((*pos != stop) && *pos) {
|
||||
++pos;
|
||||
}
|
||||
|
||||
len = pos - *line;
|
||||
res = (char *)malloc(len + 1);
|
||||
memcpy(res, *line, len);
|
||||
res[len] = 0;
|
||||
|
||||
if (stop) {
|
||||
while (*pos == stop) {
|
||||
++pos;
|
||||
}
|
||||
}
|
||||
|
||||
*line = pos;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/*
|
||||
* XXX: pst_cmd is only 64 chars of the command args.
|
||||
* according to HP forums there isn't a way to get them
|
||||
* all if > 64
|
||||
*/
|
||||
int sigar_proc_args_get(sigar_t *sigar, sigar_pid_t pid,
|
||||
sigar_proc_args_t *procargs)
|
||||
{
|
||||
char *args, *arg;
|
||||
struct pst_status status;
|
||||
|
||||
if (pstat_getproc(&status, sizeof(status), 0, pid) == -1) {
|
||||
return ESRCH;
|
||||
}
|
||||
|
||||
args = status.pst_cmd;
|
||||
sigar_proc_args_create(procargs);
|
||||
|
||||
while (*args && (arg = sigar_getword(&args, ' '))) {
|
||||
SIGAR_PROC_ARGS_GROW(procargs);
|
||||
procargs->data[procargs->number++] = arg;
|
||||
}
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
int sigar_proc_env_get(sigar_t *sigar, sigar_pid_t pid,
|
||||
sigar_proc_env_t *procenv)
|
||||
{
|
||||
return SIGAR_ENOTIMPL;
|
||||
}
|
||||
|
||||
int sigar_proc_fd_get(sigar_t *sigar, sigar_pid_t pid,
|
||||
sigar_proc_fd_t *procfd)
|
||||
{
|
||||
struct pst_status status;
|
||||
int idx, i, n;
|
||||
struct pst_fileinfo psf[16];
|
||||
|
||||
procfd->total = 0;
|
||||
|
||||
if (pstat_getproc(&status, sizeof(status), 0, pid) == -1) {
|
||||
return ESRCH;
|
||||
}
|
||||
|
||||
/* man pstat_getfile for index splaination */
|
||||
idx = (status.pst_idx << 16) | (0 & 0xffff);
|
||||
|
||||
while ((n = pstat_getfile(psf, sizeof(psf[0]),
|
||||
sizeof(psf)/sizeof(psf[0]),
|
||||
idx)) > 0)
|
||||
{
|
||||
procfd->total += n;
|
||||
idx = psf[n-1].psf_idx + 1;
|
||||
}
|
||||
|
||||
if (n == -1) {
|
||||
return errno;
|
||||
}
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
int sigar_proc_exe_get(sigar_t *sigar, sigar_pid_t pid,
|
||||
sigar_proc_exe_t *procexe)
|
||||
{
|
||||
return SIGAR_ENOTIMPL;
|
||||
}
|
||||
|
||||
#include <mntent.h>
|
||||
|
||||
int sigar_os_fs_type_get(sigar_file_system_t *fsp)
|
||||
{
|
||||
char *type = fsp->sys_type_name;
|
||||
|
||||
switch (*type) {
|
||||
case 'h':
|
||||
if (strEQ(type, "hfs")) {
|
||||
fsp->type = SIGAR_FSTYPE_LOCAL_DISK;
|
||||
}
|
||||
break;
|
||||
case 'v':
|
||||
if (strEQ(type, "vxfs")) {
|
||||
fsp->type = SIGAR_FSTYPE_LOCAL_DISK;
|
||||
}
|
||||
break;
|
||||
case 'c':
|
||||
if (strEQ(type, "cdfs")) {
|
||||
fsp->type = SIGAR_FSTYPE_CDROM;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return fsp->type;
|
||||
}
|
||||
|
||||
int sigar_file_system_list_get(sigar_t *sigar,
|
||||
sigar_file_system_list_t *fslist)
|
||||
{
|
||||
struct mntent ent;
|
||||
char buf[1025];
|
||||
|
||||
FILE *fp;
|
||||
sigar_file_system_t *fsp;
|
||||
|
||||
if (!(fp = setmntent(MNT_CHECKLIST, "r"))) {
|
||||
return errno;
|
||||
}
|
||||
|
||||
sigar_file_system_list_create(fslist);
|
||||
|
||||
while (getmntent_r(fp, &ent, buf, sizeof(buf)) == 0) {
|
||||
if ((*(ent.mnt_type) == 's') &&
|
||||
strEQ(ent.mnt_type, "swap"))
|
||||
{
|
||||
/*
|
||||
* in this case, devname == "...", for
|
||||
* which statfs chokes on. so skip it.
|
||||
* also notice hpux df command has no swap info.
|
||||
*/
|
||||
continue;
|
||||
}
|
||||
|
||||
SIGAR_FILE_SYSTEM_LIST_GROW(fslist);
|
||||
|
||||
fsp = &fslist->data[fslist->number++];
|
||||
|
||||
SIGAR_SSTRCPY(fsp->dir_name, ent.mnt_dir);
|
||||
SIGAR_SSTRCPY(fsp->dev_name, ent.mnt_fsname);
|
||||
SIGAR_SSTRCPY(fsp->sys_type_name, ent.mnt_type);
|
||||
sigar_fs_type_init(fsp);
|
||||
}
|
||||
|
||||
endmntent(fp);
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
/* XXX this is exactly the same as linux and solaris is darn close */
|
||||
#include <sys/vfs.h>
|
||||
|
||||
#define SIGAR_FS_BLOCKS_TO_BYTES(buf, f) \
|
||||
((buf.f * (buf.f_bsize / 512)) >> 1)
|
||||
|
||||
int sigar_file_system_usage_get(sigar_t *sigar,
|
||||
const char *dirname,
|
||||
sigar_file_system_usage_t *fsusage)
|
||||
{
|
||||
struct statfs buf;
|
||||
|
||||
if (statfs(dirname, &buf) != 0) {
|
||||
return errno;
|
||||
}
|
||||
|
||||
fsusage->total = SIGAR_FS_BLOCKS_TO_BYTES(buf, f_blocks);
|
||||
fsusage->free = SIGAR_FS_BLOCKS_TO_BYTES(buf, f_bfree);
|
||||
fsusage->avail = SIGAR_FS_BLOCKS_TO_BYTES(buf, f_bavail);
|
||||
fsusage->files = buf.f_files;
|
||||
fsusage->free_files = buf.f_ffree;
|
||||
fsusage->use_percent = sigar_file_system_usage_calc_used(sigar, fsusage);
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
int sigar_cpu_infos_get(sigar_t *sigar,
|
||||
sigar_cpu_infos_t *cpu_infos)
|
||||
{
|
||||
int i;
|
||||
struct pst_dynamic stats;
|
||||
|
||||
pstat_getdynamic(&stats, sizeof(stats), 1, 0);
|
||||
sigar->ncpu = stats.psd_proc_cnt;
|
||||
|
||||
sigar_cpu_infos_create(cpu_infos);
|
||||
|
||||
for (i=0; i<sigar->ncpu; i++) {
|
||||
sigar_cpu_info_t *info;
|
||||
struct pst_processor proc;
|
||||
|
||||
if (pstat_getprocessor(&proc, sizeof(proc), 1, i) < 0) {
|
||||
perror("pstat_getprocessor");
|
||||
continue;
|
||||
}
|
||||
|
||||
SIGAR_CPU_INFOS_GROW(cpu_infos);
|
||||
|
||||
info = &cpu_infos->data[cpu_infos->number++];
|
||||
|
||||
SIGAR_SSTRCPY(info->vendor, "HP"); /*XXX*/
|
||||
SIGAR_SSTRCPY(info->model, "PA RISC"); /*XXX*/
|
||||
info->mhz = sigar->ticks * proc.psp_iticksperclktick / 1000000;
|
||||
info->cache_size = -1; /*XXX*/
|
||||
}
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
int sigar_net_route_list_get(sigar_t *sigar,
|
||||
sigar_net_route_list_t *routelist)
|
||||
{
|
||||
int fd, count, i;
|
||||
unsigned int len;
|
||||
struct nmparms parms;
|
||||
mib_ipRouteEnt *routes;
|
||||
sigar_net_route_t *route;
|
||||
|
||||
if ((fd = open_mib("/dev/ip", O_RDWR, 0, 0)) < 0) {
|
||||
return errno;
|
||||
}
|
||||
|
||||
len = sizeof(count);
|
||||
parms.objid = ID_ipRouteNumEnt;
|
||||
parms.buffer = &count;
|
||||
parms.len = &len;
|
||||
|
||||
if (get_mib_info(fd, &parms) < 0) {
|
||||
return errno;
|
||||
}
|
||||
|
||||
len = count * sizeof(*routes);
|
||||
routes = malloc(len);
|
||||
|
||||
parms.objid = ID_ipRouteTable;
|
||||
parms.buffer = routes;
|
||||
parms.len = &len;
|
||||
|
||||
if (get_mib_info(fd, &parms) < 0) {
|
||||
free(routes);
|
||||
return errno;
|
||||
}
|
||||
|
||||
routelist->size = routelist->number = 0;
|
||||
|
||||
sigar_net_route_list_create(routelist);
|
||||
|
||||
for (i=0; i<count; i++) {
|
||||
mib_ipRouteEnt *ent = &routes[i];
|
||||
|
||||
SIGAR_NET_ROUTE_LIST_GROW(routelist);
|
||||
|
||||
route = &routelist->data[routelist->number++];
|
||||
SIGAR_ZERO(route); /* XXX: other fields */
|
||||
|
||||
route->destination = ent->Dest;
|
||||
route->mask = ent->Mask;
|
||||
route->gateway = ent->NextHop;
|
||||
}
|
||||
|
||||
free(routes);
|
||||
close_mib(fd);
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
static int get_mib_ifstat(sigar_t *sigar,
|
||||
const char *name,
|
||||
mib_ifEntry *mib)
|
||||
{
|
||||
int fd, count, i;
|
||||
unsigned int len;
|
||||
nmapi_phystat *stat;
|
||||
struct nmparms parms;
|
||||
|
||||
if ((fd = open_mib("/dev/ip", O_RDWR, 0, 0)) < 0) {
|
||||
return errno;
|
||||
}
|
||||
|
||||
len = sizeof(count);
|
||||
parms.objid = ID_ifNumber;
|
||||
parms.buffer = &count;
|
||||
parms.len = &len;
|
||||
|
||||
if (get_mib_info(fd, &parms) < 0) {
|
||||
return errno;
|
||||
}
|
||||
|
||||
len = sizeof(nmapi_phystat) * count;
|
||||
|
||||
if (sigar->ifconf_len < len) {
|
||||
sigar->ifconf_buf = realloc(sigar->ifconf_buf, len);
|
||||
sigar->ifconf_len = len;
|
||||
}
|
||||
|
||||
if (get_physical_stat(sigar->ifconf_buf, &len) < 0) {
|
||||
close_mib(fd);
|
||||
return errno;
|
||||
}
|
||||
|
||||
for (i=0, stat = (nmapi_phystat *)sigar->ifconf_buf;
|
||||
i<count;
|
||||
i++, stat++)
|
||||
{
|
||||
if (strEQ(stat->nm_device, name)) {
|
||||
memcpy(mib, &stat->if_entry, sizeof(*mib));
|
||||
close_mib(fd);
|
||||
return SIGAR_OK;
|
||||
}
|
||||
}
|
||||
|
||||
close_mib(fd);
|
||||
return ENXIO;
|
||||
}
|
||||
|
||||
int sigar_net_interface_stat_get(sigar_t *sigar, const char *name,
|
||||
sigar_net_interface_stat_t *ifstat)
|
||||
{
|
||||
int status;
|
||||
mib_ifEntry mib;
|
||||
|
||||
status = get_mib_ifstat(sigar, name, &mib);
|
||||
|
||||
if (status != SIGAR_OK) {
|
||||
return status;
|
||||
}
|
||||
|
||||
ifstat->rx_bytes = mib.ifInOctets;
|
||||
ifstat->rx_packets = mib.ifInUcastPkts + mib.ifInNUcastPkts;
|
||||
ifstat->rx_errors = mib.ifInErrors;
|
||||
ifstat->rx_dropped = mib.ifInDiscards;
|
||||
ifstat->rx_overruns = 0; /*XXX*/
|
||||
ifstat->rx_frame = 0; /*XXX*/
|
||||
|
||||
ifstat->tx_bytes = mib.ifOutOctets;
|
||||
ifstat->tx_packets = mib.ifOutUcastPkts + mib.ifOutNUcastPkts;
|
||||
ifstat->tx_errors = mib.ifOutErrors;
|
||||
ifstat->tx_dropped = mib.ifOutDiscards;
|
||||
ifstat->tx_overruns = 0; /*XXX*/
|
||||
ifstat->tx_collisions = 0; /*XXX*/
|
||||
ifstat->tx_carrier = 0; /*XXX*/
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
int sigar_net_connection_list_get(sigar_t *sigar,
|
||||
sigar_net_connection_list_t *connlist,
|
||||
int flags)
|
||||
{
|
||||
return SIGAR_ENOTIMPL;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#ifndef SIGAR_OS_H
|
||||
#define SIGAR_OS_H
|
||||
|
||||
#include <sys/pstat.h>
|
||||
#include <sys/mib.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
struct sigar_t {
|
||||
SIGAR_T_BASE;
|
||||
struct pst_static pstatic;
|
||||
struct pst_status *proctab;
|
||||
time_t last_getprocs;
|
||||
sigar_pid_t last_pid;
|
||||
struct pst_status *pinfo;
|
||||
};
|
||||
|
||||
int hpux_get_mib_ifentry(int ppa, mib_ifEntry *mib);
|
||||
|
||||
#endif /* SIGAR_OS_H */
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,47 @@
|
||||
#ifndef SIGAR_OS_H
|
||||
#define SIGAR_OS_H
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <ctype.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
typedef struct {
|
||||
sigar_pid_t pid;
|
||||
time_t mtime;
|
||||
sigar_uint64_t vsize;
|
||||
sigar_uint64_t rss;
|
||||
sigar_uint64_t ppid;
|
||||
int tty;
|
||||
int priority;
|
||||
int nice;
|
||||
sigar_uint64_t start_time;
|
||||
sigar_uint64_t utime;
|
||||
sigar_uint64_t stime;
|
||||
char name[SIGAR_PROC_NAME_LEN];
|
||||
char state;
|
||||
} linux_proc_stat_t;
|
||||
|
||||
struct sigar_t {
|
||||
SIGAR_T_BASE;
|
||||
int ram;
|
||||
int proc_signal_offset;
|
||||
linux_proc_stat_t last_proc_stat;
|
||||
};
|
||||
|
||||
#define HAVE_STRERROR_R
|
||||
#define HAVE_STRERROR_R_GLIBC
|
||||
#define HAVE_READDIR_R
|
||||
#define HAVE_GETPWNAM_R
|
||||
#define HAVE_GETPWUID_R
|
||||
#define HAVE_GETGRGID_R
|
||||
|
||||
#endif /* SIGAR_OS_H */
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* from sys/hme.h, private to _KERNEL.
|
||||
* we should be ok provided ksp->ks_data_size == sizeof(struct hmekstat)
|
||||
* else will need to fallback to using kstat_data_lookup.
|
||||
*/
|
||||
|
||||
struct hmekstat {
|
||||
struct kstat_named hk_ipackets; /* packets received */
|
||||
struct kstat_named hk_ierrors; /* input errors */
|
||||
struct kstat_named hk_opackets; /* packets transmitted */
|
||||
struct kstat_named hk_oerrors; /* output errors */
|
||||
struct kstat_named hk_coll; /* collisions encountered */
|
||||
struct kstat_named hk_defer; /* slots deferred */
|
||||
struct kstat_named hk_fram; /* framing errors */
|
||||
struct kstat_named hk_crc; /* crc errors */
|
||||
struct kstat_named hk_sqerr; /* SQE test errors */
|
||||
struct kstat_named hk_cvc; /* code violation errors */
|
||||
struct kstat_named hk_lenerr; /* rx len errors */
|
||||
struct kstat_named hk_ifspeed; /* interface speed */
|
||||
struct kstat_named hk_buff; /* buff errors */
|
||||
struct kstat_named hk_oflo; /* overflow errors */
|
||||
struct kstat_named hk_uflo; /* underflow errors */
|
||||
struct kstat_named hk_missed; /* missed/dropped packets */
|
||||
struct kstat_named hk_tlcol; /* late collisions */
|
||||
struct kstat_named hk_trtry; /* retry errors */
|
||||
struct kstat_named hk_fstcol; /* first collisions */
|
||||
struct kstat_named hk_tnocar; /* no carrier */
|
||||
struct kstat_named hk_inits; /* initialization */
|
||||
struct kstat_named hk_nocanput; /* nocanput errors */
|
||||
struct kstat_named hk_allocbfail; /* allocb failures */
|
||||
struct kstat_named hk_runt; /* runt errors */
|
||||
struct kstat_named hk_jab; /* jabber errors */
|
||||
struct kstat_named hk_babl; /* runt errors */
|
||||
struct kstat_named hk_tmder; /* tmd errors */
|
||||
struct kstat_named hk_txlaterr; /* tx late errors */
|
||||
struct kstat_named hk_rxlaterr; /* rx late errors */
|
||||
struct kstat_named hk_slvparerr; /* slave parity errors */
|
||||
struct kstat_named hk_txparerr; /* tx parity errors */
|
||||
struct kstat_named hk_rxparerr; /* rx parity errors */
|
||||
struct kstat_named hk_slverrack; /* slave error acks */
|
||||
struct kstat_named hk_txerrack; /* tx error acks */
|
||||
struct kstat_named hk_rxerrack; /* rx error acks */
|
||||
struct kstat_named hk_txtagerr; /* tx tag error */
|
||||
struct kstat_named hk_rxtagerr; /* rx tag error */
|
||||
struct kstat_named hk_eoperr; /* eop error */
|
||||
struct kstat_named hk_notmds; /* tmd errors */
|
||||
struct kstat_named hk_notbufs; /* tx buf errors */
|
||||
struct kstat_named hk_norbufs; /* rx buf errors */
|
||||
struct kstat_named hk_clsn; /* clsn errors */
|
||||
|
||||
/*
|
||||
* required by kstat for MIB II objects(RFC 1213)
|
||||
*/
|
||||
struct kstat_named hk_rcvbytes; /* # octets received */
|
||||
/* MIB - ifInOctets */
|
||||
struct kstat_named hk_xmtbytes; /* # octets transmitted */
|
||||
/* MIB - ifOutOctets */
|
||||
struct kstat_named hk_multircv; /* # multicast packets */
|
||||
/* delivered to upper layer */
|
||||
/* MIB - ifInNUcastPkts */
|
||||
struct kstat_named hk_multixmt; /* # multicast packets */
|
||||
/* requested to be sent */
|
||||
/* MIB - ifOutNUcastPkts */
|
||||
struct kstat_named hk_brdcstrcv; /* # broadcast packets */
|
||||
/* delivered to upper layer */
|
||||
/* MIB - ifInNUcastPkts */
|
||||
struct kstat_named hk_brdcstxmt; /* # broadcast packets */
|
||||
/* requested to be sent */
|
||||
/* MIB - ifOutNUcastPkts */
|
||||
struct kstat_named hk_norcvbuf; /* # rcv packets discarded */
|
||||
/* MIB - ifInDiscards */
|
||||
struct kstat_named hk_noxmtbuf; /* # xmt packets discarded */
|
||||
/* MIB - ifOutDiscards */
|
||||
|
||||
struct kstat_named hk_phyfail; /* phy failures */
|
||||
struct kstat_named hk_link_up; /* Link Status */
|
||||
};
|
||||
@@ -0,0 +1,255 @@
|
||||
#include "sigar.h"
|
||||
#include "sigar_private.h"
|
||||
#include "sigar_os.h"
|
||||
#include "sigar_util.h"
|
||||
|
||||
int sigar_get_multi_kstats(sigar_t *sigar,
|
||||
kstat_list_t *kl,
|
||||
const char *name,
|
||||
kstat_t **retval)
|
||||
{
|
||||
kstat_ctl_t *kc = sigar->kc;
|
||||
kstat_t *ksp;
|
||||
int i = 0;
|
||||
int dev;
|
||||
|
||||
name += kl->nlen; /* e.g. "hme0" + 3 */
|
||||
dev = atoi(name);
|
||||
|
||||
if ((kl->num == 0) || (kstat_chain_update(kc) > 0)) {
|
||||
while ((ksp = kstat_lookup(kc, kl->name, i, NULL))) {
|
||||
if (i+1 > kl->num) {
|
||||
kl->num = i+1;
|
||||
kl->ks = realloc(kl->ks, kl->num);
|
||||
}
|
||||
kl->ks[i] = ksp;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
if (dev >= kl->num) {
|
||||
return ENXIO;
|
||||
}
|
||||
|
||||
*retval = kl->ks[dev];
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
int sigar_get_kstats(sigar_t *sigar)
|
||||
{
|
||||
kstat_ctl_t *kc = sigar->kc;
|
||||
kstat_t *ksp;
|
||||
unsigned int i, ncpu = sysconf(_SC_NPROCESSORS_CONF);
|
||||
|
||||
ksp = kstat_lookup(kc, "unix", -1, "vminfo");
|
||||
sigar->ks.vminfo = ksp;
|
||||
|
||||
if (ksp) {
|
||||
kstat_read(kc, ksp, &sigar->vminfo);
|
||||
|
||||
if (!sigar->vminfo_snaptime) {
|
||||
sigar->vminfo_snaptime = ksp->ks_snaptime;
|
||||
}
|
||||
}
|
||||
|
||||
if (ncpu != sigar->ncpu) {
|
||||
if (!sigar->ks.lcpu) {
|
||||
/* init */
|
||||
sigar->ks.lcpu = ncpu;
|
||||
sigar->ks.cpu = malloc(sizeof(*(sigar->ks.cpu)) * ncpu);
|
||||
sigar->ks.cpuid = malloc(sizeof(*(sigar->ks.cpuid)) * ncpu);
|
||||
}
|
||||
else {
|
||||
if (ncpu > sigar->ks.lcpu) {
|
||||
/* one or more cpus have been added */
|
||||
sigar->ks.cpu = realloc(sigar->ks.cpu,
|
||||
sizeof(*(sigar->ks.cpu)) * ncpu);
|
||||
sigar->ks.cpuid = realloc(sigar->ks.cpuid,
|
||||
sizeof(*(sigar->ks.cpuid)) * ncpu);
|
||||
sigar->ks.lcpu = ncpu;
|
||||
}
|
||||
/* else or more cpus have been removed */
|
||||
}
|
||||
|
||||
sigar->ncpu = ncpu;
|
||||
|
||||
for (i=0, ksp=kc->kc_chain; i<ncpu; ksp=ksp->ks_next) {
|
||||
char *id;
|
||||
|
||||
if (!ksp) {
|
||||
break;
|
||||
}
|
||||
if (strncmp(ksp->ks_name, "cpu_stat", 8)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* from man p_online:
|
||||
* ``Processor numbers are integers,
|
||||
* greater than or equal to 0,
|
||||
* and are defined by the hardware platform.
|
||||
* Processor numbers are not necessarily contiguous,
|
||||
* but "not too sparse."``
|
||||
* so we maintain our own mapping in ks.cpuid[]
|
||||
*/
|
||||
id = ksp->ks_name;
|
||||
while (!sigar_isdigit(*id)) {
|
||||
id++;
|
||||
}
|
||||
|
||||
sigar->ks.cpu[i] = ksp;
|
||||
sigar->ks.cpuid[i] = atoi(id);
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
sigar->ks.system = kstat_lookup(kc, "unix", -1, "system_misc");
|
||||
sigar->ks.syspages = kstat_lookup(kc, "unix", -1, "system_pages");
|
||||
sigar->ks.mempages = kstat_lookup(kc, "bunyip", -1, "mempages");
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* bincompat is not possible with certain kstat data structures between
|
||||
* solaris 2.6, 2.7, 2.8, etc. alternative is to use kstat_data_lookup()
|
||||
* which means everytime we want a stat, must do a linear search
|
||||
* of ksp->ks_data. eek. so we meet half way and do the search for
|
||||
* each key once per sigar_t instance. once the initial search has
|
||||
* been done, we have a table of offsets to quickly access the stats via
|
||||
* ksp->ks_data + offset. this gives us bincompat without the overhead
|
||||
* of many kstat_data_lookup calls.
|
||||
*/
|
||||
static SIGAR_INLINE int kstat_named_offset(kstat_t *ksp, const char *name)
|
||||
{
|
||||
unsigned int i;
|
||||
kstat_named_t *kn;
|
||||
|
||||
for (i=0, kn=ksp->ks_data;
|
||||
i<ksp->ks_ndata;
|
||||
i++, kn++)
|
||||
{
|
||||
if (strEQ(kn->name, name)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -2; /* not found */
|
||||
}
|
||||
|
||||
static char *kstat_keys_lo[] = {
|
||||
"ipackets", /* RX_PACKETS */
|
||||
"opackets", /* TX_PACKETS */
|
||||
NULL
|
||||
};
|
||||
|
||||
static char *kstat_keys_hme[] = {
|
||||
"ipackets", /* RX_PACKETS */
|
||||
"rbytes", /* RX_BYTES */
|
||||
"ierrors", /* RX_ERRORS */
|
||||
"missed", /* RX_DROPPED */
|
||||
"oflo", /* RX_OVERRUNS */
|
||||
"framing", /* RX_FRAME */
|
||||
"opackets", /* TX_PACKETS */
|
||||
"obytes", /* TX_BYTES */
|
||||
"oerrors", /* TX_ERRORS */
|
||||
"missed", /* TX_DROPPED */
|
||||
"oflo", /* TX_OVERRUNS */
|
||||
"collisions", /* TX_COLLISIONS */
|
||||
"nocarrier", /* TX_CARRIER */
|
||||
NULL
|
||||
};
|
||||
|
||||
static char *kstat_keys_dmfe[] = {
|
||||
"ipackets", /* RX_PACKETS */
|
||||
"rbytes", /* RX_BYTES */
|
||||
"ierrors", /* RX_ERRORS */
|
||||
"missed", /* RX_DROPPED */
|
||||
"oflo", /* RX_OVERRUNS */
|
||||
"framing", /* RX_FRAME */
|
||||
"opackets", /* TX_PACKETS */
|
||||
"obytes", /* TX_BYTES */
|
||||
"oerrors", /* TX_ERRORS */
|
||||
"missed", /* TX_DROPPED */
|
||||
"oflo", /* TX_OVERRUNS */
|
||||
"collisions", /* TX_COLLISIONS */
|
||||
"nocarrier", /* TX_CARRIER */
|
||||
NULL
|
||||
};
|
||||
|
||||
static char *kstat_keys_ge[] = {
|
||||
"ipackets", /* RX_PACKETS */
|
||||
"rbytes", /* RX_BYTES */
|
||||
"ierrors", /* RX_ERRORS */
|
||||
"drop", /* RX_DROPPED */
|
||||
"toolong_errors", /* RX_OVERRUNS */
|
||||
"framing", /* RX_FRAME */
|
||||
"opackets", /* TX_PACKETS */
|
||||
"obytes", /* TX_BYTES */
|
||||
"oerrors", /* TX_ERRORS */
|
||||
"drop", /* TX_DROPPED */
|
||||
"toolong_errors", /* TX_OVERRUNS */
|
||||
"collisions", /* TX_COLLISIONS */
|
||||
"nocarrier", /* TX_CARRIER */
|
||||
NULL
|
||||
};
|
||||
|
||||
static char *kstat_keys_eri[] = {
|
||||
"ipackets", /* RX_PACKETS */
|
||||
"rbytes", /* RX_BYTES */
|
||||
"ierrors", /* RX_ERRORS */
|
||||
"drop", /* RX_DROPPED */
|
||||
"rx_overflow", /* RX_OVERRUNS */
|
||||
"parity_error", /* RX_FRAME */
|
||||
"opackets", /* TX_PACKETS */
|
||||
"obytes", /* TX_BYTES */
|
||||
"oerrors", /* TX_ERRORS */
|
||||
"drop", /* TX_DROPPED */
|
||||
"rx_overflow", /* TX_OVERRUNS */
|
||||
"collisions", /* TX_COLLISIONS */
|
||||
"nocarrier", /* TX_CARRIER */
|
||||
NULL
|
||||
};
|
||||
|
||||
static char *kstat_keys_system[] = {
|
||||
"boot_time",
|
||||
"avenrun_1min",
|
||||
"avenrun_5min",
|
||||
"avenrun_15min",
|
||||
NULL
|
||||
};
|
||||
|
||||
static char *kstat_keys_mempages[] = {
|
||||
"pages_anon",
|
||||
"pages_exec",
|
||||
"pages_vnode",
|
||||
NULL
|
||||
};
|
||||
|
||||
static char *kstat_keys_syspages[] = {
|
||||
"pagesfree",
|
||||
NULL
|
||||
};
|
||||
|
||||
static char **kstat_keys[] = {
|
||||
kstat_keys_lo,
|
||||
kstat_keys_hme,
|
||||
kstat_keys_dmfe,
|
||||
kstat_keys_ge,
|
||||
kstat_keys_eri,
|
||||
kstat_keys_system,
|
||||
kstat_keys_mempages,
|
||||
kstat_keys_syspages,
|
||||
};
|
||||
|
||||
void sigar_koffsets_lookup(kstat_t *ksp, int *offsets, int kidx)
|
||||
{
|
||||
int i;
|
||||
char **keys = kstat_keys[kidx];
|
||||
|
||||
for (i=0; keys[i]; i++) {
|
||||
offsets[i] = kstat_named_offset(ksp, keys[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
#include "sigar.h"
|
||||
#include "sigar_private.h"
|
||||
#include "sigar_os.h"
|
||||
#include "sigar_util.h"
|
||||
|
||||
#define my_pread(fd, ptr, type, offset) \
|
||||
(pread(fd, ptr, sizeof(type), offset) == sizeof(type))
|
||||
|
||||
int sigar_proc_psinfo_get(sigar_t *sigar, sigar_pid_t pid)
|
||||
{
|
||||
int fd, retval = SIGAR_OK;
|
||||
char buffer[BUFSIZ];
|
||||
time_t timenow = time(NULL);
|
||||
|
||||
if (sigar->pinfo == NULL) {
|
||||
sigar->pinfo = malloc(sizeof(*sigar->pinfo));
|
||||
}
|
||||
|
||||
if (sigar->last_pid == pid) {
|
||||
if ((timenow - sigar->last_getprocs) < SIGAR_LAST_PROC_EXPIRE) {
|
||||
return SIGAR_OK;
|
||||
}
|
||||
}
|
||||
|
||||
sigar->last_pid = pid;
|
||||
sigar->last_getprocs = timenow;
|
||||
|
||||
(void)SIGAR_PROC_FILENAME(buffer, pid, "/psinfo");
|
||||
|
||||
if ((fd = open(buffer, O_RDONLY)) < 0) {
|
||||
return ESRCH;
|
||||
}
|
||||
|
||||
if (!my_pread(fd, sigar->pinfo, psinfo_t, 0)) {
|
||||
retval = errno;
|
||||
}
|
||||
|
||||
close(fd);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
int sigar_proc_usage_get(sigar_t *sigar, prusage_t *prusage, sigar_pid_t pid)
|
||||
{
|
||||
int fd, retval = SIGAR_OK;
|
||||
char buffer[BUFSIZ];
|
||||
|
||||
(void)SIGAR_PROC_FILENAME(buffer, pid, "/usage");
|
||||
|
||||
if ((fd = open(buffer, O_RDONLY)) < 0) {
|
||||
return ESRCH;
|
||||
}
|
||||
|
||||
if (!my_pread(fd, prusage, prusage_t, 0)) {
|
||||
retval = errno;
|
||||
}
|
||||
|
||||
close(fd);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
int sigar_get_cred_get(sigar_t *sigar, prcred_t *prcred, sigar_pid_t pid)
|
||||
{
|
||||
int fd, retval = SIGAR_OK;
|
||||
char buffer[BUFSIZ];
|
||||
|
||||
(void)SIGAR_PROC_FILENAME(buffer, pid, "/cred");
|
||||
|
||||
if ((fd = open(buffer, O_RDONLY)) < 0) {
|
||||
return ESRCH;
|
||||
}
|
||||
|
||||
if (!my_pread(fd, prcred, prcred_t, 0)) {
|
||||
retval = errno;
|
||||
}
|
||||
|
||||
close(fd);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
int sigar_get_proc_status(sigar_t *sigar, pstatus_t *pstatus, sigar_pid_t pid)
|
||||
{
|
||||
int fd, retval = SIGAR_OK;
|
||||
char buffer[BUFSIZ];
|
||||
|
||||
(void)SIGAR_PROC_FILENAME(buffer, pid, "/status");
|
||||
|
||||
if ((fd = open(buffer, O_RDONLY)) < 0) {
|
||||
return ESRCH;
|
||||
}
|
||||
|
||||
if (!my_pread(fd, pstatus, pstatus_t, 0)) {
|
||||
retval = errno;
|
||||
}
|
||||
|
||||
close(fd);
|
||||
|
||||
return retval;
|
||||
}
|
||||
@@ -0,0 +1,249 @@
|
||||
#ifndef SIGAR_OS_H
|
||||
#define SIGAR_OS_H
|
||||
|
||||
typedef unsigned long long int u_int64_t;
|
||||
|
||||
#include <ctype.h>
|
||||
#include <assert.h>
|
||||
#include <malloc.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/processor.h>
|
||||
#include <sys/sysinfo.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
#include <kstat.h>
|
||||
#include <procfs.h>
|
||||
|
||||
/* avoid -Wall warning since solaris doesnt have a prototype for this */
|
||||
int getdomainname(char *, int);
|
||||
|
||||
typedef struct {
|
||||
kstat_t **ks;
|
||||
int num;
|
||||
char *name;
|
||||
int nlen;
|
||||
} kstat_list_t;
|
||||
|
||||
int sigar_get_kstats(sigar_t *sigar);
|
||||
|
||||
int sigar_get_multi_kstats(sigar_t *sigar,
|
||||
kstat_list_t *kl,
|
||||
const char *name,
|
||||
kstat_t **retval);
|
||||
|
||||
void sigar_koffsets_lookup(kstat_t *ksp, int *offsets, int kidx);
|
||||
|
||||
int sigar_proc_psinfo_get(sigar_t *sigar, sigar_pid_t pid);
|
||||
|
||||
int sigar_proc_usage_get(sigar_t *sigar, prusage_t *prusage, sigar_pid_t pid);
|
||||
|
||||
int sigar_get_cred_get(sigar_t *sigar, prcred_t *prcred, sigar_pid_t pid);
|
||||
|
||||
int sigar_get_proc_status(sigar_t *sigar, pstatus_t *pstatus, sigar_pid_t pid);
|
||||
|
||||
#define CPU_ONLINE(n) \
|
||||
(p_online(n, P_STATUS) == P_ONLINE)
|
||||
|
||||
/* loopback interface only has these two metrics */
|
||||
typedef enum {
|
||||
KSTAT_LO_RX_PACKETS,
|
||||
KSTAT_LO_TX_PACKETS,
|
||||
KSTAT_LO_MAX
|
||||
} kstat_lo_off_e;
|
||||
|
||||
/* hme, ge and dmfe network devices provide
|
||||
* the same metrics, but in some cases with
|
||||
* different names and in all cases, the
|
||||
* offsets are different.
|
||||
*/
|
||||
typedef enum {
|
||||
KSTAT_HME_RX_PACKETS,
|
||||
KSTAT_HME_RX_BYTES,
|
||||
KSTAT_HME_RX_ERRORS,
|
||||
KSTAT_HME_RX_DROPPED,
|
||||
KSTAT_HME_RX_OVERRUNS,
|
||||
KSTAT_HME_RX_FRAME,
|
||||
KSTAT_HME_TX_PACKETS,
|
||||
KSTAT_HME_TX_BYTES,
|
||||
KSTAT_HME_TX_ERRORS,
|
||||
KSTAT_HME_TX_DROPPED,
|
||||
KSTAT_HME_TX_OVERRUNS,
|
||||
KSTAT_HME_TX_COLLISIONS,
|
||||
KSTAT_HME_TX_CARRIER,
|
||||
KSTAT_HME_MAX
|
||||
} kstat_hme_off_e;
|
||||
|
||||
typedef enum {
|
||||
KSTAT_DMFE_RX_PACKETS,
|
||||
KSTAT_DMFE_RX_BYTES,
|
||||
KSTAT_DMFE_RX_ERRORS,
|
||||
KSTAT_DMFE_RX_DROPPED,
|
||||
KSTAT_DMFE_RX_OVERRUNS,
|
||||
KSTAT_DMFE_RX_FRAME,
|
||||
KSTAT_DMFE_TX_PACKETS,
|
||||
KSTAT_DMFE_TX_BYTES,
|
||||
KSTAT_DMFE_TX_ERRORS,
|
||||
KSTAT_DMFE_TX_DROPPED,
|
||||
KSTAT_DMFE_TX_OVERRUNS,
|
||||
KSTAT_DMFE_TX_COLLISIONS,
|
||||
KSTAT_DMFE_TX_CARRIER,
|
||||
KSTAT_DMFE_MAX
|
||||
} kstat_dmfe_off_e;
|
||||
|
||||
typedef enum {
|
||||
KSTAT_GE_RX_PACKETS,
|
||||
KSTAT_GE_RX_BYTES,
|
||||
KSTAT_GE_RX_ERRORS,
|
||||
KSTAT_GE_RX_DROPPED,
|
||||
KSTAT_GE_RX_OVERRUNS,
|
||||
KSTAT_GE_RX_FRAME,
|
||||
KSTAT_GE_TX_PACKETS,
|
||||
KSTAT_GE_TX_BYTES,
|
||||
KSTAT_GE_TX_ERRORS,
|
||||
KSTAT_GE_TX_DROPPED,
|
||||
KSTAT_GE_TX_OVERRUNS,
|
||||
KSTAT_GE_TX_COLLISIONS,
|
||||
KSTAT_GE_TX_CARRIER,
|
||||
KSTAT_GE_MAX
|
||||
} kstat_ge_off_e;
|
||||
|
||||
typedef enum {
|
||||
KSTAT_ERI_RX_PACKETS,
|
||||
KSTAT_ERI_RX_BYTES,
|
||||
KSTAT_ERI_RX_ERRORS,
|
||||
KSTAT_ERI_RX_DROPPED,
|
||||
KSTAT_ERI_RX_OVERRUNS,
|
||||
KSTAT_ERI_RX_FRAME,
|
||||
KSTAT_ERI_TX_PACKETS,
|
||||
KSTAT_ERI_TX_BYTES,
|
||||
KSTAT_ERI_TX_ERRORS,
|
||||
KSTAT_ERI_TX_DROPPED,
|
||||
KSTAT_ERI_TX_OVERRUNS,
|
||||
KSTAT_ERI_TX_COLLISIONS,
|
||||
KSTAT_ERI_TX_CARRIER,
|
||||
KSTAT_ERI_MAX
|
||||
} kstat_eri_off_e;
|
||||
|
||||
typedef enum {
|
||||
KSTAT_SYSTEM_BOOT_TIME,
|
||||
KSTAT_SYSTEM_LOADAVG_1,
|
||||
KSTAT_SYSTEM_LOADAVG_2,
|
||||
KSTAT_SYSTEM_LOADAVG_3,
|
||||
KSTAT_SYSTEM_MAX
|
||||
} kstat_system_off_e;
|
||||
|
||||
typedef enum {
|
||||
KSTAT_MEMPAGES_ANON,
|
||||
KSTAT_MEMPAGES_EXEC,
|
||||
KSTAT_MEMPAGES_VNODE,
|
||||
KSTAT_MEMPAGES_MAX
|
||||
} kstat_mempages_off_e;
|
||||
|
||||
typedef enum {
|
||||
KSTAT_SYSPAGES_FREE,
|
||||
KSTAT_SYSPAGES_MAX
|
||||
} kstat_syspages_off_e;
|
||||
|
||||
enum {
|
||||
KSTAT_KEYS_lo,
|
||||
KSTAT_KEYS_hme,
|
||||
KSTAT_KEYS_dmfe,
|
||||
KSTAT_KEYS_ge,
|
||||
KSTAT_KEYS_eri,
|
||||
KSTAT_KEYS_system,
|
||||
KSTAT_KEYS_mempages,
|
||||
KSTAT_KEYS_syspages,
|
||||
} kstat_keys_e;
|
||||
|
||||
struct sigar_t {
|
||||
SIGAR_T_BASE;
|
||||
|
||||
kstat_ctl_t *kc;
|
||||
|
||||
/* kstat_lookup() as needed */
|
||||
struct {
|
||||
kstat_t *vminfo;
|
||||
kstat_t **cpu;
|
||||
processorid_t *cpuid;
|
||||
unsigned int lcpu; /* number malloced slots in the cpu array above */
|
||||
kstat_t *system;
|
||||
kstat_t *syspages;
|
||||
kstat_t *mempages;
|
||||
kstat_list_t hme;
|
||||
kstat_list_t dmfe;
|
||||
kstat_list_t ge;
|
||||
kstat_list_t eri;
|
||||
kstat_list_t lo;
|
||||
} ks;
|
||||
|
||||
struct {
|
||||
int lo[KSTAT_LO_MAX];
|
||||
int hme[KSTAT_HME_MAX];
|
||||
int dmfe[KSTAT_DMFE_MAX];
|
||||
int ge[KSTAT_GE_MAX];
|
||||
int eri[KSTAT_ERI_MAX];
|
||||
int system[KSTAT_SYSTEM_MAX];
|
||||
int mempages[KSTAT_MEMPAGES_MAX];
|
||||
int syspages[KSTAT_SYSPAGES_MAX];
|
||||
} koffsets;
|
||||
|
||||
vminfo_t vminfo;
|
||||
hrtime_t vminfo_snaptime;
|
||||
|
||||
int pagesize;
|
||||
|
||||
time_t last_getprocs;
|
||||
sigar_pid_t last_pid;
|
||||
psinfo_t *pinfo;
|
||||
sigar_cpu_list_t cpulist;
|
||||
};
|
||||
|
||||
#define kSTAT_uint(v, type) \
|
||||
((sigar->koffsets.type[v] == -2) ? 0 : \
|
||||
((kstat_named_t *)ksp->ks_data + sigar->koffsets.type[v])->value.ui32)
|
||||
|
||||
#define kSYSTEM(v) kSTAT_uint(v, system)
|
||||
|
||||
#define kMEMPAGES(v) kSTAT_uint(v, mempages)
|
||||
|
||||
#define kSYSPAGES(v) kSTAT_uint(v, syspages)
|
||||
|
||||
#define sigar_koffsets_init(sigar, ksp, type) \
|
||||
if (sigar->koffsets.type[0] == -1) \
|
||||
sigar_koffsets_lookup(ksp, sigar->koffsets.type, KSTAT_KEYS_##type)
|
||||
|
||||
#define sigar_koffsets_init_lo(sigar, ksp) \
|
||||
sigar_koffsets_init(sigar, ksp, lo)
|
||||
|
||||
#define sigar_koffsets_init_hme(sigar, ksp) \
|
||||
sigar_koffsets_init(sigar, ksp, hme)
|
||||
|
||||
#define sigar_koffsets_init_dmfe(sigar, ksp) \
|
||||
sigar_koffsets_init(sigar, ksp, dmfe)
|
||||
|
||||
#define sigar_koffsets_init_ge(sigar, ksp) \
|
||||
sigar_koffsets_init(sigar, ksp, ge)
|
||||
|
||||
#define sigar_koffsets_init_eri(sigar, ksp) \
|
||||
sigar_koffsets_init(sigar, ksp, eri)
|
||||
|
||||
#define sigar_koffsets_init_system(sigar, ksp) \
|
||||
sigar_koffsets_init(sigar, ksp, system)
|
||||
|
||||
#define sigar_koffsets_init_mempages(sigar, ksp) \
|
||||
sigar_koffsets_init(sigar, ksp, mempages)
|
||||
|
||||
#define sigar_koffsets_init_syspages(sigar, ksp) \
|
||||
sigar_koffsets_init(sigar, ksp, syspages)
|
||||
|
||||
#define HAVE_READDIR_R
|
||||
#define HAVE_GETPWNAM_R
|
||||
#define HAVE_GETPWUID_R
|
||||
|
||||
#endif /* SIGAR_OS_H */
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,8 @@
|
||||
#ifndef SIGAR_OS_H
|
||||
#define SIGAR_OS_H
|
||||
|
||||
struct sigar_t {
|
||||
SIGAR_T_BASE;
|
||||
};
|
||||
|
||||
#endif /* SIGAR_OS_H */
|
||||
@@ -0,0 +1,248 @@
|
||||
#include "sigar.h"
|
||||
#include "sigar_private.h"
|
||||
#include "sigar_os.h"
|
||||
|
||||
int sigar_os_open(sigar_t **sigar)
|
||||
{
|
||||
*sigar = malloc(sizeof(**sigar));
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
int sigar_os_close(sigar_t *sigar)
|
||||
{
|
||||
free(sigar);
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
char *sigar_os_error_string(int err)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int sigar_mem_get(sigar_t *sigar, sigar_mem_t *mem)
|
||||
{
|
||||
mem->total = -1;
|
||||
mem->ram = -1;
|
||||
mem->used = -1;
|
||||
mem->free = -1;
|
||||
mem->shared = -1;
|
||||
mem->buffer = -1;
|
||||
mem->cached = -1;
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
int sigar_swap_get(sigar_t *sigar, sigar_swap_t *swap)
|
||||
{
|
||||
swap->total = -1;
|
||||
swap->used = -1;
|
||||
swap->free = -1;
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
int sigar_cpu_get(sigar_t *sigar, sigar_cpu_t *cpu)
|
||||
{
|
||||
cpu->user = -1;
|
||||
cpu->nice = -1;
|
||||
cpu->sys = -1;
|
||||
cpu->idle = -1;
|
||||
|
||||
cpu->total = cpu->user + cpu->nice + cpu->sys + cpu->idle;
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
int sigar_cpu_list_get(sigar_t *sigar, sigar_cpu_list_t *cpulist)
|
||||
{
|
||||
return SIGAR_ENOTIMPL;
|
||||
}
|
||||
|
||||
int sigar_uptime_get(sigar_t *sigar,
|
||||
sigar_uptime_t *uptime)
|
||||
{
|
||||
uptime->uptime = -1;
|
||||
uptime->idletime = -1;
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
int sigar_loadavg_get(sigar_t *sigar,
|
||||
sigar_loadavg_t *loadavg)
|
||||
{
|
||||
loadavg->loadavg[0] = -1;
|
||||
loadavg->loadavg[1] = -1;
|
||||
loadavg->loadavg[2] = -1;
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
int sigar_proc_list_get(sigar_t *sigar,
|
||||
sigar_proc_list_t *proclist)
|
||||
{
|
||||
return SIGAR_ENOTIMPL;
|
||||
}
|
||||
|
||||
int sigar_proc_stat_get(sigar_t *sigar,
|
||||
sigar_proc_stat_t *procstat)
|
||||
{
|
||||
int status = /* XXX optimize */
|
||||
sigar_proc_count(sigar, &procstat->total);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
int sigar_proc_mem_get(sigar_t *sigar, sigar_pid_t pid,
|
||||
sigar_proc_mem_t *procmem)
|
||||
{
|
||||
procmem->size = -1;
|
||||
procmem->vsize = -1;
|
||||
procmem->share = -1;
|
||||
procmem->rss = -1;
|
||||
procmem->resident = -1;
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
int sigar_proc_cred_get(sigar_t *sigar, sigar_pid_t pid,
|
||||
sigar_proc_cred_t *proccred)
|
||||
{
|
||||
proccred->uid = -1;
|
||||
proccred->gid = -1;
|
||||
proccred->euid = -1;
|
||||
proccred->egid = -1;
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
int sigar_proc_time_get(sigar_t *sigar, sigar_pid_t pid,
|
||||
sigar_proc_time_t *proctime)
|
||||
{
|
||||
proctime->start_time = -1;
|
||||
proctime->utime = -1;
|
||||
proctime->stime = -1;
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
int sigar_proc_state_get(sigar_t *sigar, sigar_pid_t pid,
|
||||
sigar_proc_state_t *procstate)
|
||||
{
|
||||
SIGAR_SSTRCPY(procstate->name, "java");
|
||||
procstate->ppid = -1;
|
||||
procstate->priority = -1;
|
||||
procstate->nice = -1;
|
||||
procstate->tty = -1;
|
||||
procstate->state = 'R';
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
int sigar_proc_args_get(sigar_t *sigar, sigar_pid_t pid,
|
||||
sigar_proc_args_t *procargs)
|
||||
{
|
||||
return SIGAR_ENOTIMPL;
|
||||
}
|
||||
|
||||
int sigar_proc_env_get(sigar_t *sigar, sigar_pid_t pid,
|
||||
sigar_proc_env_t *procenv)
|
||||
{
|
||||
return SIGAR_ENOTIMPL;
|
||||
}
|
||||
|
||||
int sigar_proc_fd_get(sigar_t *sigar, sigar_pid_t pid,
|
||||
sigar_proc_fd_t *procfd)
|
||||
{
|
||||
procfd->total = -1;
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
int sigar_proc_exe_get(sigar_t *sigar, sigar_pid_t pid,
|
||||
sigar_proc_exe_t *procexe)
|
||||
{
|
||||
return SIGAR_ENOTIMPL;
|
||||
}
|
||||
|
||||
int sigar_os_fs_type_get(sigar_file_system_t *fsp)
|
||||
{
|
||||
fsp->type = SIGAR_FSTYPE_UNKNOWN;
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
int sigar_file_system_list_get(sigar_t *sigar,
|
||||
sigar_file_system_list_t *fslist)
|
||||
{
|
||||
sigar_file_system_list_create(fslist);
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
int sigar_file_system_usage_get(sigar_t *sigar,
|
||||
const char *dirname,
|
||||
sigar_file_system_usage_t *fsusage)
|
||||
{
|
||||
fsusage->total = -1;
|
||||
fsusage->free = -1;
|
||||
fsusage->avail = -1;
|
||||
fsusage->files = -1;
|
||||
fsusage->free_files = -1;
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
int sigar_cpu_infos_get(sigar_t *sigar,
|
||||
sigar_cpu_infos_t *cpu_infos)
|
||||
{
|
||||
sigar_cpu_info_t *info;
|
||||
|
||||
sigar_cpu_infos_create(cpu_infos);
|
||||
|
||||
info = &cpu_infos->data[cpu_infos->number++];
|
||||
|
||||
SIGAR_SSTRCPY(info->vendor, "vendor");
|
||||
SIGAR_SSTRCPY(info->model, "model");
|
||||
info->mhz = -1;
|
||||
info->cache_size = -1;
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
int sigar_net_route_list_get(sigar_t *sigar,
|
||||
sigar_net_route_list_t *routelist)
|
||||
{
|
||||
sigar_net_route_t *route;
|
||||
|
||||
sigar_net_route_list_create(routelist);
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
int sigar_net_interface_stat_get(sigar_t *sigar, const char *name,
|
||||
sigar_net_interface_stat_t *ifstat)
|
||||
{
|
||||
ifstat->rx_bytes = -1;
|
||||
ifstat->rx_packets = -1;
|
||||
ifstat->rx_errors = -1;
|
||||
ifstat->rx_dropped = -1;
|
||||
ifstat->rx_overruns = -1;
|
||||
ifstat->rx_frame = -1;
|
||||
|
||||
ifstat->tx_bytes = -1;
|
||||
ifstat->tx_packets = -1;
|
||||
ifstat->tx_errors = -1;
|
||||
ifstat->tx_dropped = -1;
|
||||
ifstat->tx_overruns = -1;
|
||||
ifstat->tx_collisions = -1;
|
||||
ifstat->tx_carrier = -1;
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
int sigar_net_connection_list_get(sigar_t *sigar,
|
||||
sigar_net_connection_list_t *connlist,
|
||||
int flags)
|
||||
{
|
||||
return SIGAR_ENOTIMPL;
|
||||
}
|
||||
Executable
+2
@@ -0,0 +1,2 @@
|
||||
@echo off
|
||||
cl -I..\..\..\include -I. -DWIN32 -DCPU_MAIN cpu.c /link ADVAPI32.LIB
|
||||
@@ -0,0 +1,820 @@
|
||||
#counter names from registry key
|
||||
#SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Perflib
|
||||
0 UNDEFINED
|
||||
1 1847
|
||||
2 System
|
||||
4 Memory
|
||||
6 % Processor Time
|
||||
10 File Read Operations/sec
|
||||
12 File Write Operations/sec
|
||||
14 File Control Operations/sec
|
||||
16 File Read Bytes/sec
|
||||
18 File Write Bytes/sec
|
||||
20 File Control Bytes/sec
|
||||
24 Available Bytes
|
||||
26 Committed Bytes
|
||||
28 Page Faults/sec
|
||||
30 Commit Limit
|
||||
32 Write Copies/sec
|
||||
34 Transition Faults/sec
|
||||
36 Cache Faults/sec
|
||||
38 Demand Zero Faults/sec
|
||||
40 Pages/sec
|
||||
42 Page Reads/sec
|
||||
44 Processor Queue Length
|
||||
46 Thread State
|
||||
48 Pages Output/sec
|
||||
50 Page Writes/sec
|
||||
52 Browser
|
||||
54 Announcements Server/sec
|
||||
56 Pool Paged Bytes
|
||||
58 Pool Nonpaged Bytes
|
||||
60 Pool Paged Allocs
|
||||
64 Pool Nonpaged Allocs
|
||||
66 Pool Paged Resident Bytes
|
||||
68 System Code Total Bytes
|
||||
70 System Code Resident Bytes
|
||||
72 System Driver Total Bytes
|
||||
74 System Driver Resident Bytes
|
||||
76 System Cache Resident Bytes
|
||||
78 Announcements Domain/sec
|
||||
80 Election Packets/sec
|
||||
82 Mailslot Writes/sec
|
||||
84 Server List Requests/sec
|
||||
86 Cache
|
||||
88 Data Maps/sec
|
||||
90 Sync Data Maps/sec
|
||||
92 Async Data Maps/sec
|
||||
94 Data Map Hits %
|
||||
96 Data Map Pins/sec
|
||||
98 Pin Reads/sec
|
||||
100 Sync Pin Reads/sec
|
||||
102 Async Pin Reads/sec
|
||||
104 Pin Read Hits %
|
||||
106 Copy Reads/sec
|
||||
108 Sync Copy Reads/sec
|
||||
110 Async Copy Reads/sec
|
||||
112 Copy Read Hits %
|
||||
114 MDL Reads/sec
|
||||
116 Sync MDL Reads/sec
|
||||
118 Async MDL Reads/sec
|
||||
120 MDL Read Hits %
|
||||
122 Read Aheads/sec
|
||||
124 Fast Reads/sec
|
||||
126 Sync Fast Reads/sec
|
||||
128 Async Fast Reads/sec
|
||||
130 Fast Read Resource Misses/sec
|
||||
132 Fast Read Not Possibles/sec
|
||||
134 Lazy Write Flushes/sec
|
||||
136 Lazy Write Pages/sec
|
||||
138 Data Flushes/sec
|
||||
140 Data Flush Pages/sec
|
||||
142 % User Time
|
||||
144 % Privileged Time
|
||||
146 Context Switches/sec
|
||||
148 Interrupts/sec
|
||||
150 System Calls/sec
|
||||
152 Level 1 TLB Fills/sec
|
||||
154 Level 2 TLB Fills/sec
|
||||
156 Enumerations Server/sec
|
||||
158 Enumerations Domain/sec
|
||||
160 Enumerations Other/sec
|
||||
162 Missed Server Announcements
|
||||
164 Missed Mailslot Datagrams
|
||||
166 Missed Server List Requests
|
||||
168 Server Announce Allocations Failed/sec
|
||||
170 Mailslot Allocations Failed
|
||||
172 Virtual Bytes Peak
|
||||
174 Virtual Bytes
|
||||
178 Working Set Peak
|
||||
180 Working Set
|
||||
182 Page File Bytes Peak
|
||||
184 Page File Bytes
|
||||
186 Private Bytes
|
||||
188 Announcements Total/sec
|
||||
190 Enumerations Total/sec
|
||||
198 Current Disk Queue Length
|
||||
200 % Disk Time
|
||||
202 % Disk Read Time
|
||||
204 % Disk Write Time
|
||||
206 Avg. Disk sec/Transfer
|
||||
208 Avg. Disk sec/Read
|
||||
210 Avg. Disk sec/Write
|
||||
212 Disk Transfers/sec
|
||||
214 Disk Reads/sec
|
||||
216 Disk Writes/sec
|
||||
218 Disk Bytes/sec
|
||||
220 Disk Read Bytes/sec
|
||||
222 Disk Write Bytes/sec
|
||||
224 Avg. Disk Bytes/Transfer
|
||||
226 Avg. Disk Bytes/Read
|
||||
228 Avg. Disk Bytes/Write
|
||||
230 Process
|
||||
232 Thread
|
||||
234 PhysicalDisk
|
||||
236 LogicalDisk
|
||||
238 Processor
|
||||
240 % Total Processor Time
|
||||
242 % Total User Time
|
||||
244 % Total Privileged Time
|
||||
246 Total Interrupts/sec
|
||||
248 Processes
|
||||
250 Threads
|
||||
252 Events
|
||||
254 Semaphores
|
||||
256 Mutexes
|
||||
258 Sections
|
||||
260 Objects
|
||||
262 Redirector
|
||||
264 Bytes Received/sec
|
||||
266 Packets Received/sec
|
||||
268 Read Bytes Paging/sec
|
||||
270 Read Bytes Non-Paging/sec
|
||||
272 Read Bytes Cache/sec
|
||||
274 Read Bytes Network/sec
|
||||
276 Bytes Transmitted/sec
|
||||
278 Packets Transmitted/sec
|
||||
280 Write Bytes Paging/sec
|
||||
282 Write Bytes Non-Paging/sec
|
||||
284 Write Bytes Cache/sec
|
||||
286 Write Bytes Network/sec
|
||||
288 Read Operations/sec
|
||||
290 Read Operations Random/sec
|
||||
292 Read Packets/sec
|
||||
294 Reads Large/sec
|
||||
296 Read Packets Small/sec
|
||||
298 Write Operations/sec
|
||||
300 Write Operations Random/sec
|
||||
302 Write Packets/sec
|
||||
304 Writes Large/sec
|
||||
306 Write Packets Small/sec
|
||||
308 Reads Denied/sec
|
||||
310 Writes Denied/sec
|
||||
312 Network Errors/sec
|
||||
314 Server Sessions
|
||||
316 Server Reconnects
|
||||
318 Connects Core
|
||||
320 Connects Lan Manager 2.0
|
||||
322 Connects Lan Manager 2.1
|
||||
324 Connects Windows NT
|
||||
326 Server Disconnects
|
||||
328 Server Sessions Hung
|
||||
330 Server
|
||||
336 Thread Wait Reason
|
||||
340 Sessions Timed Out
|
||||
342 Sessions Errored Out
|
||||
344 Sessions Logged Off
|
||||
346 Sessions Forced Off
|
||||
348 Errors Logon
|
||||
350 Errors Access Permissions
|
||||
352 Errors Granted Access
|
||||
354 Errors System
|
||||
356 Blocking Requests Rejected
|
||||
358 Work Item Shortages
|
||||
360 Files Opened Total
|
||||
362 Files Open
|
||||
366 File Directory Searches
|
||||
370 Pool Nonpaged Failures
|
||||
372 Pool Nonpaged Peak
|
||||
376 Pool Paged Failures
|
||||
378 Pool Paged Peak
|
||||
388 Bytes Total/sec
|
||||
392 Current Commands
|
||||
398 NWLink NetBIOS
|
||||
400 Packets/sec
|
||||
404 Context Blocks Queued/sec
|
||||
406 File Data Operations/sec
|
||||
408 % Free Space
|
||||
410 Free Megabytes
|
||||
412 Connections Open
|
||||
414 Connections No Retries
|
||||
416 Connections With Retries
|
||||
418 Disconnects Local
|
||||
420 Disconnects Remote
|
||||
422 Failures Link
|
||||
424 Failures Adapter
|
||||
426 Connection Session Timeouts
|
||||
428 Connections Canceled
|
||||
430 Failures Resource Remote
|
||||
432 Failures Resource Local
|
||||
434 Failures Not Found
|
||||
436 Failures No Listen
|
||||
438 Datagrams/sec
|
||||
440 Datagram Bytes/sec
|
||||
442 Datagrams Sent/sec
|
||||
444 Datagram Bytes Sent/sec
|
||||
446 Datagrams Received/sec
|
||||
448 Datagram Bytes Received/sec
|
||||
452 Packets Sent/sec
|
||||
456 Frames/sec
|
||||
458 Frame Bytes/sec
|
||||
460 Frames Sent/sec
|
||||
462 Frame Bytes Sent/sec
|
||||
464 Frames Received/sec
|
||||
466 Frame Bytes Received/sec
|
||||
468 Frames Re-Sent/sec
|
||||
470 Frame Bytes Re-Sent/sec
|
||||
472 Frames Rejected/sec
|
||||
474 Frame Bytes Rejected/sec
|
||||
476 Expirations Response
|
||||
478 Expirations Ack
|
||||
480 Window Send Maximum
|
||||
482 Window Send Average
|
||||
484 Piggyback Ack Queued/sec
|
||||
486 Piggyback Ack Timeouts
|
||||
488 NWLink IPX
|
||||
490 NWLink SPX
|
||||
492 NetBEUI
|
||||
494 NetBEUI Resource
|
||||
496 Used Maximum
|
||||
498 Used Average
|
||||
500 Times Exhausted
|
||||
502 NBT Connection
|
||||
506 Bytes Sent/sec
|
||||
508 Total Bytes/sec
|
||||
510 Network Interface
|
||||
512 Bytes/sec
|
||||
520 Current Bandwidth
|
||||
524 Packets Received Unicast/sec
|
||||
526 Packets Received Non-Unicast/sec
|
||||
528 Packets Received Discarded
|
||||
530 Packets Received Errors
|
||||
532 Packets Received Unknown
|
||||
536 Packets Sent Unicast/sec
|
||||
538 Packets Sent Non-Unicast/sec
|
||||
540 Packets Outbound Discarded
|
||||
542 Packets Outbound Errors
|
||||
544 Output Queue Length
|
||||
546 IP
|
||||
552 Datagrams Received Header Errors
|
||||
554 Datagrams Received Address Errors
|
||||
556 Datagrams Forwarded/sec
|
||||
558 Datagrams Received Unknown Protocol
|
||||
560 Datagrams Received Discarded
|
||||
562 Datagrams Received Delivered/sec
|
||||
566 Datagrams Outbound Discarded
|
||||
568 Datagrams Outbound No Route
|
||||
570 Fragments Received/sec
|
||||
572 Fragments Re-assembled/sec
|
||||
574 Fragment Re-assembly Failures
|
||||
576 Fragmented Datagrams/sec
|
||||
578 Fragmentation Failures
|
||||
580 Fragments Created/sec
|
||||
582 ICMP
|
||||
584 Messages/sec
|
||||
586 Messages Received/sec
|
||||
588 Messages Received Errors
|
||||
590 Received Dest. Unreachable
|
||||
592 Received Time Exceeded
|
||||
594 Received Parameter Problem
|
||||
596 Received Source Quench
|
||||
598 Received Redirect/sec
|
||||
600 Received Echo/sec
|
||||
602 Received Echo Reply/sec
|
||||
604 Received Timestamp/sec
|
||||
606 Received Timestamp Reply/sec
|
||||
608 Received Address Mask
|
||||
610 Received Address Mask Reply
|
||||
612 Messages Sent/sec
|
||||
614 Messages Outbound Errors
|
||||
616 Sent Destination Unreachable
|
||||
618 Sent Time Exceeded
|
||||
620 Sent Parameter Problem
|
||||
622 Sent Source Quench
|
||||
624 Sent Redirect/sec
|
||||
626 Sent Echo/sec
|
||||
628 Sent Echo Reply/sec
|
||||
630 Sent Timestamp/sec
|
||||
632 Sent Timestamp Reply/sec
|
||||
634 Sent Address Mask
|
||||
636 Sent Address Mask Reply
|
||||
638 TCP
|
||||
640 Segments/sec
|
||||
642 Connections Established
|
||||
644 Connections Active
|
||||
646 Connections Passive
|
||||
648 Connection Failures
|
||||
650 Connections Reset
|
||||
652 Segments Received/sec
|
||||
654 Segments Sent/sec
|
||||
656 Segments Retransmitted/sec
|
||||
658 UDP
|
||||
660 % Total DPC Time
|
||||
662 % Total Interrupt Time
|
||||
664 Datagrams No Port/sec
|
||||
666 Datagrams Received Errors
|
||||
670 Disk Storage Unit
|
||||
672 Allocation Failures
|
||||
674 System Up Time
|
||||
676 System Handle Count
|
||||
678 Free System Page Table Entries
|
||||
680 Thread Count
|
||||
682 Priority Base
|
||||
684 Elapsed Time
|
||||
686 Alignment Fixups/sec
|
||||
688 Exception Dispatches/sec
|
||||
690 Floating Emulations/sec
|
||||
692 Logon/sec
|
||||
694 Priority Current
|
||||
696 % DPC Time
|
||||
698 % Interrupt Time
|
||||
700 Paging File
|
||||
702 % Usage
|
||||
704 % Usage Peak
|
||||
706 Start Address
|
||||
708 User PC
|
||||
710 Mapped Space No Access
|
||||
712 Mapped Space Read Only
|
||||
714 Mapped Space Read/Write
|
||||
716 Mapped Space Write Copy
|
||||
718 Mapped Space Executable
|
||||
720 Mapped Space Exec Read Only
|
||||
722 Mapped Space Exec Read/Write
|
||||
724 Mapped Space Exec Write Copy
|
||||
726 Reserved Space No Access
|
||||
728 Reserved Space Read Only
|
||||
730 Reserved Space Read/Write
|
||||
732 Reserved Space Write Copy
|
||||
734 Reserved Space Executable
|
||||
736 Reserved Space Exec Read Only
|
||||
738 Reserved Space Exec Read/Write
|
||||
740 Image
|
||||
742 Reserved Space Exec Write Copy
|
||||
744 Unassigned Space No Access
|
||||
746 Unassigned Space Read Only
|
||||
748 Unassigned Space Read/Write
|
||||
750 Unassigned Space Write Copy
|
||||
752 Unassigned Space Executable
|
||||
754 Unassigned Space Exec Read Only
|
||||
756 Unassigned Space Exec Read/Write
|
||||
758 Unassigned Space Exec Write Copy
|
||||
760 Image Space No Access
|
||||
762 Image Space Read Only
|
||||
764 Image Space Read/Write
|
||||
766 Image Space Write Copy
|
||||
768 Image Space Executable
|
||||
770 Image Space Exec Read Only
|
||||
772 Image Space Exec Read/Write
|
||||
774 Image Space Exec Write Copy
|
||||
776 Bytes Image Reserved
|
||||
778 Bytes Image Free
|
||||
780 Bytes Reserved
|
||||
782 Bytes Free
|
||||
784 ID Process
|
||||
786 Process Address Space
|
||||
788 No Access
|
||||
790 Read Only
|
||||
792 Read/Write
|
||||
794 Write Copy
|
||||
796 Executable
|
||||
798 Exec Read Only
|
||||
800 Exec Read/Write
|
||||
802 Exec Write Copy
|
||||
804 ID Thread
|
||||
806 Mailslot Receives Failed
|
||||
808 Mailslot Writes Failed
|
||||
810 Mailslot Opens Failed/sec
|
||||
812 Duplicate Master Announcements
|
||||
814 Illegal Datagrams/sec
|
||||
816 Thread Details
|
||||
818 Cache Bytes
|
||||
820 Cache Bytes Peak
|
||||
822 Pages Input/sec
|
||||
870 RAS Port
|
||||
872 Bytes Transmitted
|
||||
874 Bytes Received
|
||||
876 Frames Transmitted
|
||||
878 Frames Received.
|
||||
880 Percent Compression Out
|
||||
882 Percent Compression In
|
||||
884 CRC Errors
|
||||
886 Timeout Errors
|
||||
888 Serial Overrun Errors
|
||||
890 Alignment Errors
|
||||
892 Buffer Overrun Errors
|
||||
894 Total Errors
|
||||
896 Bytes Transmitted/Sec
|
||||
898 Bytes Received/Sec
|
||||
900 Frames Transmitted/Sec
|
||||
902 Frames Received/Sec
|
||||
904 Total Errors/Sec
|
||||
906 RAS Total
|
||||
908 Total Connections
|
||||
920 WINS Server
|
||||
922 Unique Registrations/sec
|
||||
924 Group Registrations/sec
|
||||
926 Total Number of Registrations/sec
|
||||
928 Unique Renewals/sec
|
||||
930 Group Renewals/sec
|
||||
932 Total Number of Renewals/sec
|
||||
934 Releases/sec
|
||||
936 Queries/sec
|
||||
938 Unique Conflicts/sec
|
||||
940 Group Conflicts/sec
|
||||
942 Total Number of Conflicts/sec
|
||||
944 Successful Releases/sec
|
||||
946 Failed Releases/sec
|
||||
948 Successful Queries/sec
|
||||
950 Failed Queries/sec
|
||||
952 Handle Count
|
||||
1000 MacFile Server
|
||||
1002 Max Paged Memory
|
||||
1004 Current Paged Memory
|
||||
1006 Max NonPaged Memory
|
||||
1008 Current NonPaged memory
|
||||
1010 Current Sessions
|
||||
1012 Maximum Sessions
|
||||
1014 Current Files Open
|
||||
1016 Maximum Files Open
|
||||
1018 Failed Logons
|
||||
1020 Data Read/sec
|
||||
1022 Data Written/sec
|
||||
1024 Data Received/sec
|
||||
1026 Data Transmitted/sec
|
||||
1028 Current Queue Length
|
||||
1030 Maximum Queue Length
|
||||
1032 Current Threads
|
||||
1034 Maximum Threads
|
||||
1050 AppleTalk
|
||||
1052 Packets In/sec
|
||||
1054 Packets Out/sec
|
||||
1056 Bytes In/sec
|
||||
1058 Bytes Out/sec
|
||||
1060 Average Time/DDP Packet
|
||||
1062 DDP Packets/sec
|
||||
1064 Average Time/AARP Packet
|
||||
1066 AARP Packets/sec
|
||||
1068 Average Time/ATP Packet
|
||||
1070 ATP Packets/sec
|
||||
1072 Average Time/NBP Packet
|
||||
1074 NBP Packets/sec
|
||||
1076 Average Time/ZIP Packet
|
||||
1078 ZIP Packets/sec
|
||||
1080 Average Time/RTMP Packet
|
||||
1082 RTMP Packets/sec
|
||||
1084 ATP Retries Local
|
||||
1086 ATP Response Timouts
|
||||
1088 ATP XO Response/Sec
|
||||
1090 ATP ALO Response/Sec
|
||||
1092 ATP Recvd Release/Sec
|
||||
1094 Current NonPaged Pool
|
||||
1096 Packets Routed In/Sec
|
||||
1098 Packets dropped
|
||||
1100 ATP Retries Remote
|
||||
1102 Packets Routed Out/Sec
|
||||
1110 Network Segment
|
||||
1112 Total frames received/second
|
||||
1114 Total bytes received/second
|
||||
1116 Broadcast frames received/second
|
||||
1118 Multicast frames received/second
|
||||
1120 % Network utilization
|
||||
1124 % Broadcast Frames
|
||||
1126 % Multicast Frames
|
||||
1150 Telephony
|
||||
1152 Lines
|
||||
1154 Telephone Devices
|
||||
1156 Active Lines
|
||||
1158 Active Telephones
|
||||
1160 Outgoing Calls/sec
|
||||
1162 Incoming Calls/sec
|
||||
1164 Client Apps
|
||||
1166 Current Outgoing Calls
|
||||
1168 Current Incoming Calls
|
||||
1228 Gateway Service For NetWare
|
||||
1230 Client Service For NetWare
|
||||
1232 Packet Burst Read NCP Count/sec
|
||||
1234 Packet Burst Read Timeouts/sec
|
||||
1236 Packet Burst Write NCP Count/sec
|
||||
1238 Packet Burst Write Timeouts/sec
|
||||
1240 Packet Burst IO/sec
|
||||
1242 Connect NetWare 2.x
|
||||
1244 Connect NetWare 3.x
|
||||
1246 Connect NetWare 4.x
|
||||
1260 Logon Total
|
||||
1300 Server Work Queues
|
||||
1302 Queue Length
|
||||
1304 Active Threads
|
||||
1306 Available Threads
|
||||
1308 Available Work Items
|
||||
1310 Borrowed Work Items
|
||||
1312 Work Item Shortages
|
||||
1314 Current Clients
|
||||
1320 Bytes Transferred/sec
|
||||
1324 Read Bytes/sec
|
||||
1328 Write Bytes/sec
|
||||
1332 Total Operations/sec
|
||||
1334 DPCs Queued/sec
|
||||
1336 DPC Rate
|
||||
1342 Total DPCs Queued/sec
|
||||
1344 Total DPC Rate
|
||||
1350 % Registry Quota In Use
|
||||
1360 VL Memory
|
||||
1362 VLM % Virtual Size In Use
|
||||
1364 VLM Virtual Size
|
||||
1366 VLM Virtual Size Peak
|
||||
1368 VLM Virtual Size Available
|
||||
1370 VLM Commit Charge
|
||||
1372 VLM Commit Charge Peak
|
||||
1374 System VLM Commit Charge
|
||||
1376 System VLM Commit Charge Peak
|
||||
1378 System VLM Shared Commit Charge
|
||||
1380 Available KBytes
|
||||
1382 Available MBytes
|
||||
1400 Avg. Disk Queue Length
|
||||
1402 Avg. Disk Read Queue Length
|
||||
1404 Avg. Disk Write Queue Length
|
||||
1406 % Committed Bytes In Use
|
||||
1408 Full Image
|
||||
1410 Creating Process ID
|
||||
1412 IO Read Operations/sec
|
||||
1414 IO Write Operations/sec
|
||||
1416 IO Data Operations/sec
|
||||
1418 IO Other Operations/sec
|
||||
1420 IO Read Bytes/sec
|
||||
1422 IO Write Bytes/sec
|
||||
1424 IO Data Bytes/sec
|
||||
1426 IO Other Bytes/sec
|
||||
1450 Print Queue
|
||||
1452 Total Jobs Printed
|
||||
1454 Bytes Printed/sec
|
||||
1456 Total Pages Printed
|
||||
1458 Jobs
|
||||
1460 References
|
||||
1462 Max References
|
||||
1464 Jobs Spooling
|
||||
1466 Max Jobs Spooling
|
||||
1468 Out of Paper Errors
|
||||
1470 Not Ready Errors
|
||||
1472 Job Errors
|
||||
1474 Enumerate Network Printer Calls
|
||||
1476 Add Network Printer Calls
|
||||
1478 Working Set - Private
|
||||
1480 Working Set - Shared
|
||||
1482 % Idle Time
|
||||
1484 Split IO/Sec
|
||||
1500 Job Object
|
||||
1502 Current % Processor Time
|
||||
1504 Current % User Mode Time
|
||||
1506 Current % Kernel Mode Time
|
||||
1508 This Period mSec - Processor
|
||||
1510 This Period mSec - User Mode
|
||||
1512 This Period mSec - Kernel Mode
|
||||
1514 Pages/Sec
|
||||
1516 Process Count - Total
|
||||
1518 Process Count - Active
|
||||
1520 Process Count - Terminated
|
||||
1522 Total mSec - Processor
|
||||
1524 Total mSec - User Mode
|
||||
1526 Total mSec - Kernel Mode
|
||||
1548 Job Object Details
|
||||
1746 % Idle Time
|
||||
1748 % C1 Time
|
||||
1750 % C2 Time
|
||||
1752 % C3 Time
|
||||
1754 C1 Transitions/sec
|
||||
1756 C2 Transitions/sec
|
||||
1758 C3 Transitions/sec
|
||||
1760 Heap
|
||||
1762 Committed Bytes
|
||||
1764 Reserved Bytes
|
||||
1766 Virtual Bytes
|
||||
1768 Free Bytes
|
||||
1770 Free List Length
|
||||
1772 Avg. alloc rate
|
||||
1774 Avg. free rate
|
||||
1776 Uncommitted Ranges Length
|
||||
1778 Allocs - Frees
|
||||
1780 Cached Allocs/sec
|
||||
1782 Cached Frees/sec
|
||||
1784 Allocs <1K/sec
|
||||
1786 Frees <1K/sec
|
||||
1788 Allocs 1-8K/sec
|
||||
1790 Frees 1-8K/sec
|
||||
1792 Allocs over 8K/sec
|
||||
1794 Frees over 8K/sec
|
||||
1796 Total Allocs/sec
|
||||
1798 Total Frees/sec
|
||||
1800 Blocks in Heap Cache
|
||||
1802 Largest Cache Depth
|
||||
1804 % Fragmentation
|
||||
1806 % VAFragmentation
|
||||
1808 Heap Lock contention
|
||||
1846 End Marker
|
||||
1848 RSVP Service
|
||||
1850 Network Interfaces
|
||||
1852 Network sockets
|
||||
1854 Timers
|
||||
1856 RSVP sessions
|
||||
1858 QoS clients
|
||||
1860 QoS-enabled senders
|
||||
1862 QoS-enabled receivers
|
||||
1864 Failed QoS requests
|
||||
1866 Failed QoS sends
|
||||
1868 QoS notifications
|
||||
1870 Bytes in QoS notifications
|
||||
1872 RSVP Interfaces
|
||||
1874 Signaling bytes received
|
||||
1876 Signaling bytes sent
|
||||
1878 PATH messages received
|
||||
1880 RESV messages received
|
||||
1882 PATH ERR messages received
|
||||
1884 RESV ERR messages received
|
||||
1886 PATH TEAR messages received
|
||||
1888 RESV TEAR messages received
|
||||
1890 RESV CONFIRM messages received
|
||||
1892 PATH messages sent
|
||||
1894 RESV messages sent
|
||||
1896 PATH ERR messages sent
|
||||
1898 RESV ERR messages sent
|
||||
1900 PATH TEAR messages sent
|
||||
1902 RESV TEAR messages sent
|
||||
1904 RESV CONFIRM messages sent
|
||||
1906 Resource control failures
|
||||
1908 Policy control failures
|
||||
1910 General failures
|
||||
1912 Blocked RESVs
|
||||
1914 RESV state block timeouts
|
||||
1916 PATH state block timeouts
|
||||
1918 Send messages errors - Big messages
|
||||
1920 Receive messages errors - Big messages
|
||||
1922 Send messages errors - No memory
|
||||
1924 Receive messages errors - No memory
|
||||
1926 Number of incoming messages dropped
|
||||
1928 Number of outgoing messages dropped
|
||||
1930 Number of active flows
|
||||
1932 Reserved bandwidth
|
||||
1934 Maximum admitted bandwidth
|
||||
1936 PSched Flow
|
||||
1938 PSched Pipe
|
||||
1940 Packets dropped
|
||||
1942 Packets scheduled
|
||||
1944 Packets transmitted
|
||||
1946 Average packets in shaper
|
||||
1948 Max packets in shaper
|
||||
1950 Average packets in sequencer
|
||||
1952 Max packets in sequencer
|
||||
1954 Bytes scheduled
|
||||
1956 Bytes transmitted
|
||||
1958 Bytes transmitted/sec
|
||||
1960 Bytes scheduled/sec
|
||||
1962 Packets transmitted/sec
|
||||
1964 Packets scheduled/sec
|
||||
1966 Packets dropped/sec
|
||||
1968 Nonconforming packets scheduled
|
||||
1970 Nonconforming packets scheduled/sec
|
||||
1972 Nonconforming packets transmitted
|
||||
1974 Nonconforming packets transmitted/sec
|
||||
1976 Maximum Packets in netcard
|
||||
1978 Average Packets in netcard
|
||||
1980 Out of packets
|
||||
1982 Flows opened
|
||||
1984 Flows closed
|
||||
1986 Flows rejected
|
||||
1988 Flows modified
|
||||
1990 Flow mods rejected
|
||||
1992 Max simultaneous flows
|
||||
1994 Nonconforming packets scheduled
|
||||
1996 Nonconforming packets scheduled/sec
|
||||
1998 Nonconforming packets transmitted
|
||||
2000 Nonconforming packets transmitted/sec
|
||||
2002 Average packets in shaper
|
||||
2004 Max packets in shaper
|
||||
2006 Average packets in sequencer
|
||||
2008 Max packets in sequencer
|
||||
2010 Max packets in netcard
|
||||
2012 Average packets in netcard
|
||||
2014 RAS Port
|
||||
2016 Bytes Transmitted
|
||||
2018 Bytes Received
|
||||
2020 Frames Transmitted
|
||||
2022 Frames Received
|
||||
2024 Percent Compression Out
|
||||
2026 Percent Compression In
|
||||
2028 CRC Errors
|
||||
2030 Timeout Errors
|
||||
2032 Serial Overrun Errors
|
||||
2034 Alignment Errors
|
||||
2036 Buffer Overrun Errors
|
||||
2038 Total Errors
|
||||
2040 Bytes Transmitted/Sec
|
||||
2042 Bytes Received/Sec
|
||||
2044 Frames Transmitted/Sec
|
||||
2046 Frames Received/Sec
|
||||
2048 Total Errors/Sec
|
||||
2050 RAS Total
|
||||
2052 Total Connections
|
||||
2054 Terminal Services Session
|
||||
2056 Input WdBytes
|
||||
2058 Input WdFrames
|
||||
2060 Input WaitForOutBuf
|
||||
2062 Input Frames
|
||||
2064 Input Bytes
|
||||
2066 Input Compressed Bytes
|
||||
2068 Input Compress Flushes
|
||||
2070 Input Errors
|
||||
2072 Input Timeouts
|
||||
2074 Input Async Frame Error
|
||||
2076 Input Async Overrun
|
||||
2078 Input Async Overflow
|
||||
2080 Input Async Parity Error
|
||||
2082 Input Transport Errors
|
||||
2084 Output WdBytes
|
||||
2086 Output WdFrames
|
||||
2088 Output WaitForOutBuf
|
||||
2090 Output Frames
|
||||
2092 Output Bytes
|
||||
2094 Output Compressed Bytes
|
||||
2096 Output Compress Flushes
|
||||
2098 Output Errors
|
||||
2100 Output Timeouts
|
||||
2102 Output Async Frame Error
|
||||
2104 Output Async Overrun
|
||||
2106 Output Async Overflow
|
||||
2108 Output Async Parity Error
|
||||
2110 Output Transport Errors
|
||||
2112 Total WdBytes
|
||||
2114 Total WdFrames
|
||||
2116 Total WaitForOutBuf
|
||||
2118 Total Frames
|
||||
2120 Total Bytes
|
||||
2122 Total Compressed Bytes
|
||||
2124 Total Compress Flushes
|
||||
2126 Total Errors
|
||||
2128 Total Timeouts
|
||||
2130 Total Async Frame Error
|
||||
2132 Total Async Overrun
|
||||
2134 Total Async Overflow
|
||||
2136 Total Async Parity Error
|
||||
2138 Total Transport Errors
|
||||
2140 Total Protocol Cache Reads
|
||||
2142 Total Protocol Cache Hits
|
||||
2144 Total Protocol Cache Hit Ratio
|
||||
2146 Protocol Bitmap Cache Reads
|
||||
2148 Protocol Bitmap Cache Hits
|
||||
2150 Protocol Bitmap Cache Hit Ratio
|
||||
2152 Protocol Glyph Cache Reads
|
||||
2154 Protocol Glyph Cache Hits
|
||||
2156 Protocol Glyph Cache Hit Ratio
|
||||
2158 Protocol Brush Cache Reads
|
||||
2160 Protocol Brush Cache Hits
|
||||
2162 Protocol Brush Cache Hit Ratio
|
||||
2164 Protocol Save Screen Bitmap Cache Reads
|
||||
2166 Protocol Save Screen Bitmap Cache Hits
|
||||
2168 Protocol Save Screen Bitmap Cache Hit Ratio
|
||||
2170 Input Compression Ratio
|
||||
2172 Output Compression Ratio
|
||||
2174 Total Compression Ratio
|
||||
2176 Terminal Services
|
||||
2178 Total Sessions
|
||||
2180 Active Sessions
|
||||
2182 Inactive Sessions
|
||||
2184 Distributed Transaction Coordinator
|
||||
2186 Active Transactions
|
||||
2188 Committed Transactions
|
||||
2190 Aborted Transactions
|
||||
2192 In Doubt Transactions
|
||||
2194 Active Transactions Maximum
|
||||
2196 Force Committed Transactions
|
||||
2198 Force Aborted Transactions
|
||||
2200 Response Time -- Minimum
|
||||
2202 Response Time -- Average
|
||||
2204 Response Time -- Maximum
|
||||
2206 Transactions/sec
|
||||
2208 Committed Transactions/sec
|
||||
2210 Aborted Transactions/sec
|
||||
2212 Indexing Service
|
||||
2214 Word lists
|
||||
2216 Saved indexes
|
||||
2218 Index size (MB)
|
||||
2220 Files to be indexed
|
||||
2222 Unique keys
|
||||
2224 Running queries
|
||||
2226 Merge progress
|
||||
2228 # documents indexed
|
||||
2230 Total # documents
|
||||
2232 Total # of queries
|
||||
2234 Deferred for indexing
|
||||
2236 Indexing Service Filter
|
||||
2238 Total indexing speed (MB/hr)
|
||||
2240 Binding time (msec)
|
||||
2242 Indexing speed (MB/hr)
|
||||
2244 Http Indexing Service
|
||||
2246 Cache items
|
||||
2248 % Cache hits
|
||||
2250 Total cache accesses 1
|
||||
2252 % Cache misses
|
||||
2254 Total cache accesses 2
|
||||
2256 Active queries
|
||||
2258 Total queries
|
||||
2260 Queries per minute
|
||||
2262 Current requests queued
|
||||
2264 Total requests rejected
|
||||
2266 WMI Objects
|
||||
2268 HiPerf Classes
|
||||
2270 HiPerf Validity
|
||||
2272 BatteryStatus
|
||||
2274 ChargeRate
|
||||
2276 DischargeRate
|
||||
2278 RemainingCapacity
|
||||
2280 Tag
|
||||
2282 Voltage
|
||||
@@ -0,0 +1,354 @@
|
||||
/*
|
||||
* code in this file derived from:
|
||||
* http://www.intel.com/cd/ids/developer/asmo-na/eng/technologies/20438.htm
|
||||
* license grants use of the source code.
|
||||
*/
|
||||
static unsigned int HTSupported(void);
|
||||
static unsigned char LogicalProcPerPhysicalProc(unsigned int);
|
||||
static unsigned char GetAPIC_ID(unsigned int);
|
||||
static unsigned char CPUCount(unsigned char *, unsigned char *);
|
||||
|
||||
// EDX[28] Bit 28 is set if HT is supported
|
||||
#define HT_BIT 0x10000000
|
||||
|
||||
// EAX[11:8] Bit 8-11 contains family processor ID.
|
||||
#define FAMILY_ID 0x0F00
|
||||
|
||||
#define PENTIUM4_ID 0x0F00
|
||||
|
||||
// EAX[23:20] Bit 20-23 contains extended family processor ID
|
||||
#define EXT_FAMILY_ID 0x0F00000
|
||||
|
||||
|
||||
// EBX[23:16] Bit 16-23 in ebx contains the number of logical
|
||||
// processors per physical processor when execute cpuid with
|
||||
// eax set to 1
|
||||
#define NUM_LOGICAL_BITS 0x00FF0000
|
||||
|
||||
// EBX[31:24] Bits 24-31 (8 bits) return the 8-bit unique
|
||||
// initial APIC ID for the processor this code is running on.
|
||||
// Default value = 0xff if HT is not supported
|
||||
#define INITIAL_APIC_ID_BITS 0xFF000000
|
||||
|
||||
// Status Flag
|
||||
#define HT_NOT_CAPABLE 0
|
||||
#define HT_ENABLED 1
|
||||
#define HT_DISABLED 2
|
||||
#define HT_SUPPORTED_NOT_ENABLED 3
|
||||
#define HT_CANNOT_DETECT 4
|
||||
|
||||
#include "sigar.h"
|
||||
#include "sigar_private.h"
|
||||
#include "sigar_os.h"
|
||||
|
||||
static unsigned int HTSupported(void)
|
||||
{
|
||||
unsigned int
|
||||
Regedx = 0,
|
||||
Regeax = 0,
|
||||
VendorId[3] = {0, 0, 0};
|
||||
|
||||
__try {
|
||||
__asm {
|
||||
xor eax, eax // call cpuid with eax = 0
|
||||
cpuid // Get vendor id string
|
||||
mov VendorId, ebx
|
||||
mov VendorId + 4, edx
|
||||
mov VendorId + 8, ecx
|
||||
|
||||
mov eax, 1 // call cpuid with eax = 1
|
||||
cpuid
|
||||
mov Regeax, eax // eax contains family processor type
|
||||
mov Regedx, edx // edx has info about the availability of hyper-Threading
|
||||
}
|
||||
}
|
||||
__except (EXCEPTION_EXECUTE_HANDLER) {
|
||||
return 0; // cpuid is unavailable
|
||||
}
|
||||
|
||||
if (((Regeax & FAMILY_ID) == PENTIUM4_ID) ||
|
||||
(Regeax & EXT_FAMILY_ID))
|
||||
{
|
||||
if ((VendorId[0] == 'uneG') &&
|
||||
(VendorId[1] == 'Ieni') &&
|
||||
(VendorId[2] == 'letn'))
|
||||
{
|
||||
// Genuine Intel with hyper-Threading technology
|
||||
return Regedx & HT_BIT;
|
||||
}
|
||||
}
|
||||
|
||||
return 0; // Not genuine Intel processor
|
||||
}
|
||||
|
||||
static unsigned char LogicalProcPerPhysicalProc(unsigned int ht_supported)
|
||||
{
|
||||
unsigned int Regebx = 0;
|
||||
if (!ht_supported) {
|
||||
return (unsigned char) 1; // HT not supported
|
||||
}
|
||||
|
||||
// Logical processor = 1
|
||||
__asm {
|
||||
mov eax, 1
|
||||
cpuid
|
||||
mov Regebx, ebx
|
||||
}
|
||||
|
||||
return (unsigned char) ((Regebx & NUM_LOGICAL_BITS) >> 16);
|
||||
}
|
||||
|
||||
static unsigned char GetAPIC_ID(unsigned int ht_supported)
|
||||
{
|
||||
unsigned int Regebx = 0;
|
||||
if (!ht_supported) {
|
||||
return (unsigned char) -1;
|
||||
}
|
||||
|
||||
// Logical processor = 1
|
||||
__asm {
|
||||
mov eax, 1
|
||||
cpuid
|
||||
mov Regebx, ebx
|
||||
}
|
||||
|
||||
return (unsigned char) ((Regebx & INITIAL_APIC_ID_BITS) >> 24);
|
||||
}
|
||||
|
||||
static unsigned char CPUCount(unsigned char *LogicalNum,
|
||||
unsigned char *PhysicalNum)
|
||||
{
|
||||
unsigned int ht_supported = HTSupported();
|
||||
unsigned char StatusFlag = 0;
|
||||
SYSTEM_INFO info;
|
||||
|
||||
*PhysicalNum = 0;
|
||||
*LogicalNum = 0;
|
||||
info.dwNumberOfProcessors = 0;
|
||||
GetSystemInfo(&info);
|
||||
|
||||
// Number of physical processors in a non-Intel system
|
||||
// or in a 32-bit Intel system with Hyper-Threading technology disabled
|
||||
*PhysicalNum = (unsigned char) info.dwNumberOfProcessors;
|
||||
|
||||
if (ht_supported) {
|
||||
unsigned char HT_Enabled = 0;
|
||||
|
||||
*LogicalNum = LogicalProcPerPhysicalProc(ht_supported);
|
||||
|
||||
if (*LogicalNum >= 1) { // >1 Doesn't mean HT is enabled in the BIOS
|
||||
HANDLE hCurrentProcessHandle;
|
||||
DWORD dwProcessAffinity;
|
||||
DWORD dwSystemAffinity;
|
||||
DWORD dwAffinityMask;
|
||||
|
||||
// Calculate the appropriate shifts and mask based on the
|
||||
// number of logical processors.
|
||||
|
||||
unsigned char i = 1,
|
||||
PHY_ID_MASK = 0xFF,
|
||||
PHY_ID_SHIFT = 0;
|
||||
|
||||
while (i < *LogicalNum) {
|
||||
i *= 2;
|
||||
PHY_ID_MASK <<= 1;
|
||||
PHY_ID_SHIFT++;
|
||||
}
|
||||
|
||||
hCurrentProcessHandle = GetCurrentProcess();
|
||||
|
||||
GetProcessAffinityMask(hCurrentProcessHandle,
|
||||
&dwProcessAffinity,
|
||||
&dwSystemAffinity);
|
||||
|
||||
// Check if available process affinity mask is equal to the
|
||||
// available system affinity mask
|
||||
if (dwProcessAffinity != dwSystemAffinity) {
|
||||
StatusFlag = HT_CANNOT_DETECT;
|
||||
// *PhysicalNum = (unsigned char)-1;
|
||||
return StatusFlag;
|
||||
}
|
||||
|
||||
dwAffinityMask = 1;
|
||||
|
||||
while (dwAffinityMask != 0 && dwAffinityMask <= dwProcessAffinity) {
|
||||
// Check if this CPU is available
|
||||
if (dwAffinityMask & dwProcessAffinity) {
|
||||
if (SetProcessAffinityMask(hCurrentProcessHandle,
|
||||
dwAffinityMask))
|
||||
{
|
||||
unsigned char APIC_ID,
|
||||
LOG_ID,
|
||||
PHY_ID;
|
||||
|
||||
Sleep(0); // Give OS time to switch CPU
|
||||
|
||||
APIC_ID = GetAPIC_ID(ht_supported);
|
||||
LOG_ID = APIC_ID & ~PHY_ID_MASK;
|
||||
PHY_ID = APIC_ID >> PHY_ID_SHIFT;
|
||||
|
||||
if (LOG_ID != 0) {
|
||||
HT_Enabled = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dwAffinityMask = dwAffinityMask << 1;
|
||||
}
|
||||
|
||||
// Reset the processor affinity
|
||||
SetProcessAffinityMask(hCurrentProcessHandle, dwProcessAffinity);
|
||||
|
||||
if (*LogicalNum == 1) { // Normal P4 : HT is disabled in hardware
|
||||
StatusFlag = HT_DISABLED;
|
||||
}
|
||||
else {
|
||||
if (HT_Enabled) {
|
||||
// Total physical processors in a Hyper-Threading enabled system.
|
||||
*PhysicalNum /= (*LogicalNum);
|
||||
StatusFlag = HT_ENABLED;
|
||||
}
|
||||
else {
|
||||
StatusFlag = HT_SUPPORTED_NOT_ENABLED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
// Processors do not have Hyper-Threading technology
|
||||
StatusFlag = HT_NOT_CAPABLE;
|
||||
*LogicalNum = 1;
|
||||
}
|
||||
|
||||
return StatusFlag;
|
||||
}
|
||||
|
||||
unsigned int sigar_cpu_count(sigar_t *sigar)
|
||||
{
|
||||
unsigned char
|
||||
status,
|
||||
LogicalNum = 0,
|
||||
PhysicalNum = 0;
|
||||
|
||||
if (sigar->ncpu != 0) {
|
||||
return sigar->ncpu;
|
||||
}
|
||||
|
||||
status = CPUCount(&LogicalNum, &PhysicalNum);
|
||||
|
||||
sigar->ncpu = (unsigned int)PhysicalNum;
|
||||
|
||||
if (status == HT_ENABLED) {
|
||||
sigar->ht_enabled = 1;
|
||||
}
|
||||
else {
|
||||
sigar->ht_enabled = 0;
|
||||
}
|
||||
|
||||
return sigar->ncpu;
|
||||
}
|
||||
|
||||
/* this function is not part of the intel derived code */
|
||||
|
||||
int sigar_cpu_info_get(sigar_t *sigar, sigar_cpu_info_t *info)
|
||||
{
|
||||
HKEY key, cpu;
|
||||
int i = 0;
|
||||
TCHAR id[MAX_PATH + 1];
|
||||
LPBYTE value;
|
||||
DWORD size = 0, rc;
|
||||
|
||||
RegOpenKey(HKEY_LOCAL_MACHINE,
|
||||
"HARDWARE\\DESCRIPTION\\System\\CentralProcessor", &key);
|
||||
|
||||
//just lookup the first id, then assume all cpus are the same.
|
||||
rc = RegEnumKey(key, 0, id, sizeof(id));
|
||||
if (rc != ERROR_SUCCESS) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = RegOpenKey(key, id, &cpu);
|
||||
if (rc != ERROR_SUCCESS) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
size = sizeof(info->vendor);
|
||||
if (RegQueryValueEx(cpu, "VendorIdentifier", NULL, NULL,
|
||||
(LPVOID)&info->vendor, &size))
|
||||
{
|
||||
SIGAR_SSTRCPY(info->vendor, "Intel");
|
||||
}
|
||||
|
||||
size = sizeof(info->model);
|
||||
if (RegQueryValueEx(cpu, "Identifier", NULL, NULL,
|
||||
(LPVOID)&info->model, &size))
|
||||
{
|
||||
SIGAR_SSTRCPY(info->vendor, "x86");
|
||||
}
|
||||
|
||||
size = sizeof(info->mhz); // == sizeof(DWORD)
|
||||
if (RegQueryValueEx(cpu, "~MHz", NULL, NULL,
|
||||
(LPVOID)&info->mhz, &size))
|
||||
{
|
||||
info->mhz = -1;
|
||||
}
|
||||
|
||||
info->cache_size = -1; //XXX
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
#ifdef CPU_MAIN
|
||||
void main(void)
|
||||
{
|
||||
// Number of logical CPU per ONE PHYSICAL CPU
|
||||
unsigned char LogicalNum = 0,
|
||||
PhysicalNum = 0, // Total number of physical processor
|
||||
HTStatusFlag = 0;
|
||||
|
||||
sigar_cpu_info_t info;
|
||||
|
||||
sigar_cpu_info_get(NULL, &info);
|
||||
|
||||
printf("Vendor............%s\n", info.vendor);
|
||||
printf("Model.............%s\n", info.model);
|
||||
printf("Mhz...............%d\n", info.mhz);
|
||||
|
||||
HTStatusFlag = CPUCount(&LogicalNum, &PhysicalNum);
|
||||
|
||||
switch(HTStatusFlag)
|
||||
{
|
||||
case HT_NOT_CAPABLE:
|
||||
printf("Hyper-threading...not capable\n");
|
||||
break;
|
||||
|
||||
case HT_DISABLED:
|
||||
printf("Hyper-threading...disabled\n");
|
||||
break;
|
||||
|
||||
case HT_ENABLED:
|
||||
printf("Hyper-threading...enabled\n");
|
||||
break;
|
||||
|
||||
case HT_SUPPORTED_NOT_ENABLED:
|
||||
printf("Hyper-threading...capable but not enabled\n");
|
||||
break;
|
||||
|
||||
case HT_CANNOT_DETECT:
|
||||
printf("Hyper-threading...cannot be detected\n");
|
||||
break;
|
||||
}
|
||||
|
||||
printf("Logical ratio.....%d/1\n",
|
||||
LogicalNum);
|
||||
|
||||
if (PhysicalNum != (unsigned char)-1) {
|
||||
printf("Physical CPUs.....%d\n", PhysicalNum);
|
||||
}
|
||||
else {
|
||||
printf("Can't determine number of physical processors\n");
|
||||
printf("Make sure to enable ALL processors\n");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* functions for getting info from the Process Environment Block
|
||||
*/
|
||||
#define UNICODE
|
||||
#define _UNICODE
|
||||
|
||||
#include "sigar.h"
|
||||
#include "sigar_private.h"
|
||||
#include "sigar_os.h"
|
||||
|
||||
#define START_ADDRESS (LPVOID)0x00020498
|
||||
|
||||
static int sigar_peb_get(sigar_t *sigar, HANDLE proc, DWORD *base)
|
||||
{
|
||||
MEMORY_BASIC_INFORMATION mbi;
|
||||
DWORD bytes;
|
||||
|
||||
if (!sigar->peb) {
|
||||
sigar->peb = malloc(sigar->pagesize);
|
||||
}
|
||||
|
||||
if (!VirtualQueryEx(proc, START_ADDRESS, &mbi, sizeof(mbi))) {
|
||||
return GetLastError();
|
||||
}
|
||||
|
||||
if (!ReadProcessMemory(proc, mbi.BaseAddress, sigar->peb,
|
||||
sigar->pagesize, &bytes))
|
||||
{
|
||||
return GetLastError();
|
||||
}
|
||||
|
||||
*base = (DWORD)mbi.BaseAddress;
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
//point scratch to PATH env var
|
||||
#define PEB_PATH(scratch, base) \
|
||||
scratch = sigar->peb + ((DWORD)START_ADDRESS - base)
|
||||
|
||||
//point scratch to EXE (assumes PEB_PATH)
|
||||
#define PEB_EXE(scratch) \
|
||||
scratch = scratch + (wcslen((LPWSTR)scratch) + 1) * sizeof(WCHAR)
|
||||
|
||||
int sigar_proc_exe_name_get(sigar_t *sigar, HANDLE proc, char *name)
|
||||
{
|
||||
int status;
|
||||
LPBYTE scratch;
|
||||
DWORD base;
|
||||
WCHAR buf[MAX_PATH];
|
||||
|
||||
if ((status = sigar_peb_get(sigar, proc, &base)) != SIGAR_OK) {
|
||||
return status;
|
||||
}
|
||||
|
||||
//skip env PATH
|
||||
PEB_PATH(scratch, base);
|
||||
|
||||
PEB_EXE(scratch);
|
||||
|
||||
//seems common, reason unknown.
|
||||
if (*scratch == '\0') {
|
||||
scratch += sizeof(WCHAR);
|
||||
}
|
||||
|
||||
wcsncpy(buf, (LPWSTR)scratch, MAX_PATH);
|
||||
buf[MAX_PATH-1] = L'\0';
|
||||
|
||||
SIGAR_W2A(buf, name, MAX_PATH);
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
#ifndef SIGAR_OS_H
|
||||
#define SIGAR_OS_H
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <winreg.h>
|
||||
#include <winperf.h>
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#include <stddef.h>
|
||||
#include <sys/types.h>
|
||||
#include <malloc.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#define INT64_C(val) val##i64
|
||||
|
||||
/* see apr/include/arch/win32/atime.h */
|
||||
#define EPOCH_DELTA INT64_C(11644473600000000)
|
||||
|
||||
static __inline sigar_uint64_t FileTimeToTime(FILETIME *ft)
|
||||
{
|
||||
sigar_uint64_t time;
|
||||
time = ft->dwHighDateTime;
|
||||
time = time << 32;
|
||||
time |= ft->dwLowDateTime;
|
||||
time /= 10;
|
||||
time -= EPOCH_DELTA;
|
||||
return time;
|
||||
}
|
||||
|
||||
/* XXX: support CP_UTF8 ? */
|
||||
|
||||
#define SIGAR_A2W(lpa, lpw, bytes) \
|
||||
(lpw[0] = 0, MultiByteToWideChar(CP_ACP, 0, \
|
||||
lpa, -1, lpw, (bytes/sizeof(WCHAR))))
|
||||
|
||||
#define SIGAR_W2A(lpw, lpa, chars) \
|
||||
(lpa[0] = '\0', WideCharToMultiByte(CP_ACP, 0, \
|
||||
lpw, -1, (LPSTR)lpa, chars, \
|
||||
NULL, NULL))
|
||||
|
||||
#include <iprtrmib.h>
|
||||
|
||||
/* undocumented structures */
|
||||
typedef struct {
|
||||
DWORD dwState;
|
||||
DWORD dwLocalAddr;
|
||||
DWORD dwLocalPort;
|
||||
DWORD dwRemoteAddr;
|
||||
DWORD dwRemotePort;
|
||||
DWORD dwProcessId;
|
||||
} MIB_TCPEXROW, *PMIB_TCPEXROW;
|
||||
|
||||
typedef struct {
|
||||
DWORD dwNumEntries;
|
||||
MIB_TCPEXROW table[ANY_SIZE];
|
||||
} MIB_TCPEXTABLE, *PMIB_TCPEXTABLE;
|
||||
|
||||
typedef struct {
|
||||
DWORD dwLocalAddr;
|
||||
DWORD dwLocalPort;
|
||||
DWORD dwProcessId;
|
||||
} MIB_UDPEXROW, *PMIB_UDPEXROW;
|
||||
|
||||
typedef struct {
|
||||
DWORD dwNumEntries;
|
||||
MIB_UDPEXROW table[ANY_SIZE];
|
||||
} MIB_UDPEXTABLE, *PMIB_UDPEXTABLE;
|
||||
|
||||
/* end undocumented structures */
|
||||
|
||||
typedef DWORD (CALLBACK *LPGETIPFORWARDTABLE)(PMIB_IPFORWARDTABLE, PULONG, BOOL);
|
||||
|
||||
typedef DWORD (CALLBACK *LPGETIFTABLE)(PMIB_IFTABLE, PULONG, BOOL);
|
||||
|
||||
typedef DWORD (CALLBACK *LPGETTCPTABLE)(PMIB_TCPTABLE, PDWORD, BOOL);
|
||||
|
||||
typedef DWORD (CALLBACK *LPGETUDPTABLE)(PMIB_UDPTABLE, PDWORD, BOOL);
|
||||
|
||||
typedef DWORD (CALLBACK *LPGETTCPEXTABLE)(PMIB_TCPEXTABLE *, BOOL, HANDLE,
|
||||
DWORD, DWORD);
|
||||
|
||||
typedef struct {
|
||||
sigar_pid_t pid;
|
||||
int ppid;
|
||||
int priority;
|
||||
time_t mtime;
|
||||
sigar_uint64_t vsize;
|
||||
sigar_uint64_t size;
|
||||
char name[SIGAR_PROC_NAME_LEN];
|
||||
char state;
|
||||
sigar_uint64_t handles;
|
||||
} sigar_win32_pinfo_t;
|
||||
|
||||
struct sigar_t {
|
||||
SIGAR_T_BASE;
|
||||
char *machine;
|
||||
int using_wide;
|
||||
long pagesize;
|
||||
HKEY handle;
|
||||
char *perfbuf;
|
||||
DWORD perfbuf_size;
|
||||
HINSTANCE ip_handle;
|
||||
LPGETIFTABLE get_if_table;
|
||||
LPGETIPFORWARDTABLE get_ipforward_table;
|
||||
LPGETTCPTABLE get_tcp_table;
|
||||
LPGETTCPEXTABLE get_tcpx_table;
|
||||
LPGETUDPTABLE get_udp_table;
|
||||
sigar_win32_pinfo_t pinfo;
|
||||
WORD ws_version;
|
||||
int ws_error;
|
||||
LPBYTE peb; //scratch pad for getting peb info
|
||||
int ht_enabled;
|
||||
};
|
||||
|
||||
int sigar_wsa_init(sigar_t *sigar);
|
||||
|
||||
int sigar_proc_exe_name_get(sigar_t *sigar, HANDLE proc, char *name);
|
||||
|
||||
unsigned int sigar_cpu_count(sigar_t *sigar);
|
||||
|
||||
int sigar_cpu_info_get(sigar_t *sigar, sigar_cpu_info_t *info);
|
||||
|
||||
#endif /* SIGAR_OS_H */
|
||||
@@ -0,0 +1,31 @@
|
||||
#ifndef SIGAR_PDH_H
|
||||
#define SIGAR_PDH_H
|
||||
|
||||
/* performance data helpers */
|
||||
|
||||
#define PdhFirstObject(block) \
|
||||
((PERF_OBJECT_TYPE *)((BYTE *) block + block->HeaderLength))
|
||||
|
||||
#define PdhNextObject(object) \
|
||||
((PERF_OBJECT_TYPE *)((BYTE *) object + object->TotalByteLength))
|
||||
|
||||
#define PdhFirstCounter(object) \
|
||||
((PERF_COUNTER_DEFINITION *)((BYTE *) object + object->HeaderLength))
|
||||
|
||||
#define PdhNextCounter(counter) \
|
||||
((PERF_COUNTER_DEFINITION *)((BYTE *) counter + counter->ByteLength))
|
||||
|
||||
#define PdhGetCounterBlock(inst) \
|
||||
((PERF_COUNTER_BLOCK *)((BYTE *) inst + inst->ByteLength))
|
||||
|
||||
#define PdhFirstInstance(object) \
|
||||
((PERF_INSTANCE_DEFINITION *)((BYTE *) object + object->DefinitionLength))
|
||||
|
||||
#define PdhNextInstance(inst) \
|
||||
((PERF_INSTANCE_DEFINITION *)((BYTE *)inst + inst->ByteLength + \
|
||||
PdhGetCounterBlock(inst)->ByteLength))
|
||||
|
||||
#define PdhInstanceName(inst) \
|
||||
((wchar_t *)((BYTE *)inst + inst->NameOffset))
|
||||
|
||||
#endif /* SIGAR_PDH_H */
|
||||
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user