]> git.openfabrics.org - ~shefty/ibacm.git/commitdiff
ib_acme: Add option to display output in more readable format
authorSean Hefty <sean.hefty@intel.com>
Tue, 9 Oct 2012 18:39:15 +0000 (11:39 -0700)
committerSean Hefty <sean.hefty@intel.com>
Tue, 9 Oct 2012 18:39:15 +0000 (11:39 -0700)
Signed-off-by: Sean Hefty <sean.hefty@intel.com>
src/acme.c
src/libacm.c
src/libacm.h

index 4cd1a97f5b8ffbb87f1529b8ec3e738a41c900ac..81d9e3a90245b8d577d8f001403d57f5fba9e6ac 100644 (file)
@@ -55,7 +55,13 @@ static char *src_arg;
 static char addr_type = 'u';
 static int verify;
 static int nodelay;
-static int perf_query;
+
+enum perf_query_output {
+       PERF_QUERY_NONE,
+       PERF_QUERY_ROW,
+       PERF_QUERY_COL
+};
+static enum perf_query_output perf_query;
 int verbose;
 
 struct ibv_context **verbs;
@@ -667,6 +673,7 @@ static void resolve(char *svc)
 
 static void query_perf(char *svc)
 {
+       static int lables;
        int ret, cnt, i;
        uint64_t *counters;
 
@@ -676,10 +683,24 @@ static void query_perf(char *svc)
                return;
        }
 
-       printf("%s,", svc);
-       for (i = 0; i < cnt - 1; i++)
-               printf("%llu,", (unsigned long long) counters[i]);
-       printf("%llu\n", (unsigned long long) counters[i]);
+       if (perf_query == PERF_QUERY_ROW) {
+               if (!lables) {
+                       for (i = 0; i < cnt - 1; i++)
+                               printf("%s,", ib_acm_cntr_name(i));
+                       printf("%s\n", ib_acm_cntr_name(i));
+                       lables = 1;
+               }
+               printf("%s,", svc);
+               for (i = 0; i < cnt - 1; i++)
+                       printf("%llu,", (unsigned long long) counters[i]);
+               printf("%llu\n", (unsigned long long) counters[i]);
+       } else {
+               printf("%s\n", svc);
+               for (i = 0; i < cnt; i++) {
+                       printf("%s : ", ib_acm_cntr_name(i));
+                       printf("%llu\n", (unsigned long long) counters[i]);
+               }
+       }
        ib_acm_free_perf(counters);
 }
 
@@ -694,11 +715,6 @@ static int query_svcs(void)
                return -1;
        }
 
-       if (perf_query) {
-               printf("Destination,Error Count,Resolve Count,No Data,Addr Query Count,"
-                       "Addr Cache Count,Route Query Count,Route Cache Count\n");
-       }
-
        for (i = 0; svc_list[i]; i++) {
                ret = ib_acm_connect(svc_list[i]);
                if (ret) {
@@ -741,7 +757,7 @@ int CDECL_FUNC main(int argc, char **argv)
        if (ret)
                goto out;
 
-       while ((op = getopt(argc, argv, "f:s:d:vcA::O::D:PS:V")) != -1) {
+       while ((op = getopt(argc, argv, "f:s:d:vcA::O::D:P::S:V")) != -1) {
                switch (op) {
                case 'f':
                        addr_type = optarg[0];
@@ -775,7 +791,10 @@ int CDECL_FUNC main(int argc, char **argv)
                        dest_dir = optarg;
                        break;
                case 'P':
-                       perf_query = 1;
+                       if (opt_arg(argc, argv) && !strnicmp("col", opt_arg(argc, argv), 3))
+                               perf_query = PERF_QUERY_COL;
+                       else
+                               perf_query = PERF_QUERY_ROW;
                        break;
                case 'S':
                        svc_arg = optarg;
index 5ca1abc8010ea81e4be4fe412311493fde99e860..274eb2de8e324050134378cfa94d11febfd12d8d 100644 (file)
@@ -357,3 +357,21 @@ out:
        lock_release(&lock);
        return ret;
 }
+
+const char *ib_acm_cntr_name(int index)
+{
+       static const char *const cntr_name[] = {
+               [ACM_CNTR_ERROR]        = "Error Count",
+               [ACM_CNTR_RESOLVE]      = "Resolve Count",
+               [ACM_CNTR_NODATA]       = "No Data",
+               [ACM_CNTR_ADDR_QUERY]   = "Addr Query Count",
+               [ACM_CNTR_ADDR_CACHE]   = "Addr Cache Count",
+               [ACM_CNTR_ROUTE_QUERY]  = "Route Query Count",
+               [ACM_CNTR_ROUTE_CACHE]  = "Route Cache Count",
+       };
+
+       if (index < ACM_CNTR_ERROR || index > ACM_MAX_COUNTER)
+               return "Unknown";
+
+       return cntr_name[index];
+}
index 049b7a90618d2d0e7b251c7157fdde53c0dfd080..61220d5ce9f9a90b03f0cd51ed25b9a8c15c2e0c 100644 (file)
@@ -45,4 +45,6 @@ int ib_acm_resolve_path(struct ibv_path_record *path, uint32_t flags);
 int ib_acm_query_perf(uint64_t **counters, int *count);
 #define ib_acm_free_perf(counters) free(counters)
 
+const char *ib_acm_cntr_name(int index);
+
 #endif /* LIBACM_H */