Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp2058833ybt; Thu, 2 Jul 2020 23:01:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw2XoOuc5Y+Gv2dEHOedJAT7gLddeMIxz0MFUFy5almLUpJ5MwiVa/elNtXUgTNGuzcrFpk X-Received: by 2002:a17:906:fa9b:: with SMTP id lt27mr29861276ejb.513.1593756078156; Thu, 02 Jul 2020 23:01:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593756078; cv=none; d=google.com; s=arc-20160816; b=y59xARGHg2EcWlnUV1VhrLtdlouMzDgIYqdWIqxOQ5BI5EjIwinLrsy/9/i8BVqpnG bluRBFSRYFVDeb7vrezPLK5a8ZuWWuz3yYXR4Uhz0+DxNL/GMQZiU9X4iT4HFb79HvKI a5KAK8CPw7XXrhk0bO58drC5qGhip7D7uEb4O35kYoOcHzybcswFf8vH5KBqzqsRQsN8 yQIo2JDjyk9eqh3FYclW33Yw/FoYBMy+UUM7AHyqeVclXiygDBZ2kR5/SmtOqXj0w4fd GVV6Y6iqmOVl6mbwTzbBYYNUwxmDdMdW9wFkFGgyFo0BeySAuYvEFcmDYjxYqpSADlQs FahQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=u+aPRanIMiQjjns8+RslY/lDrmQZhnXMm0sSLoknRXk=; b=tg/MLc+yT/DzmrY48QCj+OpAPdimNpff/rDQ14Xtz/k+Rz2u1x3pWOm4ohYInMDums 7o2gz7v+F3zOF+lNz1xV9sqGg1a3aPLnnLTmvp3ytQ7QBWU2dwevt7vuXJCHHG7zMsGH +g73tNNIbyLF+iuJmqbrEFPq8ckodhdMmnpprBKwh/YdHPLP+M4JWQDKcYbhwlsyNbFn cUkukplANsBQjgzXJ9vbmLoW+tGJDDNu+LX9Y2AG5NiWrfb6mEfiRWhjJ3NDVRbboxAX kesAxWRtiLA2H8acjj0CWAEgm+llJObH/2r2W+V4nQ4pfz6ZP1b+KwDQlnYlpZt21TyT O8MA== ARC-Authentication-Results: i=1; mx.google.com; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ox25si7131293ejb.408.2020.07.02.23.00.54; Thu, 02 Jul 2020 23:01:18 -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; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726063AbgGCF6d (ORCPT + 99 others); Fri, 3 Jul 2020 01:58:33 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:42483 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725764AbgGCF6c (ORCPT ); Fri, 3 Jul 2020 01:58:32 -0400 Received: by mail-wr1-f68.google.com with SMTP id o11so31349070wrv.9 for ; Thu, 02 Jul 2020 22:58:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=u+aPRanIMiQjjns8+RslY/lDrmQZhnXMm0sSLoknRXk=; b=o/p1z2gYGfi7/2svx3oqliEO4EFuoXIeBg8eqVq8g1YF8rXgG7D4/AsJQXPfSP780C YBts59B8z4oupGbpTgzpmWuB0XfaEADbAlnjttjrC8j2aZPGwdzUfxMIsr1q/0PMqUOU ULcFUmjKZY32N3dQjZHUFcY9W9+zjyBFCoNpwbxzy3o8qM+yJlXWvXDqv4nLVypkODbw bsyDT2NJDkNEIG+DhOHycwTQoaErlHuRmCCRrceZhwcBfihjlM8GhiVUczzOJHaTrqWK rmJfoz3gPYtIRnwY/mocpV0uzfI02V/wXlw+UDZ++jwG4SoFaa1Wg0uSooVb9AWe7KpF TPpA== X-Gm-Message-State: AOAM530/y6ApLE7+D1mKzZtn65OelOzxkct+NgE5tNWhsjHNU1rH8saZ tnKV/abg0qiXA3u0URh+PI3gc0657TXlbJDzGj0= X-Received: by 2002:adf:fa8b:: with SMTP id h11mr35011343wrr.391.1593755910673; Thu, 02 Jul 2020 22:58:30 -0700 (PDT) MIME-Version: 1.0 References: <20200627133654.64863-1-changbin.du@gmail.com> <20200627133654.64863-3-changbin.du@gmail.com> In-Reply-To: <20200627133654.64863-3-changbin.du@gmail.com> From: Namhyung Kim Date: Fri, 3 Jul 2020 14:58:19 +0900 Message-ID: Subject: Re: [PATCH v2 02/15] perf ftrace: add option '-F/--funcs' to list available functions To: Changbin Du Cc: Jiri Olsa , Arnaldo Carvalho de Melo , Peter Zijlstra , Ingo Molnar , Steven Rostedt , linux-kernel Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Jun 27, 2020 at 10:37 PM Changbin Du wrote: > > 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 c5718503eded..e793118e83a9 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; It seems the return value cannot be 0? Thanks Namhyung > + > +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 >