]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
perf record: Add support to collect callchains from kernel or user space only
authoryuzhoujian <yuzhoujian@didichuxing.com>
Thu, 30 May 2019 13:29:22 +0000 (14:29 +0100)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 10 Jun 2019 18:50:01 +0000 (15:50 -0300)
One can just record callchains in the kernel or user space with this new
options.

We can use it together with "--all-kernel" options.

This two options is used just like print_stack(sys) or print_ustack(usr)
for systemtap.

Shown below is the usage of this new option combined with "--all-kernel"
options:

1. Configure all used events to run in kernel space and just collect
   kernel callchains.

  $ perf record -a -g --all-kernel --kernel-callchains

2. Configure all used events to run in kernel space and just collect
   user callchains.

  $ perf record -a -g --all-kernel --user-callchains

Committer notes:

Improved documentation to state that asking for kernel callchains really
is asking for excluding user callchains, and vice versa.

Further mentioned that using both won't get both, but nothing, as both
will be excluded.

Signed-off-by: yuzhoujian <yuzhoujian@didichuxing.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Milian Wolff <milian.wolff@kdab.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/1559222962-22891-1-git-send-email-ufo19890607@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/Documentation/perf-record.txt
tools/perf/builtin-record.c
tools/perf/perf.h
tools/perf/util/evsel.c

index de269430720a4111e7c30ae7871d05fa6c01a2b5..15e0fa87241b2ce543e0346d5b835db13e2ca560 100644 (file)
@@ -490,6 +490,17 @@ Configure all used events to run in kernel space.
 --all-user::
 Configure all used events to run in user space.
 
+--kernel-callchains::
+Collect callchains only from kernel space. I.e. this option sets
+perf_event_attr.exclude_callchain_user to 1.
+
+--user-callchains::
+Collect callchains only from user space. I.e. this option sets
+perf_event_attr.exclude_callchain_kernel to 1.
+
+Don't use both --kernel-callchains and --user-callchains at the same time or no
+callchains will be collected.
+
 --timestamp-filename
 Append timestamp to output file name.
 
index e2c3a585a61eb6acc48f55dd8c6ab2757a1216ff..dca55997934e069c369c40d5be398dbae7714a4d 100644 (file)
@@ -2191,6 +2191,10 @@ static struct option __record_options[] = {
        OPT_BOOLEAN_FLAG(0, "all-user", &record.opts.all_user,
                         "Configure all used events to run in user space.",
                         PARSE_OPT_EXCLUSIVE),
+       OPT_BOOLEAN(0, "kernel-callchains", &record.opts.kernel_callchains,
+                   "collect kernel callchains"),
+       OPT_BOOLEAN(0, "user-callchains", &record.opts.user_callchains,
+                   "collect user callchains"),
        OPT_STRING(0, "clang-path", &llvm_param.clang_path, "clang path",
                   "clang binary to use for compiling BPF scriptlets"),
        OPT_STRING(0, "clang-opt", &llvm_param.clang_opt, "clang options",
index d59dee61b64d88bafd4a39e1a24f2d750624f9d9..711e009381ec417b0a6dc73ff4bb48c2f6201b42 100644 (file)
@@ -61,6 +61,8 @@ struct record_opts {
        bool         record_switch_events;
        bool         all_kernel;
        bool         all_user;
+       bool         kernel_callchains;
+       bool         user_callchains;
        bool         tail_synthesize;
        bool         overwrite;
        bool         ignore_missing_thread;
index cc6e7a0dda928c5d1628c06f33e39e48c18e19ef..9f3b5807186301be89fa21abcce872cd75557cb0 100644 (file)
@@ -680,6 +680,10 @@ static void __perf_evsel__config_callchain(struct perf_evsel *evsel,
 
        attr->sample_max_stack = param->max_stack;
 
+       if (opts->kernel_callchains)
+               attr->exclude_callchain_user = 1;
+       if (opts->user_callchains)
+               attr->exclude_callchain_kernel = 1;
        if (param->record_mode == CALLCHAIN_LBR) {
                if (!opts->branch_stack) {
                        if (attr->exclude_user) {