64eff7d9c4
Allow user to specify list of symbols which cause the dump of callchains to stop at that symbol. Committer notes: Testing it: # perf record -ag usleep 1 [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 1.177 MB perf.data (33 samples) ] # # # Without it: # # perf script swapper 0 [000] 9693.370039: 1 cycles:ppp: 2072ad x86_pmu_enable (/usr/lib/debug/lib/modules/4.8.8-300.fc25.x86_64/vmlinux) 3a29d7 perf_pmu_enable.part.90 (/usr/lib/debug/lib/modules/4.8.8-300.fc25.x86_64/vmlinux) 3a713a ctx_resched (/usr/lib/debug/lib/modules/4.8.8-300.fc25.x86_64/vmlinux) 3a76c1 __perf_event_enable (/usr/lib/debug/lib/modules/4.8.8-300.fc25.x86_64/vmlinux) 3a0390 event_function (/usr/lib/debug/lib/modules/4.8.8-300.fc25.x86_64/vmlinux) 3a1cff remote_function (/usr/lib/debug/lib/modules/4.8.8-300.fc25.x86_64/vmlinux) 326978 flush_smp_call_function_queue (/usr/lib/debug/lib/modules/4.8.8-300.fc25.x86_64/vmlinux) 327413 generic_smp_call_function_single_interrupt (/usr/lib/debug/lib/modules/4.8.8-300.fc25.x86_64/vmlinux) 249b37 smp_call_function_single_interrupt (/usr/lib/debug/lib/modules/4.8.8-300.fc25.x86_64/vmlinux) a04b2c call_function_single_interrupt (/usr/lib/debug/lib/modules/4.8.8-300.fc25.x86_64/vmlinux) 889427 cpuidle_enter (/usr/lib/debug/lib/modules/4.8.8-300.fc25.x86_64/vmlinux) 2e534a call_cpuidle (/usr/lib/debug/lib/modules/4.8.8-300.fc25.x86_64/vmlinux) 2e5730 cpu_startup_entry (/usr/lib/debug/lib/modules/4.8.8-300.fc25.x86_64/vmlinux) 9f5167 rest_init (/usr/lib/debug/lib/modules/4.8.8-300.fc25.x86_64/vmlinux) 137ffeb start_kernel ([kernel.vmlinux].init.text) 137f2ca x86_64_start_reservations ([kernel.vmlinux].init.text) 137f419 x86_64_start_kernel ([kernel.vmlinux].init.text) swapper 0 [000] 9693.370044: 1 cycles:ppp: 20ca1b intel_pmu_handle_irq (/usr/lib/debug/lib/modules/4.8.8-300.fc25.x86_64/vmlinux) 205b0c perf_event_nmi_handler (/usr/lib/debug/lib/modules/4.8.8-300.fc25.x86_64/vmlinux) 22a14a nmi_handle (/usr/lib/debug/lib/modules/4.8.8-300.fc25.x86_64/vmlinux) 22a6b3 default_do_nmi (/usr/lib/debug/lib/modules/4.8.8-300.fc25.x86_64/vmlinux) 22a83c do_nmi (/usr/lib/debug/lib/modules/4.8.8-300.fc25.x86_64/vmlinux) a03fb1 end_repeat_nmi (/usr/lib/debug/lib/modules/4.8.8-300.fc25.x86_64/vmlinux) 3a29d7 perf_pmu_enable.part.90 (/usr/lib/debug/lib/modules/4.8.8-300.fc25.x86_64/vmlinux) 3a713a ctx_resched (/usr/lib/debug/lib/modules/4.8.8-300.fc25.x86_64/vmlinux) 3a76c1 __perf_event_enable (/usr/lib/debug/lib/modules/4.8.8-300.fc25.x86_64/vmlinux) 3a0390 event_function (/usr/lib/debug/lib/modules/4.8.8-300.fc25.x86_64/vmlinux) 3a1cff remote_function (/usr/lib/debug/lib/modules/4.8.8-300.fc25.x86_64/vmlinux) 326978 flush_smp_call_function_queue (/usr/lib/debug/lib/modules/4.8.8-300.fc25.x86_64/vmlinux) 327413 generic_smp_call_function_single_interrupt (/usr/lib/debug/lib/modules/4.8.8-300.fc25.x86_64/vmlinux) 249b37 smp_call_function_single_interrupt (/usr/lib/debug/lib/modules/4.8.8-300.fc25.x86_64/vmlinux) a04b2c call_function_single_interrupt (/usr/lib/debug/lib/modules/4.8.8-300.fc25.x86_64/vmlinux) 889427 cpuidle_enter (/usr/lib/debug/lib/modules/4.8.8-300.fc25.x86_64/vmlinux) 2e534a call_cpuidle (/usr/lib/debug/lib/modules/4.8.8-300.fc25.x86_64/vmlinux) 2e5730 cpu_startup_entry (/usr/lib/debug/lib/modules/4.8.8-300.fc25.x86_64/vmlinux) 9f5167 rest_init (/usr/lib/debug/lib/modules/4.8.8-300.fc25.x86_64/vmlinux) 137ffeb start_kernel ([kernel.vmlinux].init.text) 137f2ca x86_64_start_reservations ([kernel.vmlinux].init.text) # # # Using it to see just what are the calls from the 'remote_function' function: # # perf script --stop-bt remote_function swapper 0 [000] 9693.370039: 1 cycles:ppp: 2072ad x86_pmu_enable (/usr/lib/debug/lib/modules/4.8.8-300.fc25.x86_64/vmlinux) 3a29d7 perf_pmu_enable.part.90 (/usr/lib/debug/lib/modules/4.8.8-300.fc25.x86_64/vmlinux) 3a713a ctx_resched (/usr/lib/debug/lib/modules/4.8.8-300.fc25.x86_64/vmlinux) 3a76c1 __perf_event_enable (/usr/lib/debug/lib/modules/4.8.8-300.fc25.x86_64/vmlinux) 3a0390 event_function (/usr/lib/debug/lib/modules/4.8.8-300.fc25.x86_64/vmlinux) 3a1cff remote_function (/usr/lib/debug/lib/modules/4.8.8-300.fc25.x86_64/vmlinux) swapper 0 [000] 9693.370044: 1 cycles:ppp: 20ca1b intel_pmu_handle_irq (/usr/lib/debug/lib/modules/4.8.8-300.fc25.x86_64/vmlinux) 205b0c perf_event_nmi_handler (/usr/lib/debug/lib/modules/4.8.8-300.fc25.x86_64/vmlinux) 22a14a nmi_handle (/usr/lib/debug/lib/modules/4.8.8-300.fc25.x86_64/vmlinux) 22a6b3 default_do_nmi (/usr/lib/debug/lib/modules/4.8.8-300.fc25.x86_64/vmlinux) 22a83c do_nmi (/usr/lib/debug/lib/modules/4.8.8-300.fc25.x86_64/vmlinux) a03fb1 end_repeat_nmi (/usr/lib/debug/lib/modules/4.8.8-300.fc25.x86_64/vmlinux) 3a29d7 perf_pmu_enable.part.90 (/usr/lib/debug/lib/modules/4.8.8-300.fc25.x86_64/vmlinux) 3a713a ctx_resched (/usr/lib/debug/lib/modules/4.8.8-300.fc25.x86_64/vmlinux) 3a76c1 __perf_event_enable (/usr/lib/debug/lib/modules/4.8.8-300.fc25.x86_64/vmlinux) 3a0390 event_function (/usr/lib/debug/lib/modules/4.8.8-300.fc25.x86_64/vmlinux) 3a1cff remote_function (/usr/lib/debug/lib/modules/4.8.8-300.fc25.x86_64/vmlinux) Signed-off-by: David Ahern <dsa@cumulusnetworks.com> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/1480104021-36275-1-git-send-email-dsahern@gmail.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
231 lines
5.7 KiB
C
231 lines
5.7 KiB
C
#include <stdio.h>
|
|
#include <stdbool.h>
|
|
#include <traceevent/event-parse.h>
|
|
#include "evsel.h"
|
|
#include "callchain.h"
|
|
#include "map.h"
|
|
#include "symbol.h"
|
|
|
|
static int comma_fprintf(FILE *fp, bool *first, const char *fmt, ...)
|
|
{
|
|
va_list args;
|
|
int ret = 0;
|
|
|
|
if (!*first) {
|
|
ret += fprintf(fp, ",");
|
|
} else {
|
|
ret += fprintf(fp, ":");
|
|
*first = false;
|
|
}
|
|
|
|
va_start(args, fmt);
|
|
ret += vfprintf(fp, fmt, args);
|
|
va_end(args);
|
|
return ret;
|
|
}
|
|
|
|
static int __print_attr__fprintf(FILE *fp, const char *name, const char *val, void *priv)
|
|
{
|
|
return comma_fprintf(fp, (bool *)priv, " %s: %s", name, val);
|
|
}
|
|
|
|
int perf_evsel__fprintf(struct perf_evsel *evsel,
|
|
struct perf_attr_details *details, FILE *fp)
|
|
{
|
|
bool first = true;
|
|
int printed = 0;
|
|
|
|
if (details->event_group) {
|
|
struct perf_evsel *pos;
|
|
|
|
if (!perf_evsel__is_group_leader(evsel))
|
|
return 0;
|
|
|
|
if (evsel->nr_members > 1)
|
|
printed += fprintf(fp, "%s{", evsel->group_name ?: "");
|
|
|
|
printed += fprintf(fp, "%s", perf_evsel__name(evsel));
|
|
for_each_group_member(pos, evsel)
|
|
printed += fprintf(fp, ",%s", perf_evsel__name(pos));
|
|
|
|
if (evsel->nr_members > 1)
|
|
printed += fprintf(fp, "}");
|
|
goto out;
|
|
}
|
|
|
|
printed += fprintf(fp, "%s", perf_evsel__name(evsel));
|
|
|
|
if (details->verbose) {
|
|
printed += perf_event_attr__fprintf(fp, &evsel->attr,
|
|
__print_attr__fprintf, &first);
|
|
} else if (details->freq) {
|
|
const char *term = "sample_freq";
|
|
|
|
if (!evsel->attr.freq)
|
|
term = "sample_period";
|
|
|
|
printed += comma_fprintf(fp, &first, " %s=%" PRIu64,
|
|
term, (u64)evsel->attr.sample_freq);
|
|
}
|
|
|
|
if (details->trace_fields) {
|
|
struct format_field *field;
|
|
|
|
if (evsel->attr.type != PERF_TYPE_TRACEPOINT) {
|
|
printed += comma_fprintf(fp, &first, " (not a tracepoint)");
|
|
goto out;
|
|
}
|
|
|
|
field = evsel->tp_format->format.fields;
|
|
if (field == NULL) {
|
|
printed += comma_fprintf(fp, &first, " (no trace field)");
|
|
goto out;
|
|
}
|
|
|
|
printed += comma_fprintf(fp, &first, " trace_fields: %s", field->name);
|
|
|
|
field = field->next;
|
|
while (field) {
|
|
printed += comma_fprintf(fp, &first, "%s", field->name);
|
|
field = field->next;
|
|
}
|
|
}
|
|
out:
|
|
fputc('\n', fp);
|
|
return ++printed;
|
|
}
|
|
|
|
int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment,
|
|
unsigned int print_opts, struct callchain_cursor *cursor,
|
|
FILE *fp)
|
|
{
|
|
int printed = 0;
|
|
struct callchain_cursor_node *node;
|
|
int print_ip = print_opts & EVSEL__PRINT_IP;
|
|
int print_sym = print_opts & EVSEL__PRINT_SYM;
|
|
int print_dso = print_opts & EVSEL__PRINT_DSO;
|
|
int print_symoffset = print_opts & EVSEL__PRINT_SYMOFFSET;
|
|
int print_oneline = print_opts & EVSEL__PRINT_ONELINE;
|
|
int print_srcline = print_opts & EVSEL__PRINT_SRCLINE;
|
|
int print_unknown_as_addr = print_opts & EVSEL__PRINT_UNKNOWN_AS_ADDR;
|
|
int print_arrow = print_opts & EVSEL__PRINT_CALLCHAIN_ARROW;
|
|
int print_skip_ignored = print_opts & EVSEL__PRINT_SKIP_IGNORED;
|
|
char s = print_oneline ? ' ' : '\t';
|
|
bool first = true;
|
|
|
|
if (sample->callchain) {
|
|
struct addr_location node_al;
|
|
|
|
callchain_cursor_commit(cursor);
|
|
|
|
while (1) {
|
|
u64 addr = 0;
|
|
|
|
node = callchain_cursor_current(cursor);
|
|
if (!node)
|
|
break;
|
|
|
|
if (node->sym && node->sym->ignore && print_skip_ignored)
|
|
goto next;
|
|
|
|
printed += fprintf(fp, "%-*.*s", left_alignment, left_alignment, " ");
|
|
|
|
if (print_arrow && !first)
|
|
printed += fprintf(fp, " <-");
|
|
|
|
if (print_ip)
|
|
printed += fprintf(fp, "%c%16" PRIx64, s, node->ip);
|
|
|
|
if (node->map)
|
|
addr = node->map->map_ip(node->map, node->ip);
|
|
|
|
if (print_sym) {
|
|
printed += fprintf(fp, " ");
|
|
node_al.addr = addr;
|
|
node_al.map = node->map;
|
|
|
|
if (print_symoffset) {
|
|
printed += __symbol__fprintf_symname_offs(node->sym, &node_al,
|
|
print_unknown_as_addr,
|
|
true, fp);
|
|
} else {
|
|
printed += __symbol__fprintf_symname(node->sym, &node_al,
|
|
print_unknown_as_addr, fp);
|
|
}
|
|
}
|
|
|
|
if (print_dso) {
|
|
printed += fprintf(fp, " (");
|
|
printed += map__fprintf_dsoname(node->map, fp);
|
|
printed += fprintf(fp, ")");
|
|
}
|
|
|
|
if (print_srcline)
|
|
printed += map__fprintf_srcline(node->map, addr, "\n ", fp);
|
|
|
|
if (!print_oneline)
|
|
printed += fprintf(fp, "\n");
|
|
|
|
if (symbol_conf.bt_stop_list &&
|
|
node->sym &&
|
|
node->sym->name &&
|
|
strlist__has_entry(symbol_conf.bt_stop_list,
|
|
node->sym->name)) {
|
|
break;
|
|
}
|
|
|
|
first = false;
|
|
next:
|
|
callchain_cursor_advance(cursor);
|
|
}
|
|
}
|
|
|
|
return printed;
|
|
}
|
|
|
|
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;
|
|
int print_sym = print_opts & EVSEL__PRINT_SYM;
|
|
int print_dso = print_opts & EVSEL__PRINT_DSO;
|
|
int print_symoffset = print_opts & EVSEL__PRINT_SYMOFFSET;
|
|
int print_srcline = print_opts & EVSEL__PRINT_SRCLINE;
|
|
int print_unknown_as_addr = print_opts & EVSEL__PRINT_UNKNOWN_AS_ADDR;
|
|
|
|
if (cursor != NULL) {
|
|
printed += sample__fprintf_callchain(sample, left_alignment,
|
|
print_opts, cursor, fp);
|
|
} else {
|
|
printed += fprintf(fp, "%-*.*s", left_alignment, left_alignment, " ");
|
|
|
|
if (print_ip)
|
|
printed += fprintf(fp, "%16" PRIx64, sample->ip);
|
|
|
|
if (print_sym) {
|
|
printed += fprintf(fp, " ");
|
|
if (print_symoffset) {
|
|
printed += __symbol__fprintf_symname_offs(al->sym, al,
|
|
print_unknown_as_addr,
|
|
true, fp);
|
|
} else {
|
|
printed += __symbol__fprintf_symname(al->sym, al,
|
|
print_unknown_as_addr, fp);
|
|
}
|
|
}
|
|
|
|
if (print_dso) {
|
|
printed += fprintf(fp, " (");
|
|
printed += map__fprintf_dsoname(al->map, fp);
|
|
printed += fprintf(fp, ")");
|
|
}
|
|
|
|
if (print_srcline)
|
|
printed += map__fprintf_srcline(al->map, al->addr, "\n ", fp);
|
|
}
|
|
|
|
return printed;
|
|
}
|