Skip to contentSkip to conversation

perf srcline: Introduce map__srcline() to make code more compact

tip:perf/urgent tip-bot for Arnaldo Carvalho de Melo 1 participant 1 message Jun 7, 2018 perf events

lore
Share & tools
lore
#0 lore raw
Commit-ID:  e2d88aaa649e65851463426b133d87b61d3accbd
Gitweb:     https://git.kernel.org/tip/e2d88aaa649e65851463426b133d87b61d3accbd
Author:     Arnaldo Carvalho de Melo <[email protected]>
AuthorDate: Mon, 28 May 2018 11:05:20 -0300
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 4 Jun 2018 10:28:52 -0300

perf srcline: Introduce map__srcline() to make code more compact

Replacing a common open coded sequence.

---
 tools/perf/util/map.c  | 12 ++++++----
 tools/perf/util/map.h  |  1 +
 tools/perf/util/sort.c | 60 +++++++++++---------------------------------------
 3 files changed, 22 insertions(+), 51 deletions(-)
tools/perf/util/map.c +8 -4
index 6ae97eda370b..92abc8e248c5 100644
@@ -415,16 +415,20 @@ size_t map__fprintf_dsoname(struct map *map, FILE *fp)
 	return fprintf(fp, "%s", dsoname);
 }
 
+char *map__srcline(struct map *map, u64 addr, struct symbol *sym)
+{
+	if (map == NULL)
+		return SRCLINE_UNKNOWN;
+	return get_srcline(map->dso, map__rip_2objdump(map, addr), sym, true, true, addr);
+}
+
 int map__fprintf_srcline(struct map *map, u64 addr, const char *prefix,
 			 FILE *fp)
 {
-	char *srcline;
 	int ret = 0;
 
 	if (map && map->dso) {
-		srcline = get_srcline(map->dso,
-				      map__rip_2objdump(map, addr), NULL,
-				      true, true, addr);
+		char *srcline = map__srcline(map, addr, NULL);
 		if (srcline != SRCLINE_UNKNOWN)
 			ret = fprintf(fp, "%s%s", prefix, srcline);
 		free_srcline(srcline);
tools/perf/util/map.h +1 -0
index 97e2a063bd65..4cb90f242bed 100644
@@ -169,6 +169,7 @@ static inline void __map__zput(struct map **map)
 int map__overlap(struct map *l, struct map *r);
 size_t map__fprintf(struct map *map, FILE *fp);
 size_t map__fprintf_dsoname(struct map *map, FILE *fp);
+char *map__srcline(struct map *map, u64 addr, struct symbol *sym);
 int map__fprintf_srcline(struct map *map, u64 addr, const char *prefix,
 			 FILE *fp);
 
tools/perf/util/sort.c +13 -47

82 lines not on this page · raw message