mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org,
	Milian Wolff <milian.wolff@kdab.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	David Ahern <dsahern@gmail.com>, Jiri Olsa <jolsa@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	Wang Nan <wangnan0@huawei.com>,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 10/19] perf trace: Add support for printing call chains on sys_exit events.
Date: Mon, 11 Apr 2016 22:53:41 -0300	[thread overview]
Message-ID: <1460426030-27319-11-git-send-email-acme@kernel.org> (raw)
In-Reply-To: <1460426030-27319-1-git-send-email-acme@kernel.org>

From: Milian Wolff <milian.wolff@kdab.com>

Now, one can print the call chain for every encountered sys_exit event,
e.g.:

    $ perf trace -e nanosleep --call-graph dwarf path/to/ex_sleep
    1005.757 (1000.090 ms): ex_sleep/13167 nanosleep(...) = 0
                                             syscall_slow_exit_work ([kernel.kallsyms])
                                             syscall_return_slowpath ([kernel.kallsyms])
                                             int_ret_from_sys_call ([kernel.kallsyms])
                                             __nanosleep (/usr/lib/libc-2.23.so)
                                             [unknown] (/usr/lib/libQt5Core.so.5.6.0)
                                             QThread::sleep (/usr/lib/libQt5Core.so.5.6.0)
                                             main (path/to/ex_sleep)
                                             __libc_start_main (/usr/lib/libc-2.23.so)
                                             _start (path/to/ex_sleep)

Note that it is advised to increase the number of mmap pages to prevent
event losses when using this new feature. Often, adding `-m 10M` to the
`perf trace` invocation is enough.

This feature is also available in strace when built with libunwind via
`strace -k`. Performance wise, this solution is much better:

    $ time find path/to/linux &> /dev/null

    real    0m0.051s
    user    0m0.013s
    sys     0m0.037s

    $ time perf trace -m 800M --call-graph dwarf find path/to/linux &> /dev/null

    real    0m2.624s
    user    0m1.203s
    sys     0m1.333s

    $ time strace -k find path/to/linux  &> /dev/null

    real    0m35.398s
    user    0m10.403s
    sys     0m23.173s

Note that it is currently not possible to configure the print output.
Adding such a feature, similar to what is available in `perf script` via
its `--fields` knob can be added later on.

Signed-off-by: Milian Wolff <milian.wolff@kdab.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
LPU-Reference: 1460115255-17648-1-git-send-email-milian.wolff@kdab.com
[ Split from a larger patch, do not print the IP, left align,
  remove dup call symbol__init(), added man page entry ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Documentation/perf-trace.txt |  6 ++++++
 tools/perf/builtin-trace.c              | 22 ++++++++++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/tools/perf/Documentation/perf-trace.txt b/tools/perf/Documentation/perf-trace.txt
index 13293de8869f..ed485df16409 100644
--- a/tools/perf/Documentation/perf-trace.txt
+++ b/tools/perf/Documentation/perf-trace.txt
@@ -117,6 +117,12 @@ the thread executes on the designated CPUs. Default is to monitor all CPUs.
 --syscalls::
 	Trace system calls. This options is enabled by default.
 
+--call-graph [mode,type,min[,limit],order[,key][,branch]]::
+        Setup and enable call-graph (stack chain/backtrace) recording.
+        See `--call-graph` section in perf-record and perf-report
+        man pages for details. The ones that are most useful in 'perf trace'
+        are 'dwarf' and 'lbr', where available, try: 'perf trace --call-graph dwarf'.
+
 --event::
 	Trace other events, see 'perf list' for a complete list.
 
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 27d987030627..8c587a8d3742 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -34,6 +34,7 @@
 #include "trace-event.h"
 #include "util/parse-events.h"
 #include "util/bpf-loader.h"
+#include "callchain.h"
 #include "syscalltbl.h"
 
 #include <libaudit.h> /* FIXME: Still needed for audit_errno_to_name */
@@ -2190,6 +2191,21 @@ signed_print:
 		goto signed_print;
 
 	fputc('\n', trace->output);
+
+	if (sample->callchain) {
+		struct addr_location al;
+		/* TODO: user-configurable print_opts */
+		const unsigned int print_opts = PRINT_IP_OPT_SYM
+					      | PRINT_IP_OPT_DSO;
+
+		if (machine__resolve(trace->host, &al, sample) < 0) {
+			pr_err("problem processing %d event, skipping it.\n",
+			       event->header.type);
+			goto out_put;
+		}
+		perf_evsel__print_ip(evsel, sample, &al, 38, print_opts,
+				     scripting_max_stack, trace->output);
+	}
 out:
 	ttrace->entry_pending = false;
 	err = 0;
@@ -3250,6 +3266,9 @@ 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_CALLBACK(0, "call-graph", &trace.opts,
+		     "record_mode[,record_size]", record_callchain_help,
+		     &record_parse_callchain_opt),
 	OPT_UINTEGER(0, "proc-map-timeout", &trace.opts.proc_map_timeout,
 			"per thread proc mmap processing timeout in ms"),
 	OPT_END()
@@ -3285,6 +3304,9 @@ int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused)
 		trace.opts.sample_time = true;
 	}
 
+	if (trace.opts.callgraph_set)
+		symbol_conf.use_callchain = true;
+
 	if (trace.evlist->nr_entries > 0)
 		evlist__set_evsel_handler(trace.evlist, trace__event_handler);
 
-- 
2.5.5

  parent reply	other threads:[~2016-04-12  1:55 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-12  1:53 [GIT PULL 00/19] perf/core improvements Arnaldo Carvalho de Melo
2016-04-12  1:53 ` [PATCH 01/19] perf script: Use readdir() instead of deprecated readdir_r() Arnaldo Carvalho de Melo
2016-04-12  1:53 ` [PATCH 02/19] perf thread_map: " Arnaldo Carvalho de Melo
2016-04-12  1:53 ` [PATCH 03/19] perf tools: " Arnaldo Carvalho de Melo
2016-04-12  1:53 ` [PATCH 04/19] " Arnaldo Carvalho de Melo
2016-04-12  1:53 ` [PATCH 05/19] perf dwarf: Guard !x86_64 definitions under #ifdef else clause Arnaldo Carvalho de Melo
2016-04-12  1:53 ` [PATCH 06/19] perf bpf: Clone bpf stdout events in multiple bpf scripts Arnaldo Carvalho de Melo
2016-04-12  1:53 ` [PATCH 07/19] perf bpf: Automatically create bpf-output event __bpf_stdout__ Arnaldo Carvalho de Melo
2016-04-12  1:53 ` [PATCH 08/19] perf evsel: Allow specifying a file to output in perf_evsel__print_ip Arnaldo Carvalho de Melo
2016-04-12  1:53 ` [PATCH 09/19] perf evsel: Allow passing a left alignment when printing a symbol Arnaldo Carvalho de Melo
2016-04-12  1:53 ` Arnaldo Carvalho de Melo [this message]
2016-04-12  1:53 ` [PATCH 11/19] perf evsel: Rename print_ip() to fprintf_sym() Arnaldo Carvalho de Melo
2016-04-12  1:53 ` [PATCH 12/19] perf evsel: Introduce fprintf_callchain() method out of fprintf_sym() Arnaldo Carvalho de Melo
2016-04-12  1:53 ` [PATCH 13/19] perf trace: Exclude the kernel part of the callchain leading to a syscall Arnaldo Carvalho de Melo
2016-04-12  1:53 ` [PATCH 14/19] perf evsel: Do not use globals in config() Arnaldo Carvalho de Melo
2016-04-12  1:53 ` [PATCH 15/19] perf evlist: Add (reset,set)_sample_bit methods Arnaldo Carvalho de Melo
2016-04-12  1:53 ` [PATCH 16/19] perf evsel: Rename config_callgraph() to config_callchain() and make it public Arnaldo Carvalho de Melo
2016-04-12  1:53 ` [PATCH 17/19] perf trace: Make "--call-graph" affect just "raw_syscalls:sys_exit" Arnaldo Carvalho de Melo
2016-04-12  1:53 ` [PATCH 18/19] perf evsel: Allow unresolved symbol names to be printed as addresses Arnaldo Carvalho de Melo
2016-04-12  1:53 ` [PATCH 19/19] perf trace: Print unresolved symbol names " Arnaldo Carvalho de Melo
2016-04-13  7:03 ` [GIT PULL 00/19] perf/core improvements Ingo Molnar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1460426030-27319-11-git-send-email-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=adrian.hunter@intel.com \
    --cc=dsahern@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=milian.wolff@kdab.com \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=wangnan0@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome