Restructured all the code to hopefully make adding platform specific code
authorMark Wong <markwkm@gmail.com>
Thu, 11 Sep 2008 03:23:42 +0000 (20:23 -0700)
committerMark Wong <markwkm@gmail.com>
Thu, 11 Sep 2008 03:23:42 +0000 (20:23 -0700)
easier.

pg_common.h
pg_cputime.c
pg_loadavg.c
pg_memusage.c
pg_proctab.c

index 2e17e52722708c6a7d551adaf106f52998334ed8..dd6f6524e70bb09c0bc55c5a9bbc4ee6444eea53 100644 (file)
@@ -22,7 +22,7 @@ PG_MODULE_MAGIC;
         if ((q = strchr(p, delim)) == NULL) \
         { \
             elog(ERROR, msg); \
-            SRF_RETURN_DONE(funcctx); \
+            return 0; \
         } \
         length = q - p; \
         strncpy(value, p, length); \
index bcfc7fae7f9324ec2de9453598a51b50fc22991a..a806f2a76247c711df7ecbc93389dd0f7e65217f 100644 (file)
@@ -29,6 +29,9 @@ skip_token(const char *p)
 }
 #endif /* __linux__ */
 
+enum loadavg {i_user, i_nice, i_system, i_idle, i_iowait};
+
+int get_cputime(char **);
 Datum pg_cputime(PG_FUNCTION_ARGS);
 
 PG_FUNCTION_INFO_V1(pg_cputime);
@@ -41,17 +44,6 @@ Datum pg_cputime(PG_FUNCTION_ARGS)
        TupleDesc tupdesc;
        AttInMetadata *attinmeta;
 
-#ifdef __linux__
-       struct statfs sb;
-       int fd;
-       int len;
-       char buffer[4096];
-       char *p;
-       char *q;
-#endif /* __linux__ */
-
-       enum loadavg {i_user, i_nice, i_system, i_idle, i_iowait};
-
        elog(DEBUG5, "pg_cputime: Entering stored function.");
 
        /* stuff done only on the first call of the function */
@@ -79,12 +71,6 @@ Datum pg_cputime(PG_FUNCTION_ARGS)
                attinmeta = TupleDescGetAttInMetadata(tupdesc);
                funcctx->attinmeta = attinmeta;
 
-               /* Check if /proc is mounted. */
-               if (statfs(PROCFS, &sb) < 0 || sb.f_type != PROC_SUPER_MAGIC)
-               {
-                       elog(ERROR, "proc filesystem not mounted on " PROCFS "\n");
-                       SRF_RETURN_DONE(funcctx);
-               } 
                funcctx->max_calls = 1;
 
                MemoryContextSwitchTo(oldcontext);
@@ -102,8 +88,6 @@ Datum pg_cputime(PG_FUNCTION_ARGS)
                HeapTuple tuple;
                Datum result;
 
-               int length;
-
                char **values = NULL;
 
                values = (char **) palloc(5 * sizeof(char *));
@@ -113,47 +97,8 @@ Datum pg_cputime(PG_FUNCTION_ARGS)
                values[i_idle] = (char *) palloc((BIGINT_LEN + 1) * sizeof(char));
                values[i_iowait] = (char *) palloc((BIGINT_LEN + 1) * sizeof(char));
 
-#ifdef __linux__
-               sprintf(buffer, "%s/stat", PROCFS);
-               fd = open(buffer, O_RDONLY);
-               if (fd == -1)
-               {
-                       elog(ERROR, "'%s' not found", buffer);
+               if (get_cputime(values) == 0)
                        SRF_RETURN_DONE(funcctx);
-               }
-               len = read(fd, buffer, sizeof(buffer) - 1);
-               close(fd);
-               buffer[len] = '\0';
-               elog(DEBUG5, "pg_cputime: %s", buffer);
-
-               p = buffer;
-
-               p = skip_token(p);                      /* skip cpu */
-               ++p;
-               ++p;
-
-               /* user */
-               GET_NEXT_VALUE(p, q, values[i_user], length, "user not found", ' ');
-               elog(DEBUG5, "pg_cputime: user = %s", values[i_user]);
-
-               /* nice */
-               GET_NEXT_VALUE(p, q, values[i_nice], length, "nice not found", ' ');
-               elog(DEBUG5, "pg_cputime: nice = %s", values[i_nice]);
-
-               /* system */
-               GET_NEXT_VALUE(p, q, values[i_system], length, "system not found",
-                               ' ');
-               elog(DEBUG5, "pg_cputime: system = %s", values[i_system]);
-
-               /* idle */
-               GET_NEXT_VALUE(p, q, values[i_idle], length, "idle not found", ' ');
-               elog(DEBUG5, "pg_cputime: idle = %s", values[i_idle]);
-
-               /* iowait */
-               GET_NEXT_VALUE(p, q, values[i_iowait], length, "iowait not found",
-                               ' ');
-               elog(DEBUG5, "pg_cputime: iowait = %s", values[i_iowait]);
-#endif /* __linux__ */
 
                /* build a tuple */
                tuple = BuildTupleFromCStrings(attinmeta, values);
@@ -168,3 +113,66 @@ Datum pg_cputime(PG_FUNCTION_ARGS)
                SRF_RETURN_DONE(funcctx);
        }
 }
+
+int
+get_cputime(char **values)
+{
+#ifdef __linux__
+       struct statfs sb;
+       int fd;
+       int len;
+       char buffer[4096];
+       char *p;
+       char *q;
+
+       int length;
+
+       /* Check if /proc is mounted. */
+       if (statfs(PROCFS, &sb) < 0 || sb.f_type != PROC_SUPER_MAGIC)
+       {
+               elog(ERROR, "proc filesystem not mounted on " PROCFS "\n");
+               return 0;
+       }
+
+       sprintf(buffer, "%s/stat", PROCFS);
+       fd = open(buffer, O_RDONLY);
+       if (fd == -1)
+       {
+               elog(ERROR, "'%s' not found", buffer);
+               return 0;
+       }
+       len = read(fd, buffer, sizeof(buffer) - 1);
+       close(fd);
+       buffer[len] = '\0';
+       elog(DEBUG5, "pg_cputime: %s", buffer);
+
+       p = buffer;
+
+       p = skip_token(p);                      /* skip cpu */
+       ++p;
+       ++p;
+
+       /* user */
+       GET_NEXT_VALUE(p, q, values[i_user], length, "user not found", ' ');
+
+       /* nice */
+       GET_NEXT_VALUE(p, q, values[i_nice], length, "nice not found", ' ');
+
+       /* system */
+       GET_NEXT_VALUE(p, q, values[i_system], length, "system not found", ' ');
+
+       /* idle */
+       GET_NEXT_VALUE(p, q, values[i_idle], length, "idle not found", ' ');
+
+       /* iowait */
+       GET_NEXT_VALUE(p, q, values[i_iowait], length, "iowait not found", ' ');
+#endif /* __linux__ */
+
+       elog(DEBUG5, "pg_cputime: user = %s", values[i_user]);
+       elog(DEBUG5, "pg_cputime: nice = %s", values[i_nice]);
+       elog(DEBUG5, "pg_cputime: system = %s", values[i_system]);
+       elog(DEBUG5, "pg_cputime: idle = %s", values[i_idle]);
+       elog(DEBUG5, "pg_cputime: iowait = %s", values[i_iowait]);
+
+       return 1;
+}
index 3c3543fedcd78ca6543f3c0fe5f3d182ba6b60a2..fe3dc9eccfedfbbe1700f30b07c0ada3fdf99aba 100644 (file)
@@ -29,6 +29,10 @@ skip_token(const char *p)
 }
 #endif /* __linux__ */
 
+enum loadavg {i_load1, i_load5, i_load15, i_last_pid};
+
+int get_loadavg(char **);
+
 Datum pg_loadavg(PG_FUNCTION_ARGS);
 
 PG_FUNCTION_INFO_V1(pg_loadavg);
@@ -41,17 +45,6 @@ Datum pg_loadavg(PG_FUNCTION_ARGS)
        TupleDesc tupdesc;
        AttInMetadata *attinmeta;
 
-#ifdef __linux__
-       struct statfs sb;
-       int fd;
-       int len;
-       char buffer[4096];
-       char *p;
-       char *q;
-#endif /* __linux__ */
-
-       enum loadavg {i_load1, i_load5, i_load15, i_last_pid};
-
        elog(DEBUG5, "pg_loadavg: Entering stored function.");
 
        /* stuff done only on the first call of the function */
@@ -79,12 +72,6 @@ Datum pg_loadavg(PG_FUNCTION_ARGS)
                attinmeta = TupleDescGetAttInMetadata(tupdesc);
                funcctx->attinmeta = attinmeta;
 
-               /* Check if /proc is mounted. */
-               if (statfs(PROCFS, &sb) < 0 || sb.f_type != PROC_SUPER_MAGIC)
-               {
-                       elog(ERROR, "proc filesystem not mounted on " PROCFS "\n");
-                       SRF_RETURN_DONE(funcctx);
-               } 
                funcctx->max_calls = 1;
 
                MemoryContextSwitchTo(oldcontext);
@@ -102,8 +89,6 @@ Datum pg_loadavg(PG_FUNCTION_ARGS)
                HeapTuple tuple;
                Datum result;
 
-               int length;
-
                char **values = NULL;
 
                values = (char **) palloc(4 * sizeof(char *));
@@ -112,57 +97,8 @@ Datum pg_loadavg(PG_FUNCTION_ARGS)
                values[i_load15] = (char *) palloc((FLOAT_LEN + 1) * sizeof(char));
                values[i_last_pid] = (char *) palloc((INTEGER_LEN + 1) * sizeof(char));
 
-#ifdef __linux__
-               sprintf(buffer, "%s/loadavg", PROCFS);
-               fd = open(buffer, O_RDONLY);
-               if (fd == -1)
-               {
-                       elog(ERROR, "'%s' not found", buffer);
+               if (get_loadavg(values) == 0)
                        SRF_RETURN_DONE(funcctx);
-               }
-               len = read(fd, buffer, sizeof(buffer) - 1);
-               close(fd);
-               buffer[len] = '\0';
-               elog(DEBUG5, "pg_loadavg: %s", buffer);
-
-               p = buffer;
-
-               /* load1 */
-               GET_NEXT_VALUE(p, q, values[i_load1], length, "load1 not found", ' ');
-               elog(DEBUG5, "pg_loadavg: load1 = %s", values[i_load1]);
-
-               /* load5 */
-               GET_NEXT_VALUE(p, q, values[i_load5], length, "load5 not found", ' ');
-               elog(DEBUG5, "pg_loadavg: load5 = %s", values[i_load5]);
-
-               /* load15 */
-               GET_NEXT_VALUE(p, q, values[i_load15], length, "load15 not found",
-                               ' ');
-               elog(DEBUG5, "pg_loadavg: load15 = %s", values[i_load15]);
-
-               p = skip_token(p);                      /* skip running/tasks */
-               ++p;
-
-               /* last_pid */
-               /*
-                * It appears sometimes this is the last item in /proc/PID/stat and
-                * sometimes it's not, depending on the version of the kernel and
-                * possibly the architecture.  So first test if it is the last item
-                * before determining how to deliminate it.
-                */
-               if (strchr(p, ' ') == NULL)
-               {
-                       GET_NEXT_VALUE(p, q, values[i_last_pid], length,
-                                       "last_pid not found", '\n');
-               }
-               else
-               {
-                       GET_NEXT_VALUE(p, q, values[i_last_pid], length,
-                                       "last_pid not found", ' ');
-               }
-               elog(DEBUG5, "pg_loadavg: last_pid = %s",
-                               values[i_last_pid]);
-#endif /* __linux__ */
 
                /* build a tuple */
                tuple = BuildTupleFromCStrings(attinmeta, values);
@@ -177,3 +113,76 @@ Datum pg_loadavg(PG_FUNCTION_ARGS)
                SRF_RETURN_DONE(funcctx);
        }
 }
+
+int
+get_loadavg(char **values)
+{
+#ifdef __linux__
+       int length;
+
+       struct statfs sb;
+       int fd;
+       int len;
+       char buffer[4096];
+       char *p;
+       char *q;
+
+       /* Check if /proc is mounted. */
+       if (statfs(PROCFS, &sb) < 0 || sb.f_type != PROC_SUPER_MAGIC)
+       {
+               elog(ERROR, "proc filesystem not mounted on " PROCFS "\n");
+               return 0;
+       }
+
+       sprintf(buffer, "%s/loadavg", PROCFS);
+       fd = open(buffer, O_RDONLY);
+       if (fd == -1)
+       {
+               elog(ERROR, "'%s' not found", buffer);
+               return 0;
+       }
+       len = read(fd, buffer, sizeof(buffer) - 1);
+       close(fd);
+       buffer[len] = '\0';
+       elog(DEBUG5, "pg_loadavg: %s", buffer);
+
+       p = buffer;
+
+       /* load1 */
+       GET_NEXT_VALUE(p, q, values[i_load1], length, "load1 not found", ' ');
+
+       /* load5 */
+       GET_NEXT_VALUE(p, q, values[i_load5], length, "load5 not found", ' ');
+
+       /* load15 */
+       GET_NEXT_VALUE(p, q, values[i_load15], length, "load15 not found", ' ');
+
+       p = skip_token(p);                      /* skip running/tasks */
+       ++p;
+
+       /* last_pid */
+       /*
+        * It appears sometimes this is the last item in /proc/PID/stat and
+        * sometimes it's not, depending on the version of the kernel and
+        * possibly the architecture.  So first test if it is the last item
+        * before determining how to deliminate it.
+        */
+       if (strchr(p, ' ') == NULL)
+       {
+               GET_NEXT_VALUE(p, q, values[i_last_pid], length,
+                               "last_pid not found", '\n');
+       }
+       else
+       {
+               GET_NEXT_VALUE(p, q, values[i_last_pid], length,
+                               "last_pid not found", ' ');
+       }
+#endif /* __linux__ */
+
+       elog(DEBUG5, "pg_loadavg: load1 = %s", values[i_load1]);
+       elog(DEBUG5, "pg_loadavg: load5 = %s", values[i_load5]);
+       elog(DEBUG5, "pg_loadavg: load15 = %s", values[i_load15]);
+       elog(DEBUG5, "pg_loadavg: last_pid = %s", values[i_last_pid]);
+
+       return 1;
+}
index b4903be8c56d83d56110727ca7f3dc2d0f9b4195..db2c941f6235bf692cc9867a29eba5fbb9a57028 100644 (file)
@@ -27,9 +27,13 @@ skip_token(const char *p)
                p++;
        return (char *) p;
 }
-
 #endif /* __linux__ */
 
+enum loadavg {i_memused, i_memfree, i_memshared, i_membuffers, i_memcached,
+               i_swapused, i_swapfree, i_swapcached};
+
+int get_memusage(char **);
+
 Datum pg_memusage(PG_FUNCTION_ARGS);
 
 PG_FUNCTION_INFO_V1(pg_memusage);
@@ -42,17 +46,6 @@ Datum pg_memusage(PG_FUNCTION_ARGS)
        TupleDesc tupdesc;
        AttInMetadata *attinmeta;
 
-#ifdef __linux__
-       struct statfs sb;
-       int fd;
-       int len;
-       char buffer[4096];
-       char *p;
-       char *q;
-#endif /* __linux__ */
-
-       enum loadavg {i_memused, i_memfree, i_memshared, i_membuffers,
-                       i_memcached, i_swapused, i_swapfree, i_swapcached};
 
        elog(DEBUG5, "pg_memusage: Entering stored function.");
 
@@ -81,12 +74,6 @@ Datum pg_memusage(PG_FUNCTION_ARGS)
                attinmeta = TupleDescGetAttInMetadata(tupdesc);
                funcctx->attinmeta = attinmeta;
 
-               /* Check if /proc is mounted. */
-               if (statfs(PROCFS, &sb) < 0 || sb.f_type != PROC_SUPER_MAGIC)
-               {
-                       elog(ERROR, "proc filesystem not mounted on " PROCFS "\n");
-                       SRF_RETURN_DONE(funcctx);
-               } 
                funcctx->max_calls = 1;
 
                MemoryContextSwitchTo(oldcontext);
@@ -104,12 +91,6 @@ Datum pg_memusage(PG_FUNCTION_ARGS)
                HeapTuple tuple;
                Datum result;
 
-               int length;
-               unsigned long memfree = 0;
-               unsigned long memtotal = 0;
-               unsigned long swapfree = 0;
-               unsigned long swaptotal = 0;
-
                char **values = NULL;
 
                values = (char **) palloc(8 * sizeof(char *));
@@ -124,105 +105,8 @@ Datum pg_memusage(PG_FUNCTION_ARGS)
                values[i_swapcached] =
                                (char *) palloc((BIGINT_LEN + 1) * sizeof(char));
 
-#ifdef __linux__
-               sprintf(buffer, "%s/meminfo", PROCFS);
-               fd = open(buffer, O_RDONLY);
-               if (fd == -1)
-               {
-                       elog(ERROR, "'%s' not found", buffer);
+               if (get_memusage(values) == 0)
                        SRF_RETURN_DONE(funcctx);
-               }
-               len = read(fd, buffer, sizeof(buffer) - 1);
-               close(fd);
-               buffer[len] = '\0';
-               elog(DEBUG5, "pg_memusage: %s", buffer);
-
-               p = buffer - 1;
-
-               values[i_memshared][0] = '0';
-               values[i_memshared][1] = '\0';
-
-               while (p != NULL) {
-                       ++p;
-                       if (strncmp(p, "Buffers:", 8) == 0)
-                       {
-                               p = skip_token(p);
-
-                               while (p[0] == ' ')
-                                       ++p;
-                               GET_NEXT_VALUE(p, q, values[i_membuffers], length,
-                                               "Buffers not found", ' ');
-                               elog(DEBUG5, "pg_memusage: Buffers = %s",
-                                               values[i_membuffers]);
-                       }
-                       else if (strncmp(p, "Cached:", 7) == 0)
-                       {
-                               p = skip_token(p);
-
-                               while (p[0] == ' ')
-                                       ++p;
-                               GET_NEXT_VALUE(p, q, values[i_memcached], length,
-                                               "Cached not found", ' ');
-                               elog(DEBUG5, "pg_memusage: Cached = %s",
-                                               values[i_memcached]);
-                       }
-                       else if (strncmp(p, "MemFree:", 8) == 0)
-                       {
-                               p = skip_token(p);
-
-                               memfree = strtoul(p, &p, 10);
-                               elog(DEBUG5, "pg_memusage: MemFree = %lu", memfree);
-                               sprintf(values[i_memused], "%lu", memtotal - memfree);
-                               sprintf(values[i_memfree], "%lu", memfree);
-                       }
-                       else if (strncmp(p, "MemShared:", 10) == 0)
-                       {
-                               p = skip_token(p);
-
-                               while (p[0] == ' ')
-                                       ++p;
-                               GET_NEXT_VALUE(p, q, values[i_memshared], length,
-                                               "MemShared not found", ' ');
-                               elog(DEBUG5, "pg_memusage: MemShared = %s",
-                                               values[i_memshared]);
-                       }
-                       else if (strncmp(p, "MemTotal:", 9) == 0)
-                       {
-                               p = skip_token(p);
-
-                               memtotal = strtoul(p, &p, 10);
-                               elog(DEBUG5, "pg_memusage: MemTotal = %lu", memtotal);
-                       }
-                       else if (strncmp(p, "SwapFree:", 9) == 0)
-                       {
-                               p = skip_token(p);
-
-                               swapfree = strtoul(p, &p, 10);
-                               elog(DEBUG5, "pg_memusage: SwapFree = %lu", swapfree);
-                               sprintf(values[i_swapused], "%lu", swaptotal - swapfree);
-                               sprintf(values[i_swapfree], "%lu", swapfree);
-                       }
-                       else if (strncmp(p, "SwapCached:", 11) == 0)
-                       {
-                               p = skip_token(p);
-
-                               while (p[0] == ' ')
-                                       ++p;
-                               GET_NEXT_VALUE(p, q, values[i_swapcached], length,
-                                               "SwapCached not found", ' ');
-                               elog(DEBUG5, "pg_memusage: SwapCached = %s",
-                                               values[i_swapcached]);
-                       }
-                       else if (strncmp(p, "SwapTotal:", 10) == 0)
-                       {
-                               p = skip_token(p);
-
-                               swaptotal = strtoul(p, &p, 10);
-                               elog(DEBUG5, "pg_memusage: SwapTotal = %lu", swaptotal);
-                       }
-                       p = strchr(p, '\n');
-               }
-#endif /* __linux__ */
 
                /* build a tuple */
                tuple = BuildTupleFromCStrings(attinmeta, values);
@@ -237,3 +121,128 @@ Datum pg_memusage(PG_FUNCTION_ARGS)
                SRF_RETURN_DONE(funcctx);
        }
 }
+
+int
+get_memusage(char **values)
+{
+#ifdef __linux__
+       int length;
+       unsigned long memfree = 0;
+       unsigned long memtotal = 0;
+       unsigned long swapfree = 0;
+       unsigned long swaptotal = 0;
+
+       struct statfs sb;
+       int fd;
+       int len;
+       char buffer[4096];
+       char *p;
+       char *q;
+
+       /* Check if /proc is mounted. */
+       if (statfs(PROCFS, &sb) < 0 || sb.f_type != PROC_SUPER_MAGIC)
+       {
+               elog(ERROR, "proc filesystem not mounted on " PROCFS "\n");
+               return 0;
+       }
+
+       sprintf(buffer, "%s/meminfo", PROCFS);
+       fd = open(buffer, O_RDONLY);
+       if (fd == -1)
+       {
+               elog(ERROR, "'%s' not found", buffer);
+               return 0;
+       }
+       len = read(fd, buffer, sizeof(buffer) - 1);
+       close(fd);
+       buffer[len] = '\0';
+       elog(DEBUG5, "pg_memusage: %s", buffer);
+
+       p = buffer - 1;
+
+       values[i_memshared][0] = '0';
+       values[i_memshared][1] = '\0';
+
+       while (p != NULL) {
+               ++p;
+               if (strncmp(p, "Buffers:", 8) == 0)
+               {
+                       p = skip_token(p);
+
+                       while (p[0] == ' ')
+                               ++p;
+                       GET_NEXT_VALUE(p, q, values[i_membuffers], length,
+                                       "Buffers not found", ' ');
+               }
+               else if (strncmp(p, "Cached:", 7) == 0)
+               {
+                       p = skip_token(p);
+
+                       while (p[0] == ' ')
+                               ++p;
+                       GET_NEXT_VALUE(p, q, values[i_memcached], length,
+                                       "Cached not found", ' ');
+               }
+               else if (strncmp(p, "MemFree:", 8) == 0)
+               {
+                       p = skip_token(p);
+
+                       memfree = strtoul(p, &p, 10);
+                       sprintf(values[i_memused], "%lu", memtotal - memfree);
+                       sprintf(values[i_memfree], "%lu", memfree);
+               }
+               else if (strncmp(p, "MemShared:", 10) == 0)
+               {
+                       p = skip_token(p);
+
+                       while (p[0] == ' ')
+                               ++p;
+                       GET_NEXT_VALUE(p, q, values[i_memshared], length,
+                                       "MemShared not found", ' ');
+               }
+               else if (strncmp(p, "MemTotal:", 9) == 0)
+               {
+                       p = skip_token(p);
+
+                       memtotal = strtoul(p, &p, 10);
+                       elog(DEBUG5, "pg_memusage: MemTotal = %lu", memtotal);
+               }
+               else if (strncmp(p, "SwapFree:", 9) == 0)
+               {
+                       p = skip_token(p);
+
+                       swapfree = strtoul(p, &p, 10);
+                       sprintf(values[i_swapused], "%lu", swaptotal - swapfree);
+                       sprintf(values[i_swapfree], "%lu", swapfree);
+               }
+               else if (strncmp(p, "SwapCached:", 11) == 0)
+               {
+                       p = skip_token(p);
+
+                       while (p[0] == ' ')
+                               ++p;
+                       GET_NEXT_VALUE(p, q, values[i_swapcached], length,
+                                       "SwapCached not found", ' ');
+               }
+               else if (strncmp(p, "SwapTotal:", 10) == 0)
+               {
+                       p = skip_token(p);
+
+                       swaptotal = strtoul(p, &p, 10);
+                       elog(DEBUG5, "pg_memusage: SwapTotal = %lu", swaptotal);
+               }
+               p = strchr(p, '\n');
+       }
+#endif /* __linux__ */
+
+       elog(DEBUG5, "pg_memusage: Buffers = %s", values[i_membuffers]);
+       elog(DEBUG5, "pg_memusage: Cached = %s", values[i_memcached]);
+       elog(DEBUG5, "pg_memusage: MemFree = %s", values[i_memfree]);
+       elog(DEBUG5, "pg_memusage: MemUsed = %s", values[i_memused]);
+       elog(DEBUG5, "pg_memusage: MemShared = %s", values[i_memshared]);
+       elog(DEBUG5, "pg_memusage: SwapCached = %s", values[i_swapcached]);
+       elog(DEBUG5, "pg_memusage: SwapFree = %s", values[i_swapfree]);
+       elog(DEBUG5, "pg_memusage: SwapUsed = %s", values[i_swapused]);
+
+       return 1;
+}
index 1a04c6769c5aaf57866cd020eeb89cda5218a209..b68b4043b8b9dcf6bbdaf2bfcaccc4fe6f6f1a75 100644 (file)
@@ -42,6 +42,15 @@ skip_token(const char *p)
                "SELECT procpid " \
                "FROM pg_stat_activity"
 
+enum proctab {i_pid, i_comm, i_fullcomm, i_state, i_ppid, i_pgrp, i_session,
+               i_tty_nr, i_tpgid, i_flags, i_minflt, i_cminflt, i_majflt, i_cmajflt,
+               i_utime, i_stime, i_cutime, i_cstime, i_priority, i_nice,
+               i_num_threads, i_itrealvalue, i_starttime, i_vsize, i_rss,
+               i_exit_signal, i_processor, i_rt_priority, i_policy,
+               i_delayacct_blkio_ticks, i_uid, i_username};
+
+int get_proctab(FuncCallContext *, char **);
+
 Datum pg_proctab(PG_FUNCTION_ARGS);
 
 PG_FUNCTION_INFO_V1(pg_proctab);
@@ -54,22 +63,6 @@ Datum pg_proctab(PG_FUNCTION_ARGS)
        TupleDesc tupdesc;
        AttInMetadata *attinmeta;
 
-#ifdef __linux__
-       struct statfs sb;
-       int fd;
-       int len;
-       char buffer[4096];
-       char *p;
-       char *q;
-#endif /* __linux__ */
-
-       enum proctab {i_pid, i_comm, i_fullcomm, i_state, i_ppid, i_pgrp,
-                       i_session, i_tty_nr, i_tpgid, i_flags, i_minflt, i_cminflt,
-                       i_majflt, i_cmajflt, i_utime, i_stime, i_cutime, i_cstime,
-                       i_priority, i_nice, i_num_threads, i_itrealvalue, i_starttime,
-                       i_vsize, i_rss, i_exit_signal, i_processor, i_rt_priority,
-                       i_policy, i_delayacct_blkio_ticks, i_uid, i_username};
-
        elog(DEBUG5, "pg_proctab: Entering stored function.");
 
        /* stuff done only on the first call of the function */
@@ -157,12 +150,6 @@ Datum pg_proctab(PG_FUNCTION_ARGS)
                HeapTuple tuple;
                Datum result;
 
-               int32 *ppid;
-               int32 pid;
-               int length;
-
-               struct stat stat_struct;
-
                char **values = NULL;
 
                values = (char **) palloc(32 * sizeof(char *));
@@ -205,268 +192,283 @@ Datum pg_proctab(PG_FUNCTION_ARGS)
                                (char *) palloc((BIGINT_LEN + 1) * sizeof(char));
                values[i_uid] = (char *) palloc((INTEGER_LEN + 1) * sizeof(char));
 
-#ifdef __linux__
-               /* Check if /proc is mounted. */
-               if (statfs(PROCFS, &sb) < 0 || sb.f_type != PROC_SUPER_MAGIC)
-               {
-                       elog(ERROR, "proc filesystem not mounted on " PROCFS "\n");
+               if (get_proctab(funcctx, values) == 0)
                        SRF_RETURN_DONE(funcctx);
-               } 
-               chdir(PROCFS);
 
-               /* Read the stat info for the pid. */
+               /* build a tuple */
+               tuple = BuildTupleFromCStrings(attinmeta, values);
 
-               ppid = (int32 *) funcctx->user_fctx;
-               pid = ppid[call_cntr];
-               elog(DEBUG5, "pg_proctab: accessing process table for pid[%d] %d.",
-                               call_cntr, pid);
+               /* make the tuple into a datum */
+               result = HeapTupleGetDatum(tuple);
 
-               /* Get the full command line information. */
-               sprintf(buffer, "%s/%d/cmdline", PROCFS, pid);
-               fd = open(buffer, O_RDONLY);
-               if (fd == -1)
-               {
-                       elog(ERROR, "'%s' not found", buffer);
-                       values[i_fullcomm] = NULL;
-               }
-               else
-               {
-                       values[i_fullcomm] =
-                                       (char *) palloc((FULLCOMM_LEN + 1) * sizeof(char));
-                       len = read(fd, values[i_fullcomm], FULLCOMM_LEN);
-                       close(fd);
-                       values[i_fullcomm][len] = '\0';
-               }
-               elog(DEBUG5, "pg_proctab: %s %s", buffer, values[i_fullcomm]);
+               SRF_RETURN_NEXT(funcctx, result);
+       }
+       else /* do when there is no more left */
+       {
+               SRF_RETURN_DONE(funcctx);
+       }
+}
 
-               /* Get the uid and username of the pid's owner. */
-               sprintf(buffer, "%s/%d", PROCFS, pid);
-               if (stat(buffer, &stat_struct) < 0)
-               {
-                       elog(ERROR, "'%s' not found", buffer);
-                       strcpy(values[i_uid], "-1");
+int
+get_proctab(FuncCallContext *funcctx, char **values)
+{
+#ifdef __linux__
+       int32 *ppid;
+       int32 pid;
+       int length;
+
+       struct stat stat_struct;
+
+       struct statfs sb;
+       int fd;
+       int len;
+       char buffer[4096];
+       char *p;
+       char *q;
+
+       /* Check if /proc is mounted. */
+       if (statfs(PROCFS, &sb) < 0 || sb.f_type != PROC_SUPER_MAGIC)
+       {
+               elog(ERROR, "proc filesystem not mounted on " PROCFS "\n");
+               return 0;
+       }
+       chdir(PROCFS);
+
+       /* Read the stat info for the pid. */
+
+       ppid = (int32 *) funcctx->user_fctx;
+       pid = ppid[funcctx->call_cntr];
+       elog(DEBUG5, "pg_proctab: accessing process table for pid[%d] %d.",
+                               funcctx->call_cntr, pid);
+
+       /* Get the full command line information. */
+       sprintf(buffer, "%s/%d/cmdline", PROCFS, pid);
+       fd = open(buffer, O_RDONLY);
+       if (fd == -1)
+       {
+               elog(ERROR, "'%s' not found", buffer);
+               values[i_fullcomm] = NULL;
+       }
+       else
+       {
+               values[i_fullcomm] =
+                               (char *) palloc((FULLCOMM_LEN + 1) * sizeof(char));
+               len = read(fd, values[i_fullcomm], FULLCOMM_LEN);
+               close(fd);
+               values[i_fullcomm][len] = '\0';
+       }
+       elog(DEBUG5, "pg_proctab: %s %s", buffer, values[i_fullcomm]);
+
+       /* Get the uid and username of the pid's owner. */
+       sprintf(buffer, "%s/%d", PROCFS, pid);
+       if (stat(buffer, &stat_struct) < 0)
+       {
+               elog(ERROR, "'%s' not found", buffer);
+               strcpy(values[i_uid], "-1");
+               values[i_username] = NULL;
+       }
+       else
+       {
+               struct passwd *pwd;
+
+               sprintf(values[i_uid], "%d", stat_struct.st_uid);
+               pwd = getpwuid(stat_struct.st_uid);
+               if (pwd == NULL)
                        values[i_username] = NULL;
-               }
                else
                {
-                       struct passwd *pwd;
-
-                       sprintf(values[i_uid], "%d", stat_struct.st_uid);
-                       pwd = getpwuid(stat_struct.st_uid);
-                       if (pwd == NULL)
-                               values[i_username] = NULL;
-                       else
-                       {
-                               values[i_username] = (char *) palloc((strlen(pwd->pw_name) +
-                                               1) * sizeof(char));
-                               strcpy(values[i_username], pwd->pw_name);
-                       }
+                       values[i_username] = (char *) palloc((strlen(pwd->pw_name) +
+                                       1) * sizeof(char));
+                       strcpy(values[i_username], pwd->pw_name);
                }
-               elog(DEBUG5, "pg_proctab: uid %s", values[i_uid]);
-               elog(DEBUG5, "pg_proctab: username %s", values[i_username]);
+       }
 
-               /* Get the process table information for the pid. */
-               sprintf(buffer, "%d/stat", pid);
-               fd = open(buffer, O_RDONLY);
-               if (fd == -1)
-               {
-                       elog(ERROR, "%d/stat not found", pid);
-                       SRF_RETURN_DONE(funcctx);
-               }
-               len = read(fd, buffer, sizeof(buffer) - 1);
-               close(fd);
-               buffer[len] = '\0';
-               elog(DEBUG5, "pg_proctab: %s", buffer);
+       /* Get the process table information for the pid. */
+       sprintf(buffer, "%d/stat", pid);
+       fd = open(buffer, O_RDONLY);
+       if (fd == -1)
+       {
+               elog(ERROR, "%d/stat not found", pid);
+               return 0;
+       }
+       len = read(fd, buffer, sizeof(buffer) - 1);
+       close(fd);
+       buffer[len] = '\0';
+       elog(DEBUG5, "pg_proctab: %s", buffer);
 
-               p = buffer;
+       p = buffer;
 
-               /* pid */
-               GET_NEXT_VALUE(p, q, values[i_pid], length, "pid not found", ' ');
-               elog(DEBUG5, "pg_proctab: pid = %s", values[i_pid]);
+       /* pid */
+       GET_NEXT_VALUE(p, q, values[i_pid], length, "pid not found", ' ');
 
-               /* comm */
-               ++p;
-               if ((q = strchr(p, ')')) == NULL)
-               {
-                       elog(ERROR, "comm not found");
-                       SRF_RETURN_DONE(funcctx);
-               }
-               length = q - p;
-               strncpy(values[i_comm], p, length);
-               values[i_comm][length] = '\0';
-               p = q + 2;
-               elog(DEBUG5, "pg_proctab: comm = %s", values[i_comm]);
-
-               /* state */
-               values[i_state][0] = *p;
-               values[i_state][1] = '\0';
-               p = p + 2;
-               elog(DEBUG5, "pg_proctab: state = %s", values[i_state]);
-
-               /* ppid */
-               GET_NEXT_VALUE(p, q, values[i_ppid], length, "ppid not found", ' ');
-               elog(DEBUG5, "pg_proctab: ppid = %s", values[i_ppid]);
-
-               /* pgrp */
-               GET_NEXT_VALUE(p, q, values[i_pgrp], length, "pgrp not found", ' ');
-               elog(DEBUG5, "pg_proctab: pgrp = %s", values[i_pgrp]);
-
-               /* session */
-               GET_NEXT_VALUE(p, q, values[i_session], length, "session not found",
-                               ' ');
-               elog(DEBUG5, "pg_proctab: session = %s", values[i_session]);
-
-               /* tty_nr */
-               GET_NEXT_VALUE(p, q, values[i_tty_nr], length, "tty_nr not found", ' ');
-               elog(DEBUG5, "pg_proctab: tty_nr = %s", values[i_tty_nr]);
-
-               /* tpgid */
-               GET_NEXT_VALUE(p, q, values[i_tpgid], length, "tpgid not found", ' ');
-               elog(DEBUG5, "pg_proctab: tpgid = %s", values[i_tpgid]);
-
-               /* flags */
-               GET_NEXT_VALUE(p, q, values[i_flags], length, "flags not found", ' ');
-               elog(DEBUG5, "pg_proctab: flags = %s", values[i_flags]);
-
-               /* minflt */
-               GET_NEXT_VALUE(p, q, values[i_minflt], length, "minflt not found", ' ');
-               elog(DEBUG5, "pg_proctab: minflt = %s", values[i_minflt]);
-
-               /* cminflt */
-               GET_NEXT_VALUE(p, q, values[i_cminflt], length, "cminflt not found",
-                               ' ');
-               elog(DEBUG5, "pg_proctab: cminflt = %s", values[i_cminflt]);
-
-               /* majflt */
-               GET_NEXT_VALUE(p, q, values[i_majflt], length, "majflt not found", ' ');
-               elog(DEBUG5, "pg_proctab: majflt = %s", values[i_majflt]);
-
-               /* cmajflt */
-               GET_NEXT_VALUE(p, q, values[i_cmajflt], length, "cmajflt not found",
-                               ' ');
-               elog(DEBUG5, "pg_proctab: cmajflt = %s", values[i_cmajflt]);
+       /* comm */
+       ++p;
+       if ((q = strchr(p, ')')) == NULL)
+       {
+               elog(ERROR, "pg_proctab: comm not found");
+               return 0;
+       }
+       length = q - p;
+       strncpy(values[i_comm], p, length);
+       values[i_comm][length] = '\0';
+       p = q + 2;
+
+       /* state */
+       values[i_state][0] = *p;
+       values[i_state][1] = '\0';
+       p = p + 2;
+
+       /* ppid */
+       GET_NEXT_VALUE(p, q, values[i_ppid], length, "ppid not found", ' ');
+
+       /* pgrp */
+       GET_NEXT_VALUE(p, q, values[i_pgrp], length, "pgrp not found", ' ');
+
+       /* session */
+       GET_NEXT_VALUE(p, q, values[i_session], length, "session not found", ' ');
+
+       /* tty_nr */
+       GET_NEXT_VALUE(p, q, values[i_tty_nr], length, "tty_nr not found", ' ');
+
+       /* tpgid */
+       GET_NEXT_VALUE(p, q, values[i_tpgid], length, "tpgid not found", ' ');
+
+       /* flags */
+       GET_NEXT_VALUE(p, q, values[i_flags], length, "flags not found", ' ');
+
+       /* minflt */
+       GET_NEXT_VALUE(p, q, values[i_minflt], length, "minflt not found", ' ');
+
+       /* cminflt */
+       GET_NEXT_VALUE(p, q, values[i_cminflt], length, "cminflt not found", ' ');
+
+       /* majflt */
+       GET_NEXT_VALUE(p, q, values[i_majflt], length, "majflt not found", ' ');
+
+       /* cmajflt */
+       GET_NEXT_VALUE(p, q, values[i_cmajflt], length, "cmajflt not found", ' ');
 
                /* utime */
-               GET_NEXT_VALUE(p, q, values[i_utime], length, "utime not found", ' ');
-#ifdef __linux__
-               sprintf(values[i_utime], "%f", (double) atol(values[i_utime]) /
+       GET_NEXT_VALUE(p, q, values[i_utime], length, "utime not found", ' ');
+       sprintf(values[i_utime], "%f", (double) atol(values[i_utime]) /
                                (double) HZ);
-#endif /* __linux__ */
-               elog(DEBUG5, "pg_proctab: utime = %s", values[i_utime]);
 
-               /* stime */
-               GET_NEXT_VALUE(p, q, values[i_stime], length, "stime not found", ' ');
-#ifdef __linux__
-               sprintf(values[i_stime], "%f", (double) atol(values[i_stime]) /
-                               (double) HZ);
-#endif /* __linux__ */
-               elog(DEBUG5, "pg_proctab: stime = %s", values[i_stime]);
+       /* stime */
+       GET_NEXT_VALUE(p, q, values[i_stime], length, "stime not found", ' ');
+       sprintf(values[i_stime], "%f", (double) atol(values[i_stime]) /
+                       (double) HZ);
 
-               /* cutime */
-               GET_NEXT_VALUE(p, q, values[i_cutime], length, "cutime not found", ' ');
-               elog(DEBUG5, "pg_proctab: cutime = %s", values[i_cutime]);
+       /* cutime */
+       GET_NEXT_VALUE(p, q, values[i_cutime], length, "cutime not found", ' ');
 
-               /* cstime */
-               GET_NEXT_VALUE(p, q, values[i_cstime], length, "cstime not found", ' ');
-               elog(DEBUG5, "pg_proctab: cstime = %s", values[i_cstime]);
+       /* cstime */
+       GET_NEXT_VALUE(p, q, values[i_cstime], length, "cstime not found", ' ');
 
-               /* priority */
-               GET_NEXT_VALUE(p, q, values[i_priority], length, "priority not found",
-                               ' ');
-               elog(DEBUG5, "pg_proctab: priority = %s", values[i_priority]);
+       /* priority */
+       GET_NEXT_VALUE(p, q, values[i_priority], length, "priority not found", ' ');
 
-               /* nice */
-               GET_NEXT_VALUE(p, q, values[i_nice], length, "nice not found", ' ');
-               elog(DEBUG5, "pg_proctab: nice = %s", values[i_nice]);
+       /* nice */
+       GET_NEXT_VALUE(p, q, values[i_nice], length, "nice not found", ' ');
 
-               /* num_threads */
-               GET_NEXT_VALUE(p, q, values[i_num_threads], length,
+       /* num_threads */
+       GET_NEXT_VALUE(p, q, values[i_num_threads], length,
                                "num_threads not found", ' ');
-               elog(DEBUG5, "pg_proctab: num_threads = %s", values[i_num_threads]);
-
-               /* itrealvalue */
-               GET_NEXT_VALUE(p, q, values[i_itrealvalue], length,
-                               "itrealvalue not found", ' ');
-               elog(DEBUG5, "pg_proctab: itrealvalue = %s", values[i_itrealvalue]);
-
-               /* starttime */
-               GET_NEXT_VALUE(p, q, values[i_starttime], length,
-                               "starttime not found", ' ');
-               elog(DEBUG5, "pg_proctab: starttime = %s", values[i_starttime]);
-
-               /* vsize */
-               GET_NEXT_VALUE(p, q, values[i_vsize], length, "vsize not found", ' ');
-               elog(DEBUG5, "pg_proctab: vsize = %s", values[i_vsize]);
-
-               /* rss */
-               GET_NEXT_VALUE(p, q, values[i_rss], length, "rss not found", ' ');
-               elog(DEBUG5, "pg_proctab: rss = %s", values[i_rss]);
-
-               p = skip_token(p);                      /* skip rlim */
-               p = skip_token(p);                      /* skip startcode */
-               p = skip_token(p);                      /* skip endcode */
-               p = skip_token(p);                      /* skip startstack */
-               p = skip_token(p);                      /* skip kstkesp */
-               p = skip_token(p);                      /* skip kstkeip */
-               p = skip_token(p);                      /* skip signal (obsolete) */
-               p = skip_token(p);                      /* skip blocked (obsolete) */
-               p = skip_token(p);                      /* skip sigignore (obsolete) */
-               p = skip_token(p);                      /* skip sigcatch (obsolete) */
-               p = skip_token(p);                      /* skip wchan */
-               p = skip_token(p);                      /* skip nswap (place holder) */
-               p = skip_token(p);                      /* skip cnswap (place holder) */
-               ++p;
-
-               /* exit_signal */
-               GET_NEXT_VALUE(p, q, values[i_exit_signal], length,
-                               "exit_signal not found", ' ');
-               elog(DEBUG5, "pg_proctab: exit_signal = %s", values[i_exit_signal]);
-
-               /* processor */
-               GET_NEXT_VALUE(p, q, values[i_processor], length,
-                               "processor not found", ' ');
-               elog(DEBUG5, "pg_proctab: processor = %s", values[i_processor]);
-
-               /* rt_priority */
-               GET_NEXT_VALUE(p, q, values[i_rt_priority], length,
-                               "rt_priority not found", ' ');
-               elog(DEBUG5, "pg_proctab: rt_priority = %s", values[i_rt_priority]);
-
-               /* policy */
-               GET_NEXT_VALUE(p, q, values[i_policy], length, "policy not found", ' ');
-               elog(DEBUG5, "pg_proctab: policy = %s", values[i_policy]);
-
-               /* delayacct_blkio_ticks */
-               /*
-                * It appears sometimes this is the last item in /proc/PID/stat and
-                * sometimes it's not, depending on the version of the kernel and
-                * possibly the architecture.  So first test if it is the last item
-                * before determining how to deliminate it.
-                */
-               if (strchr(p, ' ') == NULL)
-               {
-                       GET_NEXT_VALUE(p, q, values[i_delayacct_blkio_ticks], length,
-                                       "delayacct_blkio_ticks not found", '\n');
-               }
-               else
-               {
-                       GET_NEXT_VALUE(p, q, values[i_delayacct_blkio_ticks], length,
-                                       "delayacct_blkio_ticks not found", ' ');
-               }
-               elog(DEBUG5, "pg_proctab: delayacct_blkio_ticks = %s",
-                               values[i_delayacct_blkio_ticks]);
-#endif /* __linux__ */
-
-               /* build a tuple */
-               tuple = BuildTupleFromCStrings(attinmeta, values);
-
-               /* make the tuple into a datum */
-               result = HeapTupleGetDatum(tuple);
 
-               SRF_RETURN_NEXT(funcctx, result);
+       /* itrealvalue */
+       GET_NEXT_VALUE(p, q, values[i_itrealvalue], length,
+                       "itrealvalue not found", ' ');
+
+       /* starttime */
+       GET_NEXT_VALUE(p, q, values[i_starttime], length, "starttime not found",
+                       ' ');
+
+       /* vsize */
+       GET_NEXT_VALUE(p, q, values[i_vsize], length, "vsize not found", ' ');
+
+       /* rss */
+       GET_NEXT_VALUE(p, q, values[i_rss], length, "rss not found", ' ');
+
+       p = skip_token(p);                      /* skip rlim */
+       p = skip_token(p);                      /* skip startcode */
+       p = skip_token(p);                      /* skip endcode */
+       p = skip_token(p);                      /* skip startstack */
+       p = skip_token(p);                      /* skip kstkesp */
+       p = skip_token(p);                      /* skip kstkeip */
+       p = skip_token(p);                      /* skip signal (obsolete) */
+       p = skip_token(p);                      /* skip blocked (obsolete) */
+       p = skip_token(p);                      /* skip sigignore (obsolete) */
+       p = skip_token(p);                      /* skip sigcatch (obsolete) */
+       p = skip_token(p);                      /* skip wchan */
+       p = skip_token(p);                      /* skip nswap (place holder) */
+       p = skip_token(p);                      /* skip cnswap (place holder) */
+       ++p;
+
+       /* exit_signal */
+       GET_NEXT_VALUE(p, q, values[i_exit_signal], length,
+                       "exit_signal not found", ' ');
+
+       /* processor */
+       GET_NEXT_VALUE(p, q, values[i_processor], length, "processor not found",
+                       ' ');
+
+       /* rt_priority */
+       GET_NEXT_VALUE(p, q, values[i_rt_priority], length,
+                       "rt_priority not found", ' ');
+
+       /* policy */
+       GET_NEXT_VALUE(p, q, values[i_policy], length, "policy not found", ' ');
+
+       /* delayacct_blkio_ticks */
+       /*
+        * It appears sometimes this is the last item in /proc/PID/stat and
+        * sometimes it's not, depending on the version of the kernel and
+        * possibly the architecture.  So first test if it is the last item
+        * before determining how to deliminate it.
+        */
+       if (strchr(p, ' ') == NULL)
+       {
+               GET_NEXT_VALUE(p, q, values[i_delayacct_blkio_ticks], length,
+                               "delayacct_blkio_ticks not found", '\n');
        }
-       else /* do when there is no more left */
+       else
        {
-               SRF_RETURN_DONE(funcctx);
+               GET_NEXT_VALUE(p, q, values[i_delayacct_blkio_ticks], length,
+                               "delayacct_blkio_ticks not found", ' ');
        }
+#endif /* __linux__ */
+
+       elog(DEBUG5, "pg_proctab: uid %s", values[i_uid]);
+       elog(DEBUG5, "pg_proctab: username %s", values[i_username]);
+       elog(DEBUG5, "pg_proctab: pid = %s", values[i_pid]);
+       elog(DEBUG5, "pg_proctab: comm = %s", values[i_comm]);
+       elog(DEBUG5, "pg_proctab: state = %s", values[i_state]);
+       elog(DEBUG5, "pg_proctab: ppid = %s", values[i_ppid]);
+       elog(DEBUG5, "pg_proctab: pgrp = %s", values[i_pgrp]);
+       elog(DEBUG5, "pg_proctab: session = %s", values[i_session]);
+       elog(DEBUG5, "pg_proctab: tty_nr = %s", values[i_tty_nr]);
+       elog(DEBUG5, "pg_proctab: tpgid = %s", values[i_tpgid]);
+       elog(DEBUG5, "pg_proctab: flags = %s", values[i_flags]);
+       elog(DEBUG5, "pg_proctab: minflt = %s", values[i_minflt]);
+       elog(DEBUG5, "pg_proctab: cminflt = %s", values[i_cminflt]);
+       elog(DEBUG5, "pg_proctab: majflt = %s", values[i_majflt]);
+       elog(DEBUG5, "pg_proctab: cmajflt = %s", values[i_cmajflt]);
+       elog(DEBUG5, "pg_proctab: utime = %s", values[i_utime]);
+       elog(DEBUG5, "pg_proctab: stime = %s", values[i_stime]);
+       elog(DEBUG5, "pg_proctab: cutime = %s", values[i_cutime]);
+       elog(DEBUG5, "pg_proctab: cstime = %s", values[i_cstime]);
+       elog(DEBUG5, "pg_proctab: priority = %s", values[i_priority]);
+       elog(DEBUG5, "pg_proctab: nice = %s", values[i_nice]);
+       elog(DEBUG5, "pg_proctab: num_threads = %s", values[i_num_threads]);
+       elog(DEBUG5, "pg_proctab: itrealvalue = %s", values[i_itrealvalue]);
+       elog(DEBUG5, "pg_proctab: starttime = %s", values[i_starttime]);
+       elog(DEBUG5, "pg_proctab: vsize = %s", values[i_vsize]);
+       elog(DEBUG5, "pg_proctab: rss = %s", values[i_rss]);
+       elog(DEBUG5, "pg_proctab: exit_signal = %s", values[i_exit_signal]);
+       elog(DEBUG5, "pg_proctab: processor = %s", values[i_processor]);
+       elog(DEBUG5, "pg_proctab: rt_priority = %s", values[i_rt_priority]);
+       elog(DEBUG5, "pg_proctab: policy = %s", values[i_policy]);
+       elog(DEBUG5, "pg_proctab: delayacct_blkio_ticks = %s",
+                       values[i_delayacct_blkio_ticks]);
+
+       return 1;
 }