[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20200106194525.12228-1-yao.jin@linux.intel.com>
Date: Tue, 7 Jan 2020 03:45:23 +0800
From: Jin Yao <yao.jin@...ux.intel.com>
To: acme@...nel.org, jolsa@...nel.org, peterz@...radead.org,
mingo@...hat.com, alexander.shishkin@...ux.intel.com
Cc: Linux-kernel@...r.kernel.org, ak@...ux.intel.com,
kan.liang@...el.com, yao.jin@...el.com,
Jin Yao <yao.jin@...ux.intel.com>
Subject: [PATCH v2 1/3] perf util: Move block_pair_cmp to block-info
block_pair_cmp() is a function which is used to compare
two blocks. Moving it from builtin-diff.c to block-info.c
to let it be used by other builtins.
In block_pair_cmp, there is a minor change. It checks valid
for map, dso and sym first. If they are invalid, we will not
compare the address because the address might not make sense.
v2:
---
New patch created in v2
Signed-off-by: Jin Yao <yao.jin@...ux.intel.com>
---
tools/perf/builtin-diff.c | 17 -----------------
tools/perf/util/block-info.c | 23 +++++++++++++++++++++++
tools/perf/util/block-info.h | 2 ++
3 files changed, 25 insertions(+), 17 deletions(-)
diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c
index f8b6ae557d8b..5ff1e21082cb 100644
--- a/tools/perf/builtin-diff.c
+++ b/tools/perf/builtin-diff.c
@@ -572,23 +572,6 @@ static void init_block_hist(struct block_hist *bh)
bh->valid = true;
}
-static int block_pair_cmp(struct hist_entry *a, struct hist_entry *b)
-{
- struct block_info *bi_a = a->block_info;
- struct block_info *bi_b = b->block_info;
- int cmp;
-
- if (!bi_a->sym || !bi_b->sym)
- return -1;
-
- cmp = strcmp(bi_a->sym->name, bi_b->sym->name);
-
- if ((!cmp) && (bi_a->start == bi_b->start) && (bi_a->end == bi_b->end))
- return 0;
-
- return -1;
-}
-
static struct hist_entry *get_block_pair(struct hist_entry *he,
struct hists *hists_pair)
{
diff --git a/tools/perf/util/block-info.c b/tools/perf/util/block-info.c
index c4b030bf6ec2..18a445938681 100644
--- a/tools/perf/util/block-info.c
+++ b/tools/perf/util/block-info.c
@@ -475,3 +475,26 @@ float block_info__total_cycles_percent(struct hist_entry *he)
return 0.0;
}
+
+int block_pair_cmp(struct hist_entry *pair, struct hist_entry *he)
+{
+ struct block_info *bi_p = pair->block_info;
+ struct block_info *bi_h = he->block_info;
+ struct map_symbol *ms_p = &pair->ms;
+ struct map_symbol *ms_h = &he->ms;
+ int cmp;
+
+ if (!ms_p->map || !ms_p->map->dso || !ms_p->sym ||
+ !ms_h->map || !ms_h->map->dso || !ms_h->sym) {
+ return -1;
+ }
+
+ cmp = strcmp(ms_p->sym->name, ms_h->sym->name);
+ if (cmp)
+ return -1;
+
+ if ((bi_p->start == bi_h->start) && (bi_p->end == bi_h->end))
+ return 0;
+
+ return -1;
+}
diff --git a/tools/perf/util/block-info.h b/tools/perf/util/block-info.h
index bef0d75e9819..bfa22c59195d 100644
--- a/tools/perf/util/block-info.h
+++ b/tools/perf/util/block-info.h
@@ -76,4 +76,6 @@ int report__browse_block_hists(struct block_hist *bh, float min_percent,
float block_info__total_cycles_percent(struct hist_entry *he);
+int block_pair_cmp(struct hist_entry *pair, struct hist_entry *he);
+
#endif /* __PERF_BLOCK_H */
--
2.17.1
Powered by blists - more mailing lists