提交 85c116a6 编写于 作者: A Andi Kleen 提交者: Arnaldo Carvalho de Melo

perf callchain: Make get_srcline fall back to sym+offset

When the source line is not found fall back to sym + offset.  This is
generally much more useful than a raw address.

For this we need to pass in the symbol from the caller.

For some callers it's awkward to compute, so we stay at the old
behaviour.
Signed-off-by: NAndi Kleen <ak@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lkml.kernel.org/r/1415844328-4884-10-git-send-email-andi@firstfloor.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
上级 aaba4e12
...@@ -1192,7 +1192,7 @@ static int symbol__get_source_line(struct symbol *sym, struct map *map, ...@@ -1192,7 +1192,7 @@ static int symbol__get_source_line(struct symbol *sym, struct map *map,
goto next; goto next;
offset = start + i; offset = start + i;
src_line->path = get_srcline(map->dso, offset); src_line->path = get_srcline(map->dso, offset, NULL, false);
insert_source_line(&tmp_root, src_line); insert_source_line(&tmp_root, src_line);
next: next:
......
...@@ -819,7 +819,8 @@ char *callchain_list__sym_name(struct callchain_list *cl, ...@@ -819,7 +819,8 @@ char *callchain_list__sym_name(struct callchain_list *cl,
cl->ms.map && !cl->srcline) cl->ms.map && !cl->srcline)
cl->srcline = get_srcline(cl->ms.map->dso, cl->srcline = get_srcline(cl->ms.map->dso,
map__rip_2objdump(cl->ms.map, map__rip_2objdump(cl->ms.map,
cl->ip)); cl->ip),
cl->ms.sym, false);
if (cl->srcline) if (cl->srcline)
printed = scnprintf(bf, bfsize, "%s %s", printed = scnprintf(bf, bfsize, "%s %s",
cl->ms.sym->name, cl->srcline); cl->ms.sym->name, cl->srcline);
......
...@@ -360,7 +360,7 @@ int map__fprintf_srcline(struct map *map, u64 addr, const char *prefix, ...@@ -360,7 +360,7 @@ int map__fprintf_srcline(struct map *map, u64 addr, const char *prefix,
if (map && map->dso) { if (map && map->dso) {
srcline = get_srcline(map->dso, srcline = get_srcline(map->dso,
map__rip_2objdump(map, addr)); map__rip_2objdump(map, addr), NULL, true);
if (srcline != SRCLINE_UNKNOWN) if (srcline != SRCLINE_UNKNOWN)
ret = fprintf(fp, "%s%s", prefix, srcline); ret = fprintf(fp, "%s%s", prefix, srcline);
free_srcline(srcline); free_srcline(srcline);
......
...@@ -291,7 +291,8 @@ sort__srcline_cmp(struct hist_entry *left, struct hist_entry *right) ...@@ -291,7 +291,8 @@ sort__srcline_cmp(struct hist_entry *left, struct hist_entry *right)
else { else {
struct map *map = left->ms.map; struct map *map = left->ms.map;
left->srcline = get_srcline(map->dso, left->srcline = get_srcline(map->dso,
map__rip_2objdump(map, left->ip)); map__rip_2objdump(map, left->ip),
left->ms.sym, true);
} }
} }
if (!right->srcline) { if (!right->srcline) {
...@@ -300,7 +301,8 @@ sort__srcline_cmp(struct hist_entry *left, struct hist_entry *right) ...@@ -300,7 +301,8 @@ sort__srcline_cmp(struct hist_entry *left, struct hist_entry *right)
else { else {
struct map *map = right->ms.map; struct map *map = right->ms.map;
right->srcline = get_srcline(map->dso, right->srcline = get_srcline(map->dso,
map__rip_2objdump(map, right->ip)); map__rip_2objdump(map, right->ip),
right->ms.sym, true);
} }
} }
return strcmp(right->srcline, left->srcline); return strcmp(right->srcline, left->srcline);
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#include "util/util.h" #include "util/util.h"
#include "util/debug.h" #include "util/debug.h"
#include "symbol.h"
#ifdef HAVE_LIBBFD_SUPPORT #ifdef HAVE_LIBBFD_SUPPORT
/* /*
...@@ -250,7 +252,8 @@ void dso__free_a2l(struct dso *dso __maybe_unused) ...@@ -250,7 +252,8 @@ void dso__free_a2l(struct dso *dso __maybe_unused)
*/ */
#define A2L_FAIL_LIMIT 123 #define A2L_FAIL_LIMIT 123
char *get_srcline(struct dso *dso, unsigned long addr) char *get_srcline(struct dso *dso, unsigned long addr, struct symbol *sym,
bool show_sym)
{ {
char *file = NULL; char *file = NULL;
unsigned line = 0; unsigned line = 0;
...@@ -289,7 +292,11 @@ char *get_srcline(struct dso *dso, unsigned long addr) ...@@ -289,7 +292,11 @@ char *get_srcline(struct dso *dso, unsigned long addr)
dso->has_srcline = 0; dso->has_srcline = 0;
dso__free_a2l(dso); dso__free_a2l(dso);
} }
if (asprintf(&srcline, "%s[%lx]", dso->short_name, addr) < 0) if (sym) {
if (asprintf(&srcline, "%s+%ld", show_sym ? sym->name : "",
addr - sym->start) < 0)
return SRCLINE_UNKNOWN;
} else if (asprintf(&srcline, "%s[%lx]", dso->short_name, addr) < 0)
return SRCLINE_UNKNOWN; return SRCLINE_UNKNOWN;
return srcline; return srcline;
} }
......
...@@ -337,8 +337,10 @@ static inline int path__join3(char *bf, size_t size, ...@@ -337,8 +337,10 @@ static inline int path__join3(char *bf, size_t size,
} }
struct dso; struct dso;
struct symbol;
char *get_srcline(struct dso *dso, unsigned long addr); char *get_srcline(struct dso *dso, unsigned long addr, struct symbol *sym,
bool show_sym);
void free_srcline(char *srcline); void free_srcline(char *srcline);
int filename__read_int(const char *filename, int *value); int filename__read_int(const char *filename, int *value);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册