Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1166865ybk; Sun, 10 May 2020 08:10:15 -0700 (PDT) X-Google-Smtp-Source: APiQypKmxWIKy5qsxSv7ew9IESG1Ps2QGg5Vxv5p0Jw0Xc+Rn+YUPMe6I0PindtSI9XT5iNO+Uoc X-Received: by 2002:a17:907:20a2:: with SMTP id pw2mr10252051ejb.252.1589123415151; Sun, 10 May 2020 08:10:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589123415; cv=none; d=google.com; s=arc-20160816; b=N8A05pmFbPdcjQ0ND5dNdVUp3dL63euPNwqI0H4waxe75fTIDgSplSrmrUYE4BapQW a9Tu28j8DjI9hOkhA/8IlxMM1cxa5yCBFW5Mk+YT/YJ888XJxmlr3wF/I7K3S3PPC1XV 9kGcbcPfigPwTiAISLuFbfVZ6egv8blVGvSKqxZCLGWq5gvH//uPT6RLLIPxYY6lDl2X jdL2CWuvaDgbkgkcbyQ5HWA/4CqvAhEdw7CSydhOjbF+q1c3CedKD6WKo+HxFixuRU2Q Q+XfT7cgzwm81P+0usAEAp7xOvZmduKMSmV+kfwpijMSErbVuhyfMSYa3/fxSYkOpgKW zDPw== 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=/D51KRBfgHPLGzkJHJadx75PdlayeJcRyxV0asK4CGE=; b=yaDCJk2mivWg46u0OONIEdoJJcyJptuRExPFDs0BVV4E9ZYq6PpDjheY3W5BzgzNGO tJUWMnCigu3d1nW8yVE0USXiZq1f7KjYbjA0Dq7rROyRN9IUbxSVysSAqUXWkM1LnpjH NQeoBDWNRRE6WKrQFS0C4UvOFle5b2ngsboJZHbfSDzSSi86y2A72EOGp2zBbV/wzv8M +rPSlYR4mGz86vHDKpmAKhIgtI0S8zfbcl5a7xY/on21k+LhKZe3/cSZQ/rD2Z/XmxLN wqjvUVgzKrlhn2XIy2DVNqZ+EjuE3h8hHtebU78biQjFfgQMhh+KSnXfYYS7uTIMxWn4 zkrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="eGu1Qv/k"; 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 se23si37648ejb.247.2020.05.10.08.09.52; Sun, 10 May 2020 08:10:15 -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="eGu1Qv/k"; 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 S1729184AbgEJPII (ORCPT + 99 others); Sun, 10 May 2020 11:08:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726104AbgEJPII (ORCPT ); Sun, 10 May 2020 11:08:08 -0400 Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13EDFC061A0C for ; Sun, 10 May 2020 08:08:08 -0700 (PDT) Received: by mail-pl1-x642.google.com with SMTP id f15so2816008plr.3 for ; Sun, 10 May 2020 08:08:08 -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=/D51KRBfgHPLGzkJHJadx75PdlayeJcRyxV0asK4CGE=; b=eGu1Qv/kM3GdK+nvznzbqKw34j7nL438tQBFsg1roMiLyjvQKXlicBKTnZB6svOqrY tFyqKAU7h9YSg11POJZtDFZ51372dNIPJPLJuQHm6Fq2YaxOXQRgFOZKc29xvHGUrYdG cpomvqg9NUGU4nl6zk2Ol9+ijSr+fkCX2bjYzs4wS8dQ/GpSPoZ7D58A1+844fqeYJ55 Q/FqN1tLlhrhdLXetIcyTdYv9dbNOQDRs19/XNmbZeMndkuovTx2GY9nrhimzdgqyuc5 uGkcuNlVvTPszjT7JCzJuR0AH6FCyeaotjqyddlHkP/tkxX0lMOUOmlWFFNEucgYKr4+ viMQ== 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=/D51KRBfgHPLGzkJHJadx75PdlayeJcRyxV0asK4CGE=; b=hDNmmJqDQkIjk+BUuy8MW5dPT898+SQnZAFq6tSEEXqmYWHcptE3RSWNsqfVKWA8pt 5hTdApSSre4D6qsLN1oEnuBuHurNj5HyYX+2Kf7667WzX87StLvbIxYELgebUMvNMQAi KJtGS06xPSRNqmw+K6x1v4SBQdyAgHpHG/5NFGX7bVRj8BACpwa94JUf809Wlm+aVfml hwG3HdhhxREjubqfBJGGWOsseoxeXJ1AE9bAw0q8ohD00BD1ugtvx8PXWj6jDPD6MP0n nX69gKBLi+X5Ud/HdpTFy/E+2g6BzkR/KAmSBADScr+bgFop55icD87epwcOsra0Kv7x WoPg== X-Gm-Message-State: AGi0PuZXd5U0emJZuUc0+Y8J7ACKqt32lxI13Mhyr9CxiuePCd86KWUD S5zPtj05IBzox+ugTqv6xB4= X-Received: by 2002:a17:90a:d17:: with SMTP id t23mr17566493pja.77.1589123287626; Sun, 10 May 2020 08:08:07 -0700 (PDT) Received: from vultr.guest ([149.248.10.52]) by smtp.gmail.com with ESMTPSA id v7sm6870909pfm.146.2020.05.10.08.07.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 May 2020 08:08:06 -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 05/19] perf ftrace: add option '-l/--list-functions' to list available functions Date: Sun, 10 May 2020 23:06:14 +0800 Message-Id: <20200510150628.16610-6-changbin.du@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200510150628.16610-1-changbin.du@gmail.com> References: <20200510150628.16610-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 '-l/--list-functions' to list all available functions which is read from tracing file 'available_filter_functions'. Signed-off-by: Changbin Du --- tools/perf/builtin-ftrace.c | 43 +++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c index 1d30c2d5f88b..8133d910d5d8 100644 --- a/tools/perf/builtin-ftrace.c +++ b/tools/perf/builtin-ftrace.c @@ -33,6 +33,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; @@ -142,6 +143,43 @@ static int write_tracing_option_file(const char *name, const char *val) return ret; } +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); @@ -332,6 +370,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; @@ -483,6 +524,8 @@ int cmd_ftrace(int argc, const char **argv) NULL }; const struct option ftrace_options[] = { + OPT_BOOLEAN('L', "list-functions", &ftrace.list_avail_functions, + "List 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