--event::
        Trace other events, see 'perf list' for a complete list.
 
+--max-stack::
+        Set the stack depth limit when parsing the callchain, anything
+        beyond the specified depth will be ignored. Note that at this point
+        this is just about the presentation part, i.e. the kernel is still
+        not limiting, the overhead of callchains needs to be set via the
+        knobs in --call-graph dwarf.
+
+        Default: 127
+
 --proc-map-timeout::
        When processing pre-existing threads /proc/XXX/mmap, it may take a long time,
        because the file may be huge. A time out is needed in such cases.
 
 #include <linux/audit.h>
 #include <sys/ptrace.h>
 #include <linux/random.h>
+#include <linux/stringify.h>
 
 #ifndef O_CLOEXEC
 # define O_CLOEXEC             02000000
                u64             vfs_getname,
                                proc_getname;
        } stats;
+       unsigned int            max_stack;
        bool                    not_ev_qualifier;
        bool                    live;
        bool                    full_time;
 
        if (machine__resolve(trace->host, &al, sample) < 0 ||
            thread__resolve_callchain(al.thread, &callchain_cursor, evsel,
-                                     sample, NULL, NULL, scripting_max_stack)) {
+                                     sample, NULL, NULL, trace->max_stack)) {
                pr_err("Problem processing %s callchain, skipping...\n",
                        perf_evsel__name(evsel));
                return 0;
                .show_comm = true,
                .trace_syscalls = true,
                .kernel_syscallchains = false,
+               .max_stack = PERF_MAX_STACK_DEPTH,
        };
        const char *output_name = NULL;
        const char *ev_qualifier_str = NULL;
                     &record_parse_callchain_opt),
        OPT_BOOLEAN(0, "kernel-syscall-graph", &trace.kernel_syscallchains,
                    "Show the kernel callchains on the syscall exit path"),
+       OPT_UINTEGER(0, "max-stack", &trace.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_UINTEGER(0, "proc-map-timeout", &trace.opts.proc_map_timeout,
                        "per thread proc mmap processing timeout in ms"),
        OPT_END()