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 changes:

  - Replace CTRL+z with 'f' as hotkey for enable/disable events (Arnaldo Carvalho de Melo)

  - Do not exit when 'f' is pressed in 'report' mode (Arnaldo Carvalho de Melo)

  - Tell the user how to unfreeze events after pressing 'f' in 'perf top' (Arnaldo Carvalho de Melo)

  - React to unassigned hotkey pressing in 'top/report' (Arnaldo Carvalho de Melo)

  - Display total number of samples with --show-total-period in 'annotate' (Martin Liška)

  - Add timeout to make procfs mmap processing more robust (Kan Liang)

  - Fix sort__sym_cmp to also compare end of symbol (Yannick Brosseau)

Infrastructure changes:

  - Ensure thread-stack is flushed (Adrian Hunter)

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
  • Loading branch information
Ingo Molnar committed Jun 19, 2015
2 parents 7992892 + 9d9cad7 commit a9a3cd9
Show file tree
Hide file tree
Showing 26 changed files with 278 additions and 81 deletions.
4 changes: 4 additions & 0 deletions include/uapi/linux/perf_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,10 @@ struct perf_event_mmap_page {
#define PERF_RECORD_MISC_GUEST_KERNEL (4 << 0)
#define PERF_RECORD_MISC_GUEST_USER (5 << 0)

/*
* Indicates that /proc/PID/maps parsing are truncated by time out.
*/
#define PERF_RECORD_MISC_PROC_MAP_PARSE_TIMEOUT (1 << 12)
/*
* PERF_RECORD_MISC_MMAP_DATA and PERF_RECORD_MISC_COMM_EXEC are used on
* different events so can reuse the same bit position.
Expand Down
6 changes: 6 additions & 0 deletions tools/perf/Documentation/perf-kvm.txt
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ STAT LIVE OPTIONS
Show events other than HLT (x86 only) or Wait state (s390 only)
that take longer than duration usecs.

--proc-map-timeout::
When processing pre-existing threads /proc/XXX/mmap, it may take
a long time, because the file may be huge. A time out is needed
in such cases.
This option sets the time out limit. The default value is 500 ms.

SEE ALSO
--------
linkperf:perf-top[1], linkperf:perf-record[1], linkperf:perf-report[1],
Expand Down
5 changes: 5 additions & 0 deletions tools/perf/Documentation/perf-record.txt
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,11 @@ AUX area tracing event. Optionally the number of bytes to capture per
snapshot can be specified. In Snapshot Mode, trace data is captured only when
signal SIGUSR2 is received.

--proc-map-timeout::
When processing pre-existing threads /proc/XXX/mmap, it may take a long time,
because the file may be huge. A time out is needed in such cases.
This option sets the time out limit. The default value is 500 ms.

SEE ALSO
--------
linkperf:perf-stat[1], linkperf:perf-list[1]
6 changes: 6 additions & 0 deletions tools/perf/Documentation/perf-top.txt
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@ Default is to monitor all CPUS.
Force each column width to the provided list, for large terminal
readability. 0 means no limit (default behavior).

--proc-map-timeout::
When processing pre-existing threads /proc/XXX/mmap, it may take
a long time, because the file may be huge. A time out is needed
in such cases.
This option sets the time out limit. The default value is 500 ms.


INTERACTIVE PROMPTING KEYS
--------------------------
Expand Down
5 changes: 5 additions & 0 deletions tools/perf/Documentation/perf-trace.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ the thread executes on the designated CPUs. Default is to monitor all CPUs.
--event::
Trace other events, see 'perf list' for a complete list.

--proc-map-timeout::
When processing pre-existing threads /proc/XXX/mmap, it may take a long time,
because the file may be huge. A time out is needed in such cases.
This option sets the time out limit. The default value is 500 ms.

PAGEFAULTS
----------

Expand Down
2 changes: 2 additions & 0 deletions tools/perf/builtin-annotate.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused)
"objdump binary to use for disassembly and annotations"),
OPT_BOOLEAN(0, "group", &symbol_conf.event_group,
"Show event group information together"),
OPT_BOOLEAN(0, "show-total-period", &symbol_conf.show_total_period,
"Show a column with the sum of periods"),
OPT_END()
};
int ret = hists__init();
Expand Down
5 changes: 4 additions & 1 deletion tools/perf/builtin-kvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1311,6 +1311,8 @@ static int kvm_events_live(struct perf_kvm_stat *kvm,
"show events other than"
" HLT (x86 only) or Wait state (s390 only)"
" that take longer than duration usecs"),
OPT_UINTEGER(0, "proc-map-timeout", &kvm->opts.proc_map_timeout,
"per thread proc mmap processing timeout in ms"),
OPT_END()
};
const char * const live_usage[] = {
Expand Down Expand Up @@ -1338,6 +1340,7 @@ static int kvm_events_live(struct perf_kvm_stat *kvm,
kvm->opts.target.uses_mmap = false;
kvm->opts.target.uid_str = NULL;
kvm->opts.target.uid = UINT_MAX;
kvm->opts.proc_map_timeout = 500;

symbol__init(NULL);
disable_buildid_cache();
Expand Down Expand Up @@ -1393,7 +1396,7 @@ static int kvm_events_live(struct perf_kvm_stat *kvm,
perf_session__set_id_hdr_size(kvm->session);
ordered_events__set_copy_on_queue(&kvm->session->ordered_events, true);
machine__synthesize_threads(&kvm->session->machines.host, &kvm->opts.target,
kvm->evlist->threads, false);
kvm->evlist->threads, false, kvm->opts.proc_map_timeout);
err = kvm_live_open_events(kvm);
if (err)
goto out;
Expand Down
6 changes: 5 additions & 1 deletion tools/perf/builtin-record.c
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,8 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
}

err = __machine__synthesize_threads(machine, tool, &opts->target, rec->evlist->threads,
process_synthesized_event, opts->sample_address);
process_synthesized_event, opts->sample_address,
opts->proc_map_timeout);
if (err != 0)
goto out_child;

Expand Down Expand Up @@ -959,6 +960,7 @@ static struct record record = {
.uses_mmap = true,
.default_per_cpu = true,
},
.proc_map_timeout = 500,
},
.tool = {
.sample = process_sample_event,
Expand Down Expand Up @@ -1066,6 +1068,8 @@ struct option __record_options[] = {
parse_clockid),
OPT_STRING_OPTARG('S', "snapshot", &record.opts.auxtrace_snapshot_opts,
"opts", "AUX area tracing Snapshot Mode", ""),
OPT_UINTEGER(0, "proc-map-timeout", &record.opts.proc_map_timeout,
"per thread proc mmap processing timeout in ms"),
OPT_END()
};

Expand Down
15 changes: 12 additions & 3 deletions tools/perf/builtin-top.c
Original file line number Diff line number Diff line change
Expand Up @@ -591,15 +591,21 @@ static void *display_thread_tui(void *arg)
top->min_percent,
&top->session->header.env);

if (key != CTRL('z'))
if (key != 'f')
break;

perf_evlist__toggle_enable(top->evlist);
/*
* No need to refresh, resort/decay histogram entries
* if we are not collecting samples:
*/
hbt.refresh = top->evlist->enabled ? top->delay_secs : 0;
if (top->evlist->enabled) {
hbt.refresh = top->delay_secs;
help = "Press 'f' to disable the events or 'h' to see other hotkeys";
} else {
help = "Press 'f' again to re-enable the events";
hbt.refresh = 0;
}
}

done = 1;
Expand Down Expand Up @@ -971,7 +977,7 @@ static int __cmd_top(struct perf_top *top)
goto out_delete;

machine__synthesize_threads(&top->session->machines.host, &opts->target,
top->evlist->threads, false);
top->evlist->threads, false, opts->proc_map_timeout);
ret = perf_top__start_counters(top);
if (ret)
goto out_delete;
Expand Down Expand Up @@ -1081,6 +1087,7 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused)
.target = {
.uses_mmap = true,
},
.proc_map_timeout = 500,
},
.max_stack = PERF_MAX_STACK_DEPTH,
.sym_pcnt_filter = 5,
Expand Down Expand Up @@ -1180,6 +1187,8 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused)
OPT_STRING('w', "column-widths", &symbol_conf.col_width_list_str,
"width[,width...]",
"don't try to adjust column width, use these fixed values"),
OPT_UINTEGER(0, "proc-map-timeout", &opts->proc_map_timeout,
"per thread proc mmap processing timeout in ms"),
OPT_END()
};
const char * const top_usage[] = {
Expand Down
6 changes: 5 additions & 1 deletion tools/perf/builtin-trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -1518,7 +1518,8 @@ static int trace__symbols_init(struct trace *trace, struct perf_evlist *evlist)
return -ENOMEM;

err = __machine__synthesize_threads(trace->host, &trace->tool, &trace->opts.target,
evlist->threads, trace__tool_process, false);
evlist->threads, trace__tool_process, false,
trace->opts.proc_map_timeout);
if (err)
symbol__exit();

Expand Down Expand Up @@ -2747,6 +2748,7 @@ int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused)
.user_interval = ULLONG_MAX,
.no_buffering = true,
.mmap_pages = UINT_MAX,
.proc_map_timeout = 500,
},
.output = stdout,
.show_comm = true,
Expand Down Expand Up @@ -2796,6 +2798,8 @@ int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused)
"Trace pagefaults", parse_pagefaults, "maj"),
OPT_BOOLEAN(0, "syscalls", &trace.trace_syscalls, "Trace syscalls"),
OPT_BOOLEAN('f', "force", &trace.force, "don't complain, do it"),
OPT_UINTEGER(0, "proc-map-timeout", &trace.opts.proc_map_timeout,
"per thread proc mmap processing timeout in ms"),
OPT_END()
};
const char * const trace_subcommands[] = { "record", NULL };
Expand Down
1 change: 1 addition & 0 deletions tools/perf/perf.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ struct record_opts {
unsigned initial_delay;
bool use_clockid;
clockid_t clockid;
unsigned int proc_map_timeout;
};

struct option;
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/tests/code-reading.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ static int do_test_code_reading(bool try_kcore)
}

ret = perf_event__synthesize_thread_map(NULL, threads,
perf_event__process, machine, false);
perf_event__process, machine, false, 500);
if (ret < 0) {
pr_debug("perf_event__synthesize_thread_map failed\n");
goto out_err;
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/tests/dwarf-unwind.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static int init_live_machine(struct machine *machine)
pid_t pid = getpid();

return perf_event__synthesize_mmap_events(NULL, &event, pid, pid,
mmap_handler, machine, true);
mmap_handler, machine, true, 500);
}

#define MAX_STACK 8
Expand Down
4 changes: 2 additions & 2 deletions tools/perf/tests/mmap-thread-lookup.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ static int synth_all(struct machine *machine)
{
return perf_event__synthesize_threads(NULL,
perf_event__process,
machine, 0);
machine, 0, 500);
}

static int synth_process(struct machine *machine)
Expand All @@ -141,7 +141,7 @@ static int synth_process(struct machine *machine)

err = perf_event__synthesize_thread_map(NULL, map,
perf_event__process,
machine, 0);
machine, 0, 500);

thread_map__delete(map);
return err;
Expand Down
60 changes: 43 additions & 17 deletions tools/perf/ui/browsers/annotate.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,30 @@
#include "../../util/evsel.h"
#include <pthread.h>

struct disasm_line_samples {
double percent;
u64 nr;
};

struct browser_disasm_line {
struct rb_node rb_node;
u32 idx;
int idx_asm;
int jump_sources;
struct rb_node rb_node;
u32 idx;
int idx_asm;
int jump_sources;
/*
* actual length of this array is saved on the nr_events field
* of the struct annotate_browser
*/
double percent[1];
struct disasm_line_samples samples[1];
};

static struct annotate_browser_opt {
bool hide_src_code,
use_offset,
jump_arrows,
show_linenr,
show_nr_jumps;
show_nr_jumps,
show_total_period;
} annotate_browser__opts = {
.use_offset = true,
.jump_arrows = true,
Expand Down Expand Up @@ -105,15 +111,20 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int
char bf[256];

for (i = 0; i < ab->nr_events; i++) {
if (bdl->percent[i] > percent_max)
percent_max = bdl->percent[i];
if (bdl->samples[i].percent > percent_max)
percent_max = bdl->samples[i].percent;
}

if (dl->offset != -1 && percent_max != 0.0) {
for (i = 0; i < ab->nr_events; i++) {
ui_browser__set_percent_color(browser, bdl->percent[i],
ui_browser__set_percent_color(browser,
bdl->samples[i].percent,
current_entry);
slsmg_printf("%6.2f ", bdl->percent[i]);
if (annotate_browser__opts.show_total_period)
slsmg_printf("%6" PRIu64 " ",
bdl->samples[i].nr);
else
slsmg_printf("%6.2f ", bdl->samples[i].percent);
}
} else {
ui_browser__set_percent_color(browser, 0, current_entry);
Expand Down Expand Up @@ -273,9 +284,9 @@ static int disasm__cmp(struct browser_disasm_line *a,
int i;

for (i = 0; i < nr_pcnt; i++) {
if (a->percent[i] == b->percent[i])
if (a->samples[i].percent == b->samples[i].percent)
continue;
return a->percent[i] < b->percent[i];
return a->samples[i].percent < b->samples[i].percent;
}
return 0;
}
Expand Down Expand Up @@ -366,14 +377,17 @@ static void annotate_browser__calc_percent(struct annotate_browser *browser,
next = disasm__get_next_ip_line(&notes->src->source, pos);

for (i = 0; i < browser->nr_events; i++) {
bpos->percent[i] = disasm__calc_percent(notes,
u64 nr_samples;

bpos->samples[i].percent = disasm__calc_percent(notes,
evsel->idx + i,
pos->offset,
next ? next->offset : len,
&path);
&path, &nr_samples);
bpos->samples[i].nr = nr_samples;

if (max_percent < bpos->percent[i])
max_percent = bpos->percent[i];
if (max_percent < bpos->samples[i].percent)
max_percent = bpos->samples[i].percent;
}

if (max_percent < 0.01) {
Expand Down Expand Up @@ -737,6 +751,7 @@ static int annotate_browser__run(struct annotate_browser *browser,
"n Search next string\n"
"o Toggle disassembler output/simplified view\n"
"s Toggle source code view\n"
"t Toggle total period view\n"
"/ Search string\n"
"k Toggle line numbers\n"
"r Run available scripts\n"
Expand Down Expand Up @@ -812,6 +827,11 @@ static int annotate_browser__run(struct annotate_browser *browser,
ui_helpline__puts("Actions are only available for 'callq', 'retq' & jump instructions.");
}
continue;
case 't':
annotate_browser__opts.show_total_period =
!annotate_browser__opts.show_total_period;
annotate_browser__update_addr_width(browser);
continue;
case K_LEFT:
case K_ESC:
case 'q':
Expand All @@ -832,6 +852,10 @@ static int annotate_browser__run(struct annotate_browser *browser,
int map_symbol__tui_annotate(struct map_symbol *ms, struct perf_evsel *evsel,
struct hist_browser_timer *hbt)
{
/* Set default value for show_total_period. */
annotate_browser__opts.show_total_period =
symbol_conf.show_total_period;

return symbol__tui_annotate(ms->sym, ms->map, evsel, hbt);
}

Expand Down Expand Up @@ -929,7 +953,8 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map,

if (perf_evsel__is_group_event(evsel)) {
nr_pcnt = evsel->nr_members;
sizeof_bdl += sizeof(double) * (nr_pcnt - 1);
sizeof_bdl += sizeof(struct disasm_line_samples) *
(nr_pcnt - 1);
}

if (symbol__annotate(sym, map, sizeof_bdl) < 0) {
Expand Down Expand Up @@ -1006,6 +1031,7 @@ static struct annotate_config {
ANNOTATE_CFG(show_linenr),
ANNOTATE_CFG(show_nr_jumps),
ANNOTATE_CFG(use_offset),
ANNOTATE_CFG(show_total_period),
};

#undef ANNOTATE_CFG
Expand Down
Loading

0 comments on commit a9a3cd9

Please sign in to comment.