Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp175713ybh; Fri, 17 Jul 2020 23:49:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzqrsJngzmf/CsCxcSS7Bja7+51hSs2ghLQlT31AokOUiduDqJblzzBe3hMuEr+C2eJY0bm X-Received: by 2002:a17:906:ca56:: with SMTP id jx22mr11517331ejb.494.1595054989233; Fri, 17 Jul 2020 23:49:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595054989; cv=none; d=google.com; s=arc-20160816; b=qplgfX8brwtKRkIp71h0KSX1SqGANcto9J8ObUfUB1El2mSEDfSPe6ZaTBlmvujpeV mztz/CnGyscjuj0lDj+SjzY1M/0zi4JjLdglZpOe9cfpvB7f1O60EpRFqzxgFN/PmqJ4 oVl2ajt3cUj45Dq+qEbjNX2Q1MacNGr4hlZq3xBuv8rzUU5iBSPUh9CgSo5uIYKt1jSA DW84CvO4afD5B5Fx9NkBhgz2CTaQu2KhYeVXJ5RwREastkqsb/M6fV+q+029NuRUZhJM IbCDarIfQyKEgn1zc7dLr9qPvbvaDJzkvxkb84HFiF5vqtpg3zLQL+8H2NON6B4rcuYN 0V9A== 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=7wvydDy/tQ74G4O3jAzNKHUyywTE4V4qeYSnenBNOr0=; b=Iv2rjAWRVWRUMfiQgsOvU+drheM782b9iu2aT8rZQlTQdc95daU4F28n9it+4o0ipq EMLH5ucVC6Icy6bsOu35YWq99Vtm1PmB2AMEgsN9LPaTuG0ZmjUynpNLdMaZehceX/fE l7jHAq0YVwt1kKQLesi/K7WaVQ9jStt5Hj4/qmOxH401EosPRrkizfc91YxS4e85Rydf 7vfFs5n7vK+76qTfD0KIRhYmS0cocHTufuEfk1143gPmMx9Z5I8q+iXNlFrUBk+EnDva Vq0JbZY1XG0+olzfA0fTCJT+QrX5rzMmmhJOOraWsZqwN8jKhBYdS5c8LhfcG6IeFY6e BJYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=NqIBPceQ; 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 f1si6515944ejx.211.2020.07.17.23.49.26; Fri, 17 Jul 2020 23:49:49 -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=NqIBPceQ; 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 S1728975AbgGRGtA (ORCPT + 99 others); Sat, 18 Jul 2020 02:49:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725983AbgGRGtA (ORCPT ); Sat, 18 Jul 2020 02:49:00 -0400 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B509C0619D2 for ; Fri, 17 Jul 2020 23:49:00 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id a23so4827499pfk.13 for ; Fri, 17 Jul 2020 23:49:00 -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=7wvydDy/tQ74G4O3jAzNKHUyywTE4V4qeYSnenBNOr0=; b=NqIBPceQXdllqK3SLGQv24KxeUfp9ZEf9yQ0j55XsOS5NPc9phntOnCO6GS3Jx7RZe ldKqmgH5CuzJqYxVjtgF2CfTqpgZJRxlGzF+OtkJPXU3nq9UpB/nBB+Nj0U0LWmGiQ62 pGDNasYTLjaycr/4vqhXOAXg5IqdfP6XH1y7Zp8kjrkmNkBNjSwdkc6V9hQ2UYJGRw1e T1d4RuOsUfdEHJAKvo8uM1X9l1B25EGRwQ1LWz5D7YPcaOItSwUa3C4aTgfFOvIOYPxu zWvcAPdNVBuSEJIYwQ+0iPAJKHIn1y3+j5grMKm9HKsoiLuqRC8DiNr306ycGyGya/rY i6Dw== 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=7wvydDy/tQ74G4O3jAzNKHUyywTE4V4qeYSnenBNOr0=; b=L2XZprQqHK28EWdwy2cO+cnjHA5X+h8aRMrlz2OZIDCGYasJxv/lCOUd+eYx0jsylo 1CV++GXJRt2kGoXziE3/tE5jj7MSSBgA0TRZ/pUf4rX6CYNo6XfeO8zCyUiGwqn17Q1x 1zgclZQEI6FhA0/1izCGuxiAMogI4JqbaVISL+3uATWLam368Vv9dUg42MOnbGdM7K5b ZxsZIKhFVTuV7f9DOGEMPIBHRiq49uSpg2/U6mapZFcE31PRia0Y3SYRkWDB+zj5PAWM dGTiuXsnrfzatfJIcgZtLu+I/8RDHDK3GvmAmKgYj4bhi821SytdB6O7xHoSdiwf1RjK N35w== X-Gm-Message-State: AOAM533SiefSA+BfLEUVwqi/oBRZM7fcLlHCEblOJtqihXdiKjJoqL+h gh2cu4MUACYsr2VqEPXARQs= X-Received: by 2002:aa7:9e89:: with SMTP id p9mr11480507pfq.110.1595054939665; Fri, 17 Jul 2020 23:48:59 -0700 (PDT) Received: from vultr.guest ([149.248.10.52]) by smtp.gmail.com with ESMTPSA id q10sm10422781pfk.86.2020.07.17.23.48.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jul 2020 23:48: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 v7 02/18] perf ftrace: add option '-F/--funcs' to list available functions Date: Sat, 18 Jul 2020 14:48:10 +0800 Message-Id: <20200718064826.9865-3-changbin.du@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200718064826.9865-1-changbin.du@gmail.com> References: <20200718064826.9865-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 --- v3: fix return value issue. v2: option name '-l/--list-functions' -> '-F/--funcs' --- tools/perf/Documentation/perf-ftrace.txt | 4 +++ tools/perf/builtin-ftrace.c | 46 ++++++++++++++++++++++++ 2 files changed, 50 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..3c0e60fdfe0f 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,46 @@ 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) + break; + else 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 +342,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 +514,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