Re: memory fields from getrusage()

From: Justin Pryzby <pryzby(at)telsasoft(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: memory fields from getrusage()
Date: 2017-06-15 14:58:24
Message-ID: 20170615145824.GC15684@telsasoft.com
Views: Raw Message | Whole Thread | Download mbox
Thread:
Lists: pgsql-hackers

On Thu, Jun 15, 2017 at 10:29:21AM -0400, Robert Haas wrote:
> On Wed, Jun 14, 2017 at 6:28 PM, Justin Pryzby <pryzby(at)telsasoft(dot)com> wrote:
> > On Tue, Jun 13, 2017 at 12:16:00PM -0400, Robert Haas wrote:
> >> It might be worth adding platform-specific code for common platforms.
> >
> > All I care (which linux happily/happens to support) is maxrss; I was probably
> > originally interested in this while digging into an issue with hash agg.
>
> I don't think it needs to go in a separate file. I'd just patch ShowUsage().

diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
index f99dd0a..7f57a84 100644
--- a/src/backend/tcop/postgres.c
+++ b/src/backend/tcop/postgres.c
@@ -4467,6 +4467,21 @@ ShowUsage(const char *title)
r.ru_nvcsw - Save_r.ru_nvcsw,
r.ru_nivcsw - Save_r.ru_nivcsw,
r.ru_nvcsw, r.ru_nivcsw);
+
+#if defined(__linux__)
+ appendStringInfo(&str,
+ "!\t%ld max resident (kB)\n",
+ r.ru_maxrss);
+#elif defined(BSD)
+ appendStringInfo(&str,
+ "!\t%ld max resident, %ld shared, %ld unshared data, %ld unshared stack (kB)\n",
+ r.ru_maxrss, r.ru_ixrss, r.ru_idrss, r.ru_isrss);
+#elif defined(__darwin__)
+ appendStringInfo(&str,
+ "!\t%ld max resident, %ld shared, %ld unshared data, %ld unshared stack (kB)\n",
+ r.ru_maxrss/1024, r.ru_ixrss/1024, r.ru_idrss/1024, r.ru_isrss/1024);
+#endif /* __linux__ */
+
#endif /* HAVE_GETRUSAGE */

/* remove trailing newline */

Comments ?

Testing or suggestions on !linux would be useful.

Justin

Attachment Content-Type Size
pg-getrusage text/plain 989 bytes

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2017-06-15 15:05:38 Re: memory fields from getrusage()
Previous Message Tom Lane 2017-06-15 14:50:18 Re: intermittent failures in Cygwin from select_parallel tests