Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1429624 > unrolled thread

[PATCH 4/6] perf ctf: Generate comm event to CTF output

Started byWang Nan <wangnan0@huawei.com>
First post2016-06-23 11:20 +0200
Last post2016-06-24 09:10 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 4/6] perf ctf: Generate comm event to CTF output Wang Nan <wangnan0@huawei.com> - 2016-06-23 11:20 +0200
    Re: [PATCH 4/6] perf ctf: Generate comm event to CTF output Jiri Olsa <jolsa@redhat.com> - 2016-06-24 09:10 +0200

#1429624 — [PATCH 4/6] perf ctf: Generate comm event to CTF output

FromWang Nan <wangnan0@huawei.com>
Date2016-06-23 11:20 +0200
Subject[PATCH 4/6] perf ctf: Generate comm event to CTF output
Message-ID<rN8XL-7PN-15@gated-at.bofh.it>
If non_sample 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>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
---
 tools/perf/util/data-convert-bt.c | 108 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 108 insertions(+)

diff --git a/tools/perf/util/data-convert-bt.c b/tools/perf/util/data-convert-bt.c
index 0bc3ee2..bc6d42b 100644
--- a/tools/perf/util/data-convert-bt.c
+++ b/tools/perf/util/data-convert-bt.c
@@ -68,6 +68,7 @@ struct ctf_writer {
 		};
 		struct bt_ctf_field_type *array[6];
 	} data;
+	struct bt_ctf_event_class	*comm_class;
 };
 
 struct convert {
@@ -761,6 +762,55 @@ 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;						\
+								\
+	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)
 {
@@ -1035,6 +1085,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;
@@ -1330,6 +1432,9 @@ int bt_convert__perf2ctf(const char *input, const char *path,
 	struct ctf_writer *cw = &c.writer;
 	int err = -1;
 
+	if (opts->non_sample)
+		c.tool.comm = process_comm_event;
+
 	perf_config(convert__config, &c);
 
 	/* CTF writer */
@@ -1354,6 +1459,9 @@ int bt_convert__perf2ctf(const char *input, const char *path,
 	if (setup_events(cw, session))
 		goto free_session;
 
+	if (opts->non_sample && setup_non_sample_events(cw, session))
+		goto free_session;
+
 	if (setup_streams(cw, session))
 		goto free_session;
 
-- 
1.8.3.4

[toc] | [next] | [standalone]


#1430411

FromJiri Olsa <jolsa@redhat.com>
Date2016-06-24 09:10 +0200
Message-ID<rNtpw-4ZY-9@gated-at.bofh.it>
In reply to#1429624
On Thu, Jun 23, 2016 at 09:16:21AM +0000, Wang Nan wrote:
> If non_sample 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>
> Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
> Cc: Jiri Olsa <jolsa@redhat.com>
> ---
>  tools/perf/util/data-convert-bt.c | 108 ++++++++++++++++++++++++++++++++++++++
>  1 file changed, 108 insertions(+)
> 
> diff --git a/tools/perf/util/data-convert-bt.c b/tools/perf/util/data-convert-bt.c
> index 0bc3ee2..bc6d42b 100644
> --- a/tools/perf/util/data-convert-bt.c
> +++ b/tools/perf/util/data-convert-bt.c
> @@ -68,6 +68,7 @@ struct ctf_writer {
>  		};
>  		struct bt_ctf_field_type *array[6];
>  	} data;
> +	struct bt_ctf_event_class	*comm_class;
>  };
>  
>  struct convert {
> @@ -761,6 +762,55 @@ 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;						\
> +								\
> +	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);		\


coudl you please also add the global stats update,
so we get the statistics straight at the end?

        /* update stats */
        c->events_count++;
        c->events_size += _event->header.size;

thanks,
jirka

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web