[PATCH/RFC 10/16] perf hist: Add events_stats__add() and hists__add_stats()

From: Namhyung Kim
Date: Thu Dec 10 2015 - 02:54:24 EST


These two functions are to update event and hists stats. They'll be
used by multi threads to update local stats in the later patch.

Signed-off-by: Namhyung Kim <namhyung@xxxxxxxxxx>
---
tools/perf/util/hist.c | 23 +++++++++++++++++++++++
tools/perf/util/hist.h | 6 ++++++
2 files changed, 29 insertions(+)

diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index a12e5022fe04..08396a7fea23 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -1347,6 +1347,29 @@ void events_stats__inc(struct events_stats *stats, u32 type)
++stats->nr_events[type];
}

+void events_stats__add(struct events_stats *dst, struct events_stats *src)
+{
+ int i;
+
+#define ADD(_field) dst->_field += src->_field
+
+ ADD(total_period);
+ ADD(total_non_filtered_period);
+ ADD(total_lost);
+ ADD(total_invalid_chains);
+ ADD(nr_non_filtered_samples);
+ ADD(nr_lost_warned);
+ ADD(nr_unknown_events);
+ ADD(nr_invalid_chains);
+ ADD(nr_unknown_id);
+ ADD(nr_unprocessable_samples);
+
+ for (i = 0; i < PERF_RECORD_HEADER_MAX; i++)
+ ADD(nr_events[i]);
+
+#undef ADD
+}
+
void hists__inc_nr_events(struct hists *hists, u32 type)
{
events_stats__inc(&hists->stats, type);
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h
index 670720ef8acd..725afce73738 100644
--- a/tools/perf/util/hist.h
+++ b/tools/perf/util/hist.h
@@ -141,8 +141,14 @@ 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);
+void events_stats__add(struct events_stats *dst, struct events_stats *src);
size_t events_stats__fprintf(struct events_stats *stats, FILE *fp);

+static inline void hists__add_stats(struct hists *dst, struct hists *src)
+{
+ events_stats__add(&dst->stats, &src->stats);
+}
+
size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,
int max_cols, float min_pcnt, FILE *fp);
size_t perf_evlist__fprintf_nr_events(struct perf_evlist *evlist, FILE *fp);
--
2.6.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/