From: Ian Rogers <irogers@google.com>
To: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
James Clark <james.clark@linaro.org>,
Derek Foreman <derek.foreman@collabora.com>,
linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org
Subject: [PATCH v1 3/5] perf json: Pipe mode --to-ctf support
Date: Tue, 10 Feb 2026 17:52:40 -0800 [thread overview]
Message-ID: <20260211015242.2700218-4-irogers@google.com> (raw)
In-Reply-To: <20260211015242.2700218-1-irogers@google.com>
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
next prev parent reply other threads:[~2026-02-11 1:52 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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 ` [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
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=20260211015242.2700218-4-irogers@google.com \
--to=irogers@google.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=derek.foreman@collabora.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox