]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - rdma/stat.c
Merge branch 'master' into next
[mirror_iproute2.git] / rdma / stat.c
index 942c1ac352018d45736ff4172c24f0f262b7ff9a..2f57528700bc4b0fec5957e6210b3832fc0471a4 100644 (file)
@@ -6,6 +6,7 @@
 
 #include "rdma.h"
 #include "res.h"
+#include "stat.h"
 #include <inttypes.h>
 
 static int stat_help(struct rd *rd)
@@ -17,6 +18,8 @@ static int stat_help(struct rd *rd)
        pr_out("       %s statistic OBJECT set COUNTER_SCOPE [DEV/PORT_INDEX] auto {CRITERIA | off}\n", rd->filename);
        pr_out("       %s statistic OBJECT bind COUNTER_SCOPE [DEV/PORT_INDEX] [OBJECT-ID] [COUNTER-ID]\n", rd->filename);
        pr_out("       %s statistic OBJECT unbind COUNTER_SCOPE [DEV/PORT_INDEX] [COUNTER-ID]\n", rd->filename);
+       pr_out("       %s statistic show\n", rd->filename);
+       pr_out("       %s statistic show link [ DEV/PORT_INDEX ]\n", rd->filename);
        pr_out("where  OBJECT: = { qp }\n");
        pr_out("       CRITERIA : = { type }\n");
        pr_out("       COUNTER_SCOPE: = { link | dev }\n");
@@ -31,6 +34,8 @@ static int stat_help(struct rd *rd)
        pr_out("       %s statistic qp bind link mlx5_2/1 lqpn 178 cntn 4\n", rd->filename);
        pr_out("       %s statistic qp unbind link mlx5_2/1 cntn 4\n", rd->filename);
        pr_out("       %s statistic qp unbind link mlx5_2/1 cntn 4 lqpn 178\n", rd->filename);
+       pr_out("       %s statistic show\n", rd->filename);
+       pr_out("       %s statistic show link mlx5_2/1\n", rd->filename);
 
        return 0;
 }
@@ -110,14 +115,10 @@ static int qp_link_get_mode_parse_cb(const struct nlmsghdr *nlh, void *data)
                snprintf(output, sizeof(output), "qp auto off");
        }
 
-       if (rd->json_output) {
-               jsonw_uint_field(rd->jw, "ifindex", idx);
-               jsonw_uint_field(rd->jw, "port", port);
-               jsonw_string_field(rd->jw, "mode", output);
-       } else {
-               pr_out("%u/%u: %s/%u: %s\n", idx, port, name, port, output);
-       }
-
+       open_json_object(NULL);
+       print_link(rd, idx, name, port, tb);
+       print_color_string(PRINT_ANY, COLOR_NONE, "mode", "mode %s ", output);
+       newline(rd);
        return MNL_CB_OK;
 }
 
@@ -144,12 +145,7 @@ static int stat_one_qp_link_get_mode(struct rd *rd)
        if (ret)
                return ret;
 
-       if (rd->json_output)
-               jsonw_start_object(rd->jw);
        ret = rd_recv_msg(rd, qp_link_get_mode_parse_cb, rd, seq);
-       if (rd->json_output)
-               jsonw_end_object(rd->jw);
-
        return ret;
 }
 
@@ -170,7 +166,7 @@ static int stat_qp_get_mode(struct rd *rd)
        return rd_exec_cmd(rd, cmds, "parameter");
 }
 
-static int res_get_hwcounters(struct rd *rd, struct nlattr *hwc_table, bool print)
+int res_get_hwcounters(struct rd *rd, struct nlattr *hwc_table, bool print)
 {
        struct nlattr *nla_entry;
        const char *nm;
@@ -257,31 +253,17 @@ static int res_counter_line(struct rd *rd, const char *name, int index,
        err = res_get_hwcounters(rd, hwc_table, false);
        if (err != MNL_CB_OK)
                return err;
-
-       if (rd->json_output) {
-               jsonw_string_field(rd->jw, "ifname", name);
-               if (port)
-                       jsonw_uint_field(rd->jw, "port", port);
-               jsonw_uint_field(rd->jw, "cntn", cntn);
-       } else {
-               if (port)
-                       pr_out("link %s/%u cntn %u ", name, port, cntn);
-               else
-                       pr_out("dev %s cntn %u ", name, cntn);
-       }
-
+       open_json_object(NULL);
+       print_link(rd, index, name, port, nla_line);
+       print_color_uint(PRINT_ANY, COLOR_NONE, "cntn", "cntn %u ", cntn);
        res_print_uint(rd, "pid", pid, nla_line[RDMA_NLDEV_ATTR_RES_PID]);
        print_comm(rd, comm, nla_line);
-
        res_get_hwcounters(rd, hwc_table, true);
-
        isfirst = true;
+       open_json_array(PRINT_JSON, "lqpn");
+       print_color_string(PRINT_FP, COLOR_NONE, NULL, "\n    LQPN: <", NULL);
        mnl_attr_for_each_nested(nla_entry, qp_table) {
                struct nlattr *qp_line[RDMA_NLDEV_ATTR_MAX] = {};
-
-               if (isfirst && !rd->json_output)
-                       pr_out("\n    LQPN: <");
-
                err = mnl_attr_parse_nested(nla_entry, rd_attr_cb, qp_line);
                if (err != MNL_CB_OK)
                        return -EINVAL;
@@ -290,19 +272,14 @@ static int res_counter_line(struct rd *rd, const char *name, int index,
                        return -EINVAL;
 
                qpn = mnl_attr_get_u32(qp_line[RDMA_NLDEV_ATTR_RES_LQPN]);
-               if (rd->json_output) {
-                       jsonw_uint_field(rd->jw, "lqpn", qpn);
-               } else {
-                       if (isfirst)
-                               pr_out("%d", qpn);
-                       else
-                               pr_out(", %d", qpn);
-               }
+               if (!isfirst)
+                       print_color_string(PRINT_FP, COLOR_NONE, NULL, ",",
+                                          NULL);
+               print_color_uint(PRINT_ANY, COLOR_NONE, NULL, "%d", qpn);
                isfirst = false;
        }
-
-       if (!rd->json_output)
-               pr_out(">\n");
+       close_json_array(PRINT_ANY, ">");
+       newline(rd);
        return MNL_CB_OK;
 }
 
@@ -366,12 +343,7 @@ static int stat_qp_show_one_link(struct rd *rd)
        if (ret)
                return ret;
 
-       if (rd->json_output)
-               jsonw_start_object(rd->jw);
        ret = rd_recv_msg(rd, stat_qp_show_parse_cb, rd, seq);
-       if (rd->json_output)
-               jsonw_end_object(rd->jw);
-
        return ret;
 }
 
@@ -674,12 +646,77 @@ static int stat_qp(struct rd *rd)
        return rd_exec_cmd(rd, cmds, "parameter");
 }
 
+static int stat_show_parse_cb(const struct nlmsghdr *nlh, void *data)
+{
+       struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {};
+       struct rd *rd = data;
+       const char *name;
+       uint32_t port;
+       int ret;
+
+       mnl_attr_parse(nlh, 0, rd_attr_cb, tb);
+       if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME] ||
+           !tb[RDMA_NLDEV_ATTR_PORT_INDEX] ||
+           !tb[RDMA_NLDEV_ATTR_STAT_HWCOUNTERS])
+               return MNL_CB_ERROR;
+
+       name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]);
+       port = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_PORT_INDEX]);
+       open_json_object(NULL);
+       print_color_string(PRINT_ANY, COLOR_NONE, "ifname", "link %s/", name);
+       print_color_uint(PRINT_ANY, COLOR_NONE, "port", "%u ", port);
+       ret = res_get_hwcounters(rd, tb[RDMA_NLDEV_ATTR_STAT_HWCOUNTERS], true);
+
+       newline(rd);
+       return ret;
+}
+
+static int stat_show_one_link(struct rd *rd)
+{
+       int flags = NLM_F_REQUEST | NLM_F_ACK;
+       uint32_t seq;
+       int ret;
+
+       if (!rd->port_idx)
+               return 0;
+
+       rd_prepare_msg(rd, RDMA_NLDEV_CMD_STAT_GET, &seq,  flags);
+       mnl_attr_put_u32(rd->nlh, RDMA_NLDEV_ATTR_DEV_INDEX, rd->dev_idx);
+       mnl_attr_put_u32(rd->nlh, RDMA_NLDEV_ATTR_PORT_INDEX, rd->port_idx);
+       ret = rd_send_msg(rd);
+       if (ret)
+               return ret;
+
+       return rd_recv_msg(rd, stat_show_parse_cb, rd, seq);
+}
+
+static int stat_show_link(struct rd *rd)
+{
+       return rd_exec_link(rd, stat_show_one_link, false);
+}
+
+static int stat_show(struct rd *rd)
+{
+       const struct rd_cmd cmds[] = {
+               { NULL,         stat_show_link },
+               { "link",       stat_show_link },
+               { "mr",         stat_mr },
+               { "help",       stat_help },
+               { 0 }
+       };
+
+       return rd_exec_cmd(rd, cmds, "parameter");
+}
+
 int cmd_stat(struct rd *rd)
 {
        const struct rd_cmd cmds[] =  {
-               { NULL,         stat_help },
+               { NULL,         stat_show },
+               { "show",       stat_show },
+               { "list",       stat_show },
                { "help",       stat_help },
                { "qp",         stat_qp },
+               { "mr",         stat_mr },
                { 0 }
        };