lkml.org 
[lkml]   [2020]   [Jan]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v4 2/4] perf util: Validate map/dso/sym before comparing blocks
Date
block_pair_cmp() is a function which is used to compare
two blocks. This patch checks the validity of map, dso and
sym before comparing blocks.

If they are invalid, we will not compare the address because
the address might not make sense.

Another change is it returns cmp if sym->name is not equal.

This patch uses "strcmp(ms_p->sym->name, ms_h->sym->name)" is
because we have checked ms->sym yet, we don't need an additional
checking for bi->sym.

v4:
---
No change.

v3:
---
Separate from original patch.
Return cmp if it's not 0.

Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
---
tools/perf/util/block-info.c | 18 ++++++++++++------
tools/perf/util/block-info.h | 2 +-
2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/tools/perf/util/block-info.c b/tools/perf/util/block-info.c
index f0f38bdd496a..2d0929aa0a65 100644
--- a/tools/perf/util/block-info.c
+++ b/tools/perf/util/block-info.c
@@ -476,18 +476,24 @@ float block_info__total_cycles_percent(struct hist_entry *he)
return 0.0;
}

-int block_pair_cmp(struct hist_entry *a, struct hist_entry *b)
+int block_pair_cmp(struct hist_entry *pair, struct hist_entry *he)
{
- struct block_info *bi_a = a->block_info;
- struct block_info *bi_b = b->block_info;
+ 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 (!bi_a->sym || !bi_b->sym)
+ 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(bi_a->sym->name, bi_b->sym->name);
+ cmp = strcmp(ms_p->sym->name, ms_h->sym->name);
+ if (cmp)
+ return cmp;

- if ((!cmp) && (bi_a->start == bi_b->start) && (bi_a->end == bi_b->end))
+ 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 4fa91eeae92e..bfa22c59195d 100644
--- a/tools/perf/util/block-info.h
+++ b/tools/perf/util/block-info.h
@@ -76,6 +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 *a, struct hist_entry *b);
+int block_pair_cmp(struct hist_entry *pair, struct hist_entry *he);

#endif /* __PERF_BLOCK_H */
--
2.17.1
\
 
 \ /
  Last update: 2020-01-16 03:56    [W:0.081 / U:3.684 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site