diff options
author | Mark Wong <markwkm@gmail.com> | 2007-09-19 09:03:43 -0700 |
---|---|---|
committer | Mark Wong <markwkm@gmail.com> | 2007-09-19 09:03:43 -0700 |
commit | 15ea1919ca9def494e73536ebfcf818ed9518881 (patch) | |
tree | f3d5a5e83258818b490f2916d2c475fffac4a2cf | |
parent | 51ecde5715c5109ae2c4460a3a33ba4ee444738f (diff) |
Updated top to only display processes that are listed in the PostgreSQL
pg_stat_activity table.
-rw-r--r-- | machine.h | 9 | ||||
-rw-r--r-- | machine/m_linux.c | 16 | ||||
-rw-r--r-- | top.c | 7 |
3 files changed, 21 insertions, 11 deletions
@@ -4,6 +4,12 @@ * for any specific machine. */ +#include <libpq-fe.h> + +#define QUERY_PROCESSES \ + "SELECT procpid\n" \ + "FROM pg_stat_activity;" + /* * The statics struct is filled in by machine_init. Fields marked as * "optional" are not filled in by every module. @@ -67,7 +73,8 @@ struct process_select /* routines defined by the machine dependent module */ int machine_init(struct statics *); void get_system_info(struct system_info *); -caddr_t get_process_info(struct system_info *, struct process_select *, int); +caddr_t get_process_info(struct system_info *, struct process_select *, int, + PGconn *); char *format_header(char *); char *format_next_process(caddr_t, char *(*)(int)); int proc_owner(int); diff --git a/machine/m_linux.c b/machine/m_linux.c index a682204..876e1ba 100644 --- a/machine/m_linux.c +++ b/machine/m_linux.c @@ -656,7 +656,7 @@ read_one_proc_stat(pid_t pid, struct top_proc *proc, struct process_select *sel) caddr_t get_process_info(struct system_info *si, struct process_select *sel, - int compare_index) + int compare_index, PGconn *pgconn) { struct timeval thistime; double timediff, alpha, beta; @@ -717,17 +717,21 @@ get_process_info(struct system_info *si, int show_idle = sel->idle; int show_uid = sel->uid != -1; + int i; + int rows; + PGresult *pgresult; + memset(process_states, 0, sizeof(process_states)); - while ((ent = readdir(dir)) != NULL) + pgresult = PQexec(pgconn, QUERY_PROCESSES); + rows = PQntuples(pgresult); + for (i = 0; i < rows; i++) { + char *procpid = PQgetvalue(pgresult, i, 0); struct top_proc *pp; unsigned long otime; - if (!isdigit(ent->d_name[0])) - continue; - - pid = atoi(ent->d_name); + pid = atoi(procpid); /* look up hash table entry */ proc = pp = ptable[HASH(pid)]; @@ -34,8 +34,6 @@ char *copyright = #include <setjmp.h> #include <ctype.h> -#include <libpq-fe.h> - /* determine which type of signal functions to use */ #ifdef HAVE_SIGACTION #undef HAVE_SIGHOLD @@ -695,7 +693,7 @@ Usage: %s [-ISTbcinqu] [-d x] [-s x] [-o field] [-U username] [number]\n", if (statics.flags.warmup) { get_system_info(&system_info); - (void)get_process_info(&system_info, &ps, 0); + (void)get_process_info(&system_info, &ps, 0, pgconn); timeout.tv_sec = 1; timeout.tv_usec = 0; select(0, NULL, NULL, NULL, &timeout); @@ -718,7 +716,8 @@ Usage: %s [-ISTbcinqu] [-d x] [-s x] [-o field] [-U username] [number]\n", processes = get_process_info(&system_info, &ps, - order_index); + order_index, + pgconn); /* display the load averages */ (*d_loadave)(system_info.last_pid, |