Skip to content

Commit

Permalink
perf report: Add --skip-empty option to suppress 0 event stat
Browse files Browse the repository at this point in the history
To make the output more readable, I think it's better to remove 0's in
the output.  Also the dummy event has no event stats so it just wasts
the space.  Let's use the --skip-empty option to suppress it.

  $ perf report --stat --skip-empty

  Aggregated stats:
             TOTAL events:      16530
              MMAP events:        226
              COMM events:       1596
              EXIT events:          2
          THROTTLE events:        121
        UNTHROTTLE events:        117
              FORK events:       1595
            SAMPLE events:        719
             MMAP2 events:      12147
            CGROUP events:          2
    FINISHED_ROUND events:          2
        THREAD_MAP events:          1
           CPU_MAP events:          1
         TIME_CONV events:          1
  cycles stats:
            SAMPLE events:        719

Reviewed-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20210427013717.1651674-5-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
Namhyung Kim authored and Arnaldo Carvalho de Melo committed Apr 29, 2021
1 parent 55f7544 commit 2775de0
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 13 deletions.
3 changes: 3 additions & 0 deletions tools/perf/Documentation/perf-report.txt
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,9 @@ include::itrace.txt[]
sampled cycles
'Avg Cycles' - block average sampled cycles

--skip-empty::
Do not print 0 results in the --stat output.

include::callchain-overhead-calculation.txt[]

SEE ALSO
Expand Down
4 changes: 2 additions & 2 deletions tools/perf/builtin-annotate.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,8 @@ static int __cmd_annotate(struct perf_annotate *ann)
goto out;

if (dump_trace) {
perf_session__fprintf_nr_events(session, stdout);
evlist__fprintf_nr_events(session->evlist, stdout);
perf_session__fprintf_nr_events(session, stdout, false);
evlist__fprintf_nr_events(session->evlist, stdout, false);
goto out;
}

Expand Down
16 changes: 12 additions & 4 deletions tools/perf/builtin-report.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ struct report {
bool group_set;
bool stitch_lbr;
bool disable_order;
bool skip_empty;
int max_stack;
struct perf_read_values show_threads_values;
struct annotation_options annotation_opts;
Expand Down Expand Up @@ -530,6 +531,9 @@ static int evlist__tty_browse_hists(struct evlist *evlist, struct report *rep, c
if (symbol_conf.event_group && !evsel__is_group_leader(pos))
continue;

if (rep->skip_empty && !hists->stats.nr_samples)
continue;

hists__fprintf_nr_sample_events(hists, rep, evname, stdout);

if (rep->total_cycles_mode) {
Expand Down Expand Up @@ -731,8 +735,8 @@ static int stats_print(struct report *rep)
{
struct perf_session *session = rep->session;

perf_session__fprintf_nr_events(session, stdout);
perf_evlist__fprintf_nr_events(session->evlist, stdout);
perf_session__fprintf_nr_events(session, stdout, rep->skip_empty);
evlist__fprintf_nr_events(session->evlist, stdout, rep->skip_empty);
return 0;
}

Expand Down Expand Up @@ -944,8 +948,10 @@ static int __cmd_report(struct report *rep)
perf_session__fprintf_dsos(session, stdout);

if (dump_trace) {
perf_session__fprintf_nr_events(session, stdout);
evlist__fprintf_nr_events(session->evlist, stdout);
perf_session__fprintf_nr_events(session, stdout,
rep->skip_empty);
evlist__fprintf_nr_events(session->evlist, stdout,
rep->skip_empty);
return 0;
}
}
Expand Down Expand Up @@ -1313,6 +1319,8 @@ int cmd_report(int argc, const char **argv)
"Sort all blocks by 'Sampled Cycles%'"),
OPT_BOOLEAN(0, "disable-order", &report.disable_order,
"Disable raw trace ordering"),
OPT_BOOLEAN(0, "skip-empty", &report.skip_empty,
"Do not display empty (or dummy) events in the output"),
OPT_END()
};
struct perf_data data = {
Expand Down
5 changes: 4 additions & 1 deletion tools/perf/ui/stdio/hist.c
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,8 @@ size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,
return ret;
}

size_t events_stats__fprintf(struct events_stats *stats, FILE *fp)
size_t events_stats__fprintf(struct events_stats *stats, FILE *fp,
bool skip_empty)
{
int i;
size_t ret = 0;
Expand All @@ -908,6 +909,8 @@ size_t events_stats__fprintf(struct events_stats *stats, FILE *fp)
name = perf_event__name(i);
if (!strcmp(name, "UNKNOWN"))
continue;
if (skip_empty && !stats->nr_events[i])
continue;

ret += fprintf(fp, "%16s events: %10d\n", name, stats->nr_events[i]);
}
Expand Down
3 changes: 2 additions & 1 deletion tools/perf/util/events_stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ struct hists_stats {

void events_stats__inc(struct events_stats *stats, u32 type);

size_t events_stats__fprintf(struct events_stats *stats, FILE *fp);
size_t events_stats__fprintf(struct events_stats *stats, FILE *fp,
bool skip_empty);

#endif /* __PERF_EVENTS_STATS_ */
6 changes: 5 additions & 1 deletion tools/perf/util/hist.c
Original file line number Diff line number Diff line change
Expand Up @@ -2676,14 +2676,18 @@ void hist__account_cycles(struct branch_stack *bs, struct addr_location *al,
}
}

size_t evlist__fprintf_nr_events(struct evlist *evlist, FILE *fp)
size_t evlist__fprintf_nr_events(struct evlist *evlist, FILE *fp,
bool skip_empty)
{
struct evsel *pos;
size_t ret = 0;

evlist__for_each_entry(evlist, pos) {
struct hists *hists = evsel__hists(pos);

if (skip_empty && !hists->stats.nr_samples)
continue;

ret += fprintf(fp, "%s stats:\n", evsel__name(pos));
ret += fprintf(fp, "%16s events: %10d\n",
"SAMPLE", hists->stats.nr_samples);
Expand Down
3 changes: 2 additions & 1 deletion tools/perf/util/hist.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ void hists__inc_nr_samples(struct hists *hists, bool filtered);
size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,
int max_cols, float min_pcnt, FILE *fp,
bool ignore_callchains);
size_t evlist__fprintf_nr_events(struct evlist *evlist, FILE *fp);
size_t evlist__fprintf_nr_events(struct evlist *evlist, FILE *fp,
bool skip_empty);

void hists__filter_by_dso(struct hists *hists);
void hists__filter_by_thread(struct hists *hists);
Expand Down
5 changes: 3 additions & 2 deletions tools/perf/util/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -2352,7 +2352,8 @@ size_t perf_session__fprintf_dsos_buildid(struct perf_session *session, FILE *fp
return machines__fprintf_dsos_buildid(&session->machines, fp, skip, parm);
}

size_t perf_session__fprintf_nr_events(struct perf_session *session, FILE *fp)
size_t perf_session__fprintf_nr_events(struct perf_session *session, FILE *fp,
bool skip_empty)
{
size_t ret;
const char *msg = "";
Expand All @@ -2362,7 +2363,7 @@ size_t perf_session__fprintf_nr_events(struct perf_session *session, FILE *fp)

ret = fprintf(fp, "\nAggregated stats:%s\n", msg);

ret += events_stats__fprintf(&session->evlist->stats, fp);
ret += events_stats__fprintf(&session->evlist->stats, fp, skip_empty);
return ret;
}

Expand Down
3 changes: 2 additions & 1 deletion tools/perf/util/session.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ size_t perf_session__fprintf_dsos(struct perf_session *session, FILE *fp);
size_t perf_session__fprintf_dsos_buildid(struct perf_session *session, FILE *fp,
bool (fn)(struct dso *dso, int parm), int parm);

size_t perf_session__fprintf_nr_events(struct perf_session *session, FILE *fp);
size_t perf_session__fprintf_nr_events(struct perf_session *session, FILE *fp,
bool skip_empty);

struct evsel *perf_session__find_first_evtype(struct perf_session *session,
unsigned int type);
Expand Down

0 comments on commit 2775de0

Please sign in to comment.