c460ee
From f2b9d3a089cc9ff9910da0075defe306851aca5c Mon Sep 17 00:00:00 2001
c460ee
From: Ravishankar N <ravishankar@redhat.com>
c460ee
Date: Fri, 4 Jun 2021 12:27:57 +0530
c460ee
Subject: [PATCH 576/584] rpcsvc: Add latency tracking for rpc programs
c460ee
c460ee
Added latency tracking of rpc-handling code. With this change we
c460ee
should be able to monitor the amount of time rpc-handling code is
c460ee
consuming for each of the rpc call.
c460ee
c460ee
Upstream patch details:
c460ee
> https://review.gluster.org/#/c/glusterfs/+/24955/
c460ee
> fixes: #1466
c460ee
> Change-Id: I04fc7f3b12bfa5053c0fc36885f271cb78f581cd
c460ee
> Signed-off-by: Pranith Kumar K <pkarampu@redhat.com>
c460ee
c460ee
BUG: 1928676
c460ee
Change-Id: Ibcedddb5db3ff4906607050cf9f7ea3ebb266cc5
c460ee
Signed-off-by: Ravishankar N <ravishankar@redhat.com>
c460ee
Reviewed-on: https://code.engineering.redhat.com/gerrit/c/rhs-glusterfs/+/245295
c460ee
Tested-by: RHGS Build Bot <nigelb@redhat.com>
c460ee
Reviewed-by: Xavi Hernandez Juan <xhernandez@redhat.com>
c460ee
Reviewed-by: Ashish Pandey <aspandey@redhat.com>
c460ee
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
c460ee
---
c460ee
 libglusterfs/src/glusterfs/latency.h   | 22 +++++---
c460ee
 libglusterfs/src/glusterfs/mem-types.h |  1 +
c460ee
 libglusterfs/src/glusterfs/stack.h     |  7 +--
c460ee
 libglusterfs/src/glusterfs/statedump.h |  2 +
c460ee
 libglusterfs/src/glusterfs/xlator.h    |  2 +-
c460ee
 libglusterfs/src/latency.c             | 93 +++++++++++++++-------------------
c460ee
 libglusterfs/src/libglusterfs.sym      |  5 ++
c460ee
 libglusterfs/src/monitoring.c          |  8 +--
c460ee
 libglusterfs/src/statedump.c           | 38 +++++++++++++-
c460ee
 libglusterfs/src/xlator.c              |  5 ++
c460ee
 rpc/rpc-lib/src/libgfrpc.sym           |  1 +
c460ee
 rpc/rpc-lib/src/rpcsvc.c               | 72 +++++++++++++++++++++++++-
c460ee
 rpc/rpc-lib/src/rpcsvc.h               |  5 ++
c460ee
 xlators/protocol/server/src/server.c   |  2 +
c460ee
 14 files changed, 193 insertions(+), 70 deletions(-)
c460ee
c460ee
diff --git a/libglusterfs/src/glusterfs/latency.h b/libglusterfs/src/glusterfs/latency.h
c460ee
index ed47b1f..4d601bb 100644
c460ee
--- a/libglusterfs/src/glusterfs/latency.h
c460ee
+++ b/libglusterfs/src/glusterfs/latency.h
c460ee
@@ -11,13 +11,23 @@
c460ee
 #ifndef __LATENCY_H__
c460ee
 #define __LATENCY_H__
c460ee
 
c460ee
-#include "glusterfs/glusterfs.h"
c460ee
+#include <inttypes.h>
c460ee
+#include <time.h>
c460ee
 
c460ee
-typedef struct fop_latency {
c460ee
-    double min;   /* min time for the call (microseconds) */
c460ee
-    double max;   /* max time for the call (microseconds) */
c460ee
-    double total; /* total time (microseconds) */
c460ee
+typedef struct _gf_latency {
c460ee
+    uint64_t min;   /* min time for the call (nanoseconds) */
c460ee
+    uint64_t max;   /* max time for the call (nanoseconds) */
c460ee
+    uint64_t total; /* total time (nanoseconds) */
c460ee
     uint64_t count;
c460ee
-} fop_latency_t;
c460ee
+} gf_latency_t;
c460ee
 
c460ee
+gf_latency_t *
c460ee
+gf_latency_new(size_t n);
c460ee
+
c460ee
+void
c460ee
+gf_latency_reset(gf_latency_t *lat);
c460ee
+
c460ee
+void
c460ee
+gf_latency_update(gf_latency_t *lat, struct timespec *begin,
c460ee
+                  struct timespec *end);
c460ee
 #endif /* __LATENCY_H__ */
c460ee
diff --git a/libglusterfs/src/glusterfs/mem-types.h b/libglusterfs/src/glusterfs/mem-types.h
c460ee
index 92730a9..970b9ff 100644
c460ee
--- a/libglusterfs/src/glusterfs/mem-types.h
c460ee
+++ b/libglusterfs/src/glusterfs/mem-types.h
c460ee
@@ -139,6 +139,7 @@ enum gf_common_mem_types_ {
c460ee
     gf_common_mt_mgmt_v3_lock_timer_t, /* used only in one location */
c460ee
     gf_common_mt_server_cmdline_t,     /* used only in one location */
c460ee
     gf_mt_gfdb_query_record_t,
c460ee
+    gf_common_mt_latency_t,
c460ee
     gf_common_mt_end
c460ee
 };
c460ee
 #endif
c460ee
diff --git a/libglusterfs/src/glusterfs/stack.h b/libglusterfs/src/glusterfs/stack.h
c460ee
index bd466d8..536a330 100644
c460ee
--- a/libglusterfs/src/glusterfs/stack.h
c460ee
+++ b/libglusterfs/src/glusterfs/stack.h
c460ee
@@ -45,6 +45,9 @@ typedef int32_t (*ret_fn_t)(call_frame_t *frame, call_frame_t *prev_frame,
c460ee
                             xlator_t *this, int32_t op_ret, int32_t op_errno,
c460ee
                             ...);
c460ee
 
c460ee
+void
c460ee
+gf_frame_latency_update(call_frame_t *frame);
c460ee
+
c460ee
 struct call_pool {
c460ee
     union {
c460ee
         struct list_head all_frames;
c460ee
@@ -149,8 +152,6 @@ struct _call_stack {
c460ee
     } while (0);
c460ee
 
c460ee
 struct xlator_fops;
c460ee
-void
c460ee
-gf_update_latency(call_frame_t *frame);
c460ee
 
c460ee
 static inline void
c460ee
 FRAME_DESTROY(call_frame_t *frame)
c460ee
@@ -158,7 +159,7 @@ FRAME_DESTROY(call_frame_t *frame)
c460ee
     void *local = NULL;
c460ee
 
c460ee
     if (frame->root->ctx->measure_latency)
c460ee
-        gf_update_latency(frame);
c460ee
+        gf_frame_latency_update(frame);
c460ee
 
c460ee
     list_del_init(&frame->frames);
c460ee
     if (frame->local) {
c460ee
diff --git a/libglusterfs/src/glusterfs/statedump.h b/libglusterfs/src/glusterfs/statedump.h
c460ee
index 89d04f9..ce08270 100644
c460ee
--- a/libglusterfs/src/glusterfs/statedump.h
c460ee
+++ b/libglusterfs/src/glusterfs/statedump.h
c460ee
@@ -127,4 +127,6 @@ gf_proc_dump_xlator_meminfo(xlator_t *this, strfd_t *strfd);
c460ee
 void
c460ee
 gf_proc_dump_xlator_profile(xlator_t *this, strfd_t *strfd);
c460ee
 
c460ee
+void
c460ee
+gf_latency_statedump_and_reset(char *key, gf_latency_t *lat);
c460ee
 #endif /* STATEDUMP_H */
c460ee
diff --git a/libglusterfs/src/glusterfs/xlator.h b/libglusterfs/src/glusterfs/xlator.h
c460ee
index 273039a..ecb9fa4 100644
c460ee
--- a/libglusterfs/src/glusterfs/xlator.h
c460ee
+++ b/libglusterfs/src/glusterfs/xlator.h
c460ee
@@ -808,7 +808,7 @@ struct _xlator {
c460ee
 
c460ee
         struct {
c460ee
             /* for latency measurement */
c460ee
-            fop_latency_t latencies[GF_FOP_MAXVALUE];
c460ee
+            gf_latency_t latencies[GF_FOP_MAXVALUE];
c460ee
             /* for latency measurement */
c460ee
             fop_metrics_t metrics[GF_FOP_MAXVALUE];
c460ee
 
c460ee
diff --git a/libglusterfs/src/latency.c b/libglusterfs/src/latency.c
c460ee
index ce61399..ce4b0e8 100644
c460ee
--- a/libglusterfs/src/latency.c
c460ee
+++ b/libglusterfs/src/latency.c
c460ee
@@ -14,39 +14,34 @@
c460ee
  */
c460ee
 
c460ee
 #include "glusterfs/glusterfs.h"
c460ee
-#include "glusterfs/xlator.h"
c460ee
-#include "glusterfs/common-utils.h"
c460ee
 #include "glusterfs/statedump.h"
c460ee
-#include "glusterfs/libglusterfs-messages.h"
c460ee
 
c460ee
-void
c460ee
-gf_update_latency(call_frame_t *frame)
c460ee
+gf_latency_t *
c460ee
+gf_latency_new(size_t n)
c460ee
 {
c460ee
-    double elapsed;
c460ee
-    struct timespec *begin, *end;
c460ee
-
c460ee
-    fop_latency_t *lat;
c460ee
-
c460ee
-    begin = &frame->begin;
c460ee
-    end = &frame->end;
c460ee
+    int i = 0;
c460ee
+    gf_latency_t *lat = NULL;
c460ee
 
c460ee
-    if (!(begin->tv_sec && end->tv_sec))
c460ee
-        goto out;
c460ee
+    lat = GF_MALLOC(n * sizeof(*lat), gf_common_mt_latency_t);
c460ee
+    if (!lat)
c460ee
+        return NULL;
c460ee
 
c460ee
-    elapsed = gf_tsdiff(begin, end);
c460ee
+    for (i = 0; i < n; i++) {
c460ee
+        gf_latency_reset(lat + i);
c460ee
+    }
c460ee
+    return lat;
c460ee
+}
c460ee
 
c460ee
-    if (frame->op < 0 || frame->op >= GF_FOP_MAXVALUE) {
c460ee
-        gf_log("[core]", GF_LOG_WARNING, "Invalid frame op value: %d",
c460ee
-               frame->op);
c460ee
+void
c460ee
+gf_latency_update(gf_latency_t *lat, struct timespec *begin,
c460ee
+                  struct timespec *end)
c460ee
+{
c460ee
+    if (!(begin->tv_sec && end->tv_sec)) {
c460ee
+        /*Measure latency might have been enabled/disabled during the op*/
c460ee
         return;
c460ee
     }
c460ee
 
c460ee
-    /* Can happen mostly at initiator xlator, as STACK_WIND/UNWIND macros
c460ee
-       set it right anyways for those frames */
c460ee
-    if (!frame->op)
c460ee
-        frame->op = frame->root->op;
c460ee
-
c460ee
-    lat = &frame->this->stats.interval.latencies[frame->op];
c460ee
+    double elapsed = gf_tsdiff(begin, end);
c460ee
 
c460ee
     if (lat->max < elapsed)
c460ee
         lat->max = elapsed;
c460ee
@@ -56,40 +51,34 @@ gf_update_latency(call_frame_t *frame)
c460ee
 
c460ee
     lat->total += elapsed;
c460ee
     lat->count++;
c460ee
-out:
c460ee
-    return;
c460ee
 }
c460ee
 
c460ee
 void
c460ee
-gf_proc_dump_latency_info(xlator_t *xl)
c460ee
+gf_latency_reset(gf_latency_t *lat)
c460ee
 {
c460ee
-    char key_prefix[GF_DUMP_MAX_BUF_LEN];
c460ee
-    char key[GF_DUMP_MAX_BUF_LEN];
c460ee
-    int i;
c460ee
-
c460ee
-    snprintf(key_prefix, GF_DUMP_MAX_BUF_LEN, "%s.latency", xl->name);
c460ee
-    gf_proc_dump_add_section("%s", key_prefix);
c460ee
-
c460ee
-    for (i = 0; i < GF_FOP_MAXVALUE; i++) {
c460ee
-        gf_proc_dump_build_key(key, key_prefix, "%s", (char *)gf_fop_list[i]);
c460ee
-
c460ee
-        fop_latency_t *lat = &xl->stats.interval.latencies[i];
c460ee
+    if (!lat)
c460ee
+        return;
c460ee
+    memset(lat, 0, sizeof(*lat));
c460ee
+    lat->min = ULLONG_MAX;
c460ee
+    /* make sure 'min' is set to high value, so it would be
c460ee
+       properly set later */
c460ee
+}
c460ee
 
c460ee
-        /* Doesn't make sense to continue if there are no fops
c460ee
-           came in the given interval */
c460ee
-        if (!lat->count)
c460ee
-            continue;
c460ee
+void
c460ee
+gf_frame_latency_update(call_frame_t *frame)
c460ee
+{
c460ee
+    gf_latency_t *lat;
c460ee
+    /* Can happen mostly at initiator xlator, as STACK_WIND/UNWIND macros
c460ee
+       set it right anyways for those frames */
c460ee
+    if (!frame->op)
c460ee
+        frame->op = frame->root->op;
c460ee
 
c460ee
-        gf_proc_dump_write(key, "%.03f,%" PRId64 ",%.03f",
c460ee
-                           (lat->total / lat->count), lat->count, lat->total);
c460ee
+    if (frame->op < 0 || frame->op >= GF_FOP_MAXVALUE) {
c460ee
+        gf_log("[core]", GF_LOG_WARNING, "Invalid frame op value: %d",
c460ee
+               frame->op);
c460ee
+        return;
c460ee
     }
c460ee
 
c460ee
-    memset(xl->stats.interval.latencies, 0,
c460ee
-           sizeof(xl->stats.interval.latencies));
c460ee
-
c460ee
-    /* make sure 'min' is set to high value, so it would be
c460ee
-       properly set later */
c460ee
-    for (i = 0; i < GF_FOP_MAXVALUE; i++) {
c460ee
-        xl->stats.interval.latencies[i].min = 0xffffffff;
c460ee
-    }
c460ee
+    lat = &frame->this->stats.interval.latencies[frame->op];
c460ee
+    gf_latency_update(lat, &frame->begin, &frame->end);
c460ee
 }
c460ee
diff --git a/libglusterfs/src/libglusterfs.sym b/libglusterfs/src/libglusterfs.sym
c460ee
index 9072afa..4f968e1 100644
c460ee
--- a/libglusterfs/src/libglusterfs.sym
c460ee
+++ b/libglusterfs/src/libglusterfs.sym
c460ee
@@ -1183,3 +1183,8 @@ gf_latency_reset
c460ee
 gf_latency_update
c460ee
 gf_frame_latency_update
c460ee
 gf_assert
c460ee
+gf_latency_statedump_and_reset
c460ee
+gf_latency_new
c460ee
+gf_latency_reset
c460ee
+gf_latency_update
c460ee
+gf_frame_latency_update
c460ee
diff --git a/libglusterfs/src/monitoring.c b/libglusterfs/src/monitoring.c
c460ee
index 6d9bfb1..20b7f52 100644
c460ee
--- a/libglusterfs/src/monitoring.c
c460ee
+++ b/libglusterfs/src/monitoring.c
c460ee
@@ -113,15 +113,15 @@ dump_latency_and_count(xlator_t *xl, int fd)
c460ee
             dprintf(fd, "%s.interval.%s.fail_count %" PRIu64 "\n", xl->name,
c460ee
                     gf_fop_list[index], cbk);
c460ee
         }
c460ee
-        if (xl->stats.interval.latencies[index].count != 0.0) {
c460ee
+        if (xl->stats.interval.latencies[index].count != 0) {
c460ee
             dprintf(fd, "%s.interval.%s.latency %lf\n", xl->name,
c460ee
                     gf_fop_list[index],
c460ee
-                    (xl->stats.interval.latencies[index].total /
c460ee
+                    (((double)xl->stats.interval.latencies[index].total) /
c460ee
                      xl->stats.interval.latencies[index].count));
c460ee
-            dprintf(fd, "%s.interval.%s.max %lf\n", xl->name,
c460ee
+            dprintf(fd, "%s.interval.%s.max %" PRIu64 "\n", xl->name,
c460ee
                     gf_fop_list[index],
c460ee
                     xl->stats.interval.latencies[index].max);
c460ee
-            dprintf(fd, "%s.interval.%s.min %lf\n", xl->name,
c460ee
+            dprintf(fd, "%s.interval.%s.min %" PRIu64 "\n", xl->name,
c460ee
                     gf_fop_list[index],
c460ee
                     xl->stats.interval.latencies[index].min);
c460ee
         }
c460ee
diff --git a/libglusterfs/src/statedump.c b/libglusterfs/src/statedump.c
c460ee
index d18b50f..4bf4cc2 100644
c460ee
--- a/libglusterfs/src/statedump.c
c460ee
+++ b/libglusterfs/src/statedump.c
c460ee
@@ -201,6 +201,40 @@ gf_proc_dump_write(char *key, char *value, ...)
c460ee
     return ret;
c460ee
 }
c460ee
 
c460ee
+void
c460ee
+gf_latency_statedump_and_reset(char *key, gf_latency_t *lat)
c460ee
+{
c460ee
+    /* Doesn't make sense to continue if there are no fops
c460ee
+       came in the given interval */
c460ee
+    if (!lat || !lat->count)
c460ee
+        return;
c460ee
+    gf_proc_dump_write(key,
c460ee
+                       "AVG:%lf CNT:%" PRIu64 " TOTAL:%" PRIu64 " MIN:%" PRIu64
c460ee
+                       " MAX:%" PRIu64,
c460ee
+                       (((double)lat->total) / lat->count), lat->count,
c460ee
+                       lat->total, lat->min, lat->max);
c460ee
+    gf_latency_reset(lat);
c460ee
+}
c460ee
+
c460ee
+void
c460ee
+gf_proc_dump_xl_latency_info(xlator_t *xl)
c460ee
+{
c460ee
+    char key_prefix[GF_DUMP_MAX_BUF_LEN];
c460ee
+    char key[GF_DUMP_MAX_BUF_LEN];
c460ee
+    int i;
c460ee
+
c460ee
+    snprintf(key_prefix, GF_DUMP_MAX_BUF_LEN, "%s.latency", xl->name);
c460ee
+    gf_proc_dump_add_section("%s", key_prefix);
c460ee
+
c460ee
+    for (i = 0; i < GF_FOP_MAXVALUE; i++) {
c460ee
+        gf_proc_dump_build_key(key, key_prefix, "%s", (char *)gf_fop_list[i]);
c460ee
+
c460ee
+        gf_latency_t *lat = &xl->stats.interval.latencies[i];
c460ee
+
c460ee
+        gf_latency_statedump_and_reset(key, lat);
c460ee
+    }
c460ee
+}
c460ee
+
c460ee
 static void
c460ee
 gf_proc_dump_xlator_mem_info(xlator_t *xl)
c460ee
 {
c460ee
@@ -487,7 +521,7 @@ gf_proc_dump_single_xlator_info(xlator_t *trav)
c460ee
         return;
c460ee
 
c460ee
     if (ctx->measure_latency)
c460ee
-        gf_proc_dump_latency_info(trav);
c460ee
+        gf_proc_dump_xl_latency_info(trav);
c460ee
 
c460ee
     gf_proc_dump_xlator_mem_info(trav);
c460ee
 
c460ee
@@ -1024,7 +1058,7 @@ gf_proc_dump_xlator_profile(xlator_t *this, strfd_t *strfd)
c460ee
     {
c460ee
         gf_dump_strfd = strfd;
c460ee
 
c460ee
-        gf_proc_dump_latency_info(this);
c460ee
+        gf_proc_dump_xl_latency_info(this);
c460ee
 
c460ee
         gf_dump_strfd = NULL;
c460ee
     }
c460ee
diff --git a/libglusterfs/src/xlator.c b/libglusterfs/src/xlator.c
c460ee
index 36cc32c..b9ad411 100644
c460ee
--- a/libglusterfs/src/xlator.c
c460ee
+++ b/libglusterfs/src/xlator.c
c460ee
@@ -246,6 +246,7 @@ xlator_dynload_apis(xlator_t *xl)
c460ee
     void *handle = NULL;
c460ee
     volume_opt_list_t *vol_opt = NULL;
c460ee
     xlator_api_t *xlapi = NULL;
c460ee
+    int i = 0;
c460ee
 
c460ee
     handle = xl->dlhandle;
c460ee
 
c460ee
@@ -343,6 +344,10 @@ xlator_dynload_apis(xlator_t *xl)
c460ee
     memcpy(xl->op_version, xlapi->op_version,
c460ee
            sizeof(uint32_t) * GF_MAX_RELEASES);
c460ee
 
c460ee
+    for (i = 0; i < GF_FOP_MAXVALUE; i++) {
c460ee
+        gf_latency_reset(&xl->stats.interval.latencies[i]);
c460ee
+    }
c460ee
+
c460ee
     ret = 0;
c460ee
 out:
c460ee
     return ret;
c460ee
diff --git a/rpc/rpc-lib/src/libgfrpc.sym b/rpc/rpc-lib/src/libgfrpc.sym
c460ee
index f3544e3..a1757cc 100644
c460ee
--- a/rpc/rpc-lib/src/libgfrpc.sym
c460ee
+++ b/rpc/rpc-lib/src/libgfrpc.sym
c460ee
@@ -66,3 +66,4 @@ rpc_transport_unix_options_build
c460ee
 rpc_transport_unref
c460ee
 rpc_clnt_mgmt_pmap_signout
c460ee
 rpcsvc_autoscale_threads
c460ee
+rpcsvc_statedump
c460ee
diff --git a/rpc/rpc-lib/src/rpcsvc.c b/rpc/rpc-lib/src/rpcsvc.c
c460ee
index b031d93..855b512 100644
c460ee
--- a/rpc/rpc-lib/src/rpcsvc.c
c460ee
+++ b/rpc/rpc-lib/src/rpcsvc.c
c460ee
@@ -25,6 +25,7 @@
c460ee
 #include <glusterfs/syncop.h>
c460ee
 #include "rpc-drc.h"
c460ee
 #include "protocol-common.h"
c460ee
+#include <glusterfs/statedump.h>
c460ee
 
c460ee
 #include <errno.h>
c460ee
 #include <pthread.h>
c460ee
@@ -377,6 +378,10 @@ rpcsvc_program_actor(rpcsvc_request_t *req)
c460ee
         goto err;
c460ee
     }
c460ee
 
c460ee
+    if (svc->xl->ctx->measure_latency) {
c460ee
+        timespec_now(&req->begin);
c460ee
+    }
c460ee
+
c460ee
     req->ownthread = program->ownthread;
c460ee
     req->synctask = program->synctask;
c460ee
 
c460ee
@@ -1526,10 +1531,18 @@ rpcsvc_submit_generic(rpcsvc_request_t *req, struct iovec *proghdr,
c460ee
     size_t hdrlen = 0;
c460ee
     char new_iobref = 0;
c460ee
     rpcsvc_drc_globals_t *drc = NULL;
c460ee
+    gf_latency_t *lat = NULL;
c460ee
 
c460ee
     if ((!req) || (!req->trans))
c460ee
         return -1;
c460ee
 
c460ee
+    if (req->prog && req->begin.tv_sec) {
c460ee
+        if ((req->procnum >= 0) && (req->procnum < req->prog->numactors)) {
c460ee
+            timespec_now(&req->end);
c460ee
+            lat = &req->prog->latencies[req->procnum];
c460ee
+            gf_latency_update(lat, &req->begin, &req->end);
c460ee
+        }
c460ee
+    }
c460ee
     trans = req->trans;
c460ee
 
c460ee
     for (i = 0; i < hdrcount; i++) {
c460ee
@@ -1860,6 +1873,15 @@ rpcsvc_submit_message(rpcsvc_request_t *req, struct iovec *proghdr,
c460ee
                                  iobref);
c460ee
 }
c460ee
 
c460ee
+void
c460ee
+rpcsvc_program_destroy(rpcsvc_program_t *program)
c460ee
+{
c460ee
+    if (program) {
c460ee
+        GF_FREE(program->latencies);
c460ee
+        GF_FREE(program);
c460ee
+    }
c460ee
+}
c460ee
+
c460ee
 int
c460ee
 rpcsvc_program_unregister(rpcsvc_t *svc, rpcsvc_program_t *program)
c460ee
 {
c460ee
@@ -1917,8 +1939,7 @@ rpcsvc_program_unregister(rpcsvc_t *svc, rpcsvc_program_t *program)
c460ee
 
c460ee
     ret = 0;
c460ee
 out:
c460ee
-    if (prog)
c460ee
-        GF_FREE(prog);
c460ee
+    rpcsvc_program_destroy(prog);
c460ee
 
c460ee
     if (ret == -1) {
c460ee
         if (program) {
c460ee
@@ -2303,6 +2324,11 @@ rpcsvc_program_register(rpcsvc_t *svc, rpcsvc_program_t *program,
c460ee
     }
c460ee
 
c460ee
     memcpy(newprog, program, sizeof(*program));
c460ee
+    newprog->latencies = gf_latency_new(program->numactors);
c460ee
+    if (!newprog->latencies) {
c460ee
+        rpcsvc_program_destroy(newprog);
c460ee
+        goto out;
c460ee
+    }
c460ee
 
c460ee
     INIT_LIST_HEAD(&newprog->program);
c460ee
     pthread_mutexattr_init(&thr_attr);
c460ee
@@ -3240,6 +3266,48 @@ out:
c460ee
     return ret;
c460ee
 }
c460ee
 
c460ee
+void
c460ee
+rpcsvc_program_dump(rpcsvc_program_t *prog)
c460ee
+{
c460ee
+    char key_prefix[GF_DUMP_MAX_BUF_LEN];
c460ee
+    char key[GF_DUMP_MAX_BUF_LEN];
c460ee
+    int i;
c460ee
+
c460ee
+    snprintf(key_prefix, GF_DUMP_MAX_BUF_LEN, "%s", prog->progname);
c460ee
+    gf_proc_dump_add_section("%s", key_prefix);
c460ee
+
c460ee
+    gf_proc_dump_build_key(key, key_prefix, "program-number");
c460ee
+    gf_proc_dump_write(key, "%d", prog->prognum);
c460ee
+
c460ee
+    gf_proc_dump_build_key(key, key_prefix, "program-version");
c460ee
+    gf_proc_dump_write(key, "%d", prog->progver);
c460ee
+
c460ee
+    strncat(key_prefix, ".latency",
c460ee
+            sizeof(key_prefix) - strlen(key_prefix) - 1);
c460ee
+
c460ee
+    for (i = 0; i < prog->numactors; i++) {
c460ee
+        gf_proc_dump_build_key(key, key_prefix, "%s", prog->actors[i].procname);
c460ee
+        gf_latency_statedump_and_reset(key, &prog->latencies[i]);
c460ee
+    }
c460ee
+}
c460ee
+
c460ee
+void
c460ee
+rpcsvc_statedump(rpcsvc_t *svc)
c460ee
+{
c460ee
+    rpcsvc_program_t *prog = NULL;
c460ee
+    int ret = 0;
c460ee
+    ret = pthread_rwlock_tryrdlock(&svc->rpclock);
c460ee
+    if (ret)
c460ee
+        return;
c460ee
+    {
c460ee
+        list_for_each_entry(prog, &svc->programs, program)
c460ee
+        {
c460ee
+            rpcsvc_program_dump(prog);
c460ee
+        }
c460ee
+    }
c460ee
+    pthread_rwlock_unlock(&svc->rpclock);
c460ee
+}
c460ee
+
c460ee
 rpcsvc_actor_t gluster_dump_actors[GF_DUMP_MAXVALUE] = {
c460ee
     [GF_DUMP_NULL] = {"NULL", GF_DUMP_NULL, NULL, NULL, 0, DRC_NA},
c460ee
     [GF_DUMP_DUMP] = {"DUMP", GF_DUMP_DUMP, rpcsvc_dump, NULL, 0, DRC_NA},
c460ee
diff --git a/rpc/rpc-lib/src/rpcsvc.h b/rpc/rpc-lib/src/rpcsvc.h
c460ee
index a51edc7..e336d00 100644
c460ee
--- a/rpc/rpc-lib/src/rpcsvc.h
c460ee
+++ b/rpc/rpc-lib/src/rpcsvc.h
c460ee
@@ -275,6 +275,8 @@ struct rpcsvc_request {
c460ee
     gf_boolean_t ownthread;
c460ee
 
c460ee
     gf_boolean_t synctask;
c460ee
+    struct timespec begin; /*req handling start time*/
c460ee
+    struct timespec end;   /*req handling end time*/
c460ee
 };
c460ee
 
c460ee
 #define rpcsvc_request_program(req) ((rpcsvc_program_t *)((req)->prog))
c460ee
@@ -431,6 +433,7 @@ struct rpcsvc_program {
c460ee
 
c460ee
     /* Program specific state handed to actors */
c460ee
     void *private;
c460ee
+    gf_latency_t *latencies; /*Tracks latency statistics for the rpc call*/
c460ee
 
c460ee
     /* This upcall is provided by the program during registration.
c460ee
      * It is used to notify the program about events like connection being
c460ee
@@ -696,4 +699,6 @@ rpcsvc_autoscale_threads(glusterfs_ctx_t *ctx, rpcsvc_t *rpc, int incr);
c460ee
 
c460ee
 extern int
c460ee
 rpcsvc_destroy(rpcsvc_t *svc);
c460ee
+void
c460ee
+rpcsvc_statedump(rpcsvc_t *svc);
c460ee
 #endif
c460ee
diff --git a/xlators/protocol/server/src/server.c b/xlators/protocol/server/src/server.c
c460ee
index 54d9c0f..90eb3ff 100644
c460ee
--- a/xlators/protocol/server/src/server.c
c460ee
+++ b/xlators/protocol/server/src/server.c
c460ee
@@ -267,6 +267,8 @@ server_priv(xlator_t *this)
c460ee
     gf_proc_dump_build_key(key, "server", "total-bytes-write");
c460ee
     gf_proc_dump_write(key, "%" PRIu64, total_write);
c460ee
 
c460ee
+    rpcsvc_statedump(conf->rpc);
c460ee
+
c460ee
     ret = 0;
c460ee
 out:
c460ee
     if (ret)
c460ee
-- 
c460ee
1.8.3.1
c460ee