make sigar_proc_list_get a wrapper

This commit is contained in:
Doug MacEachern 2007-04-22 03:54:04 +00:00
parent 1745dcf5d4
commit ad433cf375
11 changed files with 28 additions and 39 deletions

View File

@ -164,7 +164,8 @@ int sigar_sys_info_get_uname(sigar_sys_info_t *sysinfo);
int sigar_os_sys_info_get(sigar_t *sigar, sigar_sys_info_t *sysinfo); int sigar_os_sys_info_get(sigar_t *sigar, sigar_sys_info_t *sysinfo);
int sigar_proc_list_create(sigar_proc_list_t *proclist); int sigar_os_proc_list_get(sigar_t *sigar,
sigar_proc_list_t *proclist);
int sigar_proc_list_grow(sigar_proc_list_t *proclist); int sigar_proc_list_grow(sigar_proc_list_t *proclist);

View File

@ -962,14 +962,12 @@ int sigar_loadavg_get(sigar_t *sigar,
return SIGAR_OK; return SIGAR_OK;
} }
int sigar_proc_list_get(sigar_t *sigar, int sigar_os_proc_list_get(sigar_t *sigar,
sigar_proc_list_t *proclist) sigar_proc_list_t *proclist)
{ {
pid_t pid = 0; pid_t pid = 0;
struct procsinfo info; struct procsinfo info;
sigar_proc_list_create(proclist);
for (;;) { for (;;) {
int num = getprocs(&info, sizeof(info), int num = getprocs(&info, sizeof(info),
NULL, 0, &pid, 1); NULL, 0, &pid, 1);

View File

@ -613,8 +613,8 @@ int sigar_loadavg_get(sigar_t *sigar,
#define KERN_PROC_PROC KERN_PROC_ALL #define KERN_PROC_PROC KERN_PROC_ALL
#endif #endif
int sigar_proc_list_get(sigar_t *sigar, int sigar_os_proc_list_get(sigar_t *sigar,
sigar_proc_list_t *proclist) sigar_proc_list_t *proclist)
{ {
#if defined(DARWIN) || defined(SIGAR_FREEBSD5) #if defined(DARWIN) || defined(SIGAR_FREEBSD5)
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PROC, 0 }; int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PROC, 0 };
@ -634,7 +634,6 @@ int sigar_proc_list_get(sigar_t *sigar,
} }
num = len/sizeof(*proc); num = len/sizeof(*proc);
sigar_proc_list_create(proclist);
for (i=0; i<num; i++) { for (i=0; i<num; i++) {
if (proc[i].KI_FLAG & P_SYSTEM) { if (proc[i].KI_FLAG & P_SYSTEM) {
@ -657,8 +656,6 @@ int sigar_proc_list_get(sigar_t *sigar,
proc = kvm_getprocs(sigar->kmem, KERN_PROC_PROC, 0, &num); proc = kvm_getprocs(sigar->kmem, KERN_PROC_PROC, 0, &num);
sigar_proc_list_create(proclist);
for (i=0; i<num; i++) { for (i=0; i<num; i++) {
if (proc[i].KI_FLAG & P_SYSTEM) { if (proc[i].KI_FLAG & P_SYSTEM) {
continue; continue;

View File

@ -206,14 +206,12 @@ int sigar_loadavg_get(sigar_t *sigar,
#define PROC_ELTS 16 #define PROC_ELTS 16
int sigar_proc_list_get(sigar_t *sigar, int sigar_os_proc_list_get(sigar_t *sigar,
sigar_proc_list_t *proclist) sigar_proc_list_t *proclist)
{ {
int num, idx=0; int num, idx=0;
struct pst_status proctab[PROC_ELTS]; struct pst_status proctab[PROC_ELTS];
sigar_proc_list_create(proclist);
while ((num = pstat_getproc(proctab, sizeof(proctab[0]), while ((num = pstat_getproc(proctab, sizeof(proctab[0]),
PROC_ELTS, idx)) > 0) PROC_ELTS, idx)) > 0)
{ {

View File

@ -618,8 +618,8 @@ static SIGAR_INLINE int proc_isthread(sigar_t *sigar, char *pidstr, int len)
return 1; return 1;
} }
int sigar_proc_list_get(sigar_t *sigar, int sigar_os_proc_list_get(sigar_t *sigar,
sigar_proc_list_t *proclist) sigar_proc_list_t *proclist)
{ {
DIR *dirp = opendir(PROCP_FS_ROOT); DIR *dirp = opendir(PROCP_FS_ROOT);
struct dirent *ent, dbuf; struct dirent *ent, dbuf;
@ -632,8 +632,6 @@ int sigar_proc_list_get(sigar_t *sigar,
sigar->proc_signal_offset = get_proc_signal_offset(); sigar->proc_signal_offset = get_proc_signal_offset();
} }
sigar_proc_list_create(proclist);
while (readdir_r(dirp, &dbuf, &ent) == 0) { while (readdir_r(dirp, &dbuf, &ent) == 0) {
if (!ent) { if (!ent) {
break; break;

View File

@ -165,8 +165,8 @@ int sigar_loadavg_get(sigar_t *sigar,
#define PROC_ELTS 16 #define PROC_ELTS 16
int sigar_proc_list_get(sigar_t *sigar, int sigar_os_proc_list_get(sigar_t *sigar,
sigar_proc_list_t *proclist) sigar_proc_list_t *proclist)
{ {
struct tbl_procinfo procinfo[PROC_ELTS]; struct tbl_procinfo procinfo[PROC_ELTS];
int offset; int offset;
@ -176,8 +176,6 @@ int sigar_proc_list_get(sigar_t *sigar,
sigar->nproc = table(TBL_PROCINFO, 0, NULL, INT_MAX, 0); sigar->nproc = table(TBL_PROCINFO, 0, NULL, INT_MAX, 0);
} }
sigar_proc_list_create(proclist);
for (offset=0; offset<sigar->nproc; offset+=PROC_ELTS) { for (offset=0; offset<sigar->nproc; offset+=PROC_ELTS) {
int i; int i;
int elts = table(TBL_PROCINFO, offset, &procinfo, int elts = table(TBL_PROCINFO, offset, &procinfo,

View File

@ -631,8 +631,8 @@ static int sigar_dlinfo_get(sigar_t *sigar, const char *func,
return SIGAR_OK; return SIGAR_OK;
} }
int sigar_proc_list_get(sigar_t *sigar, int sigar_os_proc_list_get(sigar_t *sigar,
sigar_proc_list_t *proclist) sigar_proc_list_t *proclist)
{ {
return sigar_proc_list_procfs_get(sigar, proclist); return sigar_proc_list_procfs_get(sigar, proclist);
} }

View File

@ -904,8 +904,6 @@ static int sigar_proc_list_get_perf(sigar_t *sigar,
} }
} }
sigar_proc_list_create(proclist);
for (i=0, inst = PdhFirstInstance(object); for (i=0, inst = PdhFirstInstance(object);
i<object->NumInstances; i<object->NumInstances;
i++, inst = PdhNextInstance(inst)) i++, inst = PdhNextInstance(inst))
@ -928,8 +926,8 @@ static int sigar_proc_list_get_perf(sigar_t *sigar,
#define sigar_EnumProcesses \ #define sigar_EnumProcesses \
sigar->psapi.enum_processes.func sigar->psapi.enum_processes.func
SIGAR_DECLARE(int) sigar_proc_list_get(sigar_t *sigar, int sigar_os_proc_list_get(sigar_t *sigar,
sigar_proc_list_t *proclist) sigar_proc_list_t *proclist)
{ {
DLLMOD_INIT(psapi, FALSE); DLLMOD_INIT(psapi, FALSE);
@ -956,16 +954,14 @@ SIGAR_DECLARE(int) sigar_proc_list_get(sigar_t *sigar,
pids = (DWORD *)sigar->perfbuf; pids = (DWORD *)sigar->perfbuf;
proclist->number = 0; size = retval / sizeof(DWORD);
proclist->size = retval / sizeof(DWORD);
proclist->data =
malloc(sizeof(*(proclist->data)) * proclist->size);
for (i=0; i<proclist->size; i++) { for (i=0; i<size; i++) {
DWORD pid = pids[i]; DWORD pid = pids[i];
if (pid == 0) { if (pid == 0) {
continue; /* dont include the system Idle process */ continue; /* dont include the system Idle process */
} }
SIGAR_PROC_LIST_GROW(proclist);
proclist->data[proclist->number++] = pid; proclist->data[proclist->number++] = pid;
} }

View File

@ -500,7 +500,7 @@ sigar_proc_cred_name_get(sigar_t *sigar, sigar_pid_t pid,
#endif /* WIN32 */ #endif /* WIN32 */
int sigar_proc_list_create(sigar_proc_list_t *proclist) static int sigar_proc_list_create(sigar_proc_list_t *proclist)
{ {
proclist->number = 0; proclist->number = 0;
proclist->size = SIGAR_PROC_LIST_MAX; proclist->size = SIGAR_PROC_LIST_MAX;
@ -530,6 +530,13 @@ SIGAR_DECLARE(int) sigar_proc_list_destroy(sigar_t *sigar,
return SIGAR_OK; return SIGAR_OK;
} }
SIGAR_DECLARE(int) sigar_proc_list_get(sigar_t *sigar,
sigar_proc_list_t *proclist)
{
sigar_proc_list_create(proclist);
return sigar_os_proc_list_get(sigar, proclist);
}
int sigar_proc_args_create(sigar_proc_args_t *procargs) int sigar_proc_args_create(sigar_proc_args_t *procargs)
{ {
procargs->number = 0; procargs->number = 0;

View File

@ -1424,8 +1424,6 @@ SIGAR_DECLARE(int) sigar_ptql_query_find(sigar_t *sigar,
return status; return status;
} }
sigar_proc_list_create(proclist);
for (i=0; i<pids.number; i++) { for (i=0; i<pids.number; i++) {
int query_status = int query_status =
sigar_ptql_query_match(sigar, query, pids.data[i]); sigar_ptql_query_match(sigar, query, pids.data[i]);
@ -1444,7 +1442,7 @@ SIGAR_DECLARE(int) sigar_ptql_query_find(sigar_t *sigar,
sigar_proc_list_destroy(sigar, &pids); sigar_proc_list_destroy(sigar, &pids);
if (status != SIGAR_OK) { if (status != SIGAR_OK) {
sigar_proc_list_create(proclist); sigar_proc_list_destroy(sigar, proclist);
return status; return status;
} }

View File

@ -163,8 +163,6 @@ int sigar_proc_list_procfs_get(sigar_t *sigar,
return errno; return errno;
} }
sigar_proc_list_create(proclist);
#ifdef HAVE_READDIR_R #ifdef HAVE_READDIR_R
while (readdir_r(dirp, &dbuf, &ent) == 0) { while (readdir_r(dirp, &dbuf, &ent) == 0) {
if (ent == NULL) { if (ent == NULL) {