Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1432315
| From | Arnaldo Carvalho de Melo <acme@kernel.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH 16/18] perf data ctf: Generate comm event to CTF output |
| Date | 2016-06-27 23:10 +0200 |
| Message-ID | <rOLX4-5DX-23@gated-at.bofh.it> (permalink) |
| References | <rOLX3-5DX-3@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
From: Wang Nan <wangnan0@huawei.com>
If 'all' is selected, convert comm event to output CTF stream.
setup_non_sample_events() is called if non_sample is selected. It
creates a comm_class for comm event.
Use macros to generate and process_comm_event and add_comm_event. These
macros can be reused for other non-sample events.
Signed-off-by: Wang Nan <wangnan0@huawei.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1466767332-114472-6-git-send-email-wangnan0@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/util/data-convert-bt.c | 110 ++++++++++++++++++++++++++++++++++++++
1 file changed, 110 insertions(+)
diff --git a/tools/perf/util/data-convert-bt.c b/tools/perf/util/data-convert-bt.c
index 3b3ac7c143e1..5dd62ba07438 100644
--- a/tools/perf/util/data-convert-bt.c
+++ b/tools/perf/util/data-convert-bt.c
@@ -69,6 +69,7 @@ struct ctf_writer {
};
struct bt_ctf_field_type *array[6];
} data;
+ struct bt_ctf_event_class *comm_class;
};
struct convert {
@@ -763,6 +764,57 @@ static int process_sample_event(struct perf_tool *tool,
return cs ? 0 : -1;
}
+#define __NON_SAMPLE_SET_FIELD(_name, _type, _field) \
+do { \
+ ret = value_set_##_type(cw, event, #_field, _event->_name._field);\
+ if (ret) \
+ return -1; \
+} while(0)
+
+#define __FUNC_PROCESS_NON_SAMPLE(_name, body) \
+static int process_##_name##_event(struct perf_tool *tool, \
+ union perf_event *_event, \
+ struct perf_sample *sample, \
+ struct machine *machine) \
+{ \
+ struct convert *c = container_of(tool, struct convert, tool);\
+ struct ctf_writer *cw = &c->writer; \
+ struct bt_ctf_event_class *event_class = cw->_name##_class;\
+ struct bt_ctf_event *event; \
+ struct ctf_stream *cs; \
+ int ret; \
+ \
+ c->non_sample_count++; \
+ c->events_size += _event->header.size; \
+ event = bt_ctf_event_create(event_class); \
+ if (!event) { \
+ pr_err("Failed to create an CTF event\n"); \
+ return -1; \
+ } \
+ \
+ bt_ctf_clock_set_time(cw->clock, sample->time); \
+ body \
+ cs = ctf_stream(cw, 0); \
+ if (cs) { \
+ if (is_flush_needed(cs)) \
+ ctf_stream__flush(cs); \
+ \
+ cs->count++; \
+ bt_ctf_stream_append_event(cs->stream, event); \
+ } \
+ bt_ctf_event_put(event); \
+ \
+ return perf_event__process_##_name(tool, _event, sample, machine);\
+}
+
+__FUNC_PROCESS_NON_SAMPLE(comm,
+ __NON_SAMPLE_SET_FIELD(comm, u32, pid);
+ __NON_SAMPLE_SET_FIELD(comm, u32, tid);
+ __NON_SAMPLE_SET_FIELD(comm, string, comm);
+)
+#undef __NON_SAMPLE_SET_FIELD
+#undef __FUNC_PROCESS_NON_SAMPLE
+
/* If dup < 0, add a prefix. Else, add _dupl_X suffix. */
static char *change_name(char *name, char *orig_name, int dup)
{
@@ -1037,6 +1089,58 @@ static int setup_events(struct ctf_writer *cw, struct perf_session *session)
return 0;
}
+#define __NON_SAMPLE_ADD_FIELD(t, n) \
+ do { \
+ pr2(" field '%s'\n", #n); \
+ if (bt_ctf_event_class_add_field(event_class, cw->data.t, #n)) {\
+ pr_err("Failed to add field '%s';\n", #n);\
+ return -1; \
+ } \
+ } while(0)
+
+#define __FUNC_ADD_NON_SAMPLE_EVENT_CLASS(_name, body) \
+static int add_##_name##_event(struct ctf_writer *cw) \
+{ \
+ struct bt_ctf_event_class *event_class; \
+ int ret; \
+ \
+ pr("Adding "#_name" event\n"); \
+ event_class = bt_ctf_event_class_create("perf_" #_name);\
+ if (!event_class) \
+ return -1; \
+ body \
+ \
+ ret = bt_ctf_stream_class_add_event_class(cw->stream_class, event_class);\
+ if (ret) { \
+ pr("Failed to add event class '"#_name"' into stream.\n");\
+ return ret; \
+ } \
+ \
+ cw->_name##_class = event_class; \
+ bt_ctf_event_class_put(event_class); \
+ return 0; \
+}
+
+__FUNC_ADD_NON_SAMPLE_EVENT_CLASS(comm,
+ __NON_SAMPLE_ADD_FIELD(u32, pid);
+ __NON_SAMPLE_ADD_FIELD(u32, tid);
+ __NON_SAMPLE_ADD_FIELD(string, comm);
+)
+
+#undef __NON_SAMPLE_ADD_FIELD
+#undef __FUNC_ADD_NON_SAMPLE_EVENT_CLASS
+
+static int setup_non_sample_events(struct ctf_writer *cw,
+ struct perf_session *session __maybe_unused)
+{
+ int ret;
+
+ ret = add_comm_event(cw);
+ if (ret)
+ return ret;
+ return 0;
+}
+
static void cleanup_events(struct perf_session *session)
{
struct perf_evlist *evlist = session->evlist;
@@ -1332,6 +1436,9 @@ int bt_convert__perf2ctf(const char *input, const char *path,
struct ctf_writer *cw = &c.writer;
int err = -1;
+ if (opts->all)
+ c.tool.comm = process_comm_event;
+
perf_config(convert__config, &c);
/* CTF writer */
@@ -1356,6 +1463,9 @@ int bt_convert__perf2ctf(const char *input, const char *path,
if (setup_events(cw, session))
goto free_session;
+ if (opts->all && setup_non_sample_events(cw, session))
+ goto free_session;
+
if (setup_streams(cw, session))
goto free_session;
--
2.7.4
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[GIT PULL 00/18] perf/core improvements and fixes Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-06-27 23:10 +0200
[PATCH 09/18] perf record: Prepare reading from multiple evlists in record__mmap_read_all() Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-06-27 23:10 +0200
[PATCH 16/18] perf data ctf: Generate comm event to CTF output Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-06-27 23:10 +0200
[PATCH 06/18] perf build: Add libbabeltrace to build-test Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-06-27 23:10 +0200
[PATCH 08/18] perf record: Move mmap setup block to separate function Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-06-27 23:10 +0200
[PATCH 11/18] perf symbols: Use proper dso name for is_regular_file Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-06-27 23:10 +0200
[PATCH 13/18] perf data ctf: Pass convert options through opts structure Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-06-27 23:10 +0200
[PATCH 07/18] perf data convert: Include config.h header Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-06-27 23:10 +0200
[PATCH 15/18] perf data ctf: Prepare collect non-sample events Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-06-27 23:10 +0200
[PATCH 12/18] perf data ctf: Add value_set_string() helper Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-06-27 23:10 +0200
[PATCH 18/18] perf data ctf: Generate fork and exit events to CTF output Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-06-27 23:10 +0200
[PATCH 17/18] perf data ctf: Add '--all' option for 'perf data convert' Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-06-27 23:10 +0200
[PATCH 02/18] perf tools: Update makefile message for installing slang devel package Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-06-27 23:10 +0200
Re: [GIT PULL 00/18] perf/core improvements and fixes Ingo Molnar <mingo@kernel.org> - 2016-06-28 09:10 +0200
Re: [GIT PULL 00/18] perf/core improvements and fixes Jiri Olsa <jolsa@redhat.com> - 2016-06-28 10:30 +0200
Re: [GIT PULL 00/18] perf/core improvements and fixes Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-06-28 16:10 +0200
Re: [GIT PULL 00/18] perf/core improvements and fixes Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-06-28 16:20 +0200
Re: [GIT PULL 00/18] perf/core improvements and fixes Ingo Molnar <mingo@kernel.org> - 2016-06-29 11:40 +0200
csiph-web