perf/core improvements and fixes:

User visible:
 
 - Fix 'perf top' annotation in --stdio (Namhyung Kim)
 
 - Support hw breakpoint events (mem:0xAddress) in the default output mode in
   'perf script' (Wang Nan)
 
 Infrastructure:
 
 - Do not hold the hists lock while emitting one specific warning (Namhyung Kim)
 
 - Fetch map names from correct strtab, worked so far because llvm/clang
   uses just one string table (Wang Nan)
 
 Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1
 
 iQIcBAABAgAGBQJWatuEAAoJENZQFvNTUqpAs84P/1BgEiLMWQ9rXVPazBiSsQDg
 vmnFdmA6K/nD7V1aryKL3sUXZHtBxR11TC0v9hec9HfplRpPOGV77/TvaHXMcwZW
 TqMgy1IA1cuuzdOnojKrYkImfLMCBq9VzMCK8DlkmNS+A1OGAIWuJp0JD3DSTtXH
 yyqpfFwz1I7ZbqPyDRVTyN79uKzOV8/ms98KjR3v4z0/tuhsIG0CIX59lzIuXr6w
 xj10HmX4aVHg41cST0SbMQmyiA34JDZrlARZwoReRrDSGKuo04SDO1k3dujRt7bv
 tQUckvLhnStMnUVH68WQ6bWrWE9Ksio2pQw98nHNf4Nd5IbHcCvQCdk1qsz+bm00
 VvCePJkHMxPoLMFmmBmYvZXLZChZeqzAxsNpu1VTSL3BtqOVUkSwdIcp/3qB1H/F
 Sfkm0iVQPUOUTwytgoeElWCgtxiImwbRSM2vZ1r550FPZzMsOtiZ3XR3FhHNLGr2
 8rkfd/zvmc5fGmmEFozWgfQVTeh5mDijkcACpFe8ec+a3Di01u0nczpdoN2p4V0/
 cJCFcuSl9RYYEgVhDSqlfKxqUo5yLZKKHJqEcYsHI+NR18xBzreU4W5fnylzQKjD
 ilGCeneDyE+JQ96py1vYaIq9xJhSEpKmLbbTB+uEIrEp2/IAE9g1ZWDA1W+o+iSy
 4j5eQcnHnLjY8B6NTTna
 =MkFX
 -----END PGP SIGNATURE-----

Merge tag 'perf-core-for-mingo' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/core

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

User visible changes:

  - Fix 'perf top' annotation in --stdio (Namhyung Kim)

  - Support hw breakpoint events (mem:0xAddress) in the default output mode in
    'perf script' (Wang Nan)

Infrastructure changes:

  - Do not hold the hists lock while emitting one specific warning (Namhyung Kim)

  - Fetch map names from correct strtab, worked so far because llvm/clang
    uses just one string table (Wang Nan)

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
This commit is contained in:
Ingo Molnar 2015-12-14 09:31:39 +01:00
commit 0d76ded582
5 changed files with 57 additions and 36 deletions

View File

@ -195,6 +195,7 @@ struct bpf_object {
Elf *elf;
GElf_Ehdr ehdr;
Elf_Data *symbols;
size_t strtabidx;
struct {
GElf_Shdr shdr;
Elf_Data *data;
@ -527,14 +528,14 @@ bpf_object__init_maps(struct bpf_object *obj, void *data,
return 0;
}
static void
static int
bpf_object__init_maps_name(struct bpf_object *obj, int maps_shndx)
{
int i;
Elf_Data *symbols = obj->efile.symbols;
if (!symbols || maps_shndx < 0)
return;
return -EINVAL;
for (i = 0; i < symbols->d_size / sizeof(GElf_Sym); i++) {
GElf_Sym sym;
@ -547,7 +548,7 @@ bpf_object__init_maps_name(struct bpf_object *obj, int maps_shndx)
continue;
map_name = elf_strptr(obj->efile.elf,
obj->efile.ehdr.e_shstrndx,
obj->efile.strtabidx,
sym.st_name);
map_idx = sym.st_value / sizeof(struct bpf_map_def);
if (map_idx >= obj->nr_maps) {
@ -556,9 +557,14 @@ bpf_object__init_maps_name(struct bpf_object *obj, int maps_shndx)
continue;
}
obj->maps[map_idx].name = strdup(map_name);
if (!obj->maps[map_idx].name) {
pr_warning("failed to alloc map name\n");
return -ENOMEM;
}
pr_debug("map %zu is \"%s\"\n", map_idx,
obj->maps[map_idx].name);
}
return 0;
}
static int bpf_object__elf_collect(struct bpf_object *obj)
@ -625,8 +631,10 @@ static int bpf_object__elf_collect(struct bpf_object *obj)
pr_warning("bpf: multiple SYMTAB in %s\n",
obj->path);
err = -LIBBPF_ERRNO__FORMAT;
} else
} else {
obj->efile.symbols = data;
obj->efile.strtabidx = sh.sh_link;
}
} else if ((sh.sh_type == SHT_PROGBITS) &&
(sh.sh_flags & SHF_EXECINSTR) &&
(data->d_size > 0)) {
@ -662,8 +670,12 @@ static int bpf_object__elf_collect(struct bpf_object *obj)
goto out;
}
if (!obj->efile.strtabidx || obj->efile.strtabidx >= idx) {
pr_warning("Corrupted ELF file: index of strtab invalid\n");
return LIBBPF_ERRNO__FORMAT;
}
if (maps_shndx >= 0)
bpf_object__init_maps_name(obj, maps_shndx);
err = bpf_object__init_maps_name(obj, maps_shndx);
out:
return err;
}
@ -1372,7 +1384,7 @@ bpf_object__get_map_by_name(struct bpf_object *obj, const char *name)
struct bpf_map *pos;
bpf_map__for_each(pos, obj) {
if (strcmp(pos->name, name) == 0)
if (pos->name && !strcmp(pos->name, name))
return pos;
}
return NULL;

View File

@ -130,6 +130,18 @@ static struct {
.invalid_fields = PERF_OUTPUT_TRACE,
},
[PERF_TYPE_BREAKPOINT] = {
.user_set = false,
.fields = PERF_OUTPUT_COMM | PERF_OUTPUT_TID |
PERF_OUTPUT_CPU | PERF_OUTPUT_TIME |
PERF_OUTPUT_EVNAME | PERF_OUTPUT_IP |
PERF_OUTPUT_SYM | PERF_OUTPUT_DSO |
PERF_OUTPUT_PERIOD,
.invalid_fields = PERF_OUTPUT_TRACE,
},
};
static bool output_set_by_user(void)
@ -1129,6 +1141,8 @@ static int parse_output_fields(const struct option *opt __maybe_unused,
type = PERF_TYPE_TRACEPOINT;
else if (!strcmp(str, "raw"))
type = PERF_TYPE_RAW;
else if (!strcmp(str, "break"))
type = PERF_TYPE_BREAKPOINT;
else {
fprintf(stderr, "Invalid event type in field string.\n");
rc = -EINVAL;

View File

@ -175,27 +175,24 @@ static void perf_top__record_precise_ip(struct perf_top *top,
int counter, u64 ip)
{
struct annotation *notes;
struct symbol *sym;
struct symbol *sym = he->ms.sym;
int err = 0;
if (he == NULL || he->ms.sym == NULL ||
((top->sym_filter_entry == NULL ||
top->sym_filter_entry->ms.sym != he->ms.sym) && use_browser != 1))
if (sym == NULL || (use_browser == 0 &&
(top->sym_filter_entry == NULL ||
top->sym_filter_entry->ms.sym != sym)))
return;
sym = he->ms.sym;
notes = symbol__annotation(sym);
if (pthread_mutex_trylock(&notes->lock))
return;
ip = he->ms.map->map_ip(he->ms.map, ip);
if (ui__has_annotation())
err = hist_entry__inc_addr_samples(he, counter, ip);
pthread_mutex_unlock(&notes->lock);
if (unlikely(err)) {
/*
* This function is now called with he->hists->lock held.
* Release it before going to sleep.
@ -212,6 +209,7 @@ static void perf_top__record_precise_ip(struct perf_top *top,
pthread_mutex_lock(&he->hists->lock);
}
}
static void perf_top__show_details(struct perf_top *top)
{
@ -687,14 +685,8 @@ static int hist_iter__top_callback(struct hist_entry_iter *iter,
struct hist_entry *he = iter->he;
struct perf_evsel *evsel = iter->evsel;
if (sort__has_sym && single) {
u64 ip = al->addr;
if (al->map)
ip = al->map->unmap_ip(al->map, ip);
perf_top__record_precise_ip(top, he, evsel->idx, ip);
}
if (sort__has_sym && single)
perf_top__record_precise_ip(top, he, evsel->idx, al->addr);
hist__account_cycles(iter->sample->branch_stack, al, iter->sample,
!(top->record_opts.branch_stack & PERF_SAMPLE_BRANCH_ANY));

View File

@ -63,6 +63,7 @@ struct ctf_writer {
struct bt_ctf_field_type *s32;
struct bt_ctf_field_type *u32;
struct bt_ctf_field_type *string;
struct bt_ctf_field_type *u32_hex;
struct bt_ctf_field_type *u64_hex;
};
struct bt_ctf_field_type *array[6];
@ -982,6 +983,7 @@ do { \
CREATE_INT_TYPE(cw->data.u64, 64, false, false);
CREATE_INT_TYPE(cw->data.s32, 32, true, false);
CREATE_INT_TYPE(cw->data.u32, 32, false, false);
CREATE_INT_TYPE(cw->data.u32_hex, 32, false, true);
CREATE_INT_TYPE(cw->data.u64_hex, 64, false, true);
cw->data.string = bt_ctf_field_type_string_create();

View File

@ -25,6 +25,7 @@ static void dsos__init(struct dsos *dsos)
int machine__init(struct machine *machine, const char *root_dir, pid_t pid)
{
memset(machine, 0, sizeof(*machine));
map_groups__init(&machine->kmaps, machine);
RB_CLEAR_NODE(&machine->rb_node);
dsos__init(&machine->dsos);