Skip to contentSkip to conversation

perf script: Move map__fprintf_srccode() to near its only user

tip: perf/urgent tip-bot2 for Arnaldo Carvalho de Melo 1 participant 1 message Nov 29, 2019 1 message not in the archive perf events

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

tip-bot2 for Arnaldo Carvalho de Melo

author merge bot Applied
#1 lore raw

The following commit has been merged into the perf/urgent branch of tip:

Commit-ID:     540a63ea30c86b2785769b9ae713efbfa7547fde
Gitweb:        https://git.kernel.org/tip/540a63ea30c86b2785769b9ae713efbfa7547fde
Author:        Arnaldo Carvalho de Melo <[email protected]>
AuthorDate:    Fri, 22 Nov 2019 12:39:06 -03:00
Committer:     Arnaldo Carvalho de Melo <[email protected]>
CommitterDate: Tue, 26 Nov 2019 11:07:45 -03:00

perf script: Move map__fprintf_srccode() to near its only user

No need to have it elsewhere.

---
 tools/perf/builtin-script.c | 42 ++++++++++++++++++++++++++++++++++-
 tools/perf/util/map.c       | 45 +------------------------------------
 tools/perf/util/map.h       |  5 +----
 3 files changed, 42 insertions(+), 50 deletions(-)
tools/perf/builtin-script.c +42 -0
index f86c5cc..7b2f092 100644
@@ -932,6 +932,48 @@ static int grab_bb(u8 *buffer, u64 start, u64 end,
 	return len;
 }
 
+static int map__fprintf_srccode(struct map *map, u64 addr, FILE *fp, struct srccode_state *state)
+{
+	char *srcfile;
+	int ret = 0;
+	unsigned line;
+	int len;
+	char *srccode;
+
+	if (!map || !map->dso)
+		return 0;
+	srcfile = get_srcline_split(map->dso,
+				    map__rip_2objdump(map, addr),
+				    &line);
+	if (!srcfile)
+		return 0;
+
+	/* Avoid redundant printing */
+	if (state &&
+	    state->srcfile &&
+	    !strcmp(state->srcfile, srcfile) &&
+	    state->line == line) {
+		free(srcfile);
+		return 0;
+	}
+
+	srccode = find_sourceline(srcfile, line, &len);
+	if (!srccode)
+		goto out_free_line;
+
+	ret = fprintf(fp, "|%-8d %.*s", line, len, srccode);
+
+	if (state) {
+		state->srcfile = srcfile;
+		state->line = line;
+	}
+	return ret;
+
+out_free_line:
+	free(srcfile);
+	return ret;
+}
+
 static int print_srccode(struct thread *thread, u8 cpumode, uint64_t addr)
 {
 	struct addr_location al;
tools/perf/util/map.c +0 -45

51 lines not on this page · raw message

tools/perf/util/map.h +0 -5
index 5e88998..1f110b5 100644
@@ -138,11 +138,6 @@ 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);
 
-struct srccode_state;
-
-int map__fprintf_srccode(struct map *map, u64 addr,
-			 FILE *fp, struct srccode_state *state);
-
 int map__load(struct map *map);
 struct symbol *map__find_symbol(struct map *map, u64 addr);
 struct symbol *map__find_symbol_by_name(struct map *map, const char *name);