From 8e1d53f14730ac1b1ca0ce9d9a0ccb32578fd4fb Mon Sep 17 00:00:00 2001 From: Mohit Agrawal Date: Thu, 9 May 2019 10:08:25 +0530 Subject: core: Capture process memory usage at the time of call gf_msg_nomem Problem: All gluster processes call gf_mgm_nomem while calloc/malloc/realloc throw an error but the message does not capture current memory usage of gluster process Solution: Call getrusage to capture current memory usage of gluster process Change-Id: I2e0319da1f33b177fa042fdc9e7268068576c9c3 fixes: bz#1708051 Signed-off-by: Mohit Agrawal --- libglusterfs/src/logging.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'libglusterfs') diff --git a/libglusterfs/src/logging.c b/libglusterfs/src/logging.c index c9d733db99d..f0fb9a097da 100644 --- a/libglusterfs/src/logging.c +++ b/libglusterfs/src/logging.c @@ -17,6 +17,7 @@ #include #include #include +#include #ifdef HAVE_BACKTRACE #include @@ -1112,6 +1113,7 @@ _gf_msg_nomem(const char *domain, const char *file, const char *function, glusterfs_ctx_t *ctx = NULL; int wlen = 0; int priority; + struct rusage r_usage; this = THIS; ctx = this->ctx; @@ -1137,15 +1139,17 @@ _gf_msg_nomem(const char *domain, const char *file, const char *function, /* TODO: Currently we print in the enhanced format, with a message ID * of 0. Need to enhance this to support format as configured */ - wlen = snprintf(msg, sizeof msg, - "[%s.%" GF_PRI_SUSECONDS "] %s [MSGID: %" PRIu64 - "]" - " [%s:%d:%s] %s: no memory " - "available for size (%" GF_PRI_SIZET - ")" - " [call stack follows]\n", - timestr, tv.tv_usec, gf_level_strings[level], (uint64_t)0, - basename, line, function, domain, size); + wlen = snprintf( + msg, sizeof msg, + "[%s.%" GF_PRI_SUSECONDS "] %s [MSGID: %" PRIu64 + "]" + " [%s:%d:%s] %s: no memory " + "available for size (%" GF_PRI_SIZET + ") current memory usage in kilobytes %ld" + " [call stack follows]\n", + timestr, tv.tv_usec, gf_level_strings[level], (uint64_t)0, basename, + line, function, domain, size, + (!getrusage(RUSAGE_SELF, &r_usage) ? r_usage.ru_maxrss : 0)); if (-1 == wlen) { ret = -1; goto out; -- cgit