233933
From 55d47524c0c8a88204129c3a94d71779aae00beb Mon Sep 17 00:00:00 2001
233933
From: Mohit Agrawal <moagrawa@redhat.com>
233933
Date: Tue, 28 May 2019 08:18:12 +0530
233933
Subject: [PATCH 145/169] core: Capture process memory usage at the time of
233933
 call gf_msg_nomem
233933
233933
Problem: All gluster processes call gf_mgm_nomem while calloc/malloc/realloc
233933
         throw an error but the message does not capture current memory usage of
233933
         gluster process
233933
233933
Solution: Call getrusage to capture current memory usage of gluster
233933
          process
233933
233933
> Change-Id: I2e0319da1f33b177fa042fdc9e7268068576c9c3
233933
> fixes: bz#1708051
233933
> Reviewed on upstream link https://review.gluster.org/#/c/glusterfs/+/22688/
233933
> Cherry pick from commit 8e1d53f14730ac1b1ca0ce9d9a0ccb32578fd4fb
233933
233933
BUG: 1709087
233933
Change-Id: I2e0319da1f33b177fa042fdc9e7268068576c9c3
233933
Signed-off-by: Mohit Agrawal <moagrawa@redhat.com>
233933
Reviewed-on: https://code.engineering.redhat.com/gerrit/171587
233933
Tested-by: RHGS Build Bot <nigelb@redhat.com>
233933
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
233933
---
233933
 libglusterfs/src/logging.c | 7 +++++--
233933
 1 file changed, 5 insertions(+), 2 deletions(-)
233933
233933
diff --git a/libglusterfs/src/logging.c b/libglusterfs/src/logging.c
233933
index 5d46916..7f0eff6 100644
233933
--- a/libglusterfs/src/logging.c
233933
+++ b/libglusterfs/src/logging.c
233933
@@ -17,6 +17,7 @@
233933
 #include <string.h>
233933
 #include <stdlib.h>
233933
 #include <syslog.h>
233933
+#include <sys/resource.h>
233933
 
233933
 #ifdef HAVE_BACKTRACE
233933
 #include <execinfo.h>
233933
@@ -1196,6 +1197,7 @@ _gf_msg_nomem(const char *domain, const char *file, const char *function,
233933
     glusterfs_ctx_t *ctx = NULL;
233933
     int wlen = 0;
233933
     int priority;
233933
+    struct rusage r_usage;
233933
 
233933
     this = THIS;
233933
     ctx = this->ctx;
233933
@@ -1231,10 +1233,11 @@ _gf_msg_nomem(const char *domain, const char *file, const char *function,
233933
                    "]"
233933
                    " [%s:%d:%s] %s: no memory "
233933
                    "available for size (%" GF_PRI_SIZET
233933
-                   ")"
233933
+                   ") current memory usage in kilobytes %ld"
233933
                    " [call stack follows]\n",
233933
                    timestr, gf_level_strings[level], (uint64_t)0, basename,
233933
-                   line, function, domain, size);
233933
+                   line, function, domain, size,
233933
+                   (!getrusage(RUSAGE_SELF, &r_usage) ? r_usage.ru_maxrss : 0));
233933
     if (-1 == ret) {
233933
         goto out;
233933
     }
233933
-- 
233933
1.8.3.1
233933