From: Masami Hiramatsu <mhiramat@kernel.org>
To: "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>,
Steven Rostedt <rostedt@goodmis.org>,
Ingo Molnar <mingo@redhat.com>,
linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
Ananth N Mavinakayanahalli <ananth@linux.vnet.ibm.com>,
Michael Ellerman <mpe@ellerman.id.au>
Subject: Re: [PATCH 5/6] perf: probes: move ftrace README parsing logic into trace-event-parse.c
Date: Tue, 7 Mar 2017 15:03:32 +0100 [thread overview]
Message-ID: <20170307150332.5ecac6a63a6c1d27247cbcb4@kernel.org> (raw)
In-Reply-To: <b5e4defdba760ea9a48681e3c3075b3517037008.1488881988.git.naveen.n.rao@linux.vnet.ibm.com>
On Tue, 7 Mar 2017 16:17:40 +0530
"Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com> wrote:
> probe-file.c needs libelf, but scanning ftrace README does not require
> that. As such, move the ftrace README scanning logic out of probe-file.c
> and into trace-event-parse.c.
Hmm, it seems probe-file.c doesn't require libelf at all...
I would like to keep ftrace related things in probe-file.c.
Thanks,
>
> Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
> ---
> tools/perf/util/probe-file.c | 87 +++---------------------------------
> tools/perf/util/probe-file.h | 2 -
> tools/perf/util/trace-event-parse.c | 89 +++++++++++++++++++++++++++++++++++++
> tools/perf/util/trace-event.h | 4 ++
> 4 files changed, 99 insertions(+), 83 deletions(-)
>
> diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c
> index 1542cd0d6799..ff872fa30cdb 100644
> --- a/tools/perf/util/probe-file.c
> +++ b/tools/perf/util/probe-file.c
> @@ -26,6 +26,7 @@
> #include <api/fs/tracing_path.h>
> #include "probe-event.h"
> #include "probe-file.h"
> +#include "trace-event.h"
> #include "session.h"
>
> #define MAX_CMDLEN 256
> @@ -70,33 +71,17 @@ static void print_both_open_warning(int kerr, int uerr)
> }
> }
>
> -int open_trace_file(const char *trace_file, bool readwrite)
> -{
> - char buf[PATH_MAX];
> - int ret;
> -
> - ret = e_snprintf(buf, PATH_MAX, "%s/%s",
> - tracing_path, trace_file);
> - if (ret >= 0) {
> - pr_debug("Opening %s write=%d\n", buf, readwrite);
> - if (readwrite && !probe_event_dry_run)
> - ret = open(buf, O_RDWR | O_APPEND, 0);
> - else
> - ret = open(buf, O_RDONLY, 0);
> -
> - if (ret < 0)
> - ret = -errno;
> - }
> - return ret;
> -}
> -
> static int open_kprobe_events(bool readwrite)
> {
> + if (probe_event_dry_run)
> + readwrite = false;
> return open_trace_file("kprobe_events", readwrite);
> }
>
> static int open_uprobe_events(bool readwrite)
> {
> + if (probe_event_dry_run)
> + readwrite = false;
> return open_trace_file("uprobe_events", readwrite);
> }
>
> @@ -877,72 +862,12 @@ int probe_cache__show_all_caches(struct strfilter *filter)
> return 0;
> }
>
> -enum ftrace_readme {
> - FTRACE_README_PROBE_TYPE_X = 0,
> - FTRACE_README_KRETPROBE_OFFSET,
> - FTRACE_README_END,
> -};
> -
> -static struct {
> - const char *pattern;
> - bool avail;
> -} ftrace_readme_table[] = {
> -#define DEFINE_TYPE(idx, pat) \
> - [idx] = {.pattern = pat, .avail = false}
> - DEFINE_TYPE(FTRACE_README_PROBE_TYPE_X, "*type: * x8/16/32/64,*"),
> - DEFINE_TYPE(FTRACE_README_KRETPROBE_OFFSET, "*place (kretprobe): *"),
> -};
> -
> -static bool scan_ftrace_readme(enum ftrace_readme type)
> -{
> - int fd;
> - FILE *fp;
> - char *buf = NULL;
> - size_t len = 0;
> - bool ret = false;
> - static bool scanned = false;
> -
> - if (scanned)
> - goto result;
> -
> - fd = open_trace_file("README", false);
> - if (fd < 0)
> - return ret;
> -
> - fp = fdopen(fd, "r");
> - if (!fp) {
> - close(fd);
> - return ret;
> - }
> -
> - while (getline(&buf, &len, fp) > 0)
> - for (enum ftrace_readme i = 0; i < FTRACE_README_END; i++)
> - if (!ftrace_readme_table[i].avail)
> - ftrace_readme_table[i].avail =
> - strglobmatch(buf, ftrace_readme_table[i].pattern);
> - scanned = true;
> -
> - fclose(fp);
> - free(buf);
> -
> -result:
> - if (type >= FTRACE_README_END)
> - return false;
> -
> - return ftrace_readme_table[type].avail;
> -}
> -
> bool probe_type_is_available(enum probe_type type)
> {
> if (type >= PROBE_TYPE_END)
> return false;
> else if (type == PROBE_TYPE_X)
> - return scan_ftrace_readme(FTRACE_README_PROBE_TYPE_X);
> + return probe_type_x_is_supported();
>
> return true;
> }
> -
> -bool kretprobe_offset_is_supported(void)
> -{
> - return scan_ftrace_readme(FTRACE_README_KRETPROBE_OFFSET);
> -}
> diff --git a/tools/perf/util/probe-file.h b/tools/perf/util/probe-file.h
> index dbf95a00864a..eba44c3e9dca 100644
> --- a/tools/perf/util/probe-file.h
> +++ b/tools/perf/util/probe-file.h
> @@ -35,7 +35,6 @@ enum probe_type {
>
> /* probe-file.c depends on libelf */
> #ifdef HAVE_LIBELF_SUPPORT
> -int open_trace_file(const char *trace_file, bool readwrite);
> int probe_file__open(int flag);
> int probe_file__open_both(int *kfd, int *ufd, int flag);
> struct strlist *probe_file__get_namelist(int fd);
> @@ -65,7 +64,6 @@ struct probe_cache_entry *probe_cache__find_by_name(struct probe_cache *pcache,
> const char *group, const char *event);
> int probe_cache__show_all_caches(struct strfilter *filter);
> bool probe_type_is_available(enum probe_type type);
> -bool kretprobe_offset_is_supported(void);
> #else /* ! HAVE_LIBELF_SUPPORT */
> static inline struct probe_cache *probe_cache__new(const char *tgt __maybe_unused)
> {
> diff --git a/tools/perf/util/trace-event-parse.c b/tools/perf/util/trace-event-parse.c
> index de0078e21408..77697c446cbd 100644
> --- a/tools/perf/util/trace-event-parse.c
> +++ b/tools/perf/util/trace-event-parse.c
> @@ -23,10 +23,12 @@
> #include <string.h>
> #include <ctype.h>
> #include <errno.h>
> +#include <api/fs/tracing_path.h>
>
> #include "../perf.h"
> #include "util.h"
> #include "trace-event.h"
> +#include "debug.h"
>
> static int get_common_field(struct scripting_context *context,
> int *offset, int *size, const char *type)
> @@ -254,3 +256,90 @@ unsigned long long eval_flag(const char *flag)
>
> return 0;
> }
> +
> +int open_trace_file(const char *trace_file, bool readwrite)
> +{
> + char buf[PATH_MAX];
> + int ret;
> +
> + ret = snprintf(buf, PATH_MAX, "%s/%s",
> + tracing_path, trace_file);
> + if (ret >= PATH_MAX)
> + ret = -E2BIG;
> + if (ret >= 0) {
> + pr_debug("Opening %s write=%d\n", buf, readwrite);
> + if (readwrite)
> + ret = open(buf, O_RDWR | O_APPEND, 0);
> + else
> + ret = open(buf, O_RDONLY, 0);
> +
> + if (ret < 0)
> + ret = -errno;
> + }
> + return ret;
> +}
> +
> +enum ftrace_readme {
> + FTRACE_README_PROBE_TYPE_X = 0,
> + FTRACE_README_KRETPROBE_OFFSET,
> + FTRACE_README_END,
> +};
> +
> +static struct {
> + const char *pattern;
> + bool avail;
> +} ftrace_readme_table[] = {
> +#define DEFINE_TYPE(idx, pat) \
> + [idx] = {.pattern = pat, .avail = false}
> + DEFINE_TYPE(FTRACE_README_PROBE_TYPE_X, "*type: * x8/16/32/64,*"),
> + DEFINE_TYPE(FTRACE_README_KRETPROBE_OFFSET, "*place (kretprobe): *"),
> +};
> +
> +static bool scan_ftrace_readme(enum ftrace_readme type)
> +{
> + int fd;
> + FILE *fp;
> + char *buf = NULL;
> + size_t len = 0;
> + bool ret = false;
> + static bool scanned = false;
> +
> + if (scanned)
> + goto result;
> +
> + fd = open_trace_file("README", false);
> + if (fd < 0)
> + return ret;
> +
> + fp = fdopen(fd, "r");
> + if (!fp) {
> + close(fd);
> + return ret;
> + }
> +
> + while (getline(&buf, &len, fp) > 0)
> + for (enum ftrace_readme i = 0; i < FTRACE_README_END; i++)
> + if (!ftrace_readme_table[i].avail)
> + ftrace_readme_table[i].avail =
> + strglobmatch(buf, ftrace_readme_table[i].pattern);
> + scanned = true;
> +
> + fclose(fp);
> + free(buf);
> +
> +result:
> + if (type >= FTRACE_README_END)
> + return false;
> +
> + return ftrace_readme_table[type].avail;
> +}
> +
> +bool kretprobe_offset_is_supported(void)
> +{
> + return scan_ftrace_readme(FTRACE_README_KRETPROBE_OFFSET);
> +}
> +
> +bool probe_type_x_is_supported(void)
> +{
> + return scan_ftrace_readme(FTRACE_README_PROBE_TYPE_X);
> +}
> diff --git a/tools/perf/util/trace-event.h b/tools/perf/util/trace-event.h
> index 1fbc044f9eb0..ecda2d822daf 100644
> --- a/tools/perf/util/trace-event.h
> +++ b/tools/perf/util/trace-event.h
> @@ -37,6 +37,10 @@ int parse_ftrace_file(struct pevent *pevent, char *buf, unsigned long size);
> int parse_event_file(struct pevent *pevent,
> char *buf, unsigned long size, char *sys);
>
> +int open_trace_file(const char *trace_file, bool readwrite);
> +bool kretprobe_offset_is_supported(void);
> +bool probe_type_x_is_supported(void);
> +
> unsigned long long
> raw_field_value(struct event_format *event, const char *name, void *data);
>
> --
> 2.11.1
>
--
Masami Hiramatsu <mhiramat@kernel.org>
next prev parent reply other threads:[~2017-03-07 17:47 UTC|newest]
Thread overview: 61+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-22 13:53 [PATCH v2 0/5] kretprobe fixes Naveen N. Rao
2017-02-22 13:53 ` [PATCH v2 1/5] kretprobes: ensure probe location is at function entry Naveen N. Rao
2017-03-07 8:13 ` [tip:perf/core] kretprobes: Ensure " tip-bot for Naveen N. Rao
2017-02-22 13:53 ` [PATCH v2 2/5] powerpc: kretprobes: override default function entry offset Naveen N. Rao
2017-02-24 19:57 ` Arnaldo Carvalho de Melo
2017-02-27 12:56 ` Michael Ellerman
2017-02-25 2:45 ` Ananth N Mavinakayanahalli
2017-02-22 13:53 ` [PATCH v2 3/5] trace/kprobes: allow return probes with offsets and absolute addresses Naveen N. Rao
2017-02-27 16:32 ` Steven Rostedt
2017-02-27 16:52 ` [PATCH v2 3.5/5] trace/kprobes: Add back warning about offset in return probes Steven Rostedt (VMware)
2017-02-28 0:01 ` Masami Hiramatsu
2017-03-01 15:16 ` Naveen N. Rao
2017-03-07 8:20 ` [tip:perf/core] " tip-bot for Steven Rostedt (VMware)
2017-03-07 8:15 ` [tip:perf/core] trace/kprobes: Allow return probes with offsets and absolute addresses tip-bot for Naveen N. Rao
2017-02-22 13:53 ` [PATCH v2 4/5] perf: kretprobes: offset from reloc_sym if kernel supports it Naveen N. Rao
2017-02-23 9:10 ` Masami Hiramatsu
2017-02-23 11:37 ` [PATCH v3 1/2] perf: probe: generalize probe event file open routine Naveen N. Rao
2017-02-24 16:46 ` Masami Hiramatsu
2017-02-24 20:07 ` Arnaldo Carvalho de Melo
2017-03-01 15:12 ` Naveen N. Rao
2017-03-07 8:17 ` [tip:perf/core] perf probe: Generalize " tip-bot for Naveen N. Rao
2017-02-23 11:37 ` [PATCH v3 2/2] perf: kretprobes: offset from reloc_sym if kernel supports it Naveen N. Rao
2017-02-24 17:12 ` Masami Hiramatsu
2017-03-01 15:11 ` Naveen N. Rao
2017-02-23 19:16 ` [PATCH v2 4/5] " Naveen N. Rao
2017-02-24 17:29 ` Masami Hiramatsu
2017-02-24 20:11 ` Arnaldo Carvalho de Melo
2017-02-24 23:55 ` Masami Hiramatsu
2017-03-01 15:14 ` Naveen N. Rao
2017-03-02 17:55 ` Naveen N. Rao
2017-03-02 19:06 ` Arnaldo Carvalho de Melo
2017-03-02 17:55 ` [PATCH v4 1/3] perf: probe: factor out the ftrace README scanning Naveen N. Rao
2017-03-04 0:09 ` Masami Hiramatsu
2017-03-07 20:45 ` Steven Rostedt
2017-03-02 17:55 ` [PATCH v4 2/3] perf: kretprobes: offset from reloc_sym if kernel supports it Naveen N. Rao
2017-03-04 0:49 ` Masami Hiramatsu
2017-03-04 2:35 ` Masami Hiramatsu
2017-03-04 2:38 ` Masami Hiramatsu
2017-03-04 4:34 ` Masami Hiramatsu
2017-03-06 16:20 ` Naveen N. Rao
2017-03-06 17:49 ` Naveen N. Rao
2017-03-06 21:06 ` Masami Hiramatsu
2017-03-07 10:47 ` [PATCH v4 2/3] perf: kretprobes: offset from reloc_sym if kernel Naveen N. Rao
2017-03-07 10:47 ` [RESEND PATCH 1/6] trace/kprobes: fix check for kretprobe offset within function entry Naveen N. Rao
2017-03-07 20:47 ` Steven Rostedt
2017-03-08 8:01 ` Naveen N. Rao
2017-03-07 10:47 ` [RESEND PATCH 2/6] powerpc: kretprobes: override default function entry offset Naveen N. Rao
2017-03-07 10:47 ` [RESEND PATCH 3/6] perf: probe: factor out the ftrace README scanning Naveen N. Rao
2017-03-07 10:47 ` [RESEND PATCH 4/6] perf: kretprobes: offset from reloc_sym if kernel supports it Naveen N. Rao
2017-03-07 10:47 ` [PATCH 5/6] perf: probes: move ftrace README parsing logic into trace-event-parse.c Naveen N. Rao
2017-03-07 14:03 ` Masami Hiramatsu [this message]
2017-03-07 14:29 ` Naveen N. Rao
2017-03-07 15:51 ` Masami Hiramatsu
2017-03-07 16:31 ` Naveen N. Rao
2017-03-07 10:47 ` [RESEND PATCH 6/6] perf: powerpc: choose local entry point with kretprobes Naveen N. Rao
2017-03-07 16:49 ` [PATCH v2 " Naveen N. Rao
2017-03-06 15:04 ` [PATCH v4 2/3] perf: kretprobes: offset from reloc_sym if kernel supports it Naveen N. Rao
2017-03-06 21:14 ` Masami Hiramatsu
2017-03-02 17:55 ` [PATCH v4 3/3] perf: powerpc: choose local entry point with kretprobes Naveen N. Rao
2017-03-04 0:50 ` Masami Hiramatsu
2017-02-22 13:53 ` [PATCH v2 5/5] " Naveen N. Rao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170307150332.5ecac6a63a6c1d27247cbcb4@kernel.org \
--to=mhiramat@kernel.org \
--cc=acme@kernel.org \
--cc=ananth@linux.vnet.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mingo@redhat.com \
--cc=mpe@ellerman.id.au \
--cc=naveen.n.rao@linux.vnet.ibm.com \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).