* [PATCH v1 1/5] perf check: Add libbabeltrace to the listed features
2026-02-11 1:52 [PATCH v1 0/5] perf data pipe mode support and tests Ian Rogers
@ 2026-02-11 1:52 ` Ian Rogers
2026-02-11 1:52 ` [PATCH v1 2/5] perf json: Pipe mode --to-json support Ian Rogers
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Ian Rogers @ 2026-02-11 1:52 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Alexander Shishkin, Jiri Olsa, Ian Rogers,
Adrian Hunter, James Clark, Derek Foreman, linux-kernel,
linux-perf-users
This enables scripts to more easily determine if `perf data --to-ctf`
is supported.
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/builtin-check.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/tools/perf/builtin-check.c b/tools/perf/builtin-check.c
index 27a41beeaddf..3641d263b345 100644
--- a/tools/perf/builtin-check.c
+++ b/tools/perf/builtin-check.c
@@ -43,6 +43,7 @@ struct feature_status supported_features[] = {
FEATURE_STATUS("dwarf_getlocations", HAVE_LIBDW_SUPPORT),
FEATURE_STATUS("dwarf-unwind", HAVE_DWARF_UNWIND_SUPPORT),
FEATURE_STATUS_TIP("libbfd", HAVE_LIBBFD_SUPPORT, "Deprecated, license incompatibility, use BUILD_NONDISTRO=1 and install binutils-dev[el]"),
+ FEATURE_STATUS("libbabeltrace", HAVE_LIBBABELTRACE_SUPPORT),
FEATURE_STATUS("libbpf-strings", HAVE_LIBBPF_STRINGS_SUPPORT),
FEATURE_STATUS("libcapstone", HAVE_LIBCAPSTONE_SUPPORT),
FEATURE_STATUS("libdw-dwarf-unwind", HAVE_LIBDW_SUPPORT),
--
2.53.0.239.g8d8fc8a987-goog
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v1 2/5] perf json: Pipe mode --to-json support
2026-02-11 1:52 [PATCH v1 0/5] perf data pipe mode support and tests Ian Rogers
2026-02-11 1:52 ` [PATCH v1 1/5] perf check: Add libbabeltrace to the listed features Ian Rogers
@ 2026-02-11 1:52 ` Ian Rogers
2026-02-11 1:52 ` [PATCH v1 3/5] perf json: Pipe mode --to-ctf support Ian Rogers
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Ian Rogers @ 2026-02-11 1:52 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Alexander Shishkin, Jiri Olsa, Ian Rogers,
Adrian Hunter, James Clark, Derek Foreman, linux-kernel,
linux-perf-users
In pipe mode the environment may not be fully initialized so be robust
to fields being NULL. Add default handling of feature and attr events.
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/util/data-convert-json.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/tools/perf/util/data-convert-json.c b/tools/perf/util/data-convert-json.c
index eefa3a94c813..6a626322476a 100644
--- a/tools/perf/util/data-convert-json.c
+++ b/tools/perf/util/data-convert-json.c
@@ -48,6 +48,9 @@ struct convert_json {
static void output_json_string(FILE *out, const char *s)
{
fputc('"', out);
+ if (!s)
+ goto out;
+
while (*s) {
switch (*s) {
@@ -71,6 +74,7 @@ static void output_json_string(FILE *out, const char *s)
++s;
}
+out:
fputc('"', out);
}
@@ -322,6 +326,16 @@ static void output_headers(struct perf_session *session, struct convert_json *c)
output_json_format(out, false, 2, "]");
}
+static int process_feature_event(const struct perf_tool *tool __maybe_unused,
+ struct perf_session *session,
+ union perf_event *event)
+{
+ if (event->feat.feat_id < HEADER_LAST_FEATURE)
+ return perf_event__process_feature(session, event);
+
+ return 0;
+}
+
int bt_convert__perf2json(const char *input_name, const char *output_name,
struct perf_data_convert_opts *opts __maybe_unused)
{
@@ -360,6 +374,8 @@ int bt_convert__perf2json(const char *input_name, const char *output_name,
c.tool.auxtrace_info = perf_event__process_auxtrace_info;
c.tool.auxtrace = perf_event__process_auxtrace;
c.tool.event_update = perf_event__process_event_update;
+ c.tool.attr = perf_event__process_attr;
+ c.tool.feature = process_feature_event;
c.tool.ordering_requires_timestamps = true;
if (opts->all) {
--
2.53.0.239.g8d8fc8a987-goog
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v1 3/5] perf json: Pipe mode --to-ctf support
2026-02-11 1:52 [PATCH v1 0/5] perf data pipe mode support and tests Ian Rogers
2026-02-11 1:52 ` [PATCH v1 1/5] perf check: Add libbabeltrace to the listed features Ian Rogers
2026-02-11 1:52 ` [PATCH v1 2/5] perf json: Pipe mode --to-json support Ian Rogers
@ 2026-02-11 1:52 ` Ian Rogers
2026-02-11 1:52 ` [PATCH v1 4/5] perf test: Test pipe mode with data conversion --to-json Ian Rogers
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Ian Rogers @ 2026-02-11 1:52 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Alexander Shishkin, Jiri Olsa, Ian Rogers,
Adrian Hunter, James Clark, Derek Foreman, linux-kernel,
linux-perf-users
In pipe mode the environment may not be fully initialized so be robust
to fields being NULL. Add default handling of attr events, use the
feature events to populate the ctf writer environment.
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/util/data-convert-bt.c | 54 +++++++++++++++++++++++++++++--
1 file changed, 52 insertions(+), 2 deletions(-)
diff --git a/tools/perf/util/data-convert-bt.c b/tools/perf/util/data-convert-bt.c
index a22e9049ff30..ba1c8e48d495 100644
--- a/tools/perf/util/data-convert-bt.c
+++ b/tools/perf/util/data-convert-bt.c
@@ -35,6 +35,7 @@
#include "clockid.h"
#include "util/sample.h"
#include "util/time-utils.h"
+#include "header.h"
#ifdef HAVE_LIBTRACEEVENT
#include <event-parse.h>
@@ -1338,7 +1339,8 @@ static void cleanup_events(struct perf_session *session)
struct evsel_priv *priv;
priv = evsel->priv;
- bt_ctf_event_class_put(priv->event_class);
+ if (priv)
+ bt_ctf_event_class_put(priv->event_class);
zfree(&evsel->priv);
}
@@ -1387,7 +1389,7 @@ static int ctf_writer__setup_env(struct ctf_writer *cw,
#define ADD(__n, __v) \
do { \
- if (bt_ctf_writer_add_environment_field(writer, __n, __v)) \
+ if (__v && bt_ctf_writer_add_environment_field(writer, __n, __v)) \
return -1; \
} while (0)
@@ -1403,6 +1405,52 @@ do { \
return 0;
}
+static int process_feature_event(const struct perf_tool *tool,
+ struct perf_session *session,
+ union perf_event *event)
+{
+ struct convert *c = container_of(tool, struct convert, tool);
+ struct ctf_writer *cw = &c->writer;
+ struct perf_record_header_feature *fe = &event->feat;
+
+ if (event->feat.feat_id < HEADER_LAST_FEATURE) {
+ int ret = perf_event__process_feature(session, event);
+
+ if (ret)
+ return ret;
+ }
+
+ switch (fe->feat_id) {
+ case HEADER_HOSTNAME:
+ if (session->header.env.hostname) {
+ return bt_ctf_writer_add_environment_field(cw->writer, "host",
+ session->header.env.hostname);
+ }
+ break;
+ case HEADER_OSRELEASE:
+ if (session->header.env.os_release) {
+ return bt_ctf_writer_add_environment_field(cw->writer, "release",
+ session->header.env.os_release);
+ }
+ break;
+ case HEADER_VERSION:
+ if (session->header.env.version) {
+ return bt_ctf_writer_add_environment_field(cw->writer, "version",
+ session->header.env.version);
+ }
+ break;
+ case HEADER_ARCH:
+ if (session->header.env.arch) {
+ return bt_ctf_writer_add_environment_field(cw->writer, "machine",
+ session->header.env.arch);
+ }
+ break;
+ default:
+ break;
+ }
+ return 0;
+}
+
static int ctf_writer__setup_clock(struct ctf_writer *cw,
struct perf_session *session,
bool tod)
@@ -1635,6 +1683,8 @@ int bt_convert__perf2ctf(const char *input, const char *path,
c.tool.tracing_data = perf_event__process_tracing_data;
c.tool.build_id = perf_event__process_build_id;
c.tool.namespaces = perf_event__process_namespaces;
+ c.tool.attr = perf_event__process_attr;
+ c.tool.feature = process_feature_event;
c.tool.ordering_requires_timestamps = true;
if (opts->all) {
--
2.53.0.239.g8d8fc8a987-goog
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v1 4/5] perf test: Test pipe mode with data conversion --to-json
2026-02-11 1:52 [PATCH v1 0/5] perf data pipe mode support and tests Ian Rogers
` (2 preceding siblings ...)
2026-02-11 1:52 ` [PATCH v1 3/5] perf json: Pipe mode --to-ctf support Ian Rogers
@ 2026-02-11 1:52 ` Ian Rogers
2026-02-11 1:52 ` [PATCH v1 5/5] perf test: perf data --to-ctf testing Ian Rogers
2026-02-11 16:35 ` [PATCH v1 0/5] perf data pipe mode support and tests Arnaldo Carvalho de Melo
5 siblings, 0 replies; 7+ messages in thread
From: Ian Rogers @ 2026-02-11 1:52 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Alexander Shishkin, Jiri Olsa, Ian Rogers,
Adrian Hunter, James Clark, Derek Foreman, linux-kernel,
linux-perf-users
Add pipe mode test for json data conversion. Tidy up exit and cleanup
code.
Signed-off-by: Ian Rogers <irogers@google.com>
---
.../shell/test_perf_data_converter_json.sh | 33 ++++++++++++++-----
1 file changed, 24 insertions(+), 9 deletions(-)
diff --git a/tools/perf/tests/shell/test_perf_data_converter_json.sh b/tools/perf/tests/shell/test_perf_data_converter_json.sh
index c4f1b59d116f..35d81e39a26c 100755
--- a/tools/perf/tests/shell/test_perf_data_converter_json.sh
+++ b/tools/perf/tests/shell/test_perf_data_converter_json.sh
@@ -15,29 +15,42 @@ result=$(mktemp /tmp/__perf_test.output.json.XXXXX)
cleanup()
{
- rm -f "${perfdata}"
+ rm -f "${perfdata}*"
rm -f "${result}"
trap - exit term int
}
trap_cleanup()
{
+ echo "Unexpected signal in ${FUNCNAME[1]}"
cleanup
- exit ${err}
+ exit 1
}
trap trap_cleanup exit term int
test_json_converter_command()
{
- echo "Testing Perf Data Convertion Command to JSON"
- perf record -o "$perfdata" -F 99 -g -- perf test -w noploop > /dev/null 2>&1
- perf data convert --to-json "$result" --force -i "$perfdata" >/dev/null 2>&1
+ echo "Testing Perf Data Conversion Command to JSON"
+ perf record -o "$perfdata" -F 99 -g -- perf test -w noploop
+ perf data convert --to-json "$result" --force -i "$perfdata"
if [ "$(cat ${result} | wc -l)" -gt "0" ] ; then
echo "Perf Data Converter Command to JSON [SUCCESS]"
else
echo "Perf Data Converter Command to JSON [FAILED]"
err=1
- exit
+ fi
+}
+
+test_json_converter_pipe()
+{
+ echo "Testing Perf Data Conversion Command to JSON (Pipe mode)"
+ perf record -o - -F 99 -g -- perf test -w noploop > "$perfdata"
+ cat "$perfdata" | perf data convert --to-json "$result" --force -i -
+ if [ "$(cat ${result} | wc -l)" -gt "0" ] ; then
+ echo "Perf Data Converter Command to JSON (Pipe mode) [SUCCESS]"
+ else
+ echo "Perf Data Converter Command to JSON (Pipe mode) [FAILED]"
+ err=1
fi
}
@@ -50,16 +63,18 @@ validate_json_format()
else
echo "The file does not contain valid JSON format [FAILED]"
err=1
- exit
fi
else
echo "File not found [FAILED]"
- err=2
- exit
+ err=1
fi
}
test_json_converter_command
validate_json_format
+test_json_converter_pipe
+validate_json_format
+
+cleanup
exit ${err}
--
2.53.0.239.g8d8fc8a987-goog
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v1 5/5] perf test: perf data --to-ctf testing
2026-02-11 1:52 [PATCH v1 0/5] perf data pipe mode support and tests Ian Rogers
` (3 preceding siblings ...)
2026-02-11 1:52 ` [PATCH v1 4/5] perf test: Test pipe mode with data conversion --to-json Ian Rogers
@ 2026-02-11 1:52 ` Ian Rogers
2026-02-11 16:35 ` [PATCH v1 0/5] perf data pipe mode support and tests Arnaldo Carvalho de Melo
5 siblings, 0 replies; 7+ messages in thread
From: Ian Rogers @ 2026-02-11 1:52 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Alexander Shishkin, Jiri Olsa, Ian Rogers,
Adrian Hunter, James Clark, Derek Foreman, linux-kernel,
linux-perf-users
If babeltrace is detected check that --to-ctf functions with a data
file and in pipe mode.
Signed-off-by: Ian Rogers <irogers@google.com>
---
.../shell/test_perf_data_converter_ctf.sh | 104 ++++++++++++++++++
1 file changed, 104 insertions(+)
create mode 100755 tools/perf/tests/shell/test_perf_data_converter_ctf.sh
diff --git a/tools/perf/tests/shell/test_perf_data_converter_ctf.sh b/tools/perf/tests/shell/test_perf_data_converter_ctf.sh
new file mode 100755
index 000000000000..334eebc9945e
--- /dev/null
+++ b/tools/perf/tests/shell/test_perf_data_converter_ctf.sh
@@ -0,0 +1,104 @@
+#!/bin/bash
+# 'perf data convert --to-ctf' command test
+# SPDX-License-Identifier: GPL-2.0
+
+set -e
+
+err=0
+
+perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
+ctf_dir=$(mktemp -d /tmp/__perf_test.ctf.XXXXX)
+
+cleanup()
+{
+ rm -f "${perfdata}"
+ rm -rf "${ctf_dir}"
+ trap - exit term int
+}
+
+trap_cleanup()
+{
+ echo "Unexpected signal in ${FUNCNAME[1]}"
+ cleanup
+ exit ${err}
+}
+trap trap_cleanup exit term int
+
+check_babeltrace_support()
+{
+ if ! perf check feature libbabeltrace
+ then
+ echo "perf not linked with libbabeltrace, skipping test"
+ exit 2
+ fi
+}
+
+test_ctf_converter_file()
+{
+ echo "Testing Perf Data Conversion Command to CTF (File input)"
+ # Record some data
+ if ! perf record -o "$perfdata" -F 99 -g -- perf test -w noploop
+ then
+ echo "Failed to record perf data"
+ err=1
+ return
+ fi
+
+ # Cleanup previous ctf dir
+ rm -rf "${ctf_dir}"
+
+ # Convert
+ if ! perf data convert --to-ctf "$ctf_dir" --force -i "$perfdata"
+ then
+ echo "Perf Data Converter Command to CTF (File input) [FAILED]"
+ err=1
+ return
+ fi
+
+ if [ -d "${ctf_dir}" ] && [ "$(ls -A "${ctf_dir}")" ]
+ then
+ echo "Perf Data Converter Command to CTF (File input) [SUCCESS]"
+ else
+ echo "Perf Data Converter Command to CTF (File input) [FAILED]"
+ echo " Output directory empty or missing"
+ err=1
+ fi
+}
+
+test_ctf_converter_pipe()
+{
+ echo "Testing Perf Data Conversion Command to CTF (Pipe mode)"
+
+ # Cleanup previous ctf dir
+ rm -rf "${ctf_dir}"
+
+ # Record to stdout and pipe to $perfdata file
+ if ! perf record -o - -F 99 -g -- perf test -w noploop > "$perfdata"
+ then
+ echo "Failed to record perf data"
+ err=1
+ return
+ fi
+
+ if ! perf data convert --to-ctf "$ctf_dir" --force -i "$perfdata"
+ then
+ echo "Perf Data Converter Command to CTF (Pipe mode) [FAILED]"
+ err=1
+ return
+ fi
+
+ if [ -d "${ctf_dir}" ] && [ "$(ls -A "${ctf_dir}")" ]
+ then
+ echo "Perf Data Converter Command to CTF (Pipe mode) [SUCCESS]"
+ else
+ echo "Perf Data Converter Command to CTF (Pipe mode) [FAILED]"
+ echo " Output directory empty or missing"
+ err=1
+ fi
+}
+
+check_babeltrace_support
+test_ctf_converter_file
+test_ctf_converter_pipe
+
+exit ${err}
--
2.53.0.239.g8d8fc8a987-goog
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH v1 0/5] perf data pipe mode support and tests
2026-02-11 1:52 [PATCH v1 0/5] perf data pipe mode support and tests Ian Rogers
` (4 preceding siblings ...)
2026-02-11 1:52 ` [PATCH v1 5/5] perf test: perf data --to-ctf testing Ian Rogers
@ 2026-02-11 16:35 ` Arnaldo Carvalho de Melo
5 siblings, 0 replies; 7+ messages in thread
From: Arnaldo Carvalho de Melo @ 2026-02-11 16:35 UTC (permalink / raw)
To: Ian Rogers
Cc: Peter Zijlstra, Ingo Molnar, Namhyung Kim, Alexander Shishkin,
Jiri Olsa, Adrian Hunter, James Clark, Derek Foreman,
linux-kernel, linux-perf-users
On Tue, Feb 10, 2026 at 05:52:37PM -0800, Ian Rogers wrote:
> Add pipe mode support to perf data conversion. Add testing to perf
> data with pipe mode and add --to-ctf testing if libbabeltrace is
> present.
>
> Ian Rogers (5):
> perf check: Add libbabeltrace to the listed features
> perf json: Pipe mode --to-json support
> perf json: Pipe mode --to-ctf support
> perf test: Test pipe mode with data conversion --to-json
> perf test: perf data --to-ctf testing
Thanks, applied to perf-tools-next,
- Arnaldo
> tools/perf/builtin-check.c | 1 +
> .../shell/test_perf_data_converter_ctf.sh | 104 ++++++++++++++++++
> .../shell/test_perf_data_converter_json.sh | 33 ++++--
> tools/perf/util/data-convert-bt.c | 54 ++++++++-
> tools/perf/util/data-convert-json.c | 16 +++
> 5 files changed, 197 insertions(+), 11 deletions(-)
> create mode 100755 tools/perf/tests/shell/test_perf_data_converter_ctf.sh
>
> --
> 2.53.0.239.g8d8fc8a987-goog
^ permalink raw reply [flat|nested] 7+ messages in thread