remove proc_list optimization. while max_proc wont change, it may be set to

an a very large number seems that can make pstat_getproc choke.
change to loop through with a small array.
This commit is contained in:
Doug MacEachern 2004-09-28 21:39:01 +00:00
parent 79f6f36447
commit 554e241136
2 changed files with 20 additions and 25 deletions

View File

@ -15,8 +15,6 @@ int sigar_os_open(sigar_t **sigar)
sizeof((*sigar)->pstatic), sizeof((*sigar)->pstatic),
1, 0); 1, 0);
(*sigar)->proctab = NULL;
(*sigar)->ticks = sysconf(_SC_CLK_TCK); (*sigar)->ticks = sysconf(_SC_CLK_TCK);
(*sigar)->last_pid = -1; (*sigar)->last_pid = -1;
@ -29,9 +27,6 @@ int sigar_os_open(sigar_t **sigar)
int sigar_os_close(sigar_t *sigar) int sigar_os_close(sigar_t *sigar)
{ {
if (sigar->proctab) {
free(sigar->proctab);
}
if (sigar->pinfo) { if (sigar->pinfo) {
free(sigar->pinfo); free(sigar->pinfo);
} }
@ -170,27 +165,28 @@ int sigar_loadavg_get(sigar_t *sigar,
return SIGAR_OK; return SIGAR_OK;
} }
#define PROC_ELTS 16
int sigar_proc_list_get(sigar_t *sigar, int sigar_proc_list_get(sigar_t *sigar,
sigar_proc_list_t *proclist) sigar_proc_list_t *proclist)
{ {
int n; int num, idx=0;
struct pst_status proctab[PROC_ELTS];
if (!sigar->proctab) { sigar_proc_list_create(proclist);
/* 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), while ((num = pstat_getproc(proctab, sizeof(proctab[0]),
sigar->pstatic.max_proc, 0); PROC_ELTS, idx)) > 0)
{
int i;
proclist->number = 0; for (i=0; i<num; i++) {
proclist->size = n; SIGAR_PROC_LIST_GROW(proclist);
proclist->data = malloc(sizeof(*(proclist->data)) * n); proclist->data[proclist->number++] =
proctab[i].pst_pid;
}
for (n=0; n<proclist->size; n++) { idx = proctab[num-1].pst_idx + 1;
proclist->data[proclist->number++] =
sigar->proctab[n].pst_pid;
} }
return SIGAR_OK; return SIGAR_OK;

View File

@ -9,7 +9,6 @@
struct sigar_t { struct sigar_t {
SIGAR_T_BASE; SIGAR_T_BASE;
struct pst_static pstatic; struct pst_static pstatic;
struct pst_status *proctab;
time_t last_getprocs; time_t last_getprocs;
sigar_pid_t last_pid; sigar_pid_t last_pid;
struct pst_status *pinfo; struct pst_status *pinfo;