From: Sean Hefty Date: Tue, 9 Oct 2012 18:39:15 +0000 (-0700) Subject: ib_acme: Add option to display output in more readable format X-Git-Tag: v1.0.8~26 X-Git-Url: https://openfabrics.org/gitweb/?a=commitdiff_plain;h=7a3adb7d1415698bc219649ff077523499549821;p=~shefty%2Fibacm.git ib_acme: Add option to display output in more readable format Signed-off-by: Sean Hefty --- diff --git a/src/acme.c b/src/acme.c index 4cd1a97..81d9e3a 100644 --- a/src/acme.c +++ b/src/acme.c @@ -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; diff --git a/src/libacm.c b/src/libacm.c index 5ca1abc..274eb2d 100644 --- a/src/libacm.c +++ b/src/libacm.c @@ -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]; +} diff --git a/src/libacm.h b/src/libacm.h index 049b7a9..61220d5 100644 --- a/src/libacm.h +++ b/src/libacm.h @@ -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 */