aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNamhyung Kim <namhyung@kernel.org>2014-04-21 20:47:25 -0400
committerJiri Olsa <jolsa@kernel.org>2014-04-24 10:29:20 -0400
commit58c311da9cec97d7a665156a726bd1653384c65c (patch)
treea5ec87aa5cfb21347e6e8f1379cca9cdf284319a
parenta81fef347b32dea2b31275826afe1c93fa0d2d54 (diff)
perf report: Count number of entries separately
The hists->nr_entries is counted in multiple places so that they can confuse readers of the code. This is a preparation of later change and do not intend any functional difference. Note that report__collapse_hists() now changed to return nothing since its return value (nr_samples) is only for checking if there's any data in the input file and this can be acheived by checking ->nr_entries. Signed-off-by: Namhyung Kim <namhyung@kernel.org> Link: http://lkml.kernel.org/r/1398327843-31845-2-git-send-email-namhyung@kernel.org Signed-off-by: Jiri Olsa <jolsa@kernel.org>
-rw-r--r--tools/perf/builtin-report.c42
1 files changed, 22 insertions, 20 deletions
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 76e2bb6cf571..aed52036468d 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -57,6 +57,7 @@ struct report {
57 const char *cpu_list; 57 const char *cpu_list;
58 const char *symbol_filter_str; 58 const char *symbol_filter_str;
59 float min_percent; 59 float min_percent;
60 u64 nr_entries;
60 DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS); 61 DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
61}; 62};
62 63
@@ -75,6 +76,17 @@ static int report__config(const char *var, const char *value, void *cb)
75 return perf_default_config(var, value, cb); 76 return perf_default_config(var, value, cb);
76} 77}
77 78
79static void report__inc_stats(struct report *rep, struct hist_entry *he)
80{
81 /*
82 * The @he is either of a newly created one or an existing one
83 * merging current sample. We only want to count a new one so
84 * checking ->nr_events being 1.
85 */
86 if (he->stat.nr_events == 1)
87 rep->nr_entries++;
88}
89
78static int report__add_mem_hist_entry(struct report *rep, struct addr_location *al, 90static int report__add_mem_hist_entry(struct report *rep, struct addr_location *al,
79 struct perf_sample *sample, struct perf_evsel *evsel) 91 struct perf_sample *sample, struct perf_evsel *evsel)
80{ 92{
@@ -121,6 +133,8 @@ static int report__add_mem_hist_entry(struct report *rep, struct addr_location *
121 goto out; 133 goto out;
122 } 134 }
123 135
136 report__inc_stats(rep, he);
137
124 evsel->hists.stats.total_period += cost; 138 evsel->hists.stats.total_period += cost;
125 hists__inc_nr_events(&evsel->hists, PERF_RECORD_SAMPLE); 139 hists__inc_nr_events(&evsel->hists, PERF_RECORD_SAMPLE);
126 if (!he->filtered) 140 if (!he->filtered)
@@ -176,6 +190,8 @@ static int report__add_branch_hist_entry(struct report *rep, struct addr_locatio
176 goto out; 190 goto out;
177 } 191 }
178 192
193 report__inc_stats(rep, he);
194
179 evsel->hists.stats.total_period += 1; 195 evsel->hists.stats.total_period += 1;
180 hists__inc_nr_events(&evsel->hists, PERF_RECORD_SAMPLE); 196 hists__inc_nr_events(&evsel->hists, PERF_RECORD_SAMPLE);
181 if (!he->filtered) 197 if (!he->filtered)
@@ -212,6 +228,8 @@ static int report__add_hist_entry(struct report *rep, struct perf_evsel *evsel,
212 if (ui__has_annotation()) 228 if (ui__has_annotation())
213 err = hist_entry__inc_addr_samples(he, evsel->idx, al->addr); 229 err = hist_entry__inc_addr_samples(he, evsel->idx, al->addr);
214 230
231 report__inc_stats(rep, he);
232
215 evsel->hists.stats.total_period += sample->period; 233 evsel->hists.stats.total_period += sample->period;
216 if (!he->filtered) 234 if (!he->filtered)
217 evsel->hists.stats.nr_non_filtered_samples++; 235 evsel->hists.stats.nr_non_filtered_samples++;
@@ -486,24 +504,12 @@ static int report__browse_hists(struct report *rep)
486 return ret; 504 return ret;
487} 505}
488 506
489static u64 report__collapse_hists(struct report *rep) 507static void report__collapse_hists(struct report *rep)
490{ 508{
491 struct ui_progress prog; 509 struct ui_progress prog;
492 struct perf_evsel *pos; 510 struct perf_evsel *pos;
493 u64 nr_samples = 0;
494 /*
495 * Count number of histogram entries to use when showing progress,
496 * reusing nr_samples variable.
497 */
498 evlist__for_each(rep->session->evlist, pos)
499 nr_samples += pos->hists.nr_entries;
500 511
501 ui_progress__init(&prog, nr_samples, "Merging related events..."); 512 ui_progress__init(&prog, rep->nr_entries, "Merging related events...");
502 /*
503 * Count total number of samples, will be used to check if this
504 * session had any.
505 */
506 nr_samples = 0;
507 513
508 evlist__for_each(rep->session->evlist, pos) { 514 evlist__for_each(rep->session->evlist, pos) {
509 struct hists *hists = &pos->hists; 515 struct hists *hists = &pos->hists;
@@ -512,7 +518,6 @@ static u64 report__collapse_hists(struct report *rep)
512 hists->symbol_filter_str = rep->symbol_filter_str; 518 hists->symbol_filter_str = rep->symbol_filter_str;
513 519
514 hists__collapse_resort(hists, &prog); 520 hists__collapse_resort(hists, &prog);
515 nr_samples += hists->stats.nr_events[PERF_RECORD_SAMPLE];
516 521
517 /* Non-group events are considered as leader */ 522 /* Non-group events are considered as leader */
518 if (symbol_conf.event_group && 523 if (symbol_conf.event_group &&
@@ -525,14 +530,11 @@ static u64 report__collapse_hists(struct report *rep)
525 } 530 }
526 531
527 ui_progress__finish(); 532 ui_progress__finish();
528
529 return nr_samples;
530} 533}
531 534
532static int __cmd_report(struct report *rep) 535static int __cmd_report(struct report *rep)
533{ 536{
534 int ret; 537 int ret;
535 u64 nr_samples;
536 struct perf_session *session = rep->session; 538 struct perf_session *session = rep->session;
537 struct perf_evsel *pos; 539 struct perf_evsel *pos;
538 struct perf_data_file *file = session->file; 540 struct perf_data_file *file = session->file;
@@ -572,12 +574,12 @@ static int __cmd_report(struct report *rep)
572 } 574 }
573 } 575 }
574 576
575 nr_samples = report__collapse_hists(rep); 577 report__collapse_hists(rep);
576 578
577 if (session_done()) 579 if (session_done())
578 return 0; 580 return 0;
579 581
580 if (nr_samples == 0) { 582 if (rep->nr_entries == 0) {
581 ui__error("The %s file has no samples!\n", file->path); 583 ui__error("The %s file has no samples!\n", file->path);
582 return 0; 584 return 0;
583 } 585 }