Commit cecaec63 authored by Namhyung Kim's avatar Namhyung Kim Committed by Arnaldo Carvalho de Melo

perf tools: Update srcline/file if needed

Normally the hist entry's srcline and/or srcfile is set during sorting.
However sometime it's possible to a hist entry's srcline is not set yet
after the sorting.  This is because the entry is so unique and other
sort keys already make it distinct.  Then the srcline/file sort didn't
have a chance to be called during the sorting.  In that case it has NULL
srcline/srcfile field and shows nothing.

Before:

  $ perf report -s comm,sym,srcline
  ...
  Overhead  Command       Symbol
  -----------------------------------------------------------------
    34.42%  swapper       [k] intel_idle          intel_idle.c:0
     2.44%  perf          [.] __poll_nocancel     (null)
     1.70%  gnome-shell   [k] fw_domains_get      (null)
     1.04%  Xorg          [k] sock_poll           (null)

After:

    34.42%  swapper       [k] intel_idle          intel_idle.c:0
     2.44%  perf          [.] __poll_nocancel     .:0
     1.70%  gnome-shell   [k] fw_domains_get      fw_domains_get+42
     1.04%  Xorg          [k] sock_poll           socket.c:0
Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
Acked-by: default avatarJiri Olsa <jolsa@kernel.org>
Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1456101111-14400-1-git-send-email-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 665aa757
...@@ -286,35 +286,34 @@ struct sort_entry sort_sym = { ...@@ -286,35 +286,34 @@ struct sort_entry sort_sym = {
/* --sort srcline */ /* --sort srcline */
static char *hist_entry__get_srcline(struct hist_entry *he)
{
struct map *map = he->ms.map;
if (!map)
return SRCLINE_UNKNOWN;
return get_srcline(map->dso, map__rip_2objdump(map, he->ip),
he->ms.sym, true);
}
static int64_t static int64_t
sort__srcline_cmp(struct hist_entry *left, struct hist_entry *right) sort__srcline_cmp(struct hist_entry *left, struct hist_entry *right)
{ {
if (!left->srcline) { if (!left->srcline)
if (!left->ms.map) left->srcline = hist_entry__get_srcline(left);
left->srcline = SRCLINE_UNKNOWN; if (!right->srcline)
else { right->srcline = hist_entry__get_srcline(right);
struct map *map = left->ms.map;
left->srcline = get_srcline(map->dso,
map__rip_2objdump(map, left->ip),
left->ms.sym, true);
}
}
if (!right->srcline) {
if (!right->ms.map)
right->srcline = SRCLINE_UNKNOWN;
else {
struct map *map = right->ms.map;
right->srcline = get_srcline(map->dso,
map__rip_2objdump(map, right->ip),
right->ms.sym, true);
}
}
return strcmp(right->srcline, left->srcline); return strcmp(right->srcline, left->srcline);
} }
static int hist_entry__srcline_snprintf(struct hist_entry *he, char *bf, static int hist_entry__srcline_snprintf(struct hist_entry *he, char *bf,
size_t size, unsigned int width) size_t size, unsigned int width)
{ {
if (!he->srcline)
he->srcline = hist_entry__get_srcline(he);
return repsep_snprintf(bf, size, "%-*.*s", width, width, he->srcline); return repsep_snprintf(bf, size, "%-*.*s", width, width, he->srcline);
} }
...@@ -329,11 +328,14 @@ struct sort_entry sort_srcline = { ...@@ -329,11 +328,14 @@ struct sort_entry sort_srcline = {
static char no_srcfile[1]; static char no_srcfile[1];
static char *get_srcfile(struct hist_entry *e) static char *hist_entry__get_srcfile(struct hist_entry *e)
{ {
char *sf, *p; char *sf, *p;
struct map *map = e->ms.map; struct map *map = e->ms.map;
if (!map)
return no_srcfile;
sf = __get_srcline(map->dso, map__rip_2objdump(map, e->ip), sf = __get_srcline(map->dso, map__rip_2objdump(map, e->ip),
e->ms.sym, false, true); e->ms.sym, false, true);
if (!strcmp(sf, SRCLINE_UNKNOWN)) if (!strcmp(sf, SRCLINE_UNKNOWN))
...@@ -350,24 +352,20 @@ static char *get_srcfile(struct hist_entry *e) ...@@ -350,24 +352,20 @@ static char *get_srcfile(struct hist_entry *e)
static int64_t static int64_t
sort__srcfile_cmp(struct hist_entry *left, struct hist_entry *right) sort__srcfile_cmp(struct hist_entry *left, struct hist_entry *right)
{ {
if (!left->srcfile) { if (!left->srcfile)
if (!left->ms.map) left->srcfile = hist_entry__get_srcfile(left);
left->srcfile = no_srcfile; if (!right->srcfile)
else right->srcfile = hist_entry__get_srcfile(right);
left->srcfile = get_srcfile(left);
}
if (!right->srcfile) {
if (!right->ms.map)
right->srcfile = no_srcfile;
else
right->srcfile = get_srcfile(right);
}
return strcmp(right->srcfile, left->srcfile); return strcmp(right->srcfile, left->srcfile);
} }
static int hist_entry__srcfile_snprintf(struct hist_entry *he, char *bf, static int hist_entry__srcfile_snprintf(struct hist_entry *he, char *bf,
size_t size, unsigned int width) size_t size, unsigned int width)
{ {
if (!he->srcfile)
he->srcfile = hist_entry__get_srcfile(he);
return repsep_snprintf(bf, size, "%-*.*s", width, width, he->srcfile); return repsep_snprintf(bf, size, "%-*.*s", width, width, he->srcfile);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment