From: Tanushree Shah <tshah@linux.ibm.com>
To: acme@kernel.org, jolsa@kernel.org, adrian.hunter@intel.com,
vmolnaro@redhat.com, mpetlan@redhat.com, tmricht@linux.ibm.com,
maddy@linux.ibm.com, irogers@google.com, namhyung@kernel.org
Cc: linux-perf-users@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
atrajeev@linux.ibm.com, hbathini@linux.ibm.com,
Tejas.Manhas1@ibm.com, Tanushree.Shah@ibm.com,
rostedt@goodmis.org, Tanushree Shah <tshah@linux.ibm.com>
Subject: [RFC PATCH v3 4/5] perf data: Add --to-trace-dat option for converting perf.data tracepoint events into trace.dat format
Date: Mon, 3 Aug 2026 20:29:54 +0530 [thread overview]
Message-ID: <20260803145958.299956-5-tshah@linux.ibm.com> (raw)
In-Reply-To: <20260803145958.299956-1-tshah@linux.ibm.com>
Add new command-line option to perf data convert for generating
trace.dat output files.
The --to-trace-dat option:
- Accepts output filename for trace.dat format
- Mutually exclusive with --to-ctf and --to-json
- Calls trace_convert__perf2dat() to perform conversion
Usage:
$ perf record -e sched:* -a sleep 1
$ perf data convert --to-trace-dat=trace.dat
$ trace-cmd report trace.dat
Document the new option in Documentation/perf-data.txt alongside
the existing --to-ctf and --to-json entries.
Signed-off-by: Tanushree Shah <tshah@linux.ibm.com>
---
tools/perf/Documentation/perf-data.txt | 7 +++++
tools/perf/builtin-data.c | 43 ++++++++++++++++++++++++++
tools/perf/util/trace-dat.c | 3 ++
3 files changed, 53 insertions(+)
diff --git a/tools/perf/Documentation/perf-data.txt b/tools/perf/Documentation/perf-data.txt
index 20f178d61ed7..578ba6357183 100644
--- a/tools/perf/Documentation/perf-data.txt
+++ b/tools/perf/Documentation/perf-data.txt
@@ -30,6 +30,13 @@ OPTIONS for 'convert'
--to-json::
Triggers JSON conversion. Specify the JSON filename to output.
+--to-trace-dat::
+ Triggers trace.dat conversion. Converts perf.data tracepoint events
+ to trace.dat format v7, compatible with trace-cmd and KernelShark.
+ Only PERF_TYPE_TRACEPOINT events are converted. Specify the
+ trace.dat filename to output. Requires libtraceevent support.
+ Mutually exclusive with --to-ctf and --to-json.
+
--tod::
Convert time to wall clock time.
diff --git a/tools/perf/builtin-data.c b/tools/perf/builtin-data.c
index 1dd73ed6bdcb..c9c863197d02 100644
--- a/tools/perf/builtin-data.c
+++ b/tools/perf/builtin-data.c
@@ -30,6 +30,11 @@ static const char *data_usage[] = {
static const char *to_json;
static const char *to_ctf;
+
+#ifdef HAVE_LIBTRACEEVENT
+static const char *trace_dat_output;
+#endif
+
static struct perf_data_convert_opts opts = {
.force = false,
.all = false,
@@ -46,6 +51,10 @@ static const struct option data_options[] = {
OPT_BOOLEAN(0, "all", &opts.all, "Convert all events"),
OPT_STRING(0, "time", &opts.time_str, "str",
"Time span of interest (start,stop)"),
+#ifdef HAVE_LIBTRACEEVENT
+ OPT_STRING(0, "to-trace-dat", &trace_dat_output,
+ "file", "Convert to trace.dat format using perf.data tracepoints"),
+#endif
OPT_END()
};
@@ -63,10 +72,44 @@ static int cmd_data_convert(int argc, const char **argv)
pr_err("You cannot specify both --to-ctf and --to-json.\n");
return -1;
}
+#ifdef HAVE_LIBTRACEEVENT
+ if (trace_dat_output && (to_json || to_ctf)) {
+ pr_err("You cannot specify --to-trace-dat with --to-ctf or --to-json.\n");
+ return -1;
+ }
+#endif
+
+#ifdef HAVE_LIBBABELTRACE_SUPPORT
+ #ifdef HAVE_LIBTRACEEVENT
+ if (!to_json && !to_ctf && !trace_dat_output) {
+ pr_err("You must specify one of --to-ctf, --to-json, or --to-trace-dat.\n");
+ return -1;
+ }
+ #else
if (!to_json && !to_ctf) {
pr_err("You must specify one of --to-ctf or --to-json.\n");
return -1;
}
+ #endif
+#else
+ #ifdef HAVE_LIBTRACEEVENT
+ if (!to_json && !trace_dat_output) {
+ pr_err("You must specify --to-json or --to-trace-dat.\n");
+ return -1;
+ }
+ #else
+ if (!to_json) {
+ pr_err("You must specify --to-json.\n");
+ return -1;
+ }
+ #endif
+#endif
+
+#ifdef HAVE_LIBTRACEEVENT
+ if (trace_dat_output)
+ return trace_convert__perf2dat(input_name ? input_name : "perf.data",
+ trace_dat_output, &opts);
+#endif
if (to_json)
return bt_convert__perf2json(input_name, to_json, &opts);
diff --git a/tools/perf/util/trace-dat.c b/tools/perf/util/trace-dat.c
index f71e03716e27..5598496c9a61 100644
--- a/tools/perf/util/trace-dat.c
+++ b/tools/perf/util/trace-dat.c
@@ -861,6 +861,9 @@ void trace_dat__free_cpu_buffers(void)
for (cpu = 0; cpu < trace_dat_nr_cpus; cpu++) {
int i;
+ if (!trace_cpu_data[cpu].events)
+ continue;
+
for (i = 0; i < trace_cpu_data[cpu].count; i++)
free(trace_cpu_data[cpu].events[i].raw);
free(trace_cpu_data[cpu].events);
--
2.47.1
next prev parent reply other threads:[~2026-08-03 15:01 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-03 14:59 [RFC PATCH v3 0/5] Add perf.data tracepoint events to trace.dat conversion Tanushree Shah
2026-08-03 14:59 ` [RFC PATCH v3 1/5] perf/trace-dat: Add trace.dat export infrastructure Tanushree Shah
2026-08-03 15:14 ` sashiko-bot
2026-08-03 14:59 ` [RFC PATCH v3 2/5] perf/trace-event: Write trace.dat metadata sections during parsing Tanushree Shah
2026-08-03 15:14 ` sashiko-bot
2026-08-03 14:59 ` [RFC PATCH v3 3/5] perf data-convert: Add perf.data to trace.dat conversion backend Tanushree Shah
2026-08-03 15:11 ` sashiko-bot
2026-08-03 14:59 ` Tanushree Shah [this message]
2026-08-03 15:13 ` [RFC PATCH v3 4/5] perf data: Add --to-trace-dat option for converting perf.data tracepoint events into trace.dat format sashiko-bot
2026-08-03 14:59 ` [RFC PATCH v3 5/5] perf test: Add test validating trace.dat generated by 'perf data convert --to-trace-dat' Tanushree Shah
2026-08-03 15:19 ` sashiko-bot
2026-08-06 0:15 ` Ian Rogers
2026-08-06 9:20 ` Tanushree Shah
2026-08-06 0:18 ` [RFC PATCH v3 0/5] Add perf.data tracepoint events to trace.dat conversion Ian Rogers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260803145958.299956-5-tshah@linux.ibm.com \
--to=tshah@linux.ibm.com \
--cc=Tanushree.Shah@ibm.com \
--cc=Tejas.Manhas1@ibm.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=atrajeev@linux.ibm.com \
--cc=hbathini@linux.ibm.com \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=maddy@linux.ibm.com \
--cc=mpetlan@redhat.com \
--cc=namhyung@kernel.org \
--cc=rostedt@goodmis.org \
--cc=tmricht@linux.ibm.com \
--cc=vmolnaro@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is 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.