From de446b40d5ddb2c3f1fe453ac405543663f9ac5d Mon Sep 17 00:00:00 2001 From: Arnaldo Carvalho de Melo Date: Thu, 14 Apr 2016 14:56:06 -0300 Subject: perf evsel: Remove symbol_conf usage # perf test -v python 16: Try 'import perf' in python, checking link problems : --- start --- test child forked, pid 672 Traceback (most recent call last): File "", line 1, in ImportError: /tmp/build/perf/python/perf.so: undefined symbol: symbol_conf test child finished with -1 ---- end ---- Try 'import perf' in python, checking link problems: FAILED! # To fix it just pass a parameter to perf_evsel__fprintf_sym telling if callchains should be printed. Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-comrsr20bsnr8bg0n6rfwv12@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-script.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tools/perf/builtin-script.c') diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 838c0bc38105..717ba0215234 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -580,6 +580,7 @@ static void print_sample_bts(struct perf_sample *sample, } } perf_evsel__fprintf_sym(evsel, sample, al, 0, print_opts, + symbol_conf.use_callchain, scripting_max_stack, stdout); } @@ -790,6 +791,7 @@ static void process_event(struct perf_script *script, perf_evsel__fprintf_sym(evsel, sample, al, 0, output[attr->type].print_ip_opts, + symbol_conf.use_callchain, scripting_max_stack, stdout); } -- cgit v1.2.3 From 6f736735e30f51805f6be31d20a4bf5b0ae91bae Mon Sep 17 00:00:00 2001 From: Arnaldo Carvalho de Melo Date: Thu, 14 Apr 2016 17:45:51 -0300 Subject: perf evsel: Require that callchains be resolved before calling fprintf_{sym,callchain} This way the print routine merely does printing, not requiring access to the resolving machinery, which helps disentangling the object files and easing creating subsets with a limited functionality set. Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-2ti2jbra8fypdfawwwm3aee3@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-script.c | 36 ++++++++++++++++++++---------------- tools/perf/builtin-trace.c | 8 +++++--- tools/perf/util/evsel.c | 39 ++++++++++++++------------------------- tools/perf/util/evsel.h | 19 +++++++++---------- 4 files changed, 48 insertions(+), 54 deletions(-) (limited to 'tools/perf/builtin-script.c') diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 717ba0215234..875d84e7ba5b 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -569,19 +569,23 @@ static void print_sample_bts(struct perf_sample *sample, /* print branch_from information */ if (PRINT_FIELD(IP)) { unsigned int print_opts = output[attr->type].print_ip_opts; + struct callchain_cursor *cursor = NULL, cursor_callchain; - if (symbol_conf.use_callchain && sample->callchain) { - printf("\n"); - } else { - printf(" "); + if (symbol_conf.use_callchain && sample->callchain && + thread__resolve_callchain(al->thread, &cursor_callchain, evsel, + sample, NULL, NULL, scripting_max_stack) == 0) + cursor = &cursor_callchain; + + if (cursor == NULL) { + putchar(' '); if (print_opts & EVSEL__PRINT_SRCLINE) { print_srcline_last = true; print_opts &= ~EVSEL__PRINT_SRCLINE; } - } - perf_evsel__fprintf_sym(evsel, sample, al, 0, print_opts, - symbol_conf.use_callchain, - scripting_max_stack, stdout); + } else + putchar('\n'); + + sample__fprintf_sym(sample, al, 0, print_opts, cursor, stdout); } /* print branch_to information */ @@ -784,15 +788,15 @@ static void process_event(struct perf_script *script, printf("%16" PRIu64, sample->weight); if (PRINT_FIELD(IP)) { - if (!symbol_conf.use_callchain) - printf(" "); - else - printf("\n"); + struct callchain_cursor *cursor = NULL, cursor_callchain; + + if (symbol_conf.use_callchain && + thread__resolve_callchain(al->thread, &cursor_callchain, evsel, + sample, NULL, NULL, scripting_max_stack) == 0) + cursor = &cursor_callchain; - perf_evsel__fprintf_sym(evsel, sample, al, 0, - output[attr->type].print_ip_opts, - symbol_conf.use_callchain, - scripting_max_stack, stdout); + putchar(cursor ? '\n' : ' '); + sample__fprintf_sym(sample, al, 0, output[attr->type].print_ip_opts, cursor, stdout); } if (PRINT_FIELD(IREGS)) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index e5f0cc16bb93..0e2a82bda22f 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -1890,14 +1890,16 @@ static int trace__fprintf_callchain(struct trace *trace, struct perf_evsel *evse if (sample->callchain == NULL) return 0; - if (machine__resolve(trace->host, &al, sample) < 0) { + if (machine__resolve(trace->host, &al, sample) < 0 || + thread__resolve_callchain(al.thread, &callchain_cursor, evsel, + sample, NULL, NULL, scripting_max_stack)) { pr_err("Problem processing %s callchain, skipping...\n", perf_evsel__name(evsel)); return 0; } - return perf_evsel__fprintf_callchain(evsel, sample, &al, 38, print_opts, - scripting_max_stack, trace->output); + return sample__fprintf_callchain(sample, &al, 38, print_opts, + &callchain_cursor, trace->output); } static int trace__sys_exit(struct trace *trace, struct perf_evsel *evsel, diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 60bba67e6959..35c5a5282239 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -2343,13 +2343,12 @@ out: return ++printed; } -int perf_evsel__fprintf_callchain(struct perf_evsel *evsel, struct perf_sample *sample, - struct addr_location *al, int left_alignment, - unsigned int print_opts, unsigned int stack_depth, - FILE *fp) +int sample__fprintf_callchain(struct perf_sample *sample, + struct addr_location *al, int left_alignment, + unsigned int print_opts, struct callchain_cursor *cursor, + FILE *fp) { int printed = 0; - struct callchain_cursor cursor; struct callchain_cursor_node *node; int print_ip = print_opts & EVSEL__PRINT_IP; int print_sym = print_opts & EVSEL__PRINT_SYM; @@ -2363,22 +2362,15 @@ int perf_evsel__fprintf_callchain(struct perf_evsel *evsel, struct perf_sample * if (sample->callchain) { struct addr_location node_al; - if (thread__resolve_callchain(al->thread, &cursor, evsel, - sample, NULL, NULL, - stack_depth) != 0) { - if (verbose) - error("Failed to resolve callchain. Skipping\n"); - return printed; - } - callchain_cursor_commit(&cursor); + callchain_cursor_commit(cursor); if (print_symoffset) node_al = *al; - while (stack_depth) { + while (1) { u64 addr = 0; - node = callchain_cursor_current(&cursor); + node = callchain_cursor_current(cursor); if (!node) break; @@ -2418,20 +2410,17 @@ int perf_evsel__fprintf_callchain(struct perf_evsel *evsel, struct perf_sample * if (!print_oneline) printed += fprintf(fp, "\n"); - - stack_depth--; next: - callchain_cursor_advance(&cursor); + callchain_cursor_advance(cursor); } } return printed; } -int perf_evsel__fprintf_sym(struct perf_evsel *evsel, struct perf_sample *sample, - struct addr_location *al, int left_alignment, - unsigned int print_opts, bool print_callchain, - unsigned int stack_depth, FILE *fp) +int sample__fprintf_sym(struct perf_sample *sample, struct addr_location *al, + int left_alignment, unsigned int print_opts, + struct callchain_cursor *cursor, FILE *fp) { int printed = 0; int print_ip = print_opts & EVSEL__PRINT_IP; @@ -2441,9 +2430,9 @@ int perf_evsel__fprintf_sym(struct perf_evsel *evsel, struct perf_sample *sample int print_srcline = print_opts & EVSEL__PRINT_SRCLINE; int print_unknown_as_addr = print_opts & EVSEL__PRINT_UNKNOWN_AS_ADDR; - if (print_callchain && sample->callchain) { - printed += perf_evsel__fprintf_callchain(evsel, sample, al, left_alignment, - print_opts, stack_depth, fp); + if (cursor != NULL) { + printed += sample__fprintf_callchain(sample, al, left_alignment, + print_opts, cursor, fp); } else if (!(al->sym && al->sym->ignore)) { printed += fprintf(fp, "%-*.*s", left_alignment, left_alignment, " "); diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 013f3615730b..abadfea1dbaa 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -395,16 +395,15 @@ int perf_evsel__fprintf(struct perf_evsel *evsel, #define EVSEL__PRINT_SRCLINE (1<<5) #define EVSEL__PRINT_UNKNOWN_AS_ADDR (1<<6) -int perf_evsel__fprintf_callchain(struct perf_evsel *evsel, - struct perf_sample *sample, - struct addr_location *al, int left_alignment, - unsigned int print_opts, - unsigned int stack_depth, FILE *fp); - -int perf_evsel__fprintf_sym(struct perf_evsel *evsel, struct perf_sample *sample, - struct addr_location *al, int left_alignment, - unsigned int print_opts, bool print_callchain, - unsigned int stack_depth, FILE *fp); +struct callchain_cursor; + +int sample__fprintf_callchain(struct perf_sample *sample, struct addr_location *al, + int left_alignment, unsigned int print_opts, + struct callchain_cursor *cursor, FILE *fp); + +int sample__fprintf_sym(struct perf_sample *sample, struct addr_location *al, + int left_alignment, unsigned int print_opts, + struct callchain_cursor *cursor, FILE *fp); bool perf_evsel__fallback(struct perf_evsel *evsel, int err, char *msg, size_t msgsize); -- cgit v1.2.3 From 6125cc8dac432948a31df4d4ac20dd2d4f8c6c27 Mon Sep 17 00:00:00 2001 From: Arnaldo Carvalho de Melo Date: Thu, 14 Apr 2016 18:15:18 -0300 Subject: perf script: Add --max-stack knob Works just like with 'perf report'. In some cases we may want to have more than 127 entries, the default maximum. Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-mqkz2p5ok2978gztb0vsnocc@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/Documentation/perf-script.txt | 10 ++++++++++ tools/perf/builtin-script.c | 5 +++++ 2 files changed, 15 insertions(+) (limited to 'tools/perf/builtin-script.c') diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt index 22ef3933342a..4fc44c75263f 100644 --- a/tools/perf/Documentation/perf-script.txt +++ b/tools/perf/Documentation/perf-script.txt @@ -259,6 +259,16 @@ include::itrace.txt[] --full-source-path:: Show the full path for source files for srcline output. +--max-stack:: + Set the stack depth limit when parsing the callchain, anything + beyond the specified depth will be ignored. This is a trade-off + between information loss and faster processing especially for + workloads that can have a very long callchain stack. + Note that when using the --itrace option the synthesized callchain size + will override this value if the synthesized callchain size is bigger. + + Default: 127 + --ns:: Use 9 decimal places when displaying time (i.e. show the nanoseconds) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 875d84e7ba5b..0e93282b405e 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -22,6 +22,7 @@ #include "util/thread_map.h" #include "util/stat.h" #include +#include #include "asm/bug.h" #include "util/mem-events.h" @@ -2027,6 +2028,10 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused) "only consider symbols in these pids"), OPT_STRING(0, "tid", &symbol_conf.tid_list_str, "tid[,tid...]", "only consider symbols in these tids"), + OPT_UINTEGER(0, "max-stack", &scripting_max_stack, + "Set the maximum stack depth when parsing the callchain, " + "anything beyond the specified depth will be ignored. " + "Default: " __stringify(PERF_MAX_STACK_DEPTH)), OPT_BOOLEAN('I', "show-info", &show_full_info, "display extended information from perf.data file"), OPT_BOOLEAN('\0', "show-kernel-path", &symbol_conf.show_kernel_path, -- cgit v1.2.3