From a0aafa365dd355864d24232bd6d7f399ef38f9ef Mon Sep 17 00:00:00 2001 From: Pranith K Date: Thu, 10 Mar 2011 02:20:39 +0000 Subject: cli: gluster profile CLI Signed-off-by: Pranith Kumar K Signed-off-by: Vijay Bellur BUG: 1965 (need a cmd to get io-stat details) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1965 --- cli/src/cli-rpc-ops.c | 319 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 319 insertions(+) (limited to 'cli/src/cli-rpc-ops.c') diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c index 1082a908fb0..31adfb33222 100644 --- a/cli/src/cli-rpc-ops.c +++ b/cli/src/cli-rpc-ops.c @@ -2646,6 +2646,324 @@ out: return ret; } +void* +cli_profile_info_elem (void *a, int index) +{ + return ((cli_profile_info_t *)a) + index; +} + +int +cli_profile_info_percentage_cmp (void *a, void *b) +{ + cli_profile_info_t *ia = NULL; + cli_profile_info_t *ib = NULL; + int ret = 0; + + ia = a; + ib = b; + if (ia->percentage_avg_latency < ib->percentage_avg_latency) + ret = -1; + else if (ia->percentage_avg_latency > ib->percentage_avg_latency) + ret = 1; + else + ret = 0; + return ret; +} + +void +cli_profile_info_swap (void *a, void *b) +{ + cli_profile_info_t *ia = NULL; + cli_profile_info_t *ib = NULL; + cli_profile_info_t tmp = {0}; + + ia = a; + ib = b; + tmp = *ia; + *ia = *ib; + *ib = tmp; +} + +void +cmd_profile_volume_brick_out (dict_t *dict, int count, int interval) +{ + char key[256] = {0}; + int i = 0; + uint64_t sec = 0; + uint64_t r_count = 0; + uint64_t w_count = 0; + char *brick = NULL; + uint64_t rb_counts[32] = {0}; + uint64_t wb_counts[32] = {0}; + cli_profile_info_t profile_info[GF_FOP_MAXVALUE] = {{0}}; + char output[128] = {0}; + int per_line = 0; + char read_blocks[128] = {0}; + char write_blocks[128] = {0}; + int index = 0; + int is_header_printed = 0; + int ret = 0; + uint64_t total_fop_hits = 0; + double total_avg_latency = 0; + + memset (key, 0, sizeof (key)); + snprintf (key, sizeof (key), "%d-brick", count); + ret = dict_get_str (dict, key, &brick); + for (i = 0; i < 32; i++) { + memset (key, 0, sizeof (key)); + snprintf (key, sizeof (key), "%d-%d-read-%d", count, + interval, (1 << i)); + ret = dict_get_uint64 (dict, key, &rb_counts[i]); + } + + for (i = 0; i < 32; i++) { + memset (key, 0, sizeof (key)); + snprintf (key, sizeof (key), "%d-%d-write-%d", count, interval, + (1<rpc_status) { + goto out; + } + + gf_log ("cli", GF_LOG_DEBUG, "Received resp to profile"); + ret = gf_xdr_to_cli_stats_volume_rsp (*iov, &rsp); + if (ret < 0) { + gf_log ("", GF_LOG_ERROR, "error"); + goto out; + } + + if (rsp.op_ret && strcmp (rsp.op_errstr, "")) { + cli_out (rsp.op_errstr); + } else { + cli_out ("volume profile %s ", + (rsp.op_ret) ? "unsuccessful": "successful"); + } + + if (rsp.op_ret) { + ret = rsp.op_ret; + goto out; + } + + dict = dict_new (); + + if (!dict) { + ret = -1; + goto out; + } + + ret = dict_unserialize (rsp.stats_info.stats_info_val, + rsp.stats_info.stats_info_len, + &dict); + + if (ret) { + gf_log ("", GF_LOG_ERROR, + "Unable to allocate memory"); + goto out; + } + + ret = dict_get_int32 (dict, "op", (int32_t*)&op); + + if (op != GF_CLI_STATS_INFO) { + ret = 0; + goto out; + } + + ret = dict_get_int32 (dict, "count", &brick_count); + if (ret) + goto out; + while (i <= brick_count) { + snprintf (key, sizeof (key), "%d-cumulative", i); + ret = dict_get_int32 (dict, key, &interval); + if (ret == 0) { + cmd_profile_volume_brick_out (dict, i, interval); + } + snprintf (key, sizeof (key), "%d-interval", i); + ret = dict_get_int32 (dict, key, &interval); + if (ret == 0) { + cmd_profile_volume_brick_out (dict, i, interval); + } + i++; + } + ret = rsp.op_ret; + +out: + cli_cmd_broadcast_response (ret); + return ret; +} + +int32_t +gf_cli3_1_profile_volume (call_frame_t *frame, xlator_t *this, void *data) +{ + int ret = -1; + gf1_cli_stats_volume_req req = {0,}; + dict_t *dict = NULL; + + GF_ASSERT (frame); + GF_ASSERT (this); + GF_ASSERT (data); + + if (!frame || !this || !data) + goto out; + dict = data; + ret = dict_get_str (dict, "volname", &req.volname); + if (ret) + goto out; + + ret = dict_get_int32 (dict, "op", (int32_t*)&req.op); + if (ret) + goto out; + + ret = cli_cmd_submit (&req, frame, cli_rpc_prog, + GLUSTER_CLI_PROFILE_VOLUME, NULL, + gf_xdr_from_cli_stats_volume_req, + this, gf_cli3_1_profile_volume_cbk); + +out: + gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret); + return ret; +} + struct rpc_clnt_procedure gluster_cli_actors[GLUSTER_CLI_MAXVALUE] = { [GLUSTER_CLI_NULL] = {"NULL", NULL }, @@ -2673,6 +2991,7 @@ struct rpc_clnt_procedure gluster_cli_actors[GLUSTER_CLI_MAXVALUE] = { [GLUSTER_CLI_RESET_VOLUME] = {"RESET_VOLUME", gf_cli3_1_reset_volume}, [GLUSTER_CLI_FSM_LOG] = {"FSM_LOG", gf_cli3_1_fsm_log}, [GLUSTER_CLI_GSYNC_SET] = {"GSYNC_SET", gf_cli3_1_gsync_set}, + [GLUSTER_CLI_PROFILE_VOLUME] = {"PROFILE_VOLUME", gf_cli3_1_profile_volume} }; struct rpc_clnt_program cli_prog = { -- cgit