All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/6] perf ctf: Convert comm, fork and exit events to CTF
@ 2016-06-23  9:16 Wang Nan
  2016-06-23  9:16 ` [PATCH 1/6] perf ctf: Add value_set_string() helper Wang Nan
                   ` (5 more replies)
  0 siblings, 6 replies; 9+ messages in thread
From: Wang Nan @ 2016-06-23  9:16 UTC (permalink / raw)
  To: acme, jolsa; +Cc: linux-kernel, pi3orama, Wang Nan

After converting perf.data to CTF, we lost pid-tid-comm mapping. Which
makes inconvience. For example, in perf script output we know which
process issue an event like this:

 compiz 19361 [001] 3275709.313929:  raw_syscalls:sys_exit: NR 7 = 0

After converting to CTF, we only get this:

  [3275709.313929985] (+0.110646118) raw_syscalls:sys_exit: { cpu_id = 1 }, { perf_ip = 0xFFFFFFFF8107B2E8, perf_tid = 19361, perf_pid = 19361, perf_id = 18920, perf_period = 1, common_type = 16, common_flags = 0, common_preempt_count = 1, common_pid = 19361, id = 7, ret = 0 }

Currently, if we want to find the name and parent of a process, we
have to collect 'sched:sched_switch' event.

This patch set add a '--all' option to 'perf convert', converts comm,
fork and exit events to CTF output. CTF user now can track the mapping
by their own.

Wang Nan (6):
  perf ctf: Add value_set_string() helper
  perf ctf: Pass convert options through structure
  perf ctf: Add non_sample option
  perf ctf: Generate comm event to CTF output
  perf ctf: Add '--all' option for 'perf data convert'
  perf ctf: Generate fork and exit events to CTF output

 tools/perf/Documentation/perf-data.txt |   5 +-
 tools/perf/builtin-data.c              |  11 +-
 tools/perf/util/data-convert-bt.c      | 185 ++++++++++++++++++++++++++++++++-
 tools/perf/util/data-convert-bt.h      |   4 +-
 tools/perf/util/data-convert.h         |   9 ++
 5 files changed, 207 insertions(+), 7 deletions(-)
 create mode 100644 tools/perf/util/data-convert.h

-- 
1.8.3.4

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/6] perf ctf: Add value_set_string() helper
  2016-06-23  9:16 [PATCH 0/6] perf ctf: Convert comm, fork and exit events to CTF Wang Nan
@ 2016-06-23  9:16 ` Wang Nan
  2016-06-23  9:16 ` [PATCH 2/6] perf ctf: Pass convert options through structure Wang Nan
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Wang Nan @ 2016-06-23  9:16 UTC (permalink / raw)
  To: acme, jolsa; +Cc: linux-kernel, pi3orama, Wang Nan, Arnaldo Carvalho de Melo

There are many value_set_##x helper for integer, but only for integer.
This patch adds value_set_string() helper to help following commits
create string fields.

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 | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/tools/perf/util/data-convert-bt.c b/tools/perf/util/data-convert-bt.c
index 9f53020..d31a1c1 100644
--- a/tools/perf/util/data-convert-bt.c
+++ b/tools/perf/util/data-convert-bt.c
@@ -140,6 +140,36 @@ FUNC_VALUE_SET(s64)
 FUNC_VALUE_SET(u64)
 __FUNC_VALUE_SET(u64_hex, u64)
 
+static int string_set_value(struct bt_ctf_field *field, const char *string);
+static __maybe_unused int
+value_set_string(struct ctf_writer *cw, struct bt_ctf_event *event,
+		 const char *name, const char *string)
+{
+	struct bt_ctf_field_type *type = cw->data.string;
+	struct bt_ctf_field *field;
+	int ret = 0;
+
+	field = bt_ctf_field_create(type);
+	if (!field) {
+		pr_err("failed to create a field %s\n", name);
+		return -1;
+	}
+
+	ret = string_set_value(field, string);
+	if (ret) {
+		pr_err("failed to set value %s\n", name);
+		goto err_put_field;
+	}
+
+	ret = bt_ctf_event_set_payload(event, name, field);
+	if (ret)
+		pr_err("failed to set payload %s\n", name);
+
+err_put_field:
+	bt_ctf_field_put(field);
+	return ret;
+}
+
 static struct bt_ctf_field_type*
 get_tracepoint_field_type(struct ctf_writer *cw, struct format_field *field)
 {
-- 
1.8.3.4

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/6] perf ctf: Pass convert options through structure
  2016-06-23  9:16 [PATCH 0/6] perf ctf: Convert comm, fork and exit events to CTF Wang Nan
  2016-06-23  9:16 ` [PATCH 1/6] perf ctf: Add value_set_string() helper Wang Nan
@ 2016-06-23  9:16 ` Wang Nan
  2016-06-23  9:16 ` [PATCH 3/6] perf ctf: Add non_sample option Wang Nan
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Wang Nan @ 2016-06-23  9:16 UTC (permalink / raw)
  To: acme, jolsa; +Cc: linux-kernel, pi3orama, Wang Nan, Arnaldo Carvalho de Melo

Following commits will add new option to 'perf data convert'. All options
should be grouped into a structure and passed to low level converter
(currently there's only one converter).

Introduce data-convert.h and define 'struct perf_data_convert_opts' in
it. Pass 'force' through opts.

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
---
 tools/perf/builtin-data.c         | 9 ++++++---
 tools/perf/util/data-convert-bt.c | 5 +++--
 tools/perf/util/data-convert-bt.h | 4 +++-
 tools/perf/util/data-convert.h    | 8 ++++++++
 4 files changed, 20 insertions(+), 6 deletions(-)
 create mode 100644 tools/perf/util/data-convert.h

diff --git a/tools/perf/builtin-data.c b/tools/perf/builtin-data.c
index b97bc15..38111a9 100644
--- a/tools/perf/builtin-data.c
+++ b/tools/perf/builtin-data.c
@@ -3,6 +3,7 @@
 #include "perf.h"
 #include "debug.h"
 #include <subcmd/parse-options.h>
+#include "data-convert.h"
 #include "data-convert-bt.h"
 
 typedef int (*data_cmd_fn_t)(int argc, const char **argv, const char *prefix);
@@ -53,14 +54,16 @@ static int cmd_data_convert(int argc, const char **argv,
 			    const char *prefix __maybe_unused)
 {
 	const char *to_ctf     = NULL;
-	bool force = false;
+	struct perf_data_convert_opts opts = {
+		.force = false,
+	};
 	const struct option options[] = {
 		OPT_INCR('v', "verbose", &verbose, "be more verbose"),
 		OPT_STRING('i', "input", &input_name, "file", "input file name"),
 #ifdef HAVE_LIBBABELTRACE_SUPPORT
 		OPT_STRING(0, "to-ctf", &to_ctf, NULL, "Convert to CTF format"),
 #endif
-		OPT_BOOLEAN('f', "force", &force, "don't complain, do it"),
+		OPT_BOOLEAN('f', "force", &opts.force, "don't complain, do it"),
 		OPT_END()
 	};
 
@@ -78,7 +81,7 @@ static int cmd_data_convert(int argc, const char **argv,
 
 	if (to_ctf) {
 #ifdef HAVE_LIBBABELTRACE_SUPPORT
-		return bt_convert__perf2ctf(input_name, to_ctf, force);
+		return bt_convert__perf2ctf(input_name, to_ctf, &opts);
 #else
 		pr_err("The libbabeltrace support is not compiled in.\n");
 		return -1;
diff --git a/tools/perf/util/data-convert-bt.c b/tools/perf/util/data-convert-bt.c
index d31a1c1..0bc3ee2 100644
--- a/tools/perf/util/data-convert-bt.c
+++ b/tools/perf/util/data-convert-bt.c
@@ -1303,13 +1303,14 @@ static int convert__config(const char *var, const char *value, void *cb)
 	return 0;
 }
 
-int bt_convert__perf2ctf(const char *input, const char *path, bool force)
+int bt_convert__perf2ctf(const char *input, const char *path,
+			 struct perf_data_convert_opts *opts)
 {
 	struct perf_session *session;
 	struct perf_data_file file = {
 		.path = input,
 		.mode = PERF_DATA_MODE_READ,
-		.force = force,
+		.force = opts->force,
 	};
 	struct convert c = {
 		.tool = {
diff --git a/tools/perf/util/data-convert-bt.h b/tools/perf/util/data-convert-bt.h
index 4c20434..9a3b587 100644
--- a/tools/perf/util/data-convert-bt.h
+++ b/tools/perf/util/data-convert-bt.h
@@ -1,8 +1,10 @@
 #ifndef __DATA_CONVERT_BT_H
 #define __DATA_CONVERT_BT_H
+#include "data-convert.h"
 #ifdef HAVE_LIBBABELTRACE_SUPPORT
 
-int bt_convert__perf2ctf(const char *input_name, const char *to_ctf, bool force);
+int bt_convert__perf2ctf(const char *input_name, const char *to_ctf,
+			 struct perf_data_convert_opts *opts);
 
 #endif /* HAVE_LIBBABELTRACE_SUPPORT */
 #endif /* __DATA_CONVERT_BT_H */
diff --git a/tools/perf/util/data-convert.h b/tools/perf/util/data-convert.h
new file mode 100644
index 0000000..97cfd36
--- /dev/null
+++ b/tools/perf/util/data-convert.h
@@ -0,0 +1,8 @@
+#ifndef __DATA_CONVERT_H
+#define __DATA_CONVERT_H
+
+struct perf_data_convert_opts {
+	bool force;
+};
+
+#endif /* __DATA_CONVERT_H */
-- 
1.8.3.4

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 3/6] perf ctf: Add non_sample option
  2016-06-23  9:16 [PATCH 0/6] perf ctf: Convert comm, fork and exit events to CTF Wang Nan
  2016-06-23  9:16 ` [PATCH 1/6] perf ctf: Add value_set_string() helper Wang Nan
  2016-06-23  9:16 ` [PATCH 2/6] perf ctf: Pass convert options through structure Wang Nan
@ 2016-06-23  9:16 ` Wang Nan
  2016-06-23  9:16 ` [PATCH 4/6] perf ctf: Generate comm event to CTF output Wang Nan
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Wang Nan @ 2016-06-23  9:16 UTC (permalink / raw)
  To: acme, jolsa; +Cc: linux-kernel, pi3orama, Wang Nan, Arnaldo Carvalho de Melo

If non_sample option is selected, 'perf data convert' should convert
not only samples, but non-sample events such as comm and fork. Add this
option in perf_data_convert_opts. Following commits will add cmdline
option to select it.

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
---
 tools/perf/builtin-data.c      | 1 +
 tools/perf/util/data-convert.h | 1 +
 2 files changed, 2 insertions(+)

diff --git a/tools/perf/builtin-data.c b/tools/perf/builtin-data.c
index 38111a9..a011a56 100644
--- a/tools/perf/builtin-data.c
+++ b/tools/perf/builtin-data.c
@@ -56,6 +56,7 @@ static int cmd_data_convert(int argc, const char **argv,
 	const char *to_ctf     = NULL;
 	struct perf_data_convert_opts opts = {
 		.force = false,
+		.non_sample = false,
 	};
 	const struct option options[] = {
 		OPT_INCR('v', "verbose", &verbose, "be more verbose"),
diff --git a/tools/perf/util/data-convert.h b/tools/perf/util/data-convert.h
index 97cfd36..66f2b2a 100644
--- a/tools/perf/util/data-convert.h
+++ b/tools/perf/util/data-convert.h
@@ -3,6 +3,7 @@
 
 struct perf_data_convert_opts {
 	bool force;
+	bool non_sample;
 };
 
 #endif /* __DATA_CONVERT_H */
-- 
1.8.3.4

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 4/6] perf ctf: Generate comm event to CTF output
  2016-06-23  9:16 [PATCH 0/6] perf ctf: Convert comm, fork and exit events to CTF Wang Nan
                   ` (2 preceding siblings ...)
  2016-06-23  9:16 ` [PATCH 3/6] perf ctf: Add non_sample option Wang Nan
@ 2016-06-23  9:16 ` Wang Nan
  2016-06-24  7:07   ` Jiri Olsa
  2016-06-23  9:16 ` [PATCH 5/6] perf ctf: Add '--all' option for 'perf data convert' Wang Nan
  2016-06-23  9:16 ` [PATCH 6/6] perf ctf: Generate fork and exit events to CTF output Wang Nan
  5 siblings, 1 reply; 9+ messages in thread
From: Wang Nan @ 2016-06-23  9:16 UTC (permalink / raw)
  To: acme, jolsa; +Cc: linux-kernel, pi3orama, Wang Nan, Arnaldo Carvalho de Melo

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

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 5/6] perf ctf: Add '--all' option for 'perf data convert'
  2016-06-23  9:16 [PATCH 0/6] perf ctf: Convert comm, fork and exit events to CTF Wang Nan
                   ` (3 preceding siblings ...)
  2016-06-23  9:16 ` [PATCH 4/6] perf ctf: Generate comm event to CTF output Wang Nan
@ 2016-06-23  9:16 ` Wang Nan
  2016-06-24  7:07   ` Jiri Olsa
  2016-06-23  9:16 ` [PATCH 6/6] perf ctf: Generate fork and exit events to CTF output Wang Nan
  5 siblings, 1 reply; 9+ messages in thread
From: Wang Nan @ 2016-06-23  9:16 UTC (permalink / raw)
  To: acme, jolsa; +Cc: linux-kernel, pi3orama, Wang Nan, Arnaldo Carvalho de Melo

After this patch, 'perf data convert' convert comm events to output
CTF stream.

Result:

 # perf record -a sleep 1
 [ perf record: Woken up 1 times to write data ]
 [ perf record: Captured and wrote 0.771 MB perf.data (79 samples) ]

 # perf data convert --to-ctf ./out.ctf
 [ perf data convert: Converted 'perf.data' into CTF data './out.ctf' ]
 [ perf data convert: Converted and wrote 0.004 MB (79 samples) ]

 # babeltrace ./out.ctf/
 [20:59:41.942633169] (+?.?????????) cycles:ppp: { cpu_id = 0 }, { perf_ip = 0xFFFFFFFF81065AF4, perf_tid = 0, perf_pid = 0, perf_period = 1 }
 [20:59:41.942636194] (+0.000003025) cycles:ppp: { cpu_id = 0 }, { perf_ip = 0xFFFFFFFF81065AF4, perf_tid = 0, perf_pid = 0, perf_period = 1 }
 ...    // only sample event is converted

 # perf data convert --all --to-ctf ./out.ctf
 [ perf data convert: Converted 'perf.data' into CTF data './out.ctf' ]
 [ perf data convert: Converted and wrote 0.004 MB (79 samples) ]

 # babeltrace ./out.ctf/
 [00:00:00.000000000] (+?.?????????) perf_comm: { cpu_id = 0 }, { comm = "init", pid = 1, tid = 1 }
 [00:00:00.000000000] (+0.000000000) perf_comm: { cpu_id = 0 }, { comm = "kthreadd", pid = 2, tid = 2 }
 [00:00:00.000000000] (+0.000000000) perf_comm: { cpu_id = 0 }, { comm = "ksoftirqd/0", pid = 3, tid = 3 }
 ...    // comm events are converted

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
---
 tools/perf/Documentation/perf-data.txt | 5 ++++-
 tools/perf/builtin-data.c              | 1 +
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/tools/perf/Documentation/perf-data.txt b/tools/perf/Documentation/perf-data.txt
index be8fa1a..f8ada39 100644
--- a/tools/perf/Documentation/perf-data.txt
+++ b/tools/perf/Documentation/perf-data.txt
@@ -34,7 +34,10 @@ OPTIONS for 'convert'
 --verbose::
         Be more verbose (show counter open errors, etc).
 
-SEE ALSO
+--all::
+	Convert all events, including non-sample events (comm, fork, ...), to output.
+	Default is off, only convert samples.
+
 --------
 linkperf:perf[1]
 [1] Common Trace Format - http://www.efficios.com/ctf
diff --git a/tools/perf/builtin-data.c b/tools/perf/builtin-data.c
index a011a56..a87c964 100644
--- a/tools/perf/builtin-data.c
+++ b/tools/perf/builtin-data.c
@@ -65,6 +65,7 @@ static int cmd_data_convert(int argc, const char **argv,
 		OPT_STRING(0, "to-ctf", &to_ctf, NULL, "Convert to CTF format"),
 #endif
 		OPT_BOOLEAN('f', "force", &opts.force, "don't complain, do it"),
+		OPT_BOOLEAN(0, "all", &opts.non_sample, "Convert all events"),
 		OPT_END()
 	};
 
-- 
1.8.3.4

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 6/6] perf ctf: Generate fork and exit events to CTF output
  2016-06-23  9:16 [PATCH 0/6] perf ctf: Convert comm, fork and exit events to CTF Wang Nan
                   ` (4 preceding siblings ...)
  2016-06-23  9:16 ` [PATCH 5/6] perf ctf: Add '--all' option for 'perf data convert' Wang Nan
@ 2016-06-23  9:16 ` Wang Nan
  5 siblings, 0 replies; 9+ messages in thread
From: Wang Nan @ 2016-06-23  9:16 UTC (permalink / raw)
  To: acme, jolsa; +Cc: linux-kernel, pi3orama, Wang Nan, Arnaldo Carvalho de Melo

If non_sample is selected, convert fork and exit events to output CTF stream.

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 | 44 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 43 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/data-convert-bt.c b/tools/perf/util/data-convert-bt.c
index bc6d42b..2c972fd 100644
--- a/tools/perf/util/data-convert-bt.c
+++ b/tools/perf/util/data-convert-bt.c
@@ -69,6 +69,8 @@ struct ctf_writer {
 		struct bt_ctf_field_type *array[6];
 	} data;
 	struct bt_ctf_event_class	*comm_class;
+	struct bt_ctf_event_class	*exit_class;
+	struct bt_ctf_event_class	*fork_class;
 };
 
 struct convert {
@@ -808,6 +810,21 @@ __FUNC_PROCESS_NON_SAMPLE(comm,
 	__NON_SAMPLE_SET_FIELD(comm, u32, tid);
 	__NON_SAMPLE_SET_FIELD(comm, string, comm);
 )
+__FUNC_PROCESS_NON_SAMPLE(fork,
+	__NON_SAMPLE_SET_FIELD(fork, u32, pid);
+	__NON_SAMPLE_SET_FIELD(fork, u32, ppid);
+	__NON_SAMPLE_SET_FIELD(fork, u32, tid);
+	__NON_SAMPLE_SET_FIELD(fork, u32, ptid);
+	__NON_SAMPLE_SET_FIELD(fork, u64, time);
+)
+
+__FUNC_PROCESS_NON_SAMPLE(exit,
+	__NON_SAMPLE_SET_FIELD(fork, u32, pid);
+	__NON_SAMPLE_SET_FIELD(fork, u32, ppid);
+	__NON_SAMPLE_SET_FIELD(fork, u32, tid);
+	__NON_SAMPLE_SET_FIELD(fork, u32, ptid);
+	__NON_SAMPLE_SET_FIELD(fork, u64, time);
+)
 #undef __NON_SAMPLE_SET_FIELD
 #undef __FUNC_PROCESS_NON_SAMPLE
 
@@ -1123,6 +1140,22 @@ __FUNC_ADD_NON_SAMPLE_EVENT_CLASS(comm,
 	__NON_SAMPLE_ADD_FIELD(string, comm);
 )
 
+__FUNC_ADD_NON_SAMPLE_EVENT_CLASS(fork,
+	__NON_SAMPLE_ADD_FIELD(u32, pid);
+	__NON_SAMPLE_ADD_FIELD(u32, ppid);
+	__NON_SAMPLE_ADD_FIELD(u32, tid);
+	__NON_SAMPLE_ADD_FIELD(u32, ptid);
+	__NON_SAMPLE_ADD_FIELD(u64, time);
+)
+
+__FUNC_ADD_NON_SAMPLE_EVENT_CLASS(exit,
+	__NON_SAMPLE_ADD_FIELD(u32, pid);
+	__NON_SAMPLE_ADD_FIELD(u32, ppid);
+	__NON_SAMPLE_ADD_FIELD(u32, tid);
+	__NON_SAMPLE_ADD_FIELD(u32, ptid);
+	__NON_SAMPLE_ADD_FIELD(u64, time);
+)
+
 #undef __NON_SAMPLE_ADD_FIELD
 #undef __FUNC_ADD_NON_SAMPLE_EVENT_CLASS
 
@@ -1134,6 +1167,12 @@ static int setup_non_sample_events(struct ctf_writer *cw,
 	ret = add_comm_event(cw);
 	if (ret)
 		return ret;
+	ret = add_exit_event(cw);
+	if (ret)
+		return ret;
+	ret = add_fork_event(cw);
+	if (ret)
+		return ret;
 	return 0;
 }
 
@@ -1432,8 +1471,11 @@ int bt_convert__perf2ctf(const char *input, const char *path,
 	struct ctf_writer *cw = &c.writer;
 	int err = -1;
 
-	if (opts->non_sample)
+	if (opts->non_sample) {
 		c.tool.comm = process_comm_event;
+		c.tool.exit = process_exit_event;
+		c.tool.fork = process_fork_event;
+	}
 
 	perf_config(convert__config, &c);
 
-- 
1.8.3.4

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 5/6] perf ctf: Add '--all' option for 'perf data convert'
  2016-06-23  9:16 ` [PATCH 5/6] perf ctf: Add '--all' option for 'perf data convert' Wang Nan
@ 2016-06-24  7:07   ` Jiri Olsa
  0 siblings, 0 replies; 9+ messages in thread
From: Jiri Olsa @ 2016-06-24  7:07 UTC (permalink / raw)
  To: Wang Nan; +Cc: acme, linux-kernel, pi3orama, Arnaldo Carvalho de Melo

On Thu, Jun 23, 2016 at 09:16:22AM +0000, Wang Nan wrote:
> After this patch, 'perf data convert' convert comm events to output
> CTF stream.
> 
> Result:
> 
>  # perf record -a sleep 1
>  [ perf record: Woken up 1 times to write data ]
>  [ perf record: Captured and wrote 0.771 MB perf.data (79 samples) ]
> 
>  # perf data convert --to-ctf ./out.ctf
>  [ perf data convert: Converted 'perf.data' into CTF data './out.ctf' ]
>  [ perf data convert: Converted and wrote 0.004 MB (79 samples) ]
> 
>  # babeltrace ./out.ctf/
>  [20:59:41.942633169] (+?.?????????) cycles:ppp: { cpu_id = 0 }, { perf_ip = 0xFFFFFFFF81065AF4, perf_tid = 0, perf_pid = 0, perf_period = 1 }
>  [20:59:41.942636194] (+0.000003025) cycles:ppp: { cpu_id = 0 }, { perf_ip = 0xFFFFFFFF81065AF4, perf_tid = 0, perf_pid = 0, perf_period = 1 }
>  ...    // only sample event is converted
> 
>  # perf data convert --all --to-ctf ./out.ctf
>  [ perf data convert: Converted 'perf.data' into CTF data './out.ctf' ]
>  [ perf data convert: Converted and wrote 0.004 MB (79 samples) ]
> 
>  # babeltrace ./out.ctf/
>  [00:00:00.000000000] (+?.?????????) perf_comm: { cpu_id = 0 }, { comm = "init", pid = 1, tid = 1 }
>  [00:00:00.000000000] (+0.000000000) perf_comm: { cpu_id = 0 }, { comm = "kthreadd", pid = 2, tid = 2 }
>  [00:00:00.000000000] (+0.000000000) perf_comm: { cpu_id = 0 }, { comm = "ksoftirqd/0", pid = 3, tid = 3 }
>  ...    // comm events are converted
> 
> Signed-off-by: Wang Nan <wangnan0@huawei.com>
> Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
> Cc: Jiri Olsa <jolsa@redhat.com>
> ---
>  tools/perf/Documentation/perf-data.txt | 5 ++++-
>  tools/perf/builtin-data.c              | 1 +
>  2 files changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/perf/Documentation/perf-data.txt b/tools/perf/Documentation/perf-data.txt
> index be8fa1a..f8ada39 100644
> --- a/tools/perf/Documentation/perf-data.txt
> +++ b/tools/perf/Documentation/perf-data.txt
> @@ -34,7 +34,10 @@ OPTIONS for 'convert'
>  --verbose::
>          Be more verbose (show counter open errors, etc).
>  
> -SEE ALSO
> +--all::
> +	Convert all events, including non-sample events (comm, fork, ...), to output.
> +	Default is off, only convert samples.

you removed the 'SEE ALSO' header ;-)

> +
>  --------
>  linkperf:perf[1]
>  [1] Common Trace Format - http://www.efficios.com/ctf
> diff --git a/tools/perf/builtin-data.c b/tools/perf/builtin-data.c
> index a011a56..a87c964 100644
> --- a/tools/perf/builtin-data.c
> +++ b/tools/perf/builtin-data.c
> @@ -65,6 +65,7 @@ static int cmd_data_convert(int argc, const char **argv,
>  		OPT_STRING(0, "to-ctf", &to_ctf, NULL, "Convert to CTF format"),
>  #endif
>  		OPT_BOOLEAN('f', "force", &opts.force, "don't complain, do it"),
> +		OPT_BOOLEAN(0, "all", &opts.non_sample, "Convert all events"),

IMO opts.all would suite better I think,
but we can always change it if needed

thanks,
jirka

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 4/6] perf ctf: Generate comm event to CTF output
  2016-06-23  9:16 ` [PATCH 4/6] perf ctf: Generate comm event to CTF output Wang Nan
@ 2016-06-24  7:07   ` Jiri Olsa
  0 siblings, 0 replies; 9+ messages in thread
From: Jiri Olsa @ 2016-06-24  7:07 UTC (permalink / raw)
  To: Wang Nan; +Cc: acme, linux-kernel, pi3orama, Arnaldo Carvalho de Melo

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2016-06-24  7:07 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-23  9:16 [PATCH 0/6] perf ctf: Convert comm, fork and exit events to CTF Wang Nan
2016-06-23  9:16 ` [PATCH 1/6] perf ctf: Add value_set_string() helper Wang Nan
2016-06-23  9:16 ` [PATCH 2/6] perf ctf: Pass convert options through structure Wang Nan
2016-06-23  9:16 ` [PATCH 3/6] perf ctf: Add non_sample option Wang Nan
2016-06-23  9:16 ` [PATCH 4/6] perf ctf: Generate comm event to CTF output Wang Nan
2016-06-24  7:07   ` Jiri Olsa
2016-06-23  9:16 ` [PATCH 5/6] perf ctf: Add '--all' option for 'perf data convert' Wang Nan
2016-06-24  7:07   ` Jiri Olsa
2016-06-23  9:16 ` [PATCH 6/6] perf ctf: Generate fork and exit events to CTF output Wang Nan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.