perf record: Allow to specify max stack depth of fp callchain
authorNamhyung Kim <namhyung@kernel.org>
Wed, 15 Jun 2022 16:32:21 +0000 (09:32 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 12 Jul 2022 12:56:05 +0000 (09:56 -0300)
Currently it has no interface to specify the max stack depth for perf
record.  Extend the command line parameter to accept a number after
'fp' to specify the depth like '--call-graph fp,32'.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Boqun Feng <boqun.feng@gmail.com>
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Waiman Long <longman@redhat.com>
Cc: Will Deacon <will@kernel.org>
Link: https://lore.kernel.org/r/20220615163222.1275500-7-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/Documentation/perf-record.txt
tools/perf/util/callchain.c

index 6bd6d07021bae8489426a0b4efe05f41304a9891..099817ef5150d7eee7c172e1b056694ea93a58d4 100644 (file)
@@ -275,6 +275,11 @@ OPTIONS
        User can change the size by passing the size after comma like
        "--call-graph dwarf,4096".
 
+       When "fp" recording is used, perf tries to save stack enties
+       up to the number specified in sysctl.kernel.perf_event_max_stack
+       by default.  User can change the number by passing it after comma
+       like "--call-graph fp,32".
+
 -q::
 --quiet::
        Don't print any message, useful for scripting.
index 5c27a4b2e7a7256d2b722b53f470f69c9cafe301..7e663673f79f96351acd14e50d1004969873db6f 100644 (file)
@@ -31,6 +31,7 @@
 #include "callchain.h"
 #include "branch.h"
 #include "symbol.h"
+#include "util.h"
 #include "../perf.h"
 
 #define CALLCHAIN_PARAM_DEFAULT                        \
@@ -266,12 +267,17 @@ int parse_callchain_record(const char *arg, struct callchain_param *param)
        do {
                /* Framepointer style */
                if (!strncmp(name, "fp", sizeof("fp"))) {
-                       if (!strtok_r(NULL, ",", &saveptr)) {
-                               param->record_mode = CALLCHAIN_FP;
-                               ret = 0;
-                       } else
-                               pr_err("callchain: No more arguments "
-                                      "needed for --call-graph fp\n");
+                       ret = 0;
+                       param->record_mode = CALLCHAIN_FP;
+
+                       tok = strtok_r(NULL, ",", &saveptr);
+                       if (tok) {
+                               unsigned long size;
+
+                               size = strtoul(tok, &name, 0);
+                               if (size < (unsigned) sysctl__max_stack())
+                                       param->max_stack = size;
+                       }
                        break;
 
                /* Dwarf style */