aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2018-05-28 10:05:20 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2018-06-04 09:28:52 -0400
commite2d88aaa649e65851463426b133d87b61d3accbd (patch)
treec0cc4ebd2f25f237e668b12f2ed561beba3974a0
parent982d410bc6b405a75086236d3c1da1f18c40d6dd (diff)
perf srcline: Introduce map__srcline() to make code more compact
Replacing a common open coded sequence. Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Wang Nan <wangnan0@huawei.com> Link: https://lkml.kernel.org/n/tip-2d7d1nzd3ksqornloqeer99r@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/util/map.c12
-rw-r--r--tools/perf/util/map.h1
-rw-r--r--tools/perf/util/sort.c60
3 files changed, 22 insertions, 51 deletions
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
index 6ae97eda370b..92abc8e248c5 100644
--- a/tools/perf/util/map.c
+++ b/tools/perf/util/map.c
@@ -415,16 +415,20 @@ size_t map__fprintf_dsoname(struct map *map, FILE *fp)
415 return fprintf(fp, "%s", dsoname); 415 return fprintf(fp, "%s", dsoname);
416} 416}
417 417
418char *map__srcline(struct map *map, u64 addr, struct symbol *sym)
419{
420 if (map == NULL)
421 return SRCLINE_UNKNOWN;
422 return get_srcline(map->dso, map__rip_2objdump(map, addr), sym, true, true, addr);
423}
424
418int map__fprintf_srcline(struct map *map, u64 addr, const char *prefix, 425int map__fprintf_srcline(struct map *map, u64 addr, const char *prefix,
419 FILE *fp) 426 FILE *fp)
420{ 427{
421 char *srcline;
422 int ret = 0; 428 int ret = 0;
423 429
424 if (map && map->dso) { 430 if (map && map->dso) {
425 srcline = get_srcline(map->dso, 431 char *srcline = map__srcline(map, addr, NULL);
426 map__rip_2objdump(map, addr), NULL,
427 true, true, addr);
428 if (srcline != SRCLINE_UNKNOWN) 432 if (srcline != SRCLINE_UNKNOWN)
429 ret = fprintf(fp, "%s%s", prefix, srcline); 433 ret = fprintf(fp, "%s%s", prefix, srcline);
430 free_srcline(srcline); 434 free_srcline(srcline);
diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h
index 97e2a063bd65..4cb90f242bed 100644
--- a/tools/perf/util/map.h
+++ b/tools/perf/util/map.h
@@ -169,6 +169,7 @@ static inline void __map__zput(struct map **map)
169int map__overlap(struct map *l, struct map *r); 169int map__overlap(struct map *l, struct map *r);
170size_t map__fprintf(struct map *map, FILE *fp); 170size_t map__fprintf(struct map *map, FILE *fp);
171size_t map__fprintf_dsoname(struct map *map, FILE *fp); 171size_t map__fprintf_dsoname(struct map *map, FILE *fp);
172char *map__srcline(struct map *map, u64 addr, struct symbol *sym);
172int map__fprintf_srcline(struct map *map, u64 addr, const char *prefix, 173int map__fprintf_srcline(struct map *map, u64 addr, const char *prefix,
173 FILE *fp); 174 FILE *fp);
174 175
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
index 4058ade352a5..71096dbfeb88 100644
--- a/tools/perf/util/sort.c
+++ b/tools/perf/util/sort.c
@@ -333,13 +333,7 @@ struct sort_entry sort_sym = {
333 333
334char *hist_entry__get_srcline(struct hist_entry *he) 334char *hist_entry__get_srcline(struct hist_entry *he)
335{ 335{
336 struct map *map = he->ms.map; 336 return map__srcline(he->ms.map, he->ip, he->ms.sym);
337
338 if (!map)
339 return SRCLINE_UNKNOWN;
340
341 return get_srcline(map->dso, map__rip_2objdump(map, he->ip),
342 he->ms.sym, true, true, he->ip);
343} 337}
344 338
345static int64_t 339static int64_t
@@ -375,28 +369,14 @@ static int64_t
375sort__srcline_from_cmp(struct hist_entry *left, struct hist_entry *right) 369sort__srcline_from_cmp(struct hist_entry *left, struct hist_entry *right)
376{ 370{
377 if (!left->branch_info->srcline_from) { 371 if (!left->branch_info->srcline_from) {
378 struct map *map = left->branch_info->from.map; 372 left->branch_info->srcline_from = map__srcline(left->branch_info->from.map,
379 if (!map) 373 left->branch_info->from.al_addr,
380 left->branch_info->srcline_from = SRCLINE_UNKNOWN; 374 left->branch_info->from.sym);
381 else
382 left->branch_info->srcline_from = get_srcline(map->dso,
383 map__rip_2objdump(map,
384 left->branch_info->from.al_addr),
385 left->branch_info->from.sym,
386 true, true,
387 left->branch_info->from.al_addr);
388 } 375 }
389 if (!right->branch_info->srcline_from) { 376 if (!right->branch_info->srcline_from) {
390 struct map *map = right->branch_info->from.map; 377 right->branch_info->srcline_from = map__srcline(right->branch_info->from.map,
391 if (!map) 378 right->branch_info->from.al_addr,
392 right->branch_info->srcline_from = SRCLINE_UNKNOWN; 379 right->branch_info->from.sym);
393 else
394 right->branch_info->srcline_from = get_srcline(map->dso,
395 map__rip_2objdump(map,
396 right->branch_info->from.al_addr),
397 right->branch_info->from.sym,
398 true, true,
399 right->branch_info->from.al_addr);
400 } 380 }
401 return strcmp(right->branch_info->srcline_from, left->branch_info->srcline_from); 381 return strcmp(right->branch_info->srcline_from, left->branch_info->srcline_from);
402} 382}
@@ -420,28 +400,14 @@ static int64_t
420sort__srcline_to_cmp(struct hist_entry *left, struct hist_entry *right) 400sort__srcline_to_cmp(struct hist_entry *left, struct hist_entry *right)
421{ 401{
422 if (!left->branch_info->srcline_to) { 402 if (!left->branch_info->srcline_to) {
423 struct map *map = left->branch_info->to.map; 403 left->branch_info->srcline_to = map__srcline(left->branch_info->to.map,
424 if (!map) 404 left->branch_info->to.al_addr,
425 left->branch_info->srcline_to = SRCLINE_UNKNOWN; 405 left->branch_info->to.sym);
426 else
427 left->branch_info->srcline_to = get_srcline(map->dso,
428 map__rip_2objdump(map,
429 left->branch_info->to.al_addr),
430 left->branch_info->from.sym,
431 true, true,
432 left->branch_info->to.al_addr);
433 } 406 }
434 if (!right->branch_info->srcline_to) { 407 if (!right->branch_info->srcline_to) {
435 struct map *map = right->branch_info->to.map; 408 right->branch_info->srcline_to = map__srcline(right->branch_info->to.map,
436 if (!map) 409 right->branch_info->to.al_addr,
437 right->branch_info->srcline_to = SRCLINE_UNKNOWN; 410 right->branch_info->to.sym);
438 else
439 right->branch_info->srcline_to = get_srcline(map->dso,
440 map__rip_2objdump(map,
441 right->branch_info->to.al_addr),
442 right->branch_info->to.sym,
443 true, true,
444 right->branch_info->to.al_addr);
445 } 411 }
446 return strcmp(right->branch_info->srcline_to, left->branch_info->srcline_to); 412 return strcmp(right->branch_info->srcline_to, left->branch_info->srcline_to);
447} 413}