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