Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2710976pxa; Fri, 7 Aug 2020 19:40:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy1MsGN8aHxkNgJfmdNP+fd5atVgaki79uOeVDFNv/IV4w78tyqtl03nce7OztKMikALBPZ X-Received: by 2002:a50:d1d8:: with SMTP id i24mr12084926edg.341.1596854420405; Fri, 07 Aug 2020 19:40:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596854420; cv=none; d=google.com; s=arc-20160816; b=K5c/SXbrDAA8a51zOUyqe+ou3L4hiXfKRNXWta2pInejoOvvqgKuwnRfMBLBfO8wHR PJOqx4tUccaK6rF6aEXBbscBy+quGV5B7DeBfOgMTJFy/SEZkvKdeBBbS4sxoeMgd8LF nZHq0uzhiaJhvxjfU9kU+IeJzDiNDskdYQK/X1qsFyngjoDY6clKMqWxvjUHine+vnhE SdWKQrJvPE9HyVjror9jXunrUskwhMjpF+0j9gd69ILIGxDaJnujAu8iCbTXY9RlZLGQ NQDdRlbWnD91TAb9kEH3pTJzCC9TXtcJvDcYtb8WRDV69NHD65HAx3aBbrPnigH1FtPo mhxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=XOAF8R7pkfmGmqrz35rVdWEvq0FEmyVSxeYF6yZIxVY=; b=TCpiCPIXi0LVotaGuOEA1C8D2d547gppGsduWcINOiUYPAaNH8m1JQmaky9vOHIWRG uzIFuG8CzpQ5z1sYtPmAtXzIRSRsV4L7uZFVhLQ0wTU4AelTLulw3S98i/RPDRWwFC8K rMsYIeOlcw3DLxoVBJETx2fhqkqXudZdKMyG4TcQnpDJ+1UYQmN2NTilprzzGNGJwEWz 37Xtj1AlCjDvr6rOM6ly2+EchbqH2RHdvHsGx6+r2J8hlZRnJ8jbDLuhZhlK/UzPCGZz SQxMWr12ZYcl9a8Wc5Tkdu84W39WcKx9bNC0f/z7OwVqGvVBhZoGxeKfBFjQHVwDIu88 6HTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=pYO7r25B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z6si6264292ejf.508.2020.08.07.19.39.57; Fri, 07 Aug 2020 19:40:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=pYO7r25B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726426AbgHHCjT (ORCPT + 99 others); Fri, 7 Aug 2020 22:39:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726200AbgHHCjT (ORCPT ); Fri, 7 Aug 2020 22:39:19 -0400 Received: from mail-qv1-xf43.google.com (mail-qv1-xf43.google.com [IPv6:2607:f8b0:4864:20::f43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1ECD7C061756 for ; Fri, 7 Aug 2020 19:39:19 -0700 (PDT) Received: by mail-qv1-xf43.google.com with SMTP id x7so1673252qvi.5 for ; Fri, 07 Aug 2020 19:39:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XOAF8R7pkfmGmqrz35rVdWEvq0FEmyVSxeYF6yZIxVY=; b=pYO7r25BQaIdiBHfry5YW81hFTRTAw5rWdeYxzU2AlHnM2TGrrM96x/sS5YYx5hkzS xIyRyjiGkLa0efX55qB+7+WWF9k1zB8y1XIHh1VqYbGBmL73RjobUpgA/RUkqe+UfyoY 9pHLvnWzpRTPu6I6rdxw/1f1JsK6Y8sySjmYX6Aa1EcTWL/iWg+C5OUCHHMyMaG4Zb7+ /IyzlKTDzQdZosX9GpcSEykWd3oRUatRZXFdIo36Ig48DEElPPoFyijpSmYvFq6gs+w6 CBRPIjfqPakKTLVNwiuSedBozyFlWO4Ee14x80EeU3bmiytq/jTS9bTUlcsHLVSTQAOs ATtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XOAF8R7pkfmGmqrz35rVdWEvq0FEmyVSxeYF6yZIxVY=; b=EzbQc1Zid7IrWkPjgpajLL72iVvjUSquUyvdlBowyMYktJE93BM2DbnqlawHWpxhQ+ h8Nr0sYtRc/k3DQ1E8mis26Nr75YCC1dZvQ3a56VSBQJhMni3Pw0V+TBPMM2cTgwtBnI 16lgiNBeduAQHQxHxyc+ZcELe4Vtwj1QeD5mpjiCLEE1hUERvNZkXpQKGf9FR4J/r5eF UNeyrgPKXsjo3uL9Z33Rw5Sa8tOiWsnEC3nnRCfogFqlGXi/3C5e+XOwztatnYBpfVs9 GZxsZvrLn37ol1FcUH8t6nNuImwqOCOnXujJzcn4JO1V4HkN0lXZIDMDhexcgYKeRe2R mnMA== X-Gm-Message-State: AOAM533206RmZOjgqPgDtuZ1Vyv/rECnirD/xQVv25lpJ0pjot5z6r8i HH+7y+A5IUUhEyTQHIBKGwA= X-Received: by 2002:a0c:99c8:: with SMTP id y8mr17542227qve.57.1596854358383; Fri, 07 Aug 2020 19:39:18 -0700 (PDT) Received: from vultr.guest ([66.42.85.36]) by smtp.gmail.com with ESMTPSA id n33sm7818702qtd.43.2020.08.07.19.39.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Aug 2020 19:39:17 -0700 (PDT) From: Changbin Du To: Jiri Olsa , Arnaldo Carvalho de Melo Cc: Peter Zijlstra , Ingo Molnar , Namhyung Kim , Steven Rostedt , linux-kernel@vger.kernel.org, Changbin Du Subject: [PATCH v8 08/18] perf ftrace: add support for tracing option 'func_stack_trace' Date: Sat, 8 Aug 2020 10:31:31 +0800 Message-Id: <20200808023141.14227-9-changbin.du@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200808023141.14227-1-changbin.du@gmail.com> References: <20200808023141.14227-1-changbin.du@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This adds support to display call trace for function tracer. To do this, just specify a '--func-opts call-graph' option. $ sudo perf ftrace -T vfs_read --func-opts call-graph iio-sensor-prox-855 [003] 6168.369657: vfs_read <-ksys_read iio-sensor-prox-855 [003] 6168.369677: => vfs_read => ksys_read => __x64_sys_read => do_syscall_64 => entry_SYSCALL_64_after_hwframe ... Signed-off-by: Changbin Du --- v3: switch to uniform option --func-opts. v2: option name '-s' -> '--func-call-graph' --- tools/perf/Documentation/perf-ftrace.txt | 4 +++ tools/perf/builtin-ftrace.c | 42 ++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/tools/perf/Documentation/perf-ftrace.txt b/tools/perf/Documentation/perf-ftrace.txt index c46d0a09b38c..8f08ad0992c2 100644 --- a/tools/perf/Documentation/perf-ftrace.txt +++ b/tools/perf/Documentation/perf-ftrace.txt @@ -76,6 +76,10 @@ OPTIONS specify multiple functions (or glob patterns). It will be passed to 'set_ftrace_notrace' in tracefs. +--func-opts:: + List of options allowed to set: + call-graph - Display kernel stack trace for function tracer. + -G:: --graph-funcs=:: Select function_graph tracer and set graph filter on the given diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c index 07b81d0c1658..469b89748c42 100644 --- a/tools/perf/builtin-ftrace.c +++ b/tools/perf/builtin-ftrace.c @@ -27,6 +27,7 @@ #include "util/cap.h" #include "util/config.h" #include "util/units.h" +#include "util/parse-sublevel-options.h" #define DEFAULT_TRACER "function_graph" @@ -42,6 +43,7 @@ struct perf_ftrace { int graph_depth; unsigned long percpu_buffer_size; bool inherit; + int func_stack_trace; }; struct filter_entry { @@ -202,6 +204,7 @@ static void reset_tracing_filters(void); static void reset_tracing_options(struct perf_ftrace *ftrace __maybe_unused) { write_tracing_option_file("function-fork", "0"); + write_tracing_option_file("func_stack_trace", "0"); } static int reset_tracing_files(struct perf_ftrace *ftrace __maybe_unused) @@ -278,6 +281,17 @@ static int set_tracing_cpu(struct perf_ftrace *ftrace) return set_tracing_cpumask(cpumap); } +static int set_tracing_func_stack_trace(struct perf_ftrace *ftrace) +{ + if (!ftrace->func_stack_trace) + return 0; + + if (write_tracing_option_file("func_stack_trace", "1") < 0) + return -1; + + return 0; +} + static int reset_tracing_cpu(void) { struct perf_cpu_map *cpumap = perf_cpu_map__new(NULL); @@ -426,6 +440,11 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv) goto out_reset; } + if (set_tracing_func_stack_trace(ftrace) < 0) { + pr_err("failed to set tracing option func_stack_trace\n"); + goto out_reset; + } + if (set_tracing_filters(ftrace) < 0) { pr_err("failed to set tracing filters\n"); goto out_reset; @@ -598,6 +617,26 @@ static int parse_buffer_size(const struct option *opt, return -1; } +static int parse_func_tracer_opts(const struct option *opt, + const char *str, int unset) +{ + int ret; + struct perf_ftrace *ftrace = (struct perf_ftrace *) opt->value; + struct sublevel_option func_tracer_opts[] = { + { .name = "call-graph", .value_ptr = &ftrace->func_stack_trace }, + { .name = NULL, } + }; + + if (unset) + return 0; + + ret = perf_parse_sublevel_options(str, func_tracer_opts); + if (ret) + return ret; + + return 0; +} + static void select_tracer(struct perf_ftrace *ftrace) { bool graph = !list_empty(&ftrace->graph_funcs) || @@ -645,6 +684,9 @@ int cmd_ftrace(int argc, const char **argv) parse_filter_func), OPT_CALLBACK('N', "notrace-funcs", &ftrace.notrace, "func", "do not trace given functions", parse_filter_func), + OPT_CALLBACK(0, "func-opts", &ftrace, "options", + "function tracer options, available options: call-graph", + parse_func_tracer_opts), OPT_CALLBACK('G', "graph-funcs", &ftrace.graph_funcs, "func", "trace given functions using function_graph tracer", parse_filter_func), -- 2.25.1