diff options
-rw-r--r-- | tools/perf/ui/hist.c | 35 | ||||
-rw-r--r-- | tools/perf/util/hist.c | 2 | ||||
-rw-r--r-- | tools/perf/util/hist.h | 1 |
3 files changed, 36 insertions, 2 deletions
diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c index 427ce687ad81..661922c4d786 100644 --- a/tools/perf/ui/hist.c +++ b/tools/perf/ui/hist.c @@ -178,6 +178,9 @@ int hpp__fmt_mem_stat(struct perf_hpp_fmt *fmt __maybe_unused, struct perf_hpp * for (int i = 0; i < MEM_STAT_LEN; i++) { u64 val = he->mem_stat[mem_stat_idx].entries[i]; + if (hists->mem_stat_total[mem_stat_idx].entries[i] == 0) + continue; + ret += hpp__call_print_fn(hpp, print_fn, fmtstr, 100.0 * val / total); } @@ -405,12 +408,31 @@ static int hpp__header_mem_stat_fn(struct perf_hpp_fmt *fmt, struct perf_hpp *hp int ret = 0; int len; enum mem_stat_type mst = hpp__mem_stat_type(fmt); + int mem_stat_idx = -1; + + for (int i = 0; i < hists->nr_mem_stats; i++) { + if (hists->mem_stat_types[i] == mst) { + mem_stat_idx = i; + break; + } + } + assert(mem_stat_idx != -1); - (void)hists; if (line == 0) { int left, right; - len = fmt->len; + len = 0; + /* update fmt->len for acutally used columns only */ + for (int i = 0; i < MEM_STAT_LEN; i++) { + if (hists->mem_stat_total[mem_stat_idx].entries[i]) + len += MEM_STAT_PRINT_LEN; + } + fmt->len = len; + + /* print header directly if single column only */ + if (len == MEM_STAT_PRINT_LEN) + return scnprintf(hpp->buf, hpp->size, "%*s", len, fmt->name); + left = (len - strlen(fmt->name)) / 2 - 1; right = len - left - strlen(fmt->name) - 2; @@ -423,10 +445,14 @@ static int hpp__header_mem_stat_fn(struct perf_hpp_fmt *fmt, struct perf_hpp *hp left, graph_dotted_line, fmt->name, right, graph_dotted_line); } + len = hpp->size; for (int i = 0; i < MEM_STAT_LEN; i++) { int printed; + if (hists->mem_stat_total[mem_stat_idx].entries[i] == 0) + continue; + printed = scnprintf(buf, len, "%*s", MEM_STAT_PRINT_LEN, mem_stat_name(mst, i)); ret += printed; @@ -1214,6 +1240,11 @@ int perf_hpp__alloc_mem_stats(struct perf_hpp_list *list, struct evlist *evlist) if (hists->mem_stat_types == NULL) return -ENOMEM; + hists->mem_stat_total = calloc(nr_mem_stats, + sizeof(*hists->mem_stat_total)); + if (hists->mem_stat_total == NULL) + return -ENOMEM; + memcpy(hists->mem_stat_types, mst, nr_mem_stats * sizeof(*mst)); hists->nr_mem_stats = nr_mem_stats; } diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index 7759c1818c1a..afc6855327ab 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c @@ -354,6 +354,7 @@ static int hists__update_mem_stat(struct hists *hists, struct hist_entry *he, assert(0 <= idx && idx < MEM_STAT_LEN); he->mem_stat[i].entries[idx] += period; + hists->mem_stat_total[i].entries[idx] += period; } return 0; } @@ -3054,6 +3055,7 @@ static void hists_evsel__exit(struct evsel *evsel) hists__delete_all_entries(hists); zfree(&hists->mem_stat_types); + zfree(&hists->mem_stat_total); list_for_each_entry_safe(node, tmp, &hists->hpp_formats, list) { perf_hpp_list__for_each_format_safe(&node->hpp, fmt, pos) { diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h index 3990cfc21b16..fa5e886e5b04 100644 --- a/tools/perf/util/hist.h +++ b/tools/perf/util/hist.h @@ -135,6 +135,7 @@ struct hists { int nr_hpp_node; int nr_mem_stats; enum mem_stat_type *mem_stat_types; + struct he_mem_stat *mem_stat_total; }; #define hists__has(__h, __f) (__h)->hpp_list->__f |