Skip to content

Commit

Permalink
Merge tag 'perf-core-for-mingo' of git://git.kernel.org/pub/scm/linux…
Browse files Browse the repository at this point in the history
…/kernel/git/acme/linux into perf/core

Pull perf/core improvements and fixes from Arnaldo Carvalho de Melo:

User visible fixes:

 - Fallback to kallsyms when using the minimal 'ELF' loader (Arnaldo Carvalho de Melo)

 - Fix annotation with kcore (Adrian Hunter)

 - Fix up srcline histogram key formatting (Arnaldo Carvalho de Melo)

 - Add missing handler for PERF_RECORD_MMAP2 events in 'perf diff' (Kan Liang)

User visible changes/new features:

 - Only print base source file for srcline histogram sort key (Andi Kleen)

 - Support source line numbers in annotate using a hotkey (Andi Kleen)

Infrastructure changes and fixes:

 - Do not poll events that use the system_wide flag (Adrian Hunter)

 - Add perf-read-vdso32 and perf-read-vdsox32 to .gitignore (Adrian Hunter)

 - Only override the default :tid comm entry (Adrian Hunter)

 - Factor out adding new call chain entries (Andi Kleen)

 - Use al.addr to set up call chain (Andi Kleen)

 - Use a common function to resolve symbol or name (Andi Kleen)

 - Fix ftrace:function event recording (Jiri Olsa)

 - Move disable_buildid_cache() to util/build-id.c (Namhyung Kim)

 - Clean up libelf feature support code (Namhyung Kim)

 - Fix typo in python 'perf test' (WANG Chao)

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
  • Loading branch information
Ingo Molnar committed Nov 20, 2014
2 parents 2565711 + a848080 commit 4e6e311
Show file tree
Hide file tree
Showing 24 changed files with 145 additions and 88 deletions.
2 changes: 2 additions & 0 deletions tools/perf/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ PERF-CFLAGS
PERF-GUI-VARS
PERF-VERSION-FILE
perf
perf-read-vdso32
perf-read-vdsox32
perf-help
perf-record
perf-report
Expand Down
2 changes: 0 additions & 2 deletions tools/perf/Makefile.perf
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,6 @@ ifneq ($(OUTPUT),)
endif

ifdef NO_LIBELF
EXTLIBS := $(filter-out -lelf,$(EXTLIBS))

# Remove ELF/DWARF dependent codes
LIB_OBJS := $(filter-out $(OUTPUT)util/symbol-elf.o,$(LIB_OBJS))
LIB_OBJS := $(filter-out $(OUTPUT)util/dwarf-aux.o,$(LIB_OBJS))
Expand Down
1 change: 1 addition & 0 deletions tools/perf/builtin-diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ static int diff__process_sample_event(struct perf_tool *tool __maybe_unused,
static struct perf_tool tool = {
.sample = diff__process_sample_event,
.mmap = perf_event__process_mmap,
.mmap2 = perf_event__process_mmap2,
.comm = perf_event__process_comm,
.exit = perf_event__process_exit,
.fork = perf_event__process_fork,
Expand Down
5 changes: 3 additions & 2 deletions tools/perf/config/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ CFLAGS += -std=gnu99
# adding assembler files missing the .GNU-stack linker note.
LDFLAGS += -Wl,-z,noexecstack

EXTLIBS = -lelf -lpthread -lrt -lm -ldl
EXTLIBS = -lpthread -lrt -lm -ldl

ifneq ($(OUTPUT),)
OUTPUT_FEATURES = $(OUTPUT)config/feature-checks/
Expand Down Expand Up @@ -354,6 +354,7 @@ endif # NO_LIBELF

ifndef NO_LIBELF
CFLAGS += -DHAVE_LIBELF_SUPPORT
EXTLIBS += -lelf

ifeq ($(feature-libelf-mmap), 1)
CFLAGS += -DHAVE_LIBELF_MMAP_SUPPORT
Expand All @@ -373,7 +374,7 @@ ifndef NO_LIBELF
else
CFLAGS += -DHAVE_DWARF_SUPPORT $(LIBDW_CFLAGS)
LDFLAGS += $(LIBDW_LDFLAGS)
EXTLIBS += -lelf -ldw
EXTLIBS += -ldw
endif # PERF_HAVE_DWARF_REGS
endif # NO_DWARF
endif # NO_LIBELF
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/tests/builtin-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ static struct test {
.func = test__hists_link,
},
{
.desc = "Try 'use perf' in python, checking link problems",
.desc = "Try 'import perf' in python, checking link problems",
.func = test__python_use,
},
{
Expand Down
13 changes: 12 additions & 1 deletion tools/perf/ui/browsers/annotate.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ static struct annotate_browser_opt {
bool hide_src_code,
use_offset,
jump_arrows,
show_linenr,
show_nr_jumps;
} annotate_browser__opts = {
.use_offset = true,
Expand Down Expand Up @@ -128,7 +129,11 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int
if (!*dl->line)
slsmg_write_nstring(" ", width - pcnt_width);
else if (dl->offset == -1) {
printed = scnprintf(bf, sizeof(bf), "%*s ",
if (dl->line_nr && annotate_browser__opts.show_linenr)
printed = scnprintf(bf, sizeof(bf), "%-*d ",
ab->addr_width + 1, dl->line_nr);
else
printed = scnprintf(bf, sizeof(bf), "%*s ",
ab->addr_width, " ");
slsmg_write_nstring(bf, printed);
slsmg_write_nstring(dl->line, width - printed - pcnt_width + 1);
Expand Down Expand Up @@ -733,6 +738,7 @@ static int annotate_browser__run(struct annotate_browser *browser,
"o Toggle disassembler output/simplified view\n"
"s Toggle source code view\n"
"/ Search string\n"
"k Toggle line numbers\n"
"r Run available scripts\n"
"? Search string backwards\n");
continue;
Expand All @@ -741,6 +747,10 @@ static int annotate_browser__run(struct annotate_browser *browser,
script_browse(NULL);
continue;
}
case 'k':
annotate_browser__opts.show_linenr =
!annotate_browser__opts.show_linenr;
break;
case 'H':
nd = browser->curr_hot;
break;
Expand Down Expand Up @@ -984,6 +994,7 @@ static struct annotate_config {
} annotate__configs[] = {
ANNOTATE_CFG(hide_src_code),
ANNOTATE_CFG(jump_arrows),
ANNOTATE_CFG(show_linenr),
ANNOTATE_CFG(show_nr_jumps),
ANNOTATE_CFG(use_offset),
};
Expand Down
17 changes: 0 additions & 17 deletions tools/perf/ui/browsers/hists.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,23 +463,6 @@ static int hist_browser__run(struct hist_browser *browser,
return key;
}

static char *callchain_list__sym_name(struct callchain_list *cl,
char *bf, size_t bfsize, bool show_dso)
{
int printed;

if (cl->ms.sym)
printed = scnprintf(bf, bfsize, "%s", cl->ms.sym->name);
else
printed = scnprintf(bf, bfsize, "%#" PRIx64, cl->ip);

if (show_dso)
scnprintf(bf + printed, bfsize - printed, " %s",
cl->ms.map ? cl->ms.map->dso->short_name : "unknown");

return bf;
}

struct callchain_print_arg {
/* for hists browser */
off_t row_offset;
Expand Down
11 changes: 1 addition & 10 deletions tools/perf/ui/gtk/hists.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,6 @@ void perf_gtk__init_hpp(void)
perf_gtk__hpp_color_overhead_acc;
}

static void callchain_list__sym_name(struct callchain_list *cl,
char *bf, size_t bfsize)
{
if (cl->ms.sym)
scnprintf(bf, bfsize, "%s", cl->ms.sym->name);
else
scnprintf(bf, bfsize, "%#" PRIx64, cl->ip);
}

static void perf_gtk__add_callchain(struct rb_root *root, GtkTreeStore *store,
GtkTreeIter *parent, int col, u64 total)
{
Expand Down Expand Up @@ -128,7 +119,7 @@ static void perf_gtk__add_callchain(struct rb_root *root, GtkTreeStore *store,
scnprintf(buf, sizeof(buf), "%5.2f%%", percent);
gtk_tree_store_set(store, &iter, 0, buf, -1);

callchain_list__sym_name(chain, buf, sizeof(buf));
callchain_list__sym_name(chain, buf, sizeof(buf), false);
gtk_tree_store_set(store, &iter, col, buf, -1);

if (need_new_parent) {
Expand Down
23 changes: 9 additions & 14 deletions tools/perf/ui/stdio/hist.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ static size_t ipchain__fprintf_graph(FILE *fp, struct callchain_list *chain,
{
int i;
size_t ret = 0;
char bf[1024];

ret += callchain__fprintf_left_margin(fp, left_margin);
for (i = 0; i < depth; i++) {
Expand All @@ -56,11 +57,8 @@ static size_t ipchain__fprintf_graph(FILE *fp, struct callchain_list *chain,
} else
ret += fprintf(fp, "%s", " ");
}
if (chain->ms.sym)
ret += fprintf(fp, "%s\n", chain->ms.sym->name);
else
ret += fprintf(fp, "0x%0" PRIx64 "\n", chain->ip);

fputs(callchain_list__sym_name(chain, bf, sizeof(bf), false), fp);
fputc('\n', fp);
return ret;
}

Expand Down Expand Up @@ -168,6 +166,7 @@ static size_t callchain__fprintf_graph(FILE *fp, struct rb_root *root,
struct rb_node *node;
int i = 0;
int ret = 0;
char bf[1024];

/*
* If have one single callchain root, don't bother printing
Expand Down Expand Up @@ -196,10 +195,8 @@ static size_t callchain__fprintf_graph(FILE *fp, struct rb_root *root,
} else
ret += callchain__fprintf_left_margin(fp, left_margin);

if (chain->ms.sym)
ret += fprintf(fp, " %s\n", chain->ms.sym->name);
else
ret += fprintf(fp, " %p\n", (void *)(long)chain->ip);
ret += fprintf(fp, "%s\n", callchain_list__sym_name(chain, bf, sizeof(bf),
false));

if (++entries_printed == callchain_param.print_limit)
break;
Expand All @@ -219,6 +216,7 @@ static size_t __callchain__fprintf_flat(FILE *fp, struct callchain_node *node,
{
struct callchain_list *chain;
size_t ret = 0;
char bf[1024];

if (!node)
return 0;
Expand All @@ -229,11 +227,8 @@ static size_t __callchain__fprintf_flat(FILE *fp, struct callchain_node *node,
list_for_each_entry(chain, &node->val, list) {
if (chain->ip >= PERF_CONTEXT_MAX)
continue;
if (chain->ms.sym)
ret += fprintf(fp, " %s\n", chain->ms.sym->name);
else
ret += fprintf(fp, " %p\n",
(void *)(long)chain->ip);
ret += fprintf(fp, " %s\n", callchain_list__sym_name(chain,
bf, sizeof(bf), false));
}

return ret;
Expand Down
32 changes: 27 additions & 5 deletions tools/perf/util/annotate.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
#include "debug.h"
#include "annotate.h"
#include "evsel.h"
#include <regex.h>
#include <pthread.h>
#include <linux/bitops.h>

const char *disassembler_style;
const char *objdump_path;
static regex_t file_lineno;

static struct ins *ins__find(const char *name);
static int disasm_line__parse(char *line, char **namep, char **rawp);
Expand Down Expand Up @@ -570,13 +572,15 @@ static int disasm_line__parse(char *line, char **namep, char **rawp)
return -1;
}

static struct disasm_line *disasm_line__new(s64 offset, char *line, size_t privsize)
static struct disasm_line *disasm_line__new(s64 offset, char *line,
size_t privsize, int line_nr)
{
struct disasm_line *dl = zalloc(sizeof(*dl) + privsize);

if (dl != NULL) {
dl->offset = offset;
dl->line = strdup(line);
dl->line_nr = line_nr;
if (dl->line == NULL)
goto out_delete;

Expand Down Expand Up @@ -788,13 +792,15 @@ static int disasm_line__print(struct disasm_line *dl, struct symbol *sym, u64 st
* The ops.raw part will be parsed further according to type of the instruction.
*/
static int symbol__parse_objdump_line(struct symbol *sym, struct map *map,
FILE *file, size_t privsize)
FILE *file, size_t privsize,
int *line_nr)
{
struct annotation *notes = symbol__annotation(sym);
struct disasm_line *dl;
char *line = NULL, *parsed_line, *tmp, *tmp2, *c;
size_t line_len;
s64 line_ip, offset = -1;
regmatch_t match[2];

if (getline(&line, &line_len, file) < 0)
return -1;
Expand All @@ -812,6 +818,12 @@ static int symbol__parse_objdump_line(struct symbol *sym, struct map *map,
line_ip = -1;
parsed_line = line;

/* /filename:linenr ? Save line number and ignore. */
if (regexec(&file_lineno, line, 2, match, 0) == 0) {
*line_nr = atoi(line + match[1].rm_so);
return 0;
}

/*
* Strip leading spaces:
*/
Expand Down Expand Up @@ -842,8 +854,9 @@ static int symbol__parse_objdump_line(struct symbol *sym, struct map *map,
parsed_line = tmp2 + 1;
}

dl = disasm_line__new(offset, parsed_line, privsize);
dl = disasm_line__new(offset, parsed_line, privsize, *line_nr);
free(line);
(*line_nr)++;

if (dl == NULL)
return -1;
Expand All @@ -869,6 +882,11 @@ static int symbol__parse_objdump_line(struct symbol *sym, struct map *map,
return 0;
}

static __attribute__((constructor)) void symbol__init_regexpr(void)
{
regcomp(&file_lineno, "^/[^:]+:([0-9]+)", REG_EXTENDED);
}

static void delete_last_nop(struct symbol *sym)
{
struct annotation *notes = symbol__annotation(sym);
Expand Down Expand Up @@ -904,6 +922,7 @@ int symbol__annotate(struct symbol *sym, struct map *map, size_t privsize)
char symfs_filename[PATH_MAX];
struct kcore_extract kce;
bool delete_extract = false;
int lineno = 0;

if (filename)
symbol__join_symfs(symfs_filename, filename);
Expand All @@ -915,6 +934,8 @@ int symbol__annotate(struct symbol *sym, struct map *map, size_t privsize)
return -ENOMEM;
}
goto fallback;
} else if (dso__is_kcore(dso)) {
goto fallback;
} else if (readlink(symfs_filename, command, sizeof(command)) < 0 ||
strstr(command, "[kernel.kallsyms]") ||
access(symfs_filename, R_OK)) {
Expand Down Expand Up @@ -982,7 +1003,7 @@ int symbol__annotate(struct symbol *sym, struct map *map, size_t privsize)
snprintf(command, sizeof(command),
"%s %s%s --start-address=0x%016" PRIx64
" --stop-address=0x%016" PRIx64
" -d %s %s -C %s 2>/dev/null|grep -v %s|expand",
" -l -d %s %s -C %s 2>/dev/null|grep -v %s|expand",
objdump_path ? objdump_path : "objdump",
disassembler_style ? "-M " : "",
disassembler_style ? disassembler_style : "",
Expand All @@ -999,7 +1020,8 @@ int symbol__annotate(struct symbol *sym, struct map *map, size_t privsize)
goto out_free_filename;

while (!feof(file))
if (symbol__parse_objdump_line(sym, map, file, privsize) < 0)
if (symbol__parse_objdump_line(sym, map, file, privsize,
&lineno) < 0)
break;

/*
Expand Down
1 change: 1 addition & 0 deletions tools/perf/util/annotate.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ struct disasm_line {
char *line;
char *name;
struct ins *ins;
int line_nr;
struct ins_operands ops;
};

Expand Down
11 changes: 11 additions & 0 deletions tools/perf/util/build-id.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
#include "header.h"
#include "vdso.h"


static bool no_buildid_cache;

int build_id__mark_dso_hit(struct perf_tool *tool __maybe_unused,
union perf_event *event,
struct perf_sample *sample,
Expand Down Expand Up @@ -251,6 +254,11 @@ int dsos__hit_all(struct perf_session *session)
return 0;
}

void disable_buildid_cache(void)
{
no_buildid_cache = true;
}

int build_id_cache__add_s(const char *sbuild_id, const char *debugdir,
const char *name, bool is_kallsyms, bool is_vdso)
{
Expand Down Expand Up @@ -404,6 +412,9 @@ int perf_session__cache_build_ids(struct perf_session *session)
int ret;
char debugdir[PATH_MAX];

if (no_buildid_cache)
return 0;

snprintf(debugdir, sizeof(debugdir), "%s", buildid_dir);

if (mkdir(debugdir, 0755) != 0 && errno != EEXIST)
Expand Down
1 change: 1 addition & 0 deletions tools/perf/util/build-id.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ int perf_session__cache_build_ids(struct perf_session *session);
int build_id_cache__add_s(const char *sbuild_id, const char *debugdir,
const char *name, bool is_kallsyms, bool is_vdso);
int build_id_cache__remove_s(const char *sbuild_id, const char *debugdir);
void disable_buildid_cache(void);

#endif
Loading

0 comments on commit 4e6e311

Please sign in to comment.