Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp710945ybt; Wed, 8 Jul 2020 09:47:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwZgmE9/ZeaeGAg4ek6iRk4pbgj6ik/0AuEM3iVzmCvTEfjijKBqrMXiDzX2/5VaELdBlql X-Received: by 2002:a17:906:add3:: with SMTP id lb19mr44146575ejb.304.1594226862473; Wed, 08 Jul 2020 09:47:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594226862; cv=none; d=google.com; s=arc-20160816; b=bS8ih21K9fZW/gxWFZ2RZ7OUq/IObaBFo/e82S9aiPxIiKUkp6Apy4QqTJzAntK6Bo dAVLTwpOmDGJZDIFLsu0/jTHHux3egsvEdySzmocSNoFSmjCtjq65mQCJ2MVL6/NoXzy H3hAm/ewwYrugV2cwP/JbRJY64SPhg5m7JqsFcbj3NqyedY5D0+YQWEj16dhBVuRBrGK IBtJg+yTGl7ocZvCHrjEsFxGLFV6U4pU3FEWwak05W2dM4RNYLf962ZxTH+h3/D8f6dD ZBx6tnh+2KtD9/kFib9t6hlvhPN3ZGGzSXc5S7BQXRSOg73r8cRlveMQJfjy3E11SQkK NWgA== 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=zzCCa8Q6aazvWcy1YhsnRae+vjyUatsl26X+UO+0obI=; b=Uk2LR02OSPi/JNOXK/UTCTxWcsYrTPHEhQq17Q7muSI7xBZC4KiP+CdHs0trjsYx2q pOlz5y8gvMXk2pIVbfdWECiMNsoCMfAoIorBETToyAcAHpFD7Gc4eJbr0yrOeB6Nh/wo 8cJ8l6MykltDUKXeAyull7pwQlziufwfe0TtBRpEr1dIh3wxR/Rm/JUsY6bhwkMaJjw2 GfkxcxTRV20l1sc/eV3W6H+IZofa0AlyJrdWBZha6s908Nf4Wm6WtB4COW+hKOT007hm RAcq9B3oJRottcy826YnldlaC24/q+hnxKpspUI/CRFElKgDk37dZN7aivg/AXT3Jysy beXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Fiwn+2pj; 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 y5si225257ejc.674.2020.07.08.09.47.19; Wed, 08 Jul 2020 09:47:42 -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=Fiwn+2pj; 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 S1730653AbgGHQq7 (ORCPT + 99 others); Wed, 8 Jul 2020 12:46:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730634AbgGHQq7 (ORCPT ); Wed, 8 Jul 2020 12:46:59 -0400 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C741C061A0B for ; Wed, 8 Jul 2020 09:46:59 -0700 (PDT) Received: by mail-pf1-x441.google.com with SMTP id x72so10782731pfc.6 for ; Wed, 08 Jul 2020 09:46:59 -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=zzCCa8Q6aazvWcy1YhsnRae+vjyUatsl26X+UO+0obI=; b=Fiwn+2pj0GgoPkonYfRHw+sVBLA/JCPlvjY+ldzFHr2RO1CkftRcVB9wlvDrj7oshk y4ZmWIQqcTjY4nm2MFaHcTXMobpwttZrpTlB2kNbbyHvJquG+jMwF/Apyo7IoYdsRCvX 66WPwtrVy2mUs9pRf/oXJRPVIuoY34DD6saj3daPKRz02xR5DHROgjsVKImSPhuAWXYJ +alX7igIbul0krOVJzfLE2UCFFI9xDn83/c1lVh6qyAdOeWKdIcyST7QNgo5cErb/ZmT Sx8uMdU0wiU2icjUXHbELFMBV7YpxRC93nWxY5hgSjAJrhwiZERy+Y/iPOXjVPEf7qHZ r9Sg== 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=zzCCa8Q6aazvWcy1YhsnRae+vjyUatsl26X+UO+0obI=; b=OHrhjJScrHiS88YVc7MBjcmpzW6rTDD4Ib7g4Ho6BhsDz3sH/Y1HBfyRXh1d3f6RC+ fZkfl5yOBLe8lxoApgGV8Zyx5MPQacoVWPOX8Sdf2xu9HyYTJ0OWLIPwzhmH1+i/Vvmr tCt8VSuK8VEPixm8gjkzgwPdHkdBp2q6Rqh9wyboW8/g1qEWDhbzzN4WN7D4GAKxJjup snguPmtW8uTFOiQt5XM9EM3PBfDDSJleZ6HSC1h+zgwQIDJdvcKJ51I+/h5RQh4X55Iy sizLScZaBDIcFSYAe9OQGadys9TygSS2XlgVsIPdNaRUxXMYaj+m+VtUBAqOQcZVJAYi iH9Q== X-Gm-Message-State: AOAM5312Z7EL8BXQwBdYce4eNSqOv0g5QhljP2A1oxGzbuDzIv4v0RIT SIYAEP+NsTuUoL6jRDmvKUU= X-Received: by 2002:a63:475c:: with SMTP id w28mr51822291pgk.222.1594226819003; Wed, 08 Jul 2020 09:46:59 -0700 (PDT) Received: from vultr.guest ([149.248.10.52]) by smtp.gmail.com with ESMTPSA id r8sm310803pfg.147.2020.07.08.09.46.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jul 2020 09:46:58 -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 v3 02/17] perf ftrace: add option '-F/--funcs' to list available functions Date: Thu, 9 Jul 2020 00:45:50 +0800 Message-Id: <20200708164605.31245-3-changbin.du@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200708164605.31245-1-changbin.du@gmail.com> References: <20200708164605.31245-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 an option '-F/--funcs' to list all available functions to trace, which is read from tracing file 'available_filter_functions'. $ sudo ./perf ftrace -F | head trace_initcall_finish_cb initcall_blacklisted do_one_initcall do_one_initcall trace_initcall_start_cb run_init_process try_to_run_init_process match_dev_by_label match_dev_by_uuid rootfs_init_fs_context Signed-off-by: Changbin Du --- v2: option name '-l/--list-functions' -> '-F/--funcs' --- tools/perf/Documentation/perf-ftrace.txt | 4 +++ tools/perf/builtin-ftrace.c | 43 ++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/tools/perf/Documentation/perf-ftrace.txt b/tools/perf/Documentation/perf-ftrace.txt index 952e46669168..d79560dea19f 100644 --- a/tools/perf/Documentation/perf-ftrace.txt +++ b/tools/perf/Documentation/perf-ftrace.txt @@ -30,6 +30,10 @@ OPTIONS --verbose=:: Verbosity level. +-F:: +--funcs:: + List all available functions to trace. + -p:: --pid=:: Trace on existing process id (comma separated list). diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c index 5f53da87040d..244cc8e6bd60 100644 --- a/tools/perf/builtin-ftrace.c +++ b/tools/perf/builtin-ftrace.c @@ -32,6 +32,7 @@ struct perf_ftrace { struct evlist *evlist; struct target target; const char *tracer; + bool list_avail_functions; struct list_head filters; struct list_head notrace; struct list_head graph_funcs; @@ -127,6 +128,43 @@ static int append_tracing_file(const char *name, const char *val) return __write_tracing_file(name, val, true); } +static int read_tracing_file_to_stdout(const char *name) +{ + char buf[4096]; + char *file; + int fd; + int ret = -1; + + file = get_tracing_file(name); + if (!file) { + pr_debug("cannot get tracing file: %s\n", name); + return -1; + } + + fd = open(file, O_RDONLY); + if (fd < 0) { + pr_debug("cannot open tracing file: %s: %s\n", + name, str_error_r(errno, buf, sizeof(buf))); + goto out; + } + + /* read contents to stdout */ + while (true) { + int n = read(fd, buf, sizeof(buf)); + if (n <= 0) + goto out_close; + if (fwrite(buf, n, 1, stdout) != 1) + goto out_close; + } + ret = 0; + +out_close: + close(fd); +out: + put_tracing_file(file); + return ret; +} + static int reset_tracing_cpu(void); static void reset_tracing_filters(void); @@ -301,6 +339,9 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv) signal(SIGCHLD, sig_handler); signal(SIGPIPE, sig_handler); + if (ftrace->list_avail_functions) + return read_tracing_file_to_stdout("available_filter_functions"); + if (reset_tracing_files(ftrace) < 0) { pr_err("failed to reset ftrace\n"); goto out; @@ -470,6 +511,8 @@ int cmd_ftrace(int argc, const char **argv) const struct option ftrace_options[] = { OPT_STRING('t', "tracer", &ftrace.tracer, "tracer", "tracer to use: function or function_graph (This option is deprecated)"), + OPT_BOOLEAN('F', "funcs", &ftrace.list_avail_functions, + "Show available functions to filter"), OPT_STRING('p', "pid", &ftrace.target.pid, "pid", "trace on existing process id"), OPT_INCR('v', "verbose", &verbose, -- 2.25.1