From: tip-bot for Tzvetomir Stoyanov <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: rostedt@goodmis.org, tstoyanov@vmware.com, jolsa@redhat.com,
acme@redhat.com, mingo@kernel.org, tglx@linutronix.de,
namhyung@kernel.org, akpm@linux-foundation.org,
linux-kernel@vger.kernel.org, hpa@zytor.com
Subject: [tip:perf/urgent] tools lib traceevent: Introduce new libtracevent API: tep_override_comm()
Date: Tue, 8 Jan 2019 23:12:34 -0800 [thread overview]
Message-ID: <tip-ca3958b1c0968a6f3105e211355f128ce871e796@git.kernel.org> (raw)
In-Reply-To: <20181130154648.038915912@goodmis.org>
Commit-ID: ca3958b1c0968a6f3105e211355f128ce871e796
Gitweb: https://git.kernel.org/tip/ca3958b1c0968a6f3105e211355f128ce871e796
Author: Tzvetomir Stoyanov <tstoyanov@vmware.com>
AuthorDate: Fri, 30 Nov 2018 10:44:11 -0500
Committer: Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Tue, 8 Jan 2019 13:28:13 -0300
tools lib traceevent: Introduce new libtracevent API: tep_override_comm()
This patch adds a new API of tracevent library: tep_override_comm() It
registers a pid / command mapping. If a mapping with the same pid
already exists, the entry is updated with the new command.
Signed-off-by: Tzvetomir Stoyanov <tstoyanov@vmware.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lkml.kernel.org/r/20181130154648.038915912@goodmis.org
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/lib/traceevent/event-parse.c | 69 +++++++++++++++++++++++++++++---------
tools/lib/traceevent/event-parse.h | 1 +
2 files changed, 55 insertions(+), 15 deletions(-)
diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
index 69a96e39f0ab..156e513074b2 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/lib/traceevent/event-parse.c
@@ -232,11 +232,13 @@ int tep_pid_is_registered(struct tep_handle *pevent, int pid)
* we must add this pid. This is much slower than when cmdlines
* are added before the array is initialized.
*/
-static int add_new_comm(struct tep_handle *pevent, const char *comm, int pid)
+static int add_new_comm(struct tep_handle *pevent,
+ const char *comm, int pid, bool override)
{
struct cmdline *cmdlines = pevent->cmdlines;
- const struct cmdline *cmdline;
+ struct cmdline *cmdline;
struct cmdline key;
+ char *new_comm;
if (!pid)
return 0;
@@ -247,8 +249,19 @@ static int add_new_comm(struct tep_handle *pevent, const char *comm, int pid)
cmdline = bsearch(&key, pevent->cmdlines, pevent->cmdline_count,
sizeof(*pevent->cmdlines), cmdline_cmp);
if (cmdline) {
- errno = EEXIST;
- return -1;
+ if (!override) {
+ errno = EEXIST;
+ return -1;
+ }
+ new_comm = strdup(comm);
+ if (!new_comm) {
+ errno = ENOMEM;
+ return -1;
+ }
+ free(cmdline->comm);
+ cmdline->comm = new_comm;
+
+ return 0;
}
cmdlines = realloc(cmdlines, sizeof(*cmdlines) * (pevent->cmdline_count + 1));
@@ -275,21 +288,13 @@ static int add_new_comm(struct tep_handle *pevent, const char *comm, int pid)
return 0;
}
-/**
- * tep_register_comm - register a pid / comm mapping
- * @pevent: handle for the pevent
- * @comm: the command line to register
- * @pid: the pid to map the command line to
- *
- * This adds a mapping to search for command line names with
- * a given pid. The comm is duplicated.
- */
-int tep_register_comm(struct tep_handle *pevent, const char *comm, int pid)
+static int _tep_register_comm(struct tep_handle *pevent,
+ const char *comm, int pid, bool override)
{
struct cmdline_list *item;
if (pevent->cmdlines)
- return add_new_comm(pevent, comm, pid);
+ return add_new_comm(pevent, comm, pid, override);
item = malloc(sizeof(*item));
if (!item)
@@ -312,6 +317,40 @@ int tep_register_comm(struct tep_handle *pevent, const char *comm, int pid)
return 0;
}
+/**
+ * tep_register_comm - register a pid / comm mapping
+ * @pevent: handle for the pevent
+ * @comm: the command line to register
+ * @pid: the pid to map the command line to
+ *
+ * This adds a mapping to search for command line names with
+ * a given pid. The comm is duplicated. If a command with the same pid
+ * already exist, -1 is returned and errno is set to EEXIST
+ */
+int tep_register_comm(struct tep_handle *pevent, const char *comm, int pid)
+{
+ return _tep_register_comm(pevent, comm, pid, false);
+}
+
+/**
+ * tep_override_comm - register a pid / comm mapping
+ * @pevent: handle for the pevent
+ * @comm: the command line to register
+ * @pid: the pid to map the command line to
+ *
+ * This adds a mapping to search for command line names with
+ * a given pid. The comm is duplicated. If a command with the same pid
+ * already exist, the command string is udapted with the new one
+ */
+int tep_override_comm(struct tep_handle *pevent, const char *comm, int pid)
+{
+ if (!pevent->cmdlines && cmdline_init(pevent)) {
+ errno = ENOMEM;
+ return -1;
+ }
+ return _tep_register_comm(pevent, comm, pid, true);
+}
+
int tep_register_trace_clock(struct tep_handle *pevent, const char *trace_clock)
{
pevent->trace_clock = strdup(trace_clock);
diff --git a/tools/lib/traceevent/event-parse.h b/tools/lib/traceevent/event-parse.h
index 35d37087d3c5..e6f4249910e6 100644
--- a/tools/lib/traceevent/event-parse.h
+++ b/tools/lib/traceevent/event-parse.h
@@ -432,6 +432,7 @@ int tep_set_function_resolver(struct tep_handle *pevent,
tep_func_resolver_t *func, void *priv);
void tep_reset_function_resolver(struct tep_handle *pevent);
int tep_register_comm(struct tep_handle *pevent, const char *comm, int pid);
+int tep_override_comm(struct tep_handle *pevent, const char *comm, int pid);
int tep_register_trace_clock(struct tep_handle *pevent, const char *trace_clock);
int tep_register_function(struct tep_handle *pevent, char *name,
unsigned long long addr, char *mod);
next prev parent reply other threads:[~2019-01-09 7:13 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-30 15:44 [PATCH 0/9] tools/lib/traceevent: More udpates to make libtraceevent into a library Steven Rostedt
2018-11-30 15:44 ` [PATCH 1/9] tools/lib/traceevent: Implemented new API tep_get_ref() Steven Rostedt
2018-12-14 20:34 ` [tip:perf/core] tools lib traceevent: Implement " tip-bot for Tzvetomir Stoyanov
2018-12-18 14:01 ` tip-bot for Tzvetomir Stoyanov
2018-11-30 15:44 ` [PATCH 2/9] tools/lib/traceevent: Added support for pkg-config Steven Rostedt
2018-12-04 7:32 ` Namhyung Kim
2018-12-04 8:51 ` Tzvetomir Stoyanov
2018-12-04 17:27 ` Steven Rostedt
2018-12-14 20:34 ` [tip:perf/core] tools lib traceevent: " tip-bot for Tzvetomir Stoyanov
2018-12-18 14:01 ` tip-bot for Tzvetomir Stoyanov
2018-11-30 15:44 ` [PATCH 3/9] tools/lib/traceevent: Install trace-seq.h API header file Steven Rostedt
2018-12-04 7:47 ` Namhyung Kim
2018-12-04 19:41 ` Steven Rostedt
2018-12-05 12:25 ` Jiri Olsa
2018-12-05 17:03 ` Steven Rostedt
2018-12-05 17:22 ` Jiri Olsa
2018-12-14 20:35 ` [tip:perf/core] tools lib traceevent: " tip-bot for Tzvetomir Stoyanov
2018-12-18 14:02 ` tip-bot for Tzvetomir Stoyanov
2018-11-30 15:44 ` [PATCH 4/9] tools/lib/traceevent, tools/perf: Rename struct tep_event_format to struct tep_event Steven Rostedt
2018-12-14 20:36 ` [tip:perf/core] tools lib traceevent, perf tools: Rename 'struct tep_event_format' to 'struct tep_event' tip-bot for Tzvetomir Stoyanov
2018-12-18 14:02 ` tip-bot for Tzvetomir Stoyanov
2018-11-30 15:44 ` [PATCH 5/9] tools/lib/traceevent: Rename tep_free_format() to tep_free_event() Steven Rostedt
2018-12-14 20:36 ` [tip:perf/core] tools lib traceevent: " tip-bot for Tzvetomir Stoyanov
2018-12-18 14:03 ` tip-bot for Tzvetomir Stoyanov
2018-11-30 15:44 ` [PATCH 6/9] tools/perf: traceevent API cleanup, remove __tep_data2host*() Steven Rostedt
2018-12-14 20:37 ` [tip:perf/core] perf tools: " tip-bot for Tzvetomir Stoyanov
2018-12-18 14:04 ` tip-bot for Tzvetomir Stoyanov
2018-11-30 15:44 ` [PATCH 7/9] tools/lib/traceevent: traceevent API cleanup Steven Rostedt
2018-11-30 19:18 ` Arnaldo Carvalho de Melo
2018-11-30 19:37 ` Steven Rostedt
2018-11-30 19:55 ` Arnaldo Carvalho de Melo
2018-11-30 19:57 ` Steven Rostedt
2018-11-30 20:09 ` Steven Rostedt
2018-11-30 20:16 ` Arnaldo Carvalho de Melo
2018-12-03 10:42 ` Arnaldo Carvalho de Melo
2018-12-14 20:37 ` [tip:perf/core] tools lib traceevent: " tip-bot for Tzvetomir Stoyanov
2018-12-18 14:04 ` tip-bot for Tzvetomir Stoyanov
2018-11-30 15:44 ` [PATCH 8/9] tools/lib/traceevent: Introduce new libtracevent API: tep_override_comm() Steven Rostedt
2019-01-08 13:35 ` Arnaldo Carvalho de Melo
2019-01-09 7:12 ` tip-bot for Tzvetomir Stoyanov [this message]
2018-11-30 15:44 ` [PATCH 9/9] tools/lib/traceevent: Add sanity check to is_timestamp_in_us() Steven Rostedt
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=tip-ca3958b1c0968a6f3105e211355f128ce871e796@git.kernel.org \
--to=tipbot@zytor.com \
--cc=acme@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=hpa@zytor.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
--cc=tstoyanov@vmware.com \
/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).