From 71635f2c1c41a3c3273cd07fda340efa4941625f Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Fri, 21 Dec 2007 22:42:31 +0000 Subject: [PATCH] Add sigar_proc_list_t to sigar_t for internal re-use --- include/sigar_private.h | 1 + src/sigar.c | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/include/sigar_private.h b/include/sigar_private.h index dd2b0c36..41d0c7df 100644 --- a/include/sigar_private.h +++ b/include/sigar_private.h @@ -63,6 +63,7 @@ char *ifconf_buf; \ int ifconf_len; \ char *self_path; \ + sigar_proc_list_t *pids; \ sigar_cache_t *fsdev; \ sigar_cache_t *proc_cpu; \ sigar_cache_t *net_listen; \ diff --git a/src/sigar.c b/src/sigar.c index a1a549e6..265519df 100644 --- a/src/sigar.c +++ b/src/sigar.c @@ -51,6 +51,7 @@ SIGAR_DECLARE(int) sigar_open(sigar_t **sigar) (*sigar)->ptql_re_data = NULL; (*sigar)->self_path = NULL; (*sigar)->fsdev = NULL; + (*sigar)->pids = NULL; (*sigar)->proc_cpu = NULL; (*sigar)->net_listen = NULL; (*sigar)->net_services_tcp = NULL; @@ -68,6 +69,10 @@ SIGAR_DECLARE(int) sigar_close(sigar_t *sigar) if (sigar->self_path) { free(sigar->self_path); } + if (sigar->pids) { + sigar_proc_list_destroy(sigar, sigar->pids); + free(sigar->pids); + } if (sigar->fsdev) { sigar_cache_destroy(sigar->fsdev); } @@ -304,7 +309,21 @@ SIGAR_DECLARE(int) sigar_proc_list_destroy(sigar_t *sigar, SIGAR_DECLARE(int) sigar_proc_list_get(sigar_t *sigar, sigar_proc_list_t *proclist) { - sigar_proc_list_create(proclist); + if (proclist == NULL) { + /* internal re-use */ + if (sigar->pids == NULL) { + sigar->pids = malloc(sizeof(*sigar->pids)); + sigar_proc_list_create(sigar->pids); + } + else { + sigar->pids->number = 0; + } + proclist = sigar->pids; + } + else { + sigar_proc_list_create(proclist); + } + return sigar_os_proc_list_get(sigar, proclist); }