From: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>,
Adrian Hunter <adrian.hunter@intel.com>,
linux-kernel@vger.kernel.org, Ingo Molnar <mingo@redhat.com>,
Paul Mackerras <paulus@samba.org>, Jiri Olsa <jolsa@kernel.org>,
Namhyung Kim <namhyung@kernel.org>, Borislav Petkov <bp@suse.de>,
Hemant Kumar <hemant@linux.vnet.ibm.com>
Subject: [RFC PATCH perf/core 02/13] perf probe: Simplify __add_probe_trace_events code
Date: Mon, 01 Jun 2015 00:11:25 +0900 [thread overview]
Message-ID: <20150531151125.15103.38591.stgit@localhost.localdomain> (raw)
In-Reply-To: <20150531151120.15103.22153.stgit@localhost.localdomain>
Simplify the __add_probe_trace_events() code by taking out the
probe_trace_event__set_name() and updating show_perf_probe_event()
Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
---
tools/perf/util/probe-event.c | 92 +++++++++++++++++++++++------------------
1 file changed, 51 insertions(+), 41 deletions(-)
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index d27edef..9dd6419 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -2127,7 +2127,8 @@ kprobe_blacklist__find_by_address(struct list_head *blacklist,
}
/* Show an event */
-static int show_perf_probe_event(struct perf_probe_event *pev,
+static int show_perf_probe_event(const char *group, const char *event,
+ struct perf_probe_event *pev,
const char *module)
{
int i, ret;
@@ -2139,7 +2140,7 @@ static int show_perf_probe_event(struct perf_probe_event *pev,
if (!place)
return -EINVAL;
- ret = e_snprintf(buf, 128, "%s:%s", pev->group, pev->event);
+ ret = e_snprintf(buf, 128, "%s:%s", group, event);
if (ret < 0)
return ret;
@@ -2201,7 +2202,8 @@ static int __show_perf_probe_events(int fd, bool is_kprobe,
ret = convert_to_perf_probe_event(&tev, &pev,
is_kprobe);
if (ret >= 0)
- ret = show_perf_probe_event(&pev,
+ ret = show_perf_probe_event(pev.group,
+ pev.event, &pev,
tev.point.module);
}
next:
@@ -2374,18 +2376,55 @@ out:
free(buf);
}
+/* Set new name from original perf_probe_event and namelist */
+static int probe_trace_event__set_name(struct probe_trace_event *tev,
+ struct perf_probe_event *pev,
+ struct strlist *namelist,
+ bool allow_suffix)
+{
+ const char *event, *group;
+ char buf[64];
+ int ret;
+
+ if (pev->event)
+ event = pev->event;
+ else
+ if (pev->point.function && !strisglob(pev->point.function))
+ event = pev->point.function;
+ else
+ event = tev->point.realname;
+ if (pev->group)
+ group = pev->group;
+ else
+ group = PERFPROBE_GROUP;
+
+ /* Get an unused new event name */
+ ret = get_new_event_name(buf, 64, event,
+ namelist, allow_suffix);
+ if (ret < 0)
+ return ret;
+
+ event = buf;
+
+ tev->event = strdup(event);
+ tev->group = strdup(group);
+ if (tev->event == NULL || tev->group == NULL)
+ return -ENOMEM;
+
+ /* Add added event name to namelist */
+ strlist__add(namelist, event);
+ return 0;
+}
+
static int __add_probe_trace_events(struct perf_probe_event *pev,
struct probe_trace_event *tevs,
int ntevs, bool allow_suffix)
{
int i, fd, ret;
struct probe_trace_event *tev = NULL;
- char buf[64];
- const char *event, *group;
struct strlist *namelist;
LIST_HEAD(blacklist);
struct kprobe_blacklist_node *node;
- bool safename;
if (pev->uprobes)
fd = open_uprobe_events(true);
@@ -2411,7 +2450,6 @@ static int __add_probe_trace_events(struct perf_probe_event *pev,
pr_debug("No kprobe blacklist support, ignored\n");
}
- safename = (pev->point.function && !strisglob(pev->point.function));
ret = 0;
pr_info("Added new event%s\n", (ntevs > 1) ? "s:" : ":");
for (i = 0; i < ntevs; i++) {
@@ -2427,47 +2465,19 @@ static int __add_probe_trace_events(struct perf_probe_event *pev,
continue;
}
- if (pev->event)
- event = pev->event;
- else
- if (safename)
- event = pev->point.function;
- else
- event = tev->point.realname;
- if (pev->group)
- group = pev->group;
- else
- group = PERFPROBE_GROUP;
-
- /* Get an unused new event name */
- ret = get_new_event_name(buf, 64, event,
- namelist, allow_suffix);
+ /* Set new name for tev (and update namelist) */
+ ret = probe_trace_event__set_name(tev, pev, namelist,
+ allow_suffix);
if (ret < 0)
break;
- event = buf;
- tev->event = strdup(event);
- tev->group = strdup(group);
- if (tev->event == NULL || tev->group == NULL) {
- ret = -ENOMEM;
- break;
- }
ret = write_probe_trace_event(fd, tev);
if (ret < 0)
break;
- /* Add added event name to namelist */
- strlist__add(namelist, event);
-
- /* Trick here - save current event/group */
- event = pev->event;
- group = pev->group;
- pev->event = tev->event;
- pev->group = tev->group;
- show_perf_probe_event(pev, tev->point.module);
- /* Trick here - restore current event/group */
- pev->event = (char *)event;
- pev->group = (char *)group;
+ /* We use tev's name for showing new events */
+ show_perf_probe_event(tev->group, tev->event, pev,
+ tev->point.module);
/*
* Probes after the first probe which comes from same
* user input are always allowed to add suffix, because
next prev parent reply other threads:[~2015-05-31 15:14 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-31 15:11 [RFC PATCH perf/core 00/13] perf-probe --cache support Masami Hiramatsu
2015-05-31 15:11 ` [RFC PATCH perf/core 01/13] perf-buildid-cache: Use path/to/bin/buildid/elf instead of path/to/bin/buildid Masami Hiramatsu
2015-05-31 15:11 ` Masami Hiramatsu [this message]
2015-05-31 15:11 ` [RFC PATCH perf/core 03/13] perf probe: Move ftrace probe-event operations to probe-file.c Masami Hiramatsu
2015-05-31 15:11 ` [RFC PATCH perf/core 04/13] perf buildid: Use SBUILD_ID_SIZE macro Masami Hiramatsu
2015-05-31 15:11 ` [RFC PATCH perf/core 05/13] perf buildid: Introduce sysfs/filename__sprintf_build_id Masami Hiramatsu
2015-05-31 15:11 ` [RFC PATCH perf/core 06/13] perf: Add lsdir to read a directory Masami Hiramatsu
2015-05-31 15:11 ` [RFC PATCH perf/core 07/13] perf-buildid-cache: Use lsdir for looking up buildid caches Masami Hiramatsu
2015-05-31 15:11 ` [RFC PATCH perf/core 08/13] perf probe: Check kprobe blacklist in converting phase Masami Hiramatsu
2015-05-31 15:11 ` [RFC PATCH perf/core 09/13] perf probe: Use strbuf for making strings in probe-event.c Masami Hiramatsu
2015-05-31 15:11 ` [RFC PATCH perf/core 10/13] perf probe: Add --cache option to cache the probe definitions Masami Hiramatsu
2015-05-31 15:11 ` [RFC PATCH perf/core 11/13] perf probe: Use cache entry if possible Masami Hiramatsu
2015-05-31 15:11 ` [RFC PATCH perf/core 12/13] perf probe: Show all cached probes Masami Hiramatsu
2015-05-31 15:11 ` [RFC PATCH perf/core 13/13] perf probe: Remove caches when --cache is given Masami Hiramatsu
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=20150531151125.15103.38591.stgit@localhost.localdomain \
--to=masami.hiramatsu.pt@hitachi.com \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=bp@suse.de \
--cc=hemant@linux.vnet.ibm.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=paulus@samba.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
all inboxes | Powered by JetHome®