perf tools: Introduce hists__inc_nr_samples()
authorNamhyung Kim <namhyung@kernel.org>
Wed, 28 May 2014 05:12:18 +0000 (14:12 +0900)
committerJiri Olsa <jolsa@kernel.org>
Sun, 1 Jun 2014 12:34:55 +0000 (14:34 +0200)
There're some duplicate code for counting number of samples.  Add
hists__inc_nr_samples() and reuse it.

Suggested-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Link: http://lkml.kernel.org/r/1401335910-16832-2-git-send-email-namhyung@kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
tools/perf/builtin-annotate.c
tools/perf/builtin-report.c
tools/perf/builtin-sched.c
tools/perf/builtin-top.c
tools/perf/tests/hists_filter.c
tools/perf/util/hist.c
tools/perf/util/hist.h

index d30d2c2e2a7a30d79846afde2487656aa8cdd92f..bf52461a88bd2a45b26c393b9f7cfc5cf8370fd0 100644 (file)
@@ -70,7 +70,7 @@ static int perf_evsel__add_sample(struct perf_evsel *evsel,
                return -ENOMEM;
 
        ret = hist_entry__inc_addr_samples(he, evsel->idx, al->addr);
-       hists__inc_nr_events(&evsel->hists, PERF_RECORD_SAMPLE);
+       hists__inc_nr_samples(&evsel->hists, true);
        return ret;
 }
 
index bc0eec1ce4beaba37509f731c79f8e1855796c08..4a3b84dd4f41b7033293bc46119068d363307ca6 100644 (file)
@@ -92,9 +92,7 @@ static void report__inc_stats(struct report *rep, struct hist_entry *he)
         * counted in perf_session_deliver_event().  The dump_trace
         * requires this info is ready before going to the output tree.
         */
-       hists__inc_nr_events(he->hists, PERF_RECORD_SAMPLE);
-       if (!he->filtered)
-               he->hists->stats.nr_non_filtered_samples++;
+       hists__inc_nr_samples(he->hists, he->filtered);
 }
 
 static int report__add_mem_hist_entry(struct report *rep, struct addr_location *al,
index d7176830b9b2fb789a61565acf113987ac59fd99..c38d06c047757281b03992522723af980b54412b 100644 (file)
@@ -1428,7 +1428,7 @@ static int perf_sched__process_tracepoint_sample(struct perf_tool *tool __maybe_
        int err = 0;
 
        evsel->hists.stats.total_period += sample->period;
-       hists__inc_nr_events(&evsel->hists, PERF_RECORD_SAMPLE);
+       hists__inc_nr_samples(&evsel->hists, true);
 
        if (evsel->handler != NULL) {
                tracepoint_handler f = evsel->handler;
index 5b389ce4cd15d03b656185f83d58f10aca94fd81..51309264d2104a75d124adb170f07370eeeafe79 100644 (file)
@@ -252,10 +252,7 @@ static struct hist_entry *perf_evsel__add_hist_entry(struct perf_evsel *evsel,
        if (he == NULL)
                return NULL;
 
-       hists__inc_nr_events(&evsel->hists, PERF_RECORD_SAMPLE);
-       if (!he->filtered)
-               evsel->hists.stats.nr_non_filtered_samples++;
-
+       hists__inc_nr_samples(&evsel->hists, he->filtered);
        return he;
 }
 
index c5ba924a3581cbda11e86b4627025e7f1a53a227..0a71ef4b91583c4c8a667d314f9a0976ac5b4fc9 100644 (file)
@@ -85,9 +85,7 @@ static int add_hist_entries(struct perf_evlist *evlist, struct machine *machine)
                        fake_samples[i].map = al.map;
                        fake_samples[i].sym = al.sym;
 
-                       hists__inc_nr_events(he->hists, PERF_RECORD_SAMPLE);
-                       if (!he->filtered)
-                               he->hists->stats.nr_non_filtered_samples++;
+                       hists__inc_nr_samples(he->hists, he->filtered);
                }
        }
 
index b262b44b7a656d8dca4fcab7488e43e3c49ebb8c..5943ba60f19335ccf49b7e2916327e3613414c75 100644 (file)
@@ -800,6 +800,13 @@ void hists__inc_nr_events(struct hists *hists, u32 type)
        events_stats__inc(&hists->stats, type);
 }
 
+void hists__inc_nr_samples(struct hists *hists, bool filtered)
+{
+       events_stats__inc(&hists->stats, PERF_RECORD_SAMPLE);
+       if (!filtered)
+               hists->stats.nr_non_filtered_samples++;
+}
+
 static struct hist_entry *hists__add_dummy_entry(struct hists *hists,
                                                 struct hist_entry *pair)
 {
index a8418d19808dc29e50cc683ea6da088062af55a4..03ae1dbb1b15745da68470ad3a065a34fddeeabd 100644 (file)
@@ -119,6 +119,7 @@ u64 hists__total_period(struct hists *hists);
 void hists__reset_stats(struct hists *hists);
 void hists__inc_stats(struct hists *hists, struct hist_entry *h);
 void hists__inc_nr_events(struct hists *hists, u32 type);
+void hists__inc_nr_samples(struct hists *hists, bool filtered);
 void events_stats__inc(struct events_stats *stats, u32 type);
 size_t events_stats__fprintf(struct events_stats *stats, FILE *fp);