From 554e24113693dc926584401f6b7cf73106561bb2 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Tue, 28 Sep 2004 21:39:01 +0000 Subject: [PATCH] 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. --- src/os/hpux/hpux_sigar.c | 44 ++++++++++++++++++---------------------- src/os/hpux/sigar_os.h | 1 - 2 files changed, 20 insertions(+), 25 deletions(-) diff --git a/src/os/hpux/hpux_sigar.c b/src/os/hpux/hpux_sigar.c index aec27602..5ad8c05a 100644 --- a/src/os/hpux/hpux_sigar.c +++ b/src/os/hpux/hpux_sigar.c @@ -15,8 +15,6 @@ int sigar_os_open(sigar_t **sigar) sizeof((*sigar)->pstatic), 1, 0); - (*sigar)->proctab = NULL; - (*sigar)->ticks = sysconf(_SC_CLK_TCK); (*sigar)->last_pid = -1; @@ -29,9 +27,6 @@ int sigar_os_open(sigar_t **sigar) int sigar_os_close(sigar_t *sigar) { - if (sigar->proctab) { - free(sigar->proctab); - } if (sigar->pinfo) { free(sigar->pinfo); } @@ -170,29 +165,30 @@ int sigar_loadavg_get(sigar_t *sigar, return SIGAR_OK; } +#define PROC_ELTS 16 + 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); + int num, idx=0; + struct pst_status proctab[PROC_ELTS]; + + sigar_proc_list_create(proclist); + + while ((num = pstat_getproc(proctab, sizeof(proctab[0]), + PROC_ELTS, idx)) > 0) + { + int i; + + for (i=0; idata[proclist->number++] = + proctab[i].pst_pid; + } + + idx = proctab[num-1].pst_idx + 1; } - - 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; nsize; n++) { - proclist->data[proclist->number++] = - sigar->proctab[n].pst_pid; - } - + return SIGAR_OK; } diff --git a/src/os/hpux/sigar_os.h b/src/os/hpux/sigar_os.h index 179af452..0c8255f8 100644 --- a/src/os/hpux/sigar_os.h +++ b/src/os/hpux/sigar_os.h @@ -9,7 +9,6 @@ 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;