Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp555407ybt; Fri, 10 Jul 2020 06:49:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyWCym8Gk1NrQsDs8rnRDS3pnEakojPUgyxctgz6I/QeG6jcMsZ0S3eEd1juRuu4SAuRShV X-Received: by 2002:a17:906:3b15:: with SMTP id g21mr59169871ejf.221.1594388945161; Fri, 10 Jul 2020 06:49:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594388945; cv=none; d=google.com; s=arc-20160816; b=oO6lCqlGY5dbxv3TLU9VSP2Vd78VlfI9cTUqQW9IPzCliR7kAPzvkgTwW2nH2NaTbt 3tWc89F5wGEG8gtpWyHwQE9n6dQ4b1RCk7l6j0wMjKtd3gPorwm/sTE9pIRYnamp+nvm 4JS8T7sUvtfGhl82lxalgKFna8/d2EQ2sMhG5UKZduMDNEoFvGI5AkvjEDazQEZ79Hmx MriiZNWiT1Io6VsI3CgT4rGhaCr/tYTnUoHIDO9wZ6UL53Oxnn/38j5l1xzsiSYzHWwd 1z4crMhWuTG8MiNGadiVOG/vg/7d2RmZJ2SRAv0/k41T3D8t1xXGQUMaWFpS+4n5crJz qSSw== 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=qI2UxEq65Bm2hy2Ar9pHiCmTMt1XFcVBUAcKn4PHYsg=; b=FqTJr+AR5e0uL4ZqT3rL1+n+yWCatCKqTH5tFfoQxPxth5XfIVrab8YAzzHNY86/41 UI+thjvxRY/mJMjLaPXCO4xfVutvhE2T3cf+gH1z6biVNl/HSiSGe8ofuzITTbyhb99d 1Z/iwOypLggS6lG9gJEzL4tVXMstA49J8uiI36QjC/6TaQHFx0qR20Al3RLeKRoBWLTB nKZ5qFHTpyT8AaqPBEv/NgQyiFuZQaE0k4VsrtoMKmT6HcTUVwnX3z+Y+Emmd521Chq2 xBPDQGHbneebwW9YNkcs6Ydac7f3ZR3JhGksy5uWo6tz/eKHZYS1TlL+Z6s1BCXxmFAS usyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=WPkW7mFb; 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 1si4053477ejo.509.2020.07.10.06.48.41; Fri, 10 Jul 2020 06:49:05 -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=WPkW7mFb; 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 S1728316AbgGJNpd (ORCPT + 99 others); Fri, 10 Jul 2020 09:45:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728205AbgGJNow (ORCPT ); Fri, 10 Jul 2020 09:44:52 -0400 Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A802C08C5CE for ; Fri, 10 Jul 2020 06:44:50 -0700 (PDT) Received: by mail-pj1-x1043.google.com with SMTP id mn17so2640259pjb.4 for ; Fri, 10 Jul 2020 06:44:50 -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=qI2UxEq65Bm2hy2Ar9pHiCmTMt1XFcVBUAcKn4PHYsg=; b=WPkW7mFbgB0DGPHTp073QS/49tUR6KsQcZ7Qkt3bMpddHokGpAV6TLEaKW4naGpTTP N3G8kAMkhUWGS26jER934EbUWehFySsEderwaLaJTBdVc298vaWRaKwGtX1z2qUGrBgr ERMRERQ2gDkQPT82AJZtB9H14Rr+1wtZLw1has1ALzJrHNfKuUFzWe+4S3gNYEsxKpC2 6YJCRf8rZRWIzzj0/1ymLpiNzldDJWLz5f7ocgewXydOgdImcEB7P/a2cgszzHT7YFQH jk6aWA1jr75JFEUa9Fa0sIFy+VET5bwvSKh10POUiJgmkkekCUf0R6we7a8k75V9aymo 1z2Q== 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=qI2UxEq65Bm2hy2Ar9pHiCmTMt1XFcVBUAcKn4PHYsg=; b=Tjx2QFHFOgzcZ0x0dudW+/EgCxdQh4CHIuEhKV2+zosjU9VG8Im0QnOInCUL8Bv0Wh G1mNtFTO8DbxyxyznIhlwa+GvOofA1CaGU6J8L+Eeu4PVeD7xBJXIqqx6TbXViPEFIHs nEIpmfCXMpqruJCM8V6I4cpHqFjmQKHmO8WOo6/NmmGRrRMnrLtTqO1TIyxducItSfzw GY0iEH+cC8YaxqHVDHxS7b3z83Ba7uhCDbankNDjpFoVfhPNYfAjl6SoNPpc/uga6LWR L5PZZPlxEoULpg7tdZ/v/ZZ5NkwpQfIaOKZkZFFAx+83HIrMXrEe0LOsXY8XEQcKSmFC NhZw== X-Gm-Message-State: AOAM532k1+IikY1/WFwcIwq8rQcmBE/V78FfOsZAoGYTt/Bkkb4VGD8g cxqar9eiykF7dtSifMFZQUc= X-Received: by 2002:a17:90b:811:: with SMTP id bk17mr5607421pjb.183.1594388689891; Fri, 10 Jul 2020 06:44:49 -0700 (PDT) Received: from vultr.guest ([149.248.10.52]) by smtp.gmail.com with ESMTPSA id 198sm6297363pfb.27.2020.07.10.06.44.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jul 2020 06:44:49 -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 v4 09/17] perf ftrace: add support for tracing option 'func_stack_trace' Date: Fri, 10 Jul 2020 21:43:14 +0800 Message-Id: <20200710134322.15400-10-changbin.du@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200710134322.15400-1-changbin.du@gmail.com> References: <20200710134322.15400-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 fd632bd9b2c1..676a30cb9b5a 100644 --- a/tools/perf/Documentation/perf-ftrace.txt +++ b/tools/perf/Documentation/perf-ftrace.txt @@ -78,6 +78,10 @@ OPTIONS (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=:: Set graph filter on the given function (or a glob pattern). diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c index 4efaa7b6a906..91611eef5deb 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" struct perf_ftrace { struct evlist *evlist; @@ -40,6 +41,7 @@ struct perf_ftrace { int graph_depth; unsigned long percpu_buffer_size; bool inherit; + int func_stack_trace; }; struct filter_entry { @@ -197,6 +199,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) @@ -273,6 +276,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); @@ -421,6 +435,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; @@ -594,6 +613,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; +} + int cmd_ftrace(int argc, const char **argv) { int ret; @@ -626,6 +665,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