[PATCH 07/14] perf diff: Add callback to hists__match/hists__link functions

From: Jiri Olsa
Date: Wed Nov 28 2012 - 08:56:47 EST


It's possible different users of hists__match/hists__link will need
specific processing of matching hists_entry data.

Adding callback to hists__match/hists__link functions to allow that.

Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx>
Cc: Arnaldo Carvalho de Melo <acme@xxxxxxxxxxxxxxxxxx>
Cc: Peter Zijlstra <a.p.zijlstra@xxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxx>
Cc: Paul Mackerras <paulus@xxxxxxxxx>
Cc: Corey Ashford <cjashfor@xxxxxxxxxxxxxxxxxx>
Cc: Frederic Weisbecker <fweisbec@xxxxxxxxx>
Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
---
tools/perf/builtin-diff.c | 11 +++++++++--
tools/perf/util/hist.c | 24 +++++++++++++++++-------
tools/perf/util/hist.h | 8 ++++++--
3 files changed, 32 insertions(+), 11 deletions(-)

diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c
index d869029..6361b55 100644
--- a/tools/perf/builtin-diff.c
+++ b/tools/perf/builtin-diff.c
@@ -472,14 +472,21 @@ static void hists__compute_resort(struct hists *hists)
hists->entries = tmp;
}

+static int match_cb(struct hist_entry *a, struct hist_entry *b,
+ void *data __maybe_unused)
+{
+ hist__entry_add_pair(a, b);
+ return 0;
+}
+
static void hists__process(struct hists *old, struct hists *new)
{
- hists__match(new, old);
+ hists__match(new, old, match_cb, NULL);

if (show_baseline_only)
hists__baseline_only(new);
else
- hists__link(new, old);
+ hists__link(new, old, match_cb, NULL);

if (sort_compute) {
hists__precompute(new);
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index cb17e2a..0c5843b 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -775,18 +775,24 @@ static struct hist_entry *hists__find_entry(struct hists *hists,
/*
* Look for pairs to link to the leader buckets (hist_entries):
*/
-void hists__match(struct hists *leader, struct hists *other)
+int hists__match(struct hists *leader, struct hists *other,
+ hists__entry_cb cb, void *data)
{
struct rb_node *nd;
struct hist_entry *pos, *pair;
+ int ret = 0;

- for (nd = rb_first(&leader->entries); nd; nd = rb_next(nd)) {
+ BUG_ON(!cb);
+
+ for (nd = rb_first(&leader->entries); nd && !ret; nd = rb_next(nd)) {
pos = rb_entry(nd, struct hist_entry, rb_node);
pair = hists__find_entry(other, pos);

if (pair)
- hist__entry_add_pair(pos, pair);
+ ret = cb(pos, pair, data);
}
+
+ return ret;
}

/*
@@ -794,21 +800,25 @@ void hists__match(struct hists *leader, struct hists *other)
* we find them, just add a dummy entry on the leader hists, with period=0,
* nr_events=0, to serve as the list header.
*/
-int hists__link(struct hists *leader, struct hists *other)
+int hists__link(struct hists *leader, struct hists *other,
+ hists__entry_cb cb, void *data)
{
struct rb_node *nd;
struct hist_entry *pos, *pair;
+ int ret = 0;

- for (nd = rb_first(&other->entries); nd; nd = rb_next(nd)) {
+ BUG_ON(!cb);
+
+ for (nd = rb_first(&other->entries); nd && !ret; nd = rb_next(nd)) {
pos = rb_entry(nd, struct hist_entry, rb_node);

if (!hist_entry__has_pairs(pos)) {
pair = hists__add_dummy_entry(leader, pos);
if (pair == NULL)
return -1;
- hist__entry_add_pair(pair, pos);
+ ret = cb(pos, pair, data);
}
}

- return 0;
+ return ret;
}
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h
index 7f5cce8..eb4dc83 100644
--- a/tools/perf/util/hist.h
+++ b/tools/perf/util/hist.h
@@ -115,8 +115,12 @@ bool hists__new_col_len(struct hists *self, enum hist_column col, u16 len);
void hists__reset_col_len(struct hists *hists);
void hists__calc_col_len(struct hists *hists, struct hist_entry *he);

-void hists__match(struct hists *leader, struct hists *other);
-int hists__link(struct hists *leader, struct hists *other);
+typedef int (hists__entry_cb)(struct hist_entry *a, struct hist_entry *b,
+ void *data);
+int hists__match(struct hists *leader, struct hists *other,
+ hists__entry_cb cb, void *data);
+int hists__link(struct hists *leader, struct hists *other,
+ hists__entry_cb cb, void *data);

struct perf_hpp {
char *buf;
--
1.7.11.7

--
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/