Skip to contentSkip to conversation

perf ctf: Convert comm, fork and exit events to CTF

PATCH Applied Wang Nan 5 participants 24 messages Jun 24, 2016 – Jun 29, 2016 perf events

lore
Share & tools
lore

Wang Nan

author
#0 lore raw

v2 cover perf ctf: Convert comm, fork and exit events to CTF

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 adds 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.

v1 -> v2: Report number of sample and non-sample events when finish.
rename opts.non_sample to opts.all.

Wang Nan (7):
perf ctf: Add value_set_string() helper
perf ctf: Pass convert options through opts structure perf ctf: Add 'all' option
perf ctf: Prepare collect non-sample events 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 |   4 +
 tools/perf/builtin-data.c              |  11 +-
 tools/perf/util/data-convert-bt.c      | 195 ++++++++++++++++++++++++++++++++-
 tools/perf/util/data-convert-bt.h      |   4 +-
 tools/perf/util/data-convert.h         |   9 ++
 5 files changed, 216 insertions(+), 7 deletions(-)
 create mode 100644 tools/perf/util/data-convert.h
Signature · 1 line
1.8.3.4
author
#1 lore raw

PATCH v2 1/7 perf ctf: Add value_set_string() helper

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.

Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Jiri Olsa <[email protected]>
---
 tools/perf/util/data-convert-bt.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
tools/perf/util/data-convert-bt.c +30 -0
index 4b59879..7908278 100644
@@ -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)
 {
Signature · 1 line
1.8.3.4
#2 lore raw

[tip:perf/core] perf data ctf: Add value_set_string() helper

perf data ctf: Add value_set_string() helper
Commit-ID:  069ee5c488d161f539bb897b1bc64b83f9773221
Gitweb:     http://git.kernel.org/tip/069ee5c488d161f539bb897b1bc64b83f9773221
Author:     Wang Nan <[email protected]>
AuthorDate: Fri, 24 Jun 2016 11:22:06 +0000
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Tue, 28 Jun 2016 10:54:55 -0300

perf data ctf: Add value_set_string() helper

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.

---
 tools/perf/util/data-convert-bt.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
tools/perf/util/data-convert-bt.c +30 -0
index 7b1bc24..4b68e7b 100644
@@ -141,6 +141,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)
 {
author
#3 lore raw

PATCH v2 2/7 perf ctf: Pass convert options through opts structure

In reply to Wang Nan

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.

Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Jiri Olsa <[email protected]>
---
 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
tools/perf/builtin-data.c +6 -3
index b97bc15..38111a9 100644
@@ -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;
tools/perf/util/data-convert-bt.c +3 -2
index 7908278..a5e0f68 100644
@@ -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 = {
tools/perf/util/data-convert-bt.h +3 -1
index 4c20434..9a3b587 100644
@@ -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 */
tools/perf/util/data-convert.h new file +8 -0
new file mode 100644
index 0000000..97cfd36
@@ -0,0 +1,8 @@
+#ifndef __DATA_CONVERT_H
+#define __DATA_CONVERT_H
+
+struct perf_data_convert_opts {
+	bool force;
+};
+
+#endif /* __DATA_CONVERT_H */
Signature · 1 line
1.8.3.4
#4 lore raw

[tip:perf/core] perf data ctf: Pass convert options through opts structure

perf data ctf: Pass convert options through opts structure
Commit-ID:  3275f68e50290acd04612c6af41173fe83fdf4b0
Gitweb:     http://git.kernel.org/tip/3275f68e50290acd04612c6af41173fe83fdf4b0
Author:     Wang Nan <[email protected]>
AuthorDate: Fri, 24 Jun 2016 11:22:07 +0000
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Tue, 28 Jun 2016 10:54:55 -0300

perf data ctf: Pass convert options through opts structure

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.

---
 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(-)
tools/perf/builtin-data.c +6 -3
index b97bc15..38111a9 100644
@@ -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;
tools/perf/util/data-convert-bt.c +3 -2
index 4b68e7b..09571b3 100644
@@ -1304,13 +1304,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 = {
tools/perf/util/data-convert-bt.h +3 -1
index 4c20434..9a3b587 100644
@@ -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 */
tools/perf/util/data-convert.h new file +8 -0
new file mode 100644
index 0000000..97cfd36
@@ -0,0 +1,8 @@
+#ifndef __DATA_CONVERT_H
+#define __DATA_CONVERT_H
+
+struct perf_data_convert_opts {
+	bool force;
+};
+
+#endif /* __DATA_CONVERT_H */
author
#5 lore raw

PATCH v2 3/7 perf ctf: Add 'all' option

In reply to Wang Nan

If 'all' 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.

Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Jiri Olsa <[email protected]>
---
 tools/perf/builtin-data.c      | 1 +
 tools/perf/util/data-convert.h | 1 +
 2 files changed, 2 insertions(+)
tools/perf/builtin-data.c +1 -0
index 38111a9..ddfe3ac4 100644
@@ -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,
+		.all = false,
 	};
 	const struct option options[] = {
 		OPT_INCR('v', "verbose", &verbose, "be more verbose"),
tools/perf/util/data-convert.h +1 -0
index 97cfd36..5314962 100644
@@ -3,6 +3,7 @@
 
 struct perf_data_convert_opts {
 	bool force;
+	bool all;
 };
 
 #endif /* __DATA_CONVERT_H */
Signature · 1 line
1.8.3.4
#6 lore raw

[tip:perf/core] perf data ctf: Add 'all' option

perf data ctf: Add 'all' option
Commit-ID:  f02a6489d1e181c6c2731e80ff37024a130c326a
Gitweb:     http://git.kernel.org/tip/f02a6489d1e181c6c2731e80ff37024a130c326a
Author:     Wang Nan <[email protected]>
AuthorDate: Fri, 24 Jun 2016 11:22:08 +0000
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Tue, 28 Jun 2016 10:54:56 -0300

perf data ctf: Add 'all' option

If 'all' 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.

---
 tools/perf/builtin-data.c      | 1 +
 tools/perf/util/data-convert.h | 1 +
 2 files changed, 2 insertions(+)
tools/perf/builtin-data.c +1 -0
index 38111a9..ddfe3ac4 100644
@@ -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,
+		.all = false,
 	};
 	const struct option options[] = {
 		OPT_INCR('v', "verbose", &verbose, "be more verbose"),
tools/perf/util/data-convert.h +1 -0
index 97cfd36..5314962 100644
@@ -3,6 +3,7 @@
 
 struct perf_data_convert_opts {
 	bool force;
+	bool all;
 };
 
 #endif /* __DATA_CONVERT_H */
author
#7 lore raw

PATCH v2 4/7 perf ctf: Prepare collect non-sample events

In reply to Wang Nan

Following commits are going to allow 'perf data convert' to collect not only samples, but also non-sample events like comm and fork. In this patch we count non-sample events using c.non_sample_count, and prepare to print number of both type of events like:

# ~/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.846 MB (6508 samples, 686 non-samples) ]

Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Jiri Olsa <[email protected]>
---
 tools/perf/util/data-convert-bt.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
tools/perf/util/data-convert-bt.c +7 -1
index a5e0f68..bf4c15f 100644
@@ -76,6 +76,7 @@ struct convert {
 
 	u64			events_size;
 	u64			events_count;
+	u64			non_sample_count;
 
 	/* Ordered events configured queue size. */
 	u64			queue_size;
@@ -1368,10 +1369,15 @@ int bt_convert__perf2ctf(const char *input, const char *path,
 		file.path, path);
 
 	fprintf(stderr,
-		"[ perf data convert: Converted and wrote %.3f MB (%" PRIu64 " samples) ]\n",
+		"[ perf data convert: Converted and wrote %.3f MB (%" PRIu64 " samples",
 		(double) c.events_size / 1024.0 / 1024.0,
 		c.events_count);
 
+	if (!c.non_sample_count)
+		fprintf(stderr, ") ]\n");
+	else
+		fprintf(stderr, ", %" PRIu64 " non-samples) ]\n", c.non_sample_count);
+
 	cleanup_events(session);
 	perf_session__delete(session);
 	ctf_writer__cleanup(cw);
Signature · 1 line
1.8.3.4
#8 lore raw

[tip:perf/core] perf data ctf: Prepare collect non-sample events

perf data ctf: Prepare collect non-sample events
Commit-ID:  8ee4c46c5ec2481dd18098c5604f791ff911d427
Gitweb:     http://git.kernel.org/tip/8ee4c46c5ec2481dd18098c5604f791ff911d427
Author:     Wang Nan <[email protected]>
AuthorDate: Fri, 24 Jun 2016 11:22:09 +0000
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Tue, 28 Jun 2016 10:54:56 -0300

perf data ctf: Prepare collect non-sample events

Following commits are going to allow 'perf data convert' to collect not only samples, but also non-sample events like comm and fork. In this patch we count non-sample events using c.non_sample_count, and prepare to print number of both type of events like:

# ~/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.846 MB (6508 samples, 686 non-samples) ]

---
 tools/perf/util/data-convert-bt.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
tools/perf/util/data-convert-bt.c +7 -1
index 09571b3..3b3ac7c 100644
@@ -77,6 +77,7 @@ struct convert {
 
 	u64			events_size;
 	u64			events_count;
+	u64			non_sample_count;
 
 	/* Ordered events configured queue size. */
 	u64			queue_size;
@@ -1369,10 +1370,15 @@ int bt_convert__perf2ctf(const char *input, const char *path,
 		file.path, path);
 
 	fprintf(stderr,
-		"[ perf data convert: Converted and wrote %.3f MB (%" PRIu64 " samples) ]\n",
+		"[ perf data convert: Converted and wrote %.3f MB (%" PRIu64 " samples",
 		(double) c.events_size / 1024.0 / 1024.0,
 		c.events_count);
 
+	if (!c.non_sample_count)
+		fprintf(stderr, ") ]\n");
+	else
+		fprintf(stderr, ", %" PRIu64 " non-samples) ]\n", c.non_sample_count);
+
 	cleanup_events(session);
 	perf_session__delete(session);
 	ctf_writer__cleanup(cw);
author
#9 lore raw

PATCH v2 5/7 perf ctf: Generate comm event to CTF output

In reply to Wang Nan

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.

Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Jiri Olsa <[email protected]>
---
 tools/perf/util/data-convert-bt.c | 110 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 110 insertions(+)
tools/perf/util/data-convert-bt.c +110 -0
index bf4c15f..31bc81a 100644
@@ -68,6 +68,7 @@ struct ctf_writer {
 		};
 		struct bt_ctf_field_type *array[6];
 	} data;
+	struct bt_ctf_event_class	*comm_class;
 };
 
 struct convert {
@@ -762,6 +763,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)
 {
@@ -1036,6 +1088,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;
@@ -1331,6 +1435,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 */
@@ -1355,6 +1462,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;
 
Signature · 1 line
1.8.3.4
#10 lore raw

[tip:perf/core] perf data ctf: Generate comm event to CTF output

perf data ctf: Generate comm event to CTF output
Commit-ID:  f5a08ceda55bee91f879d2ac19edeb4a8916d04f
Gitweb:     http://git.kernel.org/tip/f5a08ceda55bee91f879d2ac19edeb4a8916d04f
Author:     Wang Nan <[email protected]>
AuthorDate: Fri, 24 Jun 2016 11:22:10 +0000
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Tue, 28 Jun 2016 10:54:57 -0300

perf data ctf: Generate comm event to CTF output

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.

---
 tools/perf/util/data-convert-bt.c | 110 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 110 insertions(+)
tools/perf/util/data-convert-bt.c +110 -0
index 3b3ac7c..5dd62ba 100644
@@ -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;
 
author
#11 lore raw

PATCH v2 6/7 perf ctf: Add '--all' option for 'perf data convert'

In reply to Wang Nan

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.378 MB perf.data (73 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.003 MB (73 samples) ]
 # babeltrace --clock-seconds ./out.ctf/
 [10627.402515791] (+?.?????????) cycles:ppp: { cpu_id = 0 }, { perf_ip = 0xFFFFFFFF81065AF4, perf_tid = 0, perf_pid = 0, perf_period = 1 }
 [10627.402518972] (+0.000003181) 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.023 MB (73 samples, 384 non-samples) ]
 # babeltrace --clock-seconds ./out.ctf/
 [  0.000000000] (+?.?????????) perf_comm: { cpu_id = 0 }, { pid = 1, tid = 1, comm = "init" }
 [  0.000000000] (+0.000000000) perf_comm: { cpu_id = 0 }, { pid = 2, tid = 2, comm = "kthreadd" }
 [  0.000000000] (+0.000000000) perf_comm: { cpu_id = 0 }, { pid = 3, tid = 3, comm = "ksoftirqd/0" }
 ...    // comm events are converted
 [10627.402515791] (+10627.402515791) cycles:ppp: { cpu_id = 0 }, { perf_ip = 0xFFFFFFFF81065AF4, perf_tid = 0, perf_pid = 0, perf_period = 1 }
 [10627.402518972] (+0.000003181) cycles:ppp: { cpu_id = 0 }, { perf_ip = 0xFFFFFFFF81065AF4, perf_tid = 0, perf_pid = 0, perf_period = 1 }
 ...    // samples are also converted
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Jiri Olsa <[email protected]>
---
 tools/perf/Documentation/perf-data.txt | 4 ++++
 tools/perf/builtin-data.c              | 1 +
 2 files changed, 5 insertions(+)
tools/perf/Documentation/perf-data.txt +4 -0
index be8fa1a..f0796a4 100644
@@ -34,6 +34,10 @@ OPTIONS for 'convert'
 --verbose::
         Be more verbose (show counter open errors, etc).
 
+--all::
+	Convert all events, including non-sample events (comm, fork, ...), to output.
+	Default is off, only convert samples.
+
 SEE ALSO
 --------
 linkperf:perf[1]
tools/perf/builtin-data.c +1 -0
index ddfe3ac4..7ad6e17 100644
@@ -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.all, "Convert all events"),
 		OPT_END()
 	};
 
Signature · 1 line
1.8.3.4
#12 lore raw

[tip:perf/core] perf data ctf: Add '--all' option for 'perf data convert'

perf data ctf: Add '--all' option for 'perf data convert'
Commit-ID:  9e1a7ea19f9f8e3e40c5ad1a5cc3615c1746ae7b
Gitweb:     http://git.kernel.org/tip/9e1a7ea19f9f8e3e40c5ad1a5cc3615c1746ae7b
Author:     Wang Nan <[email protected]>
AuthorDate: Fri, 24 Jun 2016 11:22:11 +0000
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Tue, 28 Jun 2016 10:54:57 -0300

perf data ctf: Add '--all' option for 'perf data convert'

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.378 MB perf.data (73 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.003 MB (73 samples) ]
  # babeltrace --clock-seconds ./out.ctf/
  [10627.402515791] (+?.?????????) cycles:ppp: { cpu_id = 0 }, { perf_ip = 0xFFFFFFFF81065AF4, perf_tid = 0, perf_pid = 0, perf_period = 1 }
  [10627.402518972] (+0.000003181) 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.023 MB (73 samples, 384 non-samples) ]
  # babeltrace --clock-seconds ./out.ctf/
  [  0.000000000] (+?.?????????) perf_comm: { cpu_id = 0 }, { pid = 1, tid = 1, comm = "init" }
  [  0.000000000] (+0.000000000) perf_comm: { cpu_id = 0 }, { pid = 2, tid = 2, comm = "kthreadd" }
  [  0.000000000] (+0.000000000) perf_comm: { cpu_id = 0 }, { pid = 3, tid = 3, comm = "ksoftirqd/0" }
  ...    // comm events are converted
  [10627.402515791] (+10627.402515791) cycles:ppp: { cpu_id = 0 }, { perf_ip = 0xFFFFFFFF81065AF4, perf_tid = 0, perf_pid = 0, perf_period = 1 }
  [10627.402518972] (+0.000003181) cycles:ppp: { cpu_id = 0 }, { perf_ip = 0xFFFFFFFF81065AF4, perf_tid = 0, perf_pid = 0, perf_period = 1 }
  ...    // samples are also converted
---
 tools/perf/Documentation/perf-data.txt | 4 ++++
 tools/perf/builtin-data.c              | 1 +
 2 files changed, 5 insertions(+)
tools/perf/Documentation/perf-data.txt +4 -0
index be8fa1a..f0796a4 100644
@@ -34,6 +34,10 @@ OPTIONS for 'convert'
 --verbose::
         Be more verbose (show counter open errors, etc).
 
+--all::
+	Convert all events, including non-sample events (comm, fork, ...), to output.
+	Default is off, only convert samples.
+
 SEE ALSO
 --------
 linkperf:perf[1]
tools/perf/builtin-data.c +1 -0
index ddfe3ac4..7ad6e17 100644
@@ -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.all, "Convert all events"),
 		OPT_END()
 	};
 
author
#13 lore raw

PATCH v2 7/7 perf ctf: Generate fork and exit events to CTF output

In reply to Wang Nan

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

Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Jiri Olsa <[email protected]>
---
 tools/perf/util/data-convert-bt.c | 44 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 43 insertions(+), 1 deletion(-)
tools/perf/util/data-convert-bt.c +43 -1
index 31bc81a..acd11d4 100644
@@ -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 {
@@ -811,6 +813,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
 
@@ -1126,6 +1143,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
 
@@ -1137,6 +1170,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;
 }
 
@@ -1435,8 +1474,11 @@ int bt_convert__perf2ctf(const char *input, const char *path,
 	struct ctf_writer *cw = &c.writer;
 	int err = -1;
 
-	if (opts->all)
+	if (opts->all) {
 		c.tool.comm = process_comm_event;
+		c.tool.exit = process_exit_event;
+		c.tool.fork = process_fork_event;
+	}
 
 	perf_config(convert__config, &c);
 
Signature · 1 line
1.8.3.4
#14 lore raw

[tip:perf/core] perf data ctf: Generate fork and exit events to CTF output

perf data ctf: Generate fork and exit events to CTF output
Commit-ID:  ebccba3fe0a02f622f80e6be0e8ecb1a9a3ed983
Gitweb:     http://git.kernel.org/tip/ebccba3fe0a02f622f80e6be0e8ecb1a9a3ed983
Author:     Wang Nan <[email protected]>
AuthorDate: Fri, 24 Jun 2016 11:22:12 +0000
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Tue, 28 Jun 2016 10:54:58 -0300

perf data ctf: Generate fork and exit events to CTF output

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

---
 tools/perf/util/data-convert-bt.c | 44 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 43 insertions(+), 1 deletion(-)
tools/perf/util/data-convert-bt.c +43 -1
index 5dd62ba..4f979bb 100644
@@ -70,6 +70,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 {
@@ -812,6 +814,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
 
@@ -1127,6 +1144,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
 
@@ -1138,6 +1171,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;
 }
 
@@ -1436,8 +1475,11 @@ int bt_convert__perf2ctf(const char *input, const char *path,
 	struct ctf_writer *cw = &c.writer;
 	int err = -1;
 
-	if (opts->all)
+	if (opts->all) {
 		c.tool.comm = process_comm_event;
+		c.tool.exit = process_exit_event;
+		c.tool.fork = process_fork_event;
+	}
 
 	perf_config(convert__config, &c);
 
Acked-by on the v2 series
#15 lore raw
In reply to Wang Nan
Quoted 20 lines · 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 adds 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.

v1 -> v2: Report number of sample and non-sample events when finish.
rename opts.non_sample to opts.all.

Quoted 8 lines

Wang Nan (7):
perf ctf: Add value_set_string() helper
perf ctf: Pass convert options through opts structure perf ctf: Add 'all' option
perf ctf: Prepare collect non-sample events 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

thanks,
jirka

maintainer Applied
#16 lore raw

Em Fri, Jun 24, 2016 at 02:28:51PM +0200, Jiri Olsa escreveu:

Quoted 30 lines · Wang Nan
Quoted 20 lines

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 adds 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.

v1 -> v2: Report number of sample and non-sample events when finish.
rename opts.non_sample to opts.all.

Quoted 8 lines

Wang Nan (7):
perf ctf: Add value_set_string() helper
perf ctf: Pass convert options through opts structure perf ctf: Add 'all' option
perf ctf: Prepare collect non-sample events 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

Quoted 1 line

Thanks, applied.

- Arnaldo
- Arnaldo

#17 lore raw
In reply to Wang Nan
Quoted 20 lines · 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 adds 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.

v1 -> v2: Report number of sample and non-sample events when finish.
rename opts.non_sample to opts.all.

Quoted 8 lines

Wang Nan (7):
perf ctf: Add value_set_string() helper
perf ctf: Pass convert options through opts structure perf ctf: Add 'all' option
perf ctf: Prepare collect non-sample events 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

I can't compile unless I can include config.h

[jolsa@krava perf]$ make LIBBABELTRACE_DIR=/opt/libbabeltrace/ LIBBABELTRACE=1
BUILD: Doing 'make -j4' parallel build
CC util/data-convert-bt.o
util/data-convert-bt.c: In function ‘convert__config’:
util/data-convert-bt.c:1299:19: error: implicit declaration of function ‘perf_config_u64’ [-Werror=implicit-function-declaration]

   c->queue_size = perf_config_u64(var, value);
                   ^

util/data-convert-bt.c:1299:3: error: nested extern declaration of ‘perf_config_u64’ [-Werror=nested-externs]
c->queue_size = perf_config_u64(var, value);
^
util/data-convert-bt.c: In function ‘bt_convert__perf2ctf’:
util/data-convert-bt.c:1332:2: error: implicit declaration of function ‘perf_config’ [-Werror=implicit-function-declaration]
perf_config(convert__config, &c);
^
util/data-convert-bt.c:1332:2: error: nested extern declaration of ‘perf_config’ [-Werror=nested-externs]
cc1: all warnings being treated as errors

your compiler's not that strict I guess ;-)
I'll post it shortly

jirka

---

tools/perf/util/data-convert-bt.c +1 -0
index 79082782e7d2..4b68e7b9ee0c 100644
@@ -26,6 +26,7 @@
 #include "evlist.h"
 #include "evsel.h"
 #include "machine.h"
+#include "config.h"
 
 #define pr_N(n, fmt, ...) \
 	eprintf(n, debug_data_convert, fmt, ##__VA_ARGS__)
#18 lore raw

发自我的 iPhone

Quoted 41 lines · 在 2016年6月24日,下午8:29,Jiri Olsa <[email protected]> 写道:
Quoted 22 lines · 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 adds 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.

v1 -> v2: Report number of sample and non-sample events when finish.
rename opts.non_sample to opts.all.

Quoted 8 lines

Wang Nan (7):
perf ctf: Add value_set_string() helper
perf ctf: Pass convert options through opts structure perf ctf: Add 'all' option
perf ctf: Prepare collect non-sample events 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

I can't compile unless I can include config.h

[jolsa@krava perf]$ make LIBBABELTRACE_DIR=/opt/libbabeltrace/ LIBBABELTRACE=1
BUILD: Doing 'make -j4' parallel build
CC util/data-convert-bt.o
util/data-convert-bt.c: In function ‘convert__config’:
util/data-convert-bt.c:1299:19: error: implicit declaration of function ‘perf_config_u64’ [-Werror=implicit-function-declaration]

  c->queue_size = perf_config_u64(var, value);
                  ^
Quoted 10 lines

util/data-convert-bt.c:1299:3: error: nested extern declaration of ‘perf_config_u64’ [-Werror=nested-externs]
c->queue_size = perf_config_u64(var, value);
^
util/data-convert-bt.c: In function ‘bt_convert__perf2ctf’:
util/data-convert-bt.c:1332:2: error: implicit declaration of function ‘perf_config’ [-Werror=implicit-function-declaration]
perf_config(convert__config, &c);
^
util/data-convert-bt.c:1332:2: error: nested extern declaration of ‘perf_config’ [-Werror=nested-externs]
cc1: all warnings being treated as errors

Strange.

The error message seems unrelated to my
patch, right?

Thank you.

Quoted 19 lines

your compiler's not that strict I guess ;-)
I'll post it shortly

jirka

---

tools/perf/util/data-convert-bt.c +1 -0
index 79082782e7d2..4b68e7b9ee0c 100644
@@ -26,6 +26,7 @@
 #include "evlist.h"
 #include "evsel.h"
 #include "machine.h"
+#include "config.h"
 
 #define pr_N(n, fmt, ...) \
   eprintf(n, debug_data_convert, fmt, ##__VA_ARGS__)
#19 lore raw

On Fri, Jun 24, 2016 at 08:33:27PM +0800, pi3orama wrote:

SNIP

Quoted 20 lines
Quoted 9 lines

I can't compile unless I can include config.h

[jolsa@krava perf]$ make LIBBABELTRACE_DIR=/opt/libbabeltrace/ LIBBABELTRACE=1
BUILD: Doing 'make -j4' parallel build
CC util/data-convert-bt.o
util/data-convert-bt.c: In function ‘convert__config’:
util/data-convert-bt.c:1299:19: error: implicit declaration of function ‘perf_config_u64’ [-Werror=implicit-function-declaration]

  c->queue_size = perf_config_u64(var, value);
                  ^
Quoted 10 lines

util/data-convert-bt.c:1299:3: error: nested extern declaration of ‘perf_config_u64’ [-Werror=nested-externs]
c->queue_size = perf_config_u64(var, value);
^
util/data-convert-bt.c: In function ‘bt_convert__perf2ctf’:
util/data-convert-bt.c:1332:2: error: implicit declaration of function ‘perf_config’ [-Werror=implicit-function-declaration]
perf_config(convert__config, &c);
^
util/data-convert-bt.c:1332:2: error: nested extern declaration of ‘perf_config’ [-Werror=nested-externs]
cc1: all warnings being treated as errors

Quoted 4 lines

Strange.

The error message seems unrelated to my
patch, right?

yep, it's unrelated and I just posted the fix

I haven't enabled/compiled this code for a while and that's what I've got.. I assume we're using different compilers

jirka

#20 lore raw
In reply to Jiri Olsa

Em Fri, Jun 24, 2016 at 02:29:07PM +0200, Jiri Olsa escreveu:

Quoted 30 lines · Wang Nan
Quoted 20 lines

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 adds 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.

v1 -> v2: Report number of sample and non-sample events when finish.
rename opts.non_sample to opts.all.

Quoted 8 lines

Wang Nan (7):
perf ctf: Add value_set_string() helper
perf ctf: Pass convert options through opts structure perf ctf: Add 'all' option
perf ctf: Prepare collect non-sample events 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

Quoted 1 line

I can't compile unless I can include config.h

Waiting for this fix to proceed, but it seems we don't have this covered in 'build-test', right? ;-)

- Arnaldo

Quoted 36 lines

[jolsa@krava perf]$ make LIBBABELTRACE_DIR=/opt/libbabeltrace/ LIBBABELTRACE=1
BUILD: Doing 'make -j4' parallel build
CC util/data-convert-bt.o
util/data-convert-bt.c: In function ‘convert__config’:
util/data-convert-bt.c:1299:19: error: implicit declaration of function ‘perf_config_u64’ [-Werror=implicit-function-declaration]

   c->queue_size = perf_config_u64(var, value);
                   ^
util/data-convert-bt.c:1299:3: error: nested extern declaration of ‘perf_config_u64’ [-Werror=nested-externs]
   c->queue_size = perf_config_u64(var, value);
   ^

util/data-convert-bt.c: In function ‘bt_convert__perf2ctf’:
util/data-convert-bt.c:1332:2: error: implicit declaration of function ‘perf_config’ [-Werror=implicit-function-declaration]
perf_config(convert__config, &c);
^
util/data-convert-bt.c:1332:2: error: nested extern declaration of ‘perf_config’ [-Werror=nested-externs]
cc1: all warnings being treated as errors

your compiler's not that strict I guess ;-)
I'll post it shortly

jirka

---

tools/perf/util/data-convert-bt.c +1 -0
index 79082782e7d2..4b68e7b9ee0c 100644
@@ -26,6 +26,7 @@
 #include "evlist.h"
 #include "evsel.h"
 #include "machine.h"
+#include "config.h"
 
 #define pr_N(n, fmt, ...) \
 	eprintf(n, debug_data_convert, fmt, ##__VA_ARGS__)
#21 lore raw

发自我的 iPhone

Quoted 33 lines · 在 2016年6月24日,下午8:41,Arnaldo Carvalho de Melo <[email protected]> 写道:

Em Fri, Jun 24, 2016 at 02:29:07PM +0200, Jiri Olsa escreveu:

Quoted 30 lines · Wang Nan
Quoted 28 lines

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 adds 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.

v1 -> v2: Report number of sample and non-sample events when finish.
rename opts.non_sample to opts.all.

Wang Nan (7):
perf ctf: Add value_set_string() helper
perf ctf: Pass convert options through opts structure perf ctf: Add 'all' option
perf ctf: Prepare collect non-sample events 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

Quoted 5 lines
Quoted 1 line

I can't compile unless I can include config.h

Waiting for this fix to proceed, but it seems we don't have this covered in 'build-test', right? ;-)

CTF support is off by default. When can we
turn it on like other options?

Thank you.

Quoted 38 lines

- Arnaldo

Quoted 36 lines

[jolsa@krava perf]$ make LIBBABELTRACE_DIR=/opt/libbabeltrace/ LIBBABELTRACE=1
BUILD: Doing 'make -j4' parallel build
CC util/data-convert-bt.o
util/data-convert-bt.c: In function ‘convert__config’:
util/data-convert-bt.c:1299:19: error: implicit declaration of function ‘perf_config_u64’ [-Werror=implicit-function-declaration]

  c->queue_size = perf_config_u64(var, value);
                  ^

util/data-convert-bt.c:1299:3: error: nested extern declaration of ‘perf_config_u64’ [-Werror=nested-externs]
c->queue_size = perf_config_u64(var, value);
^
util/data-convert-bt.c: In function ‘bt_convert__perf2ctf’:
util/data-convert-bt.c:1332:2: error: implicit declaration of function ‘perf_config’ [-Werror=implicit-function-declaration]
perf_config(convert__config, &c);
^
util/data-convert-bt.c:1332:2: error: nested extern declaration of ‘perf_config’ [-Werror=nested-externs]
cc1: all warnings being treated as errors

your compiler's not that strict I guess ;-)
I'll post it shortly

jirka

---

tools/perf/util/data-convert-bt.c +1 -0
index 79082782e7d2..4b68e7b9ee0c 100644
@@ -26,6 +26,7 @@
 #include "evlist.h"
 #include "evsel.h"
 #include "machine.h"
+#include "config.h"
 
 #define pr_N(n, fmt, ...) \
   eprintf(n, debug_data_convert, fmt, ##__VA_ARGS__)
#22 lore raw
Quoted 37 lines · On Fri, Jun 24, 2016 at 08:43:56PM +0800, pi3orama wrote:

发自我的 iPhone

Quoted 33 lines · 在 2016年6月24日,下午8:41,Arnaldo Carvalho de Melo <[email protected]> 写道:

Em Fri, Jun 24, 2016 at 02:29:07PM +0200, Jiri Olsa escreveu:

Quoted 30 lines · Wang Nan
Quoted 28 lines

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 adds 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.

v1 -> v2: Report number of sample and non-sample events when finish.
rename opts.non_sample to opts.all.

Wang Nan (7):
perf ctf: Add value_set_string() helper
perf ctf: Pass convert options through opts structure perf ctf: Add 'all' option
perf ctf: Prepare collect non-sample events 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

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

I can't compile unless I can include config.h

Waiting for this fix to proceed, but it seems we don't have this covered in 'build-test', right? ;-)

CTF support is off by default. When can we
turn it on like other options?

we switched it off because the latest version we needed wasn't part of main distros.. it might have changed now

jirka

#23 lore raw
In reply to Arnaldo Carvalho de Melo
Quoted 31 lines · Arnaldo Carvalho de Melo

Em Fri, Jun 24, 2016 at 02:29:07PM +0200, Jiri Olsa escreveu:

Quoted 30 lines · Wang Nan
Quoted 28 lines

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 adds 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.

v1 -> v2: Report number of sample and non-sample events when finish.
rename opts.non_sample to opts.all.

Wang Nan (7):
perf ctf: Add value_set_string() helper
perf ctf: Pass convert options through opts structure perf ctf: Add 'all' option
perf ctf: Prepare collect non-sample events 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

Quoted 3 lines
Quoted 1 line

I can't compile unless I can include config.h

Waiting for this fix to proceed, but it seems we don't have this covered

just posted it ;-)

Quoted 1 line

in 'build-test', right? ;-)

right, but we dont cover babletrace stuff in tests/make

jirka