From afc623f85e766a9006d7ba7cb81123ca3e10a719 Mon Sep 17 00:00:00 2001 From: Kaushal M Date: Sun, 13 May 2012 09:32:56 +0530 Subject: cli,glusterd,debug/io-stats: Clear top stats Introduces a cli command to clear "volume top" stats. The syntax for clearing stats is # gluster volume top clear [nfs] This patch also fixes io-stats xlator, to create ios_stat struct for open fop as well, along with create and mkdir fops. This allows stats to be recorded for files that exist already after clearing stats or restarting brick process, which would not occur otherwise. Change-Id: I1b87e192025be7bb8a51eaff3d09c747d05d7def BUG: 771709 Signed-off-by: Kaushal M Reviewed-on: http://review.gluster.com/3334 Tested-by: Gluster Build System Reviewed-by: Amar Tumballi Reviewed-by: Anand Avati --- cli/src/cli-cmd-parser.c | 9 ++++++++- cli/src/cli-cmd-volume.c | 4 ++-- cli/src/cli-rpc-ops.c | 30 +++++++++++++++++++++++++----- 3 files changed, 35 insertions(+), 8 deletions(-) (limited to 'cli') diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c index 2dde1674..6c8d374e 100644 --- a/cli/src/cli-cmd-parser.c +++ b/cli/src/cli-cmd-parser.c @@ -1672,7 +1672,7 @@ cli_cmd_volume_top_parse (const char **words, int wordcount, char *delimiter = NULL; char *opwords[] = { "open", "read", "write", "opendir", "readdir", "read-perf", "write-perf", - NULL }; + "clear", NULL }; char *w = NULL; GF_ASSERT (words); @@ -1717,6 +1717,13 @@ cli_cmd_volume_top_parse (const char **words, int wordcount, } else if (strcmp (w, "write-perf") == 0) { top_op = GF_CLI_TOP_WRITE_PERF; perf = 1; + } else if (strcmp (w, "clear") == 0) { + ret = dict_set_int32 (dict, "clear-stats", 1); + if (ret) { + gf_log ("cli", GF_LOG_ERROR, + "Could not set clear-stats in dict"); + goto out; + } } else GF_ASSERT (!"opword mismatch"); ret = dict_set_int32 (dict, "top-op", (int32_t)top_op); diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c index bad9351f..704f9ddd 100644 --- a/cli/src/cli-cmd-volume.c +++ b/cli/src/cli-cmd-volume.c @@ -1890,8 +1890,8 @@ struct cli_cmd volume_cmds[] = { "quota translator specific operations"}, { "volume top {[open|read|write|opendir|readdir [nfs]] " - "|[read-perf|write-perf [nfs|{bs count }]]} " - " [brick ] [list-cnt ]", + "|[read-perf|write-perf [nfs|{bs count }]]" + "|[clear [nfs]]} [brick ] [list-cnt ]", cli_cmd_volume_top_cbk, "volume top operations"}, diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c index e54d4d21..9737e13f 100644 --- a/cli/src/cli-rpc-ops.c +++ b/cli/src/cli-rpc-ops.c @@ -4048,7 +4048,7 @@ gf_cli3_1_top_volume_cbk (struct rpc_req *req, struct iovec *iov, gf_cli_rsp rsp = {0,}; int ret = -1; dict_t *dict = NULL; - gf1_cli_stats_op op = GF_CLI_STATS_NONE; + gf1_cli_stats_op op = GF_CLI_STATS_NONE; char key[256] = {0}; int i = 0; int32_t brick_count = 0; @@ -4056,7 +4056,7 @@ gf_cli3_1_top_volume_cbk (struct rpc_req *req, struct iovec *iov, int32_t members = 0; char *filename; char *bricks; - uint64_t value = 0; + uint64_t value = 0; int32_t j = 0; gf1_cli_top_op top_op = GF_CLI_TOP_NONE; uint64_t nr_open = 0; @@ -4064,10 +4064,13 @@ gf_cli3_1_top_volume_cbk (struct rpc_req *req, struct iovec *iov, double throughput = 0; double time = 0; long int time_sec = 0; - long int time_usec = 0; + long int time_usec = 0; struct tm *tm = NULL; char timestr[256] = {0, }; char *openfd_str = NULL; + gf_boolean_t nfs = _gf_false; + gf_boolean_t clear_stats = _gf_false; + int stats_cleared = 0; if (-1 == req->rpc_status) { goto out; @@ -4132,14 +4135,31 @@ gf_cli3_1_top_volume_cbk (struct rpc_req *req, struct iovec *iov, ret = dict_get_int32 (dict, key, (int32_t*)&top_op); if (ret) goto out; + + clear_stats = dict_get_str_boolean (dict, "clear-stats", _gf_false); + while (i < brick_count) { i++; snprintf (brick, sizeof (brick), "%d-brick", i); ret = dict_get_str (dict, brick, &bricks); if (ret) goto out; - ret = dict_get_str_boolean (dict, "nfs", _gf_false); - if (ret) + + nfs = dict_get_str_boolean (dict, "nfs", _gf_false); + + if (clear_stats) { + memset (key, 0, sizeof (key)); + snprintf (key, sizeof (key), "%d-stats-cleared", i); + ret = dict_get_int32 (dict, key, &stats_cleared); + if (ret) + goto out; + cli_out (stats_cleared ? "Cleared stats for %s %s" : + "Failed to clear stats for %s %s", + nfs ? "NFS server on" : "brick", bricks); + continue; + } + + if (nfs) cli_out ("NFS Server : %s", bricks); else cli_out ("Brick: %s", bricks); -- cgit