Skip to contentSkip to conversation

perf data ctf: replace libbabeltrace with babeltrace2-ctf-writer

PATCH Superseded Michael Jeanson 4 participants 18 messages May 12 – Jun 4 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf data ctf: replace libbabeltrace with babeltrace2-ctf-writer

The 1.x branch of Babeltrace has been superseded by 2.x in 2020 and has been unmaintained since 2022, efforts have started to remove it from popular distributions.

Babeltrace 2.x offers a very similar 'ctf-writer' library that can be used with minimal changes for the '--to-ctf' feature and has been packaged since Debian 11 and Fedora 32.

This patch replaces the 'libbabeltrace' build feature with 'babeltrace2-ctf-writer' using pkgconfig detection, adjusts the naming of the public headers and applies minor API cleanups.

No changes to the output ctf traces, this API still implements version 1.8 of the CTF specification that can be read by either Babeltrace 1 / 2 or any CTF compliant reader.

Also remove some ifdefs in the cli option parsing to allow printing the helpful error message with '--to-ctf' when built without babeltrace2.

Cc Adrian Hunter <[email protected]>
Cc Alexander Shishkin <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Derek Foreman <[email protected]>
Cc Ian Rogers <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc James Clark <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Mathieu Desnoyers <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Peter Zijlstra <[email protected]>
---
 tools/build/Makefile.feature                  |  5 +--
 tools/build/feature/Makefile                  |  6 ++--
 tools/build/feature/test-all.c                | 13 ++------
 ...ltrace.c => test-babeltrace2-ctf-writer.c} |  3 +-
 tools/perf/Makefile.config                    | 28 ++++++++--------
 tools/perf/Makefile.perf                      |  2 +-
 tools/perf/builtin-check.c                    |  2 +-
 tools/perf/builtin-data.c                     | 18 +++-------
 tools/perf/tests/make                         |  4 +--
 .../shell/test_perf_data_converter_ctf.sh     |  8 ++---
 tools/perf/util/Build                         |  2 +-
 tools/perf/util/data-convert-bt.c             | 33 +++++++++----------
 tools/perf/util/data-convert.h                |  4 +--
 13 files changed, 55 insertions(+), 73 deletions(-)
 rename tools/build/feature/{test-libbabeltrace.c => test-babeltrace2-ctf-writer.c} (59%)
tools/build/Makefile.feature +3 -2
index 0b7a7c38cb88..9e097144817e 100644
@@ -113,7 +113,7 @@ FEATURE_TESTS_EXTRA :=                  \
          gtk2                           \
          gtk2-infobar                   \
          hello                          \
-         libbabeltrace                  \
+         babeltrace2-ctf-writer         \
          libcapstone                    \
          libbfd-liberty                 \
          libbfd-liberty-z               \
@@ -162,6 +162,7 @@ FEATURE_GROUP_MEMBERS-libbfd = libbfd-liberty libbfd-liberty-z
 # Declare list of feature dependency packages that provide pkg-config files.
 #
 FEATURE_PKG_CONFIG ?=           \
+	 babeltrace2-ctf-writer \
          libtraceevent          \
          libtracefs
 
@@ -208,7 +209,7 @@ ifeq ($(feature-all), 1)
   $(call feature_check,compile-32)
   $(call feature_check,compile-x32)
   $(call feature_check,bionic)
-  $(call feature_check,libbabeltrace)
+  $(call feature_check,babeltrace2-ctf-writer)
 else
   $(foreach feat,$(FEATURE_TESTS),$(call feature_check,$(feat)))
 endif
tools/build/feature/Makefile +3 -3
index 1fbcb3ce74d2..7735e257c263 100644
@@ -48,7 +48,7 @@ FILES=                                          \
          test-pthread-barrier.bin		\
          test-stackprotector-all.bin            \
          test-timerfd.bin                       \
-         test-libbabeltrace.bin                 \
+         test-babeltrace2-ctf-writer.bin        \
          test-libcapstone.bin			\
          test-compile-32.bin                    \
          test-compile-x32.bin                   \
@@ -301,8 +301,8 @@ $(OUTPUT)test-backtrace.bin:
 $(OUTPUT)test-timerfd.bin:
 	$(BUILD)
 
-$(OUTPUT)test-libbabeltrace.bin:
-	$(BUILD) # -lbabeltrace provided by $(FEATURE_CHECK_LDFLAGS-libbabeltrace)
+$(OUTPUT)test-babeltrace2-ctf-writer.bin:
+	$(BUILD) # -lbabeltrace2-ctf-writer provided by $(FEATURE_CHECK_LDFLAGS-babeltrace2-ctf-writer)
 
 $(OUTPUT)test-libcapstone.bin:
 	$(BUILD) # -lcapstone provided by $(FEATURE_CHECK_LDFLAGS-libcapstone)
tools/build/feature/test-all.c +3 -10
index 1488bf6e6078..145abdee049d 100644
@@ -98,17 +98,9 @@
 # include "test-sched_getcpu.c"
 #undef main
 
-# if 0
-/*
- * Disable libbabeltrace check for test-all, because the requested
- * library version is not released yet in most distributions. Will
- * reenable later.
- */
-
-#define main main_test_libbabeltrace
-# include "test-libbabeltrace.c"
+#define main main_test_babeltrace2_ctf_writer
+# include "test-babeltrace2-ctf-writer.c"
 #undef main
-#endif
 
 #define main main_test_lzma
 # include "test-lzma.c"
@@ -178,6 +170,7 @@ int main(int argc, char *argv[])
 	main_test_libzstd();
 	main_test_libtraceevent();
 	main_test_libopenssl();
+	main_test_babeltrace2_ctf_writer();
 
 	return 0;
 }
tools/build/feature/test-babeltrace2-ctf-writer.c renamed from tools/build/feature/test-libbabeltrace.c +1 -2
similarity index 59%
rename from tools/build/feature/test-libbabeltrace.c
rename to tools/build/feature/test-babeltrace2-ctf-writer.c
index 10bb69d55694..9c89082e9f88 100644
@@ -1,7 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 
-#include <babeltrace/ctf-writer/writer.h>
-#include <babeltrace/ctf-ir/stream-class.h>
+#include <babeltrace2-ctf-writer/writer.h>
 
 int main(void)
 {
tools/perf/Makefile.config +14 -14
index 15fbba9f4ca8..f2f5051c94e3 100644
@@ -196,13 +196,13 @@ FEATURE_CHECK_CFLAGS-libdw := $(LIBDW_CFLAGS)
 FEATURE_CHECK_LDFLAGS-libdw := $(LIBDW_LDFLAGS) $(DWARFLIBS)
 
 # for linking with debug library, run like:
-# make DEBUG=1 LIBBABELTRACE_DIR=/opt/libbabeltrace/
-ifdef LIBBABELTRACE_DIR
-  LIBBABELTRACE_CFLAGS  := -I$(LIBBABELTRACE_DIR)/include
-  LIBBABELTRACE_LDFLAGS := -L$(LIBBABELTRACE_DIR)/lib
+# make DEBUG=1 PKG_CONFIG_PATH=/opt/babeltrace2/(lib|lib64)/pkgconfig
+
+ifneq ($(NO_BABELTRACE2),1)
+  ifeq ($(call get-executable,$(PKG_CONFIG)),)
+    $(error Error: $(PKG_CONFIG) needed by babeltrace2 is missing on this system, please install it)
+  endif
 endif
-FEATURE_CHECK_CFLAGS-libbabeltrace := $(LIBBABELTRACE_CFLAGS)
-FEATURE_CHECK_LDFLAGS-libbabeltrace := $(LIBBABELTRACE_LDFLAGS) -lbabeltrace-ctf
 
 # for linking with debug library, run like:
 # make DEBUG=1 LIBCAPSTONE_DIR=/opt/capstone/
@@ -1058,15 +1058,15 @@ else
   NO_PERF_READ_VDSOX32 := 1
 endif
 
-ifndef NO_LIBBABELTRACE
-  $(call feature_check,libbabeltrace)
-  ifeq ($(feature-libbabeltrace), 1)
-    CFLAGS += -DHAVE_LIBBABELTRACE_SUPPORT $(LIBBABELTRACE_CFLAGS)
-    LDFLAGS += $(LIBBABELTRACE_LDFLAGS)
-    EXTLIBS += -lbabeltrace-ctf
-    $(call detected,CONFIG_LIBBABELTRACE)
+ifndef NO_BABELTRACE2
+  $(call feature_check,babeltrace2-ctf-writer)
+  ifeq ($(feature-babeltrace2-ctf-writer), 1)
+    CFLAGS += -DHAVE_BABELTRACE2_SUPPORT $(shell $(PKG_CONFIG) --cflags babeltrace2-ctf-writer)
+    LDFLAGS += $(shell $(PKG_CONFIG) --libs-only-L babeltrace2-ctf-writer)
+    EXTLIBS += $(shell $(PKG_CONFIG) --libs-only-l babeltrace2-ctf-writer)
+    $(call detected,CONFIG_BABELTRACE2)
   else
-    $(warning No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev)
+    $(warning No babeltrace2 found, disables 'perf data' CTF format support, please install libbabeltrace2-dev[el])
   endif
 endif
 
tools/perf/Makefile.perf +1 -1
index f7b936deeaa2..1f4e84a8472e 100644
@@ -79,7 +79,7 @@ include ../scripts/utilities.mak
 #
 # Define NO_ZLIB if you do not want to support compressed kernel modules
 #
-# Define NO_LIBBABELTRACE if you do not want libbabeltrace support
+# Define NO_BABELTRACE2 if you do not want babeltrace2-ctf-writer support
 # for CTF data format.
 #
 # Define NO_CAPSTONE if you do not want libcapstone support
tools/perf/builtin-check.c +1 -1
index 3641d263b345..e9d14a960a03 100644
@@ -43,7 +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("babeltrace2-ctf-writer", HAVE_BABELTRACE2_SUPPORT),
 	FEATURE_STATUS("libbpf-strings", HAVE_LIBBPF_STRINGS_SUPPORT),
 	FEATURE_STATUS("libcapstone", HAVE_LIBCAPSTONE_SUPPORT),
 	FEATURE_STATUS("libdw-dwarf-unwind", HAVE_LIBDW_SUPPORT),
tools/perf/builtin-data.c +4 -14
index 85f59886b5cf..260d74476439 100644
@@ -40,10 +40,8 @@ const struct option data_options[] = {
 		OPT_INCR('v', "verbose", &verbose, "be more verbose"),
 		OPT_STRING('i', "input", &input_name, "file", "input file name"),
 		OPT_STRING(0, "to-json", &to_json, NULL, "Convert to JSON format"),
-#ifdef HAVE_LIBBABELTRACE_SUPPORT
 		OPT_STRING(0, "to-ctf", &to_ctf, NULL, "Convert to CTF format"),
 		OPT_BOOLEAN(0, "tod", &opts.tod, "Convert time to wall clock time"),
-#endif
 		OPT_BOOLEAN('f', "force", &opts.force, "don't complain, do it"),
 		OPT_BOOLEAN(0, "all", &opts.all, "Convert all events"),
 		OPT_STRING(0, "time", &opts.time_str, "str",
@@ -65,29 +63,21 @@ 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_LIBBABELTRACE_SUPPORT
 	if (!to_json && !to_ctf) {
 		pr_err("You must specify one of --to-ctf or --to-json.\n");
 		return -1;
 	}
-#else
-	if (!to_json) {
-		pr_err("You must specify --to-json.\n");
-	return -1;
-}
-#endif
 
 	if (to_json)
 		return bt_convert__perf2json(input_name, to_json, &opts);
 
 	if (to_ctf) {
-#if defined(HAVE_LIBBABELTRACE_SUPPORT) && defined(HAVE_LIBTRACEEVENT)
+#if defined(HAVE_BABELTRACE2_SUPPORT) && defined(HAVE_LIBTRACEEVENT)
 		return bt_convert__perf2ctf(input_name, to_ctf, &opts);
 #else
-		pr_err("The libbabeltrace support is not compiled in. perf should be "
-		       "compiled with environment variables LIBBABELTRACE=1 and "
-		       "LIBBABELTRACE_DIR=/path/to/libbabeltrace/.\n"
-		       "Check also if libbtraceevent devel files are available.\n");
+		pr_err("The babeltrace2 support is not compiled in. Ensure you have both\n"
+			"libbabeltrace2-dev[el] and libtraceevent-dev[el] installed or set\n"
+			"PKG_CONFIG_PATH to find a local installation of those libraries.\n");
 		return -1;
 #endif
 	}
tools/perf/tests/make +2 -2
index 6587dc326d1b..04f9b686cec0 100644
@@ -93,7 +93,7 @@ make_no_libbpf	    := NO_LIBBPF=1
 make_libbpf_dynamic := LIBBPF_DYNAMIC=1
 make_no_libbpf_DEBUG := NO_LIBBPF=1 DEBUG=1
 make_no_libllvm     := NO_LIBLLVM=1
-make_with_babeltrace:= LIBBABELTRACE=1
+make_with_babeltrace2 := BABELTRACE2=1
 make_with_coresight := CORESIGHT=1
 make_no_sdt	    := NO_SDT=1
 make_no_libpfm4     := NO_LIBPFM4=1
@@ -170,7 +170,7 @@ run += make_no_libbpf_DEBUG
 run += make_no_libllvm
 run += make_no_sdt
 run += make_no_syscall_tbl
-run += make_with_babeltrace
+run += make_with_babeltrace2
 run += make_with_coresight
 run += make_with_clangllvm
 run += make_no_libpfm4
tools/perf/tests/shell/test_perf_data_converter_ctf.sh +4 -4
index 334eebc9945e..65d49a10c028 100755
@@ -24,11 +24,11 @@ trap_cleanup()
 }
 trap trap_cleanup exit term int
 
-check_babeltrace_support()
+check_babeltrace2_support()
 {
-	if ! perf check feature libbabeltrace
+	if ! perf check feature babeltrace2-ctf-writer
 	then
-		echo "perf not linked with libbabeltrace, skipping test"
+		echo "perf not linked with libbabeltrace2-ctf-writer, skipping test"
 		exit 2
 	fi
 }
@@ -97,7 +97,7 @@ test_ctf_converter_pipe()
 	fi
 }
 
-check_babeltrace_support
+check_babeltrace2_support
 test_ctf_converter_file
 test_ctf_converter_pipe
 
tools/perf/util/Build +1 -1
index bcccad7487a9..7f3b67c8eeab 100644
@@ -233,7 +233,7 @@ perf-util-$(CONFIG_LIBUNWIND_X86)      += libunwind/x86_32.o
 perf-util-$(CONFIG_LIBUNWIND_AARCH64)  += libunwind/arm64.o
 
 ifeq ($(CONFIG_LIBTRACEEVENT),y)
-  perf-util-$(CONFIG_LIBBABELTRACE) += data-convert-bt.o
+  perf-util-$(CONFIG_BABELTRACE2) += data-convert-bt.o
 endif
 
 perf-util-y += data-convert-json.o
tools/perf/util/data-convert-bt.c +16 -17
index ba1c8e48d495..91d8cdc9e8c7 100644
@@ -11,14 +11,13 @@
 #include <linux/compiler.h>
 #include <linux/kernel.h>
 #include <linux/zalloc.h>
-#include <babeltrace/ctf-writer/writer.h>
-#include <babeltrace/ctf-writer/clock.h>
-#include <babeltrace/ctf-writer/stream.h>
-#include <babeltrace/ctf-writer/event.h>
-#include <babeltrace/ctf-writer/event-types.h>
-#include <babeltrace/ctf-writer/event-fields.h>
-#include <babeltrace/ctf-ir/utils.h>
-#include <babeltrace/ctf/events.h>
+#include <babeltrace2-ctf-writer/writer.h>
+#include <babeltrace2-ctf-writer/clock.h>
+#include <babeltrace2-ctf-writer/stream.h>
+#include <babeltrace2-ctf-writer/event.h>
+#include <babeltrace2-ctf-writer/event-types.h>
+#include <babeltrace2-ctf-writer/event-fields.h>
+#include <babeltrace2-ctf-writer/utils.h>
 #include "asm/bug.h"
 #include "data-convert.h"
 #include "session.h"
@@ -121,13 +120,13 @@ static int value_set(struct bt_ctf_field_type *type,
 	}
 
 	if (sign) {
-		ret = bt_ctf_field_signed_integer_set_value(field, val);
+		ret = bt_ctf_field_integer_signed_set_value(field, val);
 		if (ret) {
 			pr_err("failed to set field value %s\n", name);
 			goto err;
 		}
 	} else {
-		ret = bt_ctf_field_unsigned_integer_set_value(field, val);
+		ret = bt_ctf_field_integer_unsigned_set_value(field, val);
 		if (ret) {
 			pr_err("failed to set field value %s\n", name);
 			goto err;
@@ -374,10 +373,10 @@ static int add_tracepoint_field_value(struct ctf_writer *cw,
 					data + offset + i * len, len);
 
 			if (!(flags & TEP_FIELD_IS_SIGNED))
-				ret = bt_ctf_field_unsigned_integer_set_value(
+				ret = bt_ctf_field_integer_unsigned_set_value(
 						field, value_int);
 			else
-				ret = bt_ctf_field_signed_integer_set_value(
+				ret = bt_ctf_field_integer_signed_set_value(
 						field, adjust_signedness(value_int, len));
 		}
 
@@ -471,7 +470,7 @@ add_bpf_output_values(struct bt_ctf_event_class *event_class,
 		goto put_len_type;
 	}
 
-	ret = bt_ctf_field_unsigned_integer_set_value(len_field, nr_elements);
+	ret = bt_ctf_field_integer_unsigned_set_value(len_field, nr_elements);
 	if (ret) {
 		pr_err("failed to set field value for raw_len\n");
 		goto put_len_field;
@@ -500,7 +499,7 @@ add_bpf_output_values(struct bt_ctf_event_class *event_class,
 		struct bt_ctf_field *elem_field =
 			bt_ctf_field_sequence_get_field(seq_field, i);
 
-		ret = bt_ctf_field_unsigned_integer_set_value(elem_field,
+		ret = bt_ctf_field_integer_unsigned_set_value(elem_field,
 				((u32 *)(sample->raw_data))[i]);
 
 		bt_ctf_field_put(elem_field);
@@ -545,7 +544,7 @@ add_callchain_output_values(struct bt_ctf_event_class *event_class,
 		goto put_len_type;
 	}
 
-	ret = bt_ctf_field_unsigned_integer_set_value(len_field, nr_elements);
+	ret = bt_ctf_field_integer_unsigned_set_value(len_field, nr_elements);
 	if (ret) {
 		pr_err("failed to set field value for perf_callchain_size\n");
 		goto put_len_field;
@@ -575,7 +574,7 @@ add_callchain_output_values(struct bt_ctf_event_class *event_class,
 		struct bt_ctf_field *elem_field =
 			bt_ctf_field_sequence_get_field(seq_field, i);
 
-		ret = bt_ctf_field_unsigned_integer_set_value(elem_field,
+		ret = bt_ctf_field_integer_unsigned_set_value(elem_field,
 				((u64 *)(callchain->ips))[i]);
 
 		bt_ctf_field_put(elem_field);
@@ -728,7 +727,7 @@ static struct ctf_stream *ctf_stream__create(struct ctf_writer *cw, int cpu)
 		goto out;
 	}
 
-	ret = bt_ctf_field_unsigned_integer_set_value(cpu_field, (u32) cpu);
+	ret = bt_ctf_field_integer_unsigned_set_value(cpu_field, (u32) cpu);
 	if (ret) {
 		pr_err("Failed to update CPU number\n");
 		goto out;
tools/perf/util/data-convert.h +2 -2
index ee651fa680a1..d174e6f2729d 100644
@@ -11,10 +11,10 @@ struct perf_data_convert_opts {
 	const char *time_str;
 };
 
-#ifdef HAVE_LIBBABELTRACE_SUPPORT
+#ifdef HAVE_BABELTRACE2_SUPPORT
 int bt_convert__perf2ctf(const char *input_name, const char *to_ctf,
 			 struct perf_data_convert_opts *opts);
-#endif /* HAVE_LIBBABELTRACE_SUPPORT */
+#endif /* HAVE_BABELTRACE2_SUPPORT */
 
 int bt_convert__perf2json(const char *input_name, const char *to_ctf,
 			 struct perf_data_convert_opts *opts);
Signature · 1 line
2.47.3
reviewer
#1 lore raw
Quoted 113 lines · Michael Jeanson

The 1.x branch of Babeltrace has been superseded by 2.x in 2020 and has been unmaintained since 2022, efforts have started to remove it from popular distributions.

Babeltrace 2.x offers a very similar 'ctf-writer' library that can be used with minimal changes for the '--to-ctf' feature and has been packaged since Debian 11 and Fedora 32.

This patch replaces the 'libbabeltrace' build feature with 'babeltrace2-ctf-writer' using pkgconfig detection, adjusts the naming of the public headers and applies minor API cleanups.

No changes to the output ctf traces, this API still implements version 1.8 of the CTF specification that can be read by either Babeltrace 1 / 2 or any CTF compliant reader.

Also remove some ifdefs in the cli option parsing to allow printing the helpful error message with '--to-ctf' when built without babeltrace2.

Cc Adrian Hunter <[email protected]>
Cc Alexander Shishkin <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Derek Foreman <[email protected]>
Cc Ian Rogers <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc James Clark <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Mathieu Desnoyers <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Peter Zijlstra <[email protected]>
---
 tools/build/Makefile.feature                  |  5 +--
 tools/build/feature/Makefile                  |  6 ++--
 tools/build/feature/test-all.c                | 13 ++------
 ...ltrace.c => test-babeltrace2-ctf-writer.c} |  3 +-
 tools/perf/Makefile.config                    | 28 ++++++++--------
 tools/perf/Makefile.perf                      |  2 +-
 tools/perf/builtin-check.c                    |  2 +-
 tools/perf/builtin-data.c                     | 18 +++-------
 tools/perf/tests/make                         |  4 +--
 .../shell/test_perf_data_converter_ctf.sh     |  8 ++---
 tools/perf/util/Build                         |  2 +-
 tools/perf/util/data-convert-bt.c             | 33 +++++++++----------
 tools/perf/util/data-convert.h                |  4 +--
 13 files changed, 55 insertions(+), 73 deletions(-)
 rename tools/build/feature/{test-libbabeltrace.c => test-babeltrace2-ctf-writer.c} (59%)
tools/build/Makefile.feature +3 -2
index 0b7a7c38cb88..9e097144817e 100644
@@ -113,7 +113,7 @@ FEATURE_TESTS_EXTRA :=                  \
          gtk2                           \
          gtk2-infobar                   \
          hello                          \
-         libbabeltrace                  \
+         babeltrace2-ctf-writer         \
          libcapstone                    \
          libbfd-liberty                 \
          libbfd-liberty-z               \
@@ -162,6 +162,7 @@ FEATURE_GROUP_MEMBERS-libbfd = libbfd-liberty libbfd-liberty-z
 # Declare list of feature dependency packages that provide pkg-config files.
 #
 FEATURE_PKG_CONFIG ?=           \
+        babeltrace2-ctf-writer \
          libtraceevent          \
          libtracefs
 
@@ -208,7 +209,7 @@ ifeq ($(feature-all), 1)
   $(call feature_check,compile-32)
   $(call feature_check,compile-x32)
   $(call feature_check,bionic)
-  $(call feature_check,libbabeltrace)
+  $(call feature_check,babeltrace2-ctf-writer)
 else
   $(foreach feat,$(FEATURE_TESTS),$(call feature_check,$(feat)))
 endif
tools/build/feature/Makefile +3 -3
index 1fbcb3ce74d2..7735e257c263 100644
@@ -48,7 +48,7 @@ FILES=                                          \
          test-pthread-barrier.bin              \
          test-stackprotector-all.bin            \
          test-timerfd.bin                       \
-         test-libbabeltrace.bin                 \
+         test-babeltrace2-ctf-writer.bin        \
          test-libcapstone.bin                  \
          test-compile-32.bin                    \
          test-compile-x32.bin                   \
@@ -301,8 +301,8 @@ $(OUTPUT)test-backtrace.bin:
 $(OUTPUT)test-timerfd.bin:
        $(BUILD)
 
-$(OUTPUT)test-libbabeltrace.bin:
-       $(BUILD) # -lbabeltrace provided by $(FEATURE_CHECK_LDFLAGS-libbabeltrace)
+$(OUTPUT)test-babeltrace2-ctf-writer.bin:
+       $(BUILD) # -lbabeltrace2-ctf-writer provided by $(FEATURE_CHECK_LDFLAGS-babeltrace2-ctf-writer)
 
 $(OUTPUT)test-libcapstone.bin:
        $(BUILD) # -lcapstone provided by $(FEATURE_CHECK_LDFLAGS-libcapstone)
tools/build/feature/test-all.c +0 -1
index 1488bf6e6078..145abdee049d 100644
@@ -98,17 +98,9 @@
 # include "test-sched_getcpu.c"
 #undef main
 
-# if 0

tools/build/feature/test-all.c line 102

Quoted 10 lines
tools/build/feature/test-all.c +2 -8
-/*
- * Disable libbabeltrace check for test-all, because the requested
- * library version is not released yet in most distributions. Will
- * reenable later.
- */
-
-#define main main_test_libbabeltrace
-# include "test-libbabeltrace.c"
+#define main main_test_babeltrace2_ctf_writer
+# include "test-babeltrace2-ctf-writer.c"

So I still think the comment about libbabeltrace is probably valid:
most distributions won't have it by default, so a separate test is likely better than testing with test-all. You also need to update FEATURE_TESTS_BASIFEATURE_TESTS_BASIC.

Quoted 34 lines
tools/build/feature/test-all.c +1 -1
 #undef main
-#endif
 
 #define main main_test_lzma
 # include "test-lzma.c"
@@ -178,6 +170,7 @@ int main(int argc, char *argv[])
        main_test_libzstd();
        main_test_libtraceevent();
        main_test_libopenssl();
+       main_test_babeltrace2_ctf_writer();
 
        return 0;
 }
tools/build/feature/test-babeltrace2-ctf-writer.c renamed from tools/build/feature/test-libbabeltrace.c +1 -2
similarity index 59%
rename from tools/build/feature/test-libbabeltrace.c
rename to tools/build/feature/test-babeltrace2-ctf-writer.c
index 10bb69d55694..9c89082e9f88 100644
@@ -1,7 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 
-#include <babeltrace/ctf-writer/writer.h>
-#include <babeltrace/ctf-ir/stream-class.h>
+#include <babeltrace2-ctf-writer/writer.h>
 
 int main(void)
 {
tools/perf/Makefile.config +0 -0
index 15fbba9f4ca8..f2f5051c94e3 100644

tools/perf/Makefile.config FEATURE_CHECK_CFLAGS-libdw := $(LIBDW_CFLAGS) · line 199

Quoted 8 lines
tools/perf/Makefile.config +1 -4
@@ -196,13 +196,13 @@ FEATURE_CHECK_CFLAGS-libdw := $(LIBDW_CFLAGS)
 FEATURE_CHECK_LDFLAGS-libdw := $(LIBDW_LDFLAGS) $(DWARFLIBS)
 
 # for linking with debug library, run like:
-# make DEBUG=1 LIBBABELTRACE_DIR=/opt/libbabeltrace/
-ifdef LIBBABELTRACE_DIR
-  LIBBABELTRACE_CFLAGS  := -I$(LIBBABELTRACE_DIR)/include
-  LIBBABELTRACE_LDFLAGS := -L$(LIBBABELTRACE_DIR)/lib
+# make DEBUG=1 PKG_CONFIG_PATH=/opt/babeltrace2/(lib|lib64)/pkgconfig

Delete?

Quoted 186 lines
tools/perf/Makefile.config +13 -10
+
+ifneq ($(NO_BABELTRACE2),1)
+  ifeq ($(call get-executable,$(PKG_CONFIG)),)
+    $(error Error: $(PKG_CONFIG) needed by babeltrace2 is missing on this system, please install it)
+  endif
 endif
-FEATURE_CHECK_CFLAGS-libbabeltrace := $(LIBBABELTRACE_CFLAGS)
-FEATURE_CHECK_LDFLAGS-libbabeltrace := $(LIBBABELTRACE_LDFLAGS) -lbabeltrace-ctf
 
 # for linking with debug library, run like:
 # make DEBUG=1 LIBCAPSTONE_DIR=/opt/capstone/
@@ -1058,15 +1058,15 @@ else
   NO_PERF_READ_VDSOX32 := 1
 endif
 
-ifndef NO_LIBBABELTRACE
-  $(call feature_check,libbabeltrace)
-  ifeq ($(feature-libbabeltrace), 1)
-    CFLAGS += -DHAVE_LIBBABELTRACE_SUPPORT $(LIBBABELTRACE_CFLAGS)
-    LDFLAGS += $(LIBBABELTRACE_LDFLAGS)
-    EXTLIBS += -lbabeltrace-ctf
-    $(call detected,CONFIG_LIBBABELTRACE)
+ifndef NO_BABELTRACE2
+  $(call feature_check,babeltrace2-ctf-writer)
+  ifeq ($(feature-babeltrace2-ctf-writer), 1)
+    CFLAGS += -DHAVE_BABELTRACE2_SUPPORT $(shell $(PKG_CONFIG) --cflags babeltrace2-ctf-writer)
+    LDFLAGS += $(shell $(PKG_CONFIG) --libs-only-L babeltrace2-ctf-writer)
+    EXTLIBS += $(shell $(PKG_CONFIG) --libs-only-l babeltrace2-ctf-writer)
+    $(call detected,CONFIG_BABELTRACE2)
   else
-    $(warning No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev)
+    $(warning No babeltrace2 found, disables 'perf data' CTF format support, please install libbabeltrace2-dev[el])
   endif
 endif
 
tools/perf/Makefile.perf +1 -1
index f7b936deeaa2..1f4e84a8472e 100644
@@ -79,7 +79,7 @@ include ../scripts/utilities.mak
 #
 # Define NO_ZLIB if you do not want to support compressed kernel modules
 #
-# Define NO_LIBBABELTRACE if you do not want libbabeltrace support
+# Define NO_BABELTRACE2 if you do not want babeltrace2-ctf-writer support
 # for CTF data format.
 #
 # Define NO_CAPSTONE if you do not want libcapstone support
tools/perf/builtin-check.c +1 -1
index 3641d263b345..e9d14a960a03 100644
@@ -43,7 +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("babeltrace2-ctf-writer", HAVE_BABELTRACE2_SUPPORT),
        FEATURE_STATUS("libbpf-strings", HAVE_LIBBPF_STRINGS_SUPPORT),
        FEATURE_STATUS("libcapstone", HAVE_LIBCAPSTONE_SUPPORT),
        FEATURE_STATUS("libdw-dwarf-unwind", HAVE_LIBDW_SUPPORT),
tools/perf/builtin-data.c +4 -14
index 85f59886b5cf..260d74476439 100644
@@ -40,10 +40,8 @@ const struct option data_options[] = {
                OPT_INCR('v', "verbose", &verbose, "be more verbose"),
                OPT_STRING('i', "input", &input_name, "file", "input file name"),
                OPT_STRING(0, "to-json", &to_json, NULL, "Convert to JSON format"),
-#ifdef HAVE_LIBBABELTRACE_SUPPORT
                OPT_STRING(0, "to-ctf", &to_ctf, NULL, "Convert to CTF format"),
                OPT_BOOLEAN(0, "tod", &opts.tod, "Convert time to wall clock time"),
-#endif
                OPT_BOOLEAN('f', "force", &opts.force, "don't complain, do it"),
                OPT_BOOLEAN(0, "all", &opts.all, "Convert all events"),
                OPT_STRING(0, "time", &opts.time_str, "str",
@@ -65,29 +63,21 @@ 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_LIBBABELTRACE_SUPPORT
        if (!to_json && !to_ctf) {
                pr_err("You must specify one of --to-ctf or --to-json.\n");
                return -1;
        }
-#else
-       if (!to_json) {
-               pr_err("You must specify --to-json.\n");
-       return -1;
-}
-#endif
 
        if (to_json)
                return bt_convert__perf2json(input_name, to_json, &opts);
 
        if (to_ctf) {
-#if defined(HAVE_LIBBABELTRACE_SUPPORT) && defined(HAVE_LIBTRACEEVENT)
+#if defined(HAVE_BABELTRACE2_SUPPORT) && defined(HAVE_LIBTRACEEVENT)
                return bt_convert__perf2ctf(input_name, to_ctf, &opts);
 #else
-               pr_err("The libbabeltrace support is not compiled in. perf should be "
-                      "compiled with environment variables LIBBABELTRACE=1 and "
-                      "LIBBABELTRACE_DIR=/path/to/libbabeltrace/.\n"
-                      "Check also if libbtraceevent devel files are available.\n");
+               pr_err("The babeltrace2 support is not compiled in. Ensure you have both\n"
+                       "libbabeltrace2-dev[el] and libtraceevent-dev[el] installed or set\n"
+                       "PKG_CONFIG_PATH to find a local installation of those libraries.\n");
                return -1;
 #endif
        }
tools/perf/tests/make +2 -2
index 6587dc326d1b..04f9b686cec0 100644
@@ -93,7 +93,7 @@ make_no_libbpf            := NO_LIBBPF=1
 make_libbpf_dynamic := LIBBPF_DYNAMIC=1
 make_no_libbpf_DEBUG := NO_LIBBPF=1 DEBUG=1
 make_no_libllvm     := NO_LIBLLVM=1
-make_with_babeltrace:= LIBBABELTRACE=1
+make_with_babeltrace2 := BABELTRACE2=1
 make_with_coresight := CORESIGHT=1
 make_no_sdt        := NO_SDT=1
 make_no_libpfm4     := NO_LIBPFM4=1
@@ -170,7 +170,7 @@ run += make_no_libbpf_DEBUG
 run += make_no_libllvm
 run += make_no_sdt
 run += make_no_syscall_tbl
-run += make_with_babeltrace
+run += make_with_babeltrace2
 run += make_with_coresight
 run += make_with_clangllvm
 run += make_no_libpfm4
tools/perf/tests/shell/test_perf_data_converter_ctf.sh +4 -4
index 334eebc9945e..65d49a10c028 100755
@@ -24,11 +24,11 @@ trap_cleanup()
 }
 trap trap_cleanup exit term int
 
-check_babeltrace_support()
+check_babeltrace2_support()
 {
-       if ! perf check feature libbabeltrace
+       if ! perf check feature babeltrace2-ctf-writer
        then
-               echo "perf not linked with libbabeltrace, skipping test"
+               echo "perf not linked with libbabeltrace2-ctf-writer, skipping test"
                exit 2
        fi
 }
@@ -97,7 +97,7 @@ test_ctf_converter_pipe()
        fi
 }
 
-check_babeltrace_support
+check_babeltrace2_support
 test_ctf_converter_file
 test_ctf_converter_pipe
 
tools/perf/util/Build +1 -1
index bcccad7487a9..7f3b67c8eeab 100644
@@ -233,7 +233,7 @@ perf-util-$(CONFIG_LIBUNWIND_X86)      += libunwind/x86_32.o
 perf-util-$(CONFIG_LIBUNWIND_AARCH64)  += libunwind/arm64.o
 
 ifeq ($(CONFIG_LIBTRACEEVENT),y)
-  perf-util-$(CONFIG_LIBBABELTRACE) += data-convert-bt.o
+  perf-util-$(CONFIG_BABELTRACE2) += data-convert-bt.o
 endif
 
 perf-util-y += data-convert-json.o
tools/perf/util/data-convert-bt.c +0 -5
index ba1c8e48d495..91d8cdc9e8c7 100644
@@ -11,14 +11,13 @@
 #include <linux/compiler.h>
 #include <linux/kernel.h>
 #include <linux/zalloc.h>
-#include <babeltrace/ctf-writer/writer.h>
-#include <babeltrace/ctf-writer/clock.h>
-#include <babeltrace/ctf-writer/stream.h>
-#include <babeltrace/ctf-writer/event.h>
-#include <babeltrace/ctf-writer/event-types.h>

tools/perf/util/data-convert-bt.c line 20

Quoted 10 lines
tools/perf/util/data-convert-bt.c +7 -3
-#include <babeltrace/ctf-writer/event-fields.h>
-#include <babeltrace/ctf-ir/utils.h>
-#include <babeltrace/ctf/events.h>
+#include <babeltrace2-ctf-writer/writer.h>
+#include <babeltrace2-ctf-writer/clock.h>
+#include <babeltrace2-ctf-writer/stream.h>
+#include <babeltrace2-ctf-writer/event.h>
+#include <babeltrace2-ctf-writer/event-types.h>
+#include <babeltrace2-ctf-writer/event-fields.h>
+#include <babeltrace2-ctf-writer/utils.h>

This is cool, I'm surprised at how non-invasive the change is. I'd done a similar thing but keeping both babeltrace 1 and 2. I'll post my WIP in reply just as a heads up, but I have to do much more heavy engineering.

Thanks,
Ian

Quoted 97 lines
tools/perf/util/data-convert-bt.c +9 -9
 #include "asm/bug.h"
 #include "data-convert.h"
 #include "session.h"
@@ -121,13 +120,13 @@ static int value_set(struct bt_ctf_field_type *type,
        }
 
        if (sign) {
-               ret = bt_ctf_field_signed_integer_set_value(field, val);
+               ret = bt_ctf_field_integer_signed_set_value(field, val);
                if (ret) {
                        pr_err("failed to set field value %s\n", name);
                        goto err;
                }
        } else {
-               ret = bt_ctf_field_unsigned_integer_set_value(field, val);
+               ret = bt_ctf_field_integer_unsigned_set_value(field, val);
                if (ret) {
                        pr_err("failed to set field value %s\n", name);
                        goto err;
@@ -374,10 +373,10 @@ static int add_tracepoint_field_value(struct ctf_writer *cw,
                                        data + offset + i * len, len);
 
                        if (!(flags & TEP_FIELD_IS_SIGNED))
-                               ret = bt_ctf_field_unsigned_integer_set_value(
+                               ret = bt_ctf_field_integer_unsigned_set_value(
                                                field, value_int);
                        else
-                               ret = bt_ctf_field_signed_integer_set_value(
+                               ret = bt_ctf_field_integer_signed_set_value(
                                                field, adjust_signedness(value_int, len));
                }
 
@@ -471,7 +470,7 @@ add_bpf_output_values(struct bt_ctf_event_class *event_class,
                goto put_len_type;
        }
 
-       ret = bt_ctf_field_unsigned_integer_set_value(len_field, nr_elements);
+       ret = bt_ctf_field_integer_unsigned_set_value(len_field, nr_elements);
        if (ret) {
                pr_err("failed to set field value for raw_len\n");
                goto put_len_field;
@@ -500,7 +499,7 @@ add_bpf_output_values(struct bt_ctf_event_class *event_class,
                struct bt_ctf_field *elem_field =
                        bt_ctf_field_sequence_get_field(seq_field, i);
 
-               ret = bt_ctf_field_unsigned_integer_set_value(elem_field,
+               ret = bt_ctf_field_integer_unsigned_set_value(elem_field,
                                ((u32 *)(sample->raw_data))[i]);
 
                bt_ctf_field_put(elem_field);
@@ -545,7 +544,7 @@ add_callchain_output_values(struct bt_ctf_event_class *event_class,
                goto put_len_type;
        }
 
-       ret = bt_ctf_field_unsigned_integer_set_value(len_field, nr_elements);
+       ret = bt_ctf_field_integer_unsigned_set_value(len_field, nr_elements);
        if (ret) {
                pr_err("failed to set field value for perf_callchain_size\n");
                goto put_len_field;
@@ -575,7 +574,7 @@ add_callchain_output_values(struct bt_ctf_event_class *event_class,
                struct bt_ctf_field *elem_field =
                        bt_ctf_field_sequence_get_field(seq_field, i);
 
-               ret = bt_ctf_field_unsigned_integer_set_value(elem_field,
+               ret = bt_ctf_field_integer_unsigned_set_value(elem_field,
                                ((u64 *)(callchain->ips))[i]);
 
                bt_ctf_field_put(elem_field);
@@ -728,7 +727,7 @@ static struct ctf_stream *ctf_stream__create(struct ctf_writer *cw, int cpu)
                goto out;
        }
 
-       ret = bt_ctf_field_unsigned_integer_set_value(cpu_field, (u32) cpu);
+       ret = bt_ctf_field_integer_unsigned_set_value(cpu_field, (u32) cpu);
        if (ret) {
                pr_err("Failed to update CPU number\n");
                goto out;
tools/perf/util/data-convert.h +2 -3
index ee651fa680a1..d174e6f2729d 100644
@@ -11,10 +11,10 @@ struct perf_data_convert_opts {
        const char *time_str;
 };
 
-#ifdef HAVE_LIBBABELTRACE_SUPPORT
+#ifdef HAVE_BABELTRACE2_SUPPORT
 int bt_convert__perf2ctf(const char *input_name, const char *to_ctf,
                         struct perf_data_convert_opts *opts);
-#endif /* HAVE_LIBBABELTRACE_SUPPORT */
+#endif /* HAVE_BABELTRACE2_SUPPORT */
 
 int bt_convert__perf2json(const char *input_name, const char *to_ctf,
                         struct perf_data_convert_opts *opts);
--

2.47.3

reviewer
#2 lore raw

PATCH 1/2 tools build: Add libbabeltrace2 feature test

libbabeltrace2 is a rewrite libbabeltrace from 2020, add support for detecting it so that perf builds may prefer using it to libbabeltrace which dates from 2010.

---
 tools/build/Makefile.feature              | 1 +
 tools/build/feature/Makefile              | 4 ++++
 tools/build/feature/test-libbabeltrace2.c | 9 +++++++++
 3 files changed, 14 insertions(+)
 create mode 100644 tools/build/feature/test-libbabeltrace2.c
tools/build/Makefile.feature +1 -0
index 2f192d3bf61b..5425430582d2 100644
@@ -114,6 +114,7 @@ FEATURE_TESTS_EXTRA :=                  \
          gtk2-infobar                   \
          hello                          \
          libbabeltrace                  \
+         libbabeltrace2                 \
          libcapstone                    \
          libcheck                       \
          libbfd-liberty                 \
tools/build/feature/Makefile +4 -0
index 704c687ed3ad..9cf00d3fbefb 100644
@@ -49,6 +49,7 @@ FILES=                                          \
          test-stackprotector-all.bin            \
          test-timerfd.bin                       \
          test-libbabeltrace.bin                 \
+         test-libbabeltrace2.bin                \
          test-libcapstone.bin			\
          test-libcheck.bin			\
          test-compile-32.bin                    \
@@ -311,6 +312,9 @@ $(OUTPUT)test-timerfd.bin:
 $(OUTPUT)test-libbabeltrace.bin:
 	$(BUILD) # -lbabeltrace provided by $(FEATURE_CHECK_LDFLAGS-libbabeltrace)
 
+$(OUTPUT)test-libbabeltrace2.bin:
+	$(BUILD) # -lbabeltrace2 provided by $(FEATURE_CHECK_LDFLAGS-libbabeltrace2)
+
 $(OUTPUT)test-libcapstone.bin:
 	$(BUILD) # -lcapstone provided by $(FEATURE_CHECK_LDFLAGS-libcapstone)
 
tools/build/feature/test-libbabeltrace2.c new file +9 -0
new file mode 100644
index 000000000000..0c964994a34e
@@ -0,0 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <babeltrace2/babeltrace.h>
+
+int main(void)
+{
+	bt_graph_create(0);
+	return 0;
+}
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
reviewer
#3 lore raw

PATCH 2/2 perf data convert ctf: Initial babeltrace2 support

The libbabeltrace support is incomplete but as libbabeltrace is no longer developed it is hard to debug what is happening. Add some minimal libbabeltrace2 support that allows logging. When the support is comparable to the libbabeltrace 1 support it'd be worth dropping the libbabeltrace 1 support.

---
 tools/perf/Makefile.config        |   13 +-
 tools/perf/util/data-convert-bt.c | 1044 ++++++++++++++++++++++++-----
 tools/perf/util/data-convert.h    |    2 +-
 3 files changed, 878 insertions(+), 181 deletions(-)
tools/perf/Makefile.config +12 -1
index 06d7a3f9990c..af70f9436586 100644
@@ -203,6 +203,8 @@ ifdef LIBBABELTRACE_DIR
 endif
 FEATURE_CHECK_CFLAGS-libbabeltrace := $(LIBBABELTRACE_CFLAGS)
 FEATURE_CHECK_LDFLAGS-libbabeltrace := $(LIBBABELTRACE_LDFLAGS) -lbabeltrace-ctf
+FEATURE_CHECK_CFLAGS-libbabeltrace2 := $(LIBBABELTRACE_CFLAGS)
+FEATURE_CHECK_LDFLAGS-libbabeltrace2 := $(LIBBABELTRACE_LDFLAGS) -lbabeltrace2
 
 # for linking with debug library, run like:
 # make DEBUG=1 LIBCAPSTONE_DIR=/opt/capstone/
@@ -1067,7 +1069,16 @@ ifndef NO_LIBBABELTRACE
     EXTLIBS += -lbabeltrace-ctf
     $(call detected,CONFIG_LIBBABELTRACE)
   else
-    $(warning No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev)
+    $(call feature_check,libbabeltrace2)
+    ifeq ($(feature-libbabeltrace2), 1)
+      $(info Experimental libbabeltrace2 support enabled)
+      CFLAGS += -DHAVE_LIBBABELTRACE2_SUPPORT $(LIBBABELTRACE_CFLAGS)
+      LDFLAGS += $(LIBBABELTRACE_LDFLAGS)
+      EXTLIBS += -lbabeltrace2
+      $(call detected,CONFIG_LIBBABELTRACE)
+    else
+      $(warning No libbabeltrace found, disables 'perf data' CTF format support)
+    endif
   endif
 endif
 
tools/perf/util/data-convert-bt.c +865 -179

1,517 lines not on this page · raw message

tools/perf/util/data-convert.h +1 -1
index ee651fa680a1..75c835496cbd 100644
@@ -11,7 +11,7 @@ struct perf_data_convert_opts {
 	const char *time_str;
 };
 
-#ifdef HAVE_LIBBABELTRACE_SUPPORT
+#if defined(HAVE_LIBBABELTRACE_SUPPORT) || defined(HAVE_LIBBABELTRACE2_SUPPORT)
 int bt_convert__perf2ctf(const char *input_name, const char *to_ctf,
 			 struct perf_data_convert_opts *opts);
 #endif /* HAVE_LIBBABELTRACE_SUPPORT */
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
#4 lore raw

Re: [PATCH 2/2] perf data convert ctf: Initial babeltrace2 support

Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider: - [High] Dead code in `ctf_writer__init` masks initialization errors and causes a NULL pointer dereference.…

Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider:
- [High] Dead code in ctf_writer__init masks initialization errors and causes a NULL pointer dereference.
- [High] Broken CLEANUP macro in ctf_writer__cleanup_data leaks Babeltrace data types and causes double-frees.
- [High] Queue state corruption in queue_push silently drops all queued messages if flushing fails.
- [High] Infinite loop (hang) occurs in ctf_writer__flush_streams if the Babeltrace2 graph fails.
- [Medium] Missing feature test source file makes Babeltrace 2 support impossible to enable.
- [Medium] Unchecked allocation and memory leak of the message queue array c.queue.
- [Medium] Redundant double-cleanup in bt_convert__perf2ctf when Babeltrace 2 is disabled.
--

commit 2a217a42e8def55aac066b30e548c1ca1f15911c
Author: Ian Rogers <[email protected]>

perf data convert ctf: Initial babeltrace2 support

This commit adds experimental support for libbabeltrace2 to the perf data CTF conversion tool. It introduces a message iterator, graph, and component classes to replace the deprecated libbabeltrace 1 stream writer APIs.

Quoted 4 lines
tools/perf/Makefile.config +0 -0
index 333ddd0e4bd81..3e3c4f240ee8f 100644

[ ... ]

tools/perf/Makefile.config ifndef NO_LIBBABELTRACE · line 1072

Quoted 6 lines
tools/perf/Makefile.config +1 -1
@@ -1067,7 +1069,16 @@ ifndef NO_LIBBABELTRACE
     EXTLIBS += -lbabeltrace-ctf
     $(call detected,CONFIG_LIBBABELTRACE)
   else
-    $(warning No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev)
+    $(call feature_check,libbabeltrace2)

Is there a missing feature test source file for libbabeltrace2? The build system's feature_check relies on compiling a matching test file in tools/build/feature/test-libbabeltrace2.c. Because this test file is missing, the compilation test will permanently fail, preventing HAVE_LIBBABELTRACE2_SUPPORT from being enabled.

[ ... ]

Quoted 4 lines
tools/perf/util/data-convert-bt.c +0 -0
index 3b8f2df823a9b..b16544f8b9b9a 100644

[ ... ]

tools/perf/util/data-convert-bt.c struct convert { · line 190

Quoted 13 lines
tools/perf/util/data-convert-bt.c +13 -0
+static void queue_push(struct convert *c, bt_message *msg)
+{
+	unsigned int next_head = (c->queue_head + 1) & c->queue_mask;
+
+	while (next_head == c->queue_tail) {
+		/* Queue is full, drive the graph to consume */
+		if (ctf_writer__flush_queue(c) < 0)
+			break;
+		next_head = (c->queue_head + 1) & c->queue_mask;
+	}
+
+	c->queue[c->queue_head] = msg;
+	c->queue_head = next_head;

Does this code corrupt the queue state if flushing fails?
If ctf_writer__flush_queue() returns < 0, the loop breaks and assigns next_head to c->queue_head. Since next_head still equals c->queue_tail, the head and tail pointers become identical. This effectively marks the ring buffer as empty, silently dropping all queued messages.

[ ... ]

tools/perf/util/data-convert-bt.c static struct bt_ctf_field_type *create_int_type(int size, bool sign, bool hex) · line 2080

Quoted 12 lines

static void ctf_writer__cleanup_data(struct ctf_writer *cw) {

tools/perf/util/data-convert-bt.c +6 -4
-	unsigned int i;
-
-	for (i = 0; i < ARRAY_SIZE(cw->data.array); i++)
-		bt_ctf_field_type_put(cw->data.array[i]);
+#ifdef HAVE_LIBBABELTRACE2_SUPPORT
+#define CLEANUP(type)					\
+	if (cw->data.type) {				\
+		bt_field_class_put_ref(cw->data.s64);	\
+		cw->data.s64 = NULL;			\
+	}

Could this macro cause memory leaks and double-frees?
It hardcodes cw->data.s64 instead of operating on the provided type parameter. When expanded for subsequent types (e.g., u64, s32), it checks their presence but exclusively frees and nullifies s64, leaving the other field classes leaked and potentially double-freeing s64.

[ ... ]

Quoted 6 lines

static int ctf_writer__init(struct ctf_writer *cw, const char *path,

tools/perf/util/data-convert-bt.c +3 -1
-			    struct perf_session *session, bool tod)
+			    struct perf_session *session __maybe_unused,
+			    bool tod __maybe_unused, struct convert *c __maybe_unused)
 {
+#ifdef HAVE_LIBBABELTRACE2_SUPPORT

[ ... ]

Quoted 4 lines
tools/perf/util/data-convert-bt.c +4 -0
+	err = setup_streams(cw, session);
+err:
+	if (sink_comp_class)
+		bt_component_class_sink_put_ref(sink_comp_class);

tools/perf/util/data-convert-bt.c do { \ · line 2240

Quoted 10 lines
tools/perf/util/data-convert-bt.c +10 -0
+	if (src_comp_class)
+		bt_component_class_source_put_ref(src_comp_class);
+	if (iter_class)
+		bt_message_iterator_class_put_ref(iter_class);
+	return 0;
+
+	ctf_writer__cleanup(cw);
+	if (err)
+		pr_err("Failed to setup CTF writer.\n");
+	return err;

Does the unconditional return 0 here mask initialization errors? It leaves the actual error reporting and cleanup logic unreachable. If graph creation or component initialization fails, the function will falsely report success, which could lead to a NULL pointer dereference later when bt_graph_run_once() is called on the uninitialized graph.

[ ... ]

Quoted 3 lines
tools/perf/util/data-convert-bt.c +1 -1
-static int ctf_writer__flush_streams(struct ctf_writer *cw)
+static int ctf_writer__flush_streams(struct convert *c)
 {

[ ... ]

tools/perf/util/data-convert-bt.c static int ctf_writer__init(struct ctf_writer *cw, const char *path, · line 2355

Quoted 3 lines
tools/perf/util/data-convert-bt.c +3 -0
+#ifdef HAVE_LIBBABELTRACE2_SUPPORT
+	while (c->queue_head != c->queue_tail)
+		ctf_writer__flush_queue(c);

Could this result in an infinite loop?
If ctf_writer__flush_queue() encounters an error and returns -1, it does not advance the queue pointers. Since the return value is ignored, the loop will spin indefinitely without consuming any messages.

[ ... ]

Quoted 3 lines

int bt_convert__perf2ctf(const char *input, const char *path,
struct perf_data_convert_opts *opts)
{

[ ... ]

Quoted 4 lines
tools/perf/util/data-convert-bt.c +1 -3
-	struct convert c = {};
-	struct ctf_writer *cw = &c.writer;
-	int err;
+	struct convert c = {0};

tools/perf/util/data-convert-bt.c int bt_convert__perf2ctf(const char *input, const char *path, · line 2400

Quoted 10 lines
tools/perf/util/data-convert-bt.c +10 -0
+	int err = -1;
+
+	dump_trace = 1;
+	debug_data_convert = 3;
+	/* Setup queue */
+	c.queue_size = QUEUE_SIZE;
+#ifdef HAVE_LIBBABELTRACE2_SUPPORT
+	c.queue = zalloc(sizeof(bt_message *) * c.queue_size);
+	c.queue_mask = c.queue_size - 1;
+#endif

Is there a missing allocation check and free for c.queue?
The dynamically allocated c.queue is never checked for failure, which would cause a NULL pointer dereference in queue_push() under memory pressure. Additionally, there appears to be no corresponding free() in the cleanup path, leading to a memory leak.

[ ... ]

Quoted 10 lines
tools/perf/util/data-convert-bt.c +0 -8
 	cleanup_events(session);
 	perf_session__delete(session);
-	ctf_writer__cleanup(cw);
-
-	return err;
-
-free_writer:
-	ctf_writer__cleanup(cw);
-free_session:
-	if (c.ptime_range)

tools/perf/util/data-convert-bt.c int bt_convert__perf2ctf(const char *input, const char *path, · line 2519

Quoted 10 lines
tools/perf/util/data-convert-bt.c +4 -4
-		zfree(&c.ptime_range);
-
-	perf_session__delete(session);
-	pr_err("Error during conversion setup.\n");
+	ctf_writer__cleanup(&c.writer);
+#ifndef HAVE_LIBBABELTRACE2_SUPPORT
+	ctf_writer__cleanup(&c.writer);
+#endif
 	return err;
 }

Is the double-cleanup intentional when Babeltrace 2 is disabled? ctf_writer__cleanup() is called unconditionally, and then a second time inside the #ifndef block. While the first call zeroes the structure, feeding a zeroed state back into the cleanup function might be unsafe for older libbabeltrace1 APIs.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#5 lore raw
In reply to Ian Rogers
Quoted 113 lines · Ian Rogers
Quoted 112 lines · Michael Jeanson

The 1.x branch of Babeltrace has been superseded by 2.x in 2020 and has been unmaintained since 2022, efforts have started to remove it from popular distributions.

Babeltrace 2.x offers a very similar 'ctf-writer' library that can be used with minimal changes for the '--to-ctf' feature and has been packaged since Debian 11 and Fedora 32.

This patch replaces the 'libbabeltrace' build feature with 'babeltrace2-ctf-writer' using pkgconfig detection, adjusts the naming of the public headers and applies minor API cleanups.

No changes to the output ctf traces, this API still implements version 1.8 of the CTF specification that can be read by either Babeltrace 1 / 2 or any CTF compliant reader.

Also remove some ifdefs in the cli option parsing to allow printing the helpful error message with '--to-ctf' when built without babeltrace2.

Cc Adrian Hunter <[email protected]>
Cc Alexander Shishkin <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Derek Foreman <[email protected]>
Cc Ian Rogers <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc James Clark <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Mathieu Desnoyers <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Peter Zijlstra <[email protected]>
---
  tools/build/Makefile.feature                  |  5 +--
  tools/build/feature/Makefile                  |  6 ++--
  tools/build/feature/test-all.c                | 13 ++------
  ...ltrace.c => test-babeltrace2-ctf-writer.c} |  3 +-
  tools/perf/Makefile.config                    | 28 ++++++++--------
  tools/perf/Makefile.perf                      |  2 +-
  tools/perf/builtin-check.c                    |  2 +-
  tools/perf/builtin-data.c                     | 18 +++-------
  tools/perf/tests/make                         |  4 +--
  .../shell/test_perf_data_converter_ctf.sh     |  8 ++---
  tools/perf/util/Build                         |  2 +-
  tools/perf/util/data-convert-bt.c             | 33 +++++++++----------
  tools/perf/util/data-convert.h                |  4 +--
  13 files changed, 55 insertions(+), 73 deletions(-)

rename tools/build/feature/{test-libbabeltrace.c => test-babeltrace2-ctf-writer.c} (59%)

tools/build/Makefile.feature +3 -2
index 0b7a7c38cb88..9e097144817e 100644
@@ -113,7 +113,7 @@ FEATURE_TESTS_EXTRA :=                  \
           gtk2                           \
           gtk2-infobar                   \
           hello                          \
-         libbabeltrace                  \
+         babeltrace2-ctf-writer         \
           libcapstone                    \
           libbfd-liberty                 \
           libbfd-liberty-z               \
@@ -162,6 +162,7 @@ FEATURE_GROUP_MEMBERS-libbfd = libbfd-liberty libbfd-liberty-z
  # Declare list of feature dependency packages that provide pkg-config files.
  #
  FEATURE_PKG_CONFIG ?=           \
+        babeltrace2-ctf-writer \
           libtraceevent          \
           libtracefs
 
@@ -208,7 +209,7 @@ ifeq ($(feature-all), 1)
    $(call feature_check,compile-32)
    $(call feature_check,compile-x32)
    $(call feature_check,bionic)
-  $(call feature_check,libbabeltrace)
+  $(call feature_check,babeltrace2-ctf-writer)
  else
    $(foreach feat,$(FEATURE_TESTS),$(call feature_check,$(feat)))
  endif
tools/build/feature/Makefile +3 -3
index 1fbcb3ce74d2..7735e257c263 100644
@@ -48,7 +48,7 @@ FILES=                                          \
           test-pthread-barrier.bin              \
           test-stackprotector-all.bin            \
           test-timerfd.bin                       \
-         test-libbabeltrace.bin                 \
+         test-babeltrace2-ctf-writer.bin        \
           test-libcapstone.bin                  \
           test-compile-32.bin                    \
           test-compile-x32.bin                   \
@@ -301,8 +301,8 @@ $(OUTPUT)test-backtrace.bin:
  $(OUTPUT)test-timerfd.bin:
         $(BUILD)
 
-$(OUTPUT)test-libbabeltrace.bin:
-       $(BUILD) # -lbabeltrace provided by $(FEATURE_CHECK_LDFLAGS-libbabeltrace)
+$(OUTPUT)test-babeltrace2-ctf-writer.bin:
+       $(BUILD) # -lbabeltrace2-ctf-writer provided by $(FEATURE_CHECK_LDFLAGS-babeltrace2-ctf-writer)
 
  $(OUTPUT)test-libcapstone.bin:
         $(BUILD) # -lcapstone provided by $(FEATURE_CHECK_LDFLAGS-libcapstone)
tools/build/feature/test-all.c +0 -0
index 1488bf6e6078..145abdee049d 100644
@@ -98,17 +98,9 @@
  # include "test-sched_getcpu.c"
  #undef main
 
Quoted 16 lines

tools/build/feature/test-all.c line 102

Quoted 11 lines
tools/build/feature/test-all.c +2 -9
-# if 0
-/*
- * Disable libbabeltrace check for test-all, because the requested
- * library version is not released yet in most distributions. Will
- * reenable later.
- */
-
-#define main main_test_libbabeltrace
-# include "test-libbabeltrace.c"
+#define main main_test_babeltrace2_ctf_writer
+# include "test-babeltrace2-ctf-writer.c"

So I still think the comment about libbabeltrace is probably valid:
most distributions won't have it by default, so a separate test is likely better than testing with test-all. You also need to update FEATURE_TESTS_BASIFEATURE_TESTS_BASIC.

I went by the comment in 'Makefile.feature' that says features in FEATURE_TESTS_EXTRA should be included in 'test-all.c'. I'll remove it.

Quoted 37 lines
Quoted 37 lines
tools/build/feature/test-all.c +1 -1
  #undef main
-#endif
 
  #define main main_test_lzma
  # include "test-lzma.c"
@@ -178,6 +170,7 @@ int main(int argc, char *argv[])
         main_test_libzstd();
         main_test_libtraceevent();
         main_test_libopenssl();
+       main_test_babeltrace2_ctf_writer();
 
         return 0;
  }
tools/build/feature/test-babeltrace2-ctf-writer.c renamed from tools/build/feature/test-libbabeltrace.c +1 -2
similarity index 59%
rename from tools/build/feature/test-libbabeltrace.c
rename to tools/build/feature/test-babeltrace2-ctf-writer.c
index 10bb69d55694..9c89082e9f88 100644
@@ -1,7 +1,6 @@
  // SPDX-License-Identifier: GPL-2.0
 
-#include <babeltrace/ctf-writer/writer.h>
-#include <babeltrace/ctf-ir/stream-class.h>
+#include <babeltrace2-ctf-writer/writer.h>
 
  int main(void)
  {
tools/perf/Makefile.config +0 -0
index 15fbba9f4ca8..f2f5051c94e3 100644
@@ -196,13 +196,13 @@ FEATURE_CHECK_CFLAGS-libdw := $(LIBDW_CFLAGS)
  FEATURE_CHECK_LDFLAGS-libdw := $(LIBDW_LDFLAGS) $(DWARFLIBS)
 
Quoted 8 lines

tools/perf/Makefile.config FEATURE_CHECK_CFLAGS-libdw := $(LIBDW_CFLAGS) · line 199

Quoted 6 lines
tools/perf/Makefile.config +1 -4
  # for linking with debug library, run like:
-# make DEBUG=1 LIBBABELTRACE_DIR=/opt/libbabeltrace/
-ifdef LIBBABELTRACE_DIR
-  LIBBABELTRACE_CFLAGS  := -I$(LIBBABELTRACE_DIR)/include
-  LIBBABELTRACE_LDFLAGS := -L$(LIBBABELTRACE_DIR)/lib
+# make DEBUG=1 PKG_CONFIG_PATH=/opt/babeltrace2/(lib|lib64)/pkgconfig

Delete?

Sure.

Quoted 194 lines
Quoted 194 lines
tools/perf/Makefile.config +13 -10
+
+ifneq ($(NO_BABELTRACE2),1)
+  ifeq ($(call get-executable,$(PKG_CONFIG)),)
+    $(error Error: $(PKG_CONFIG) needed by babeltrace2 is missing on this system, please install it)
+  endif
  endif
-FEATURE_CHECK_CFLAGS-libbabeltrace := $(LIBBABELTRACE_CFLAGS)
-FEATURE_CHECK_LDFLAGS-libbabeltrace := $(LIBBABELTRACE_LDFLAGS) -lbabeltrace-ctf
 
  # for linking with debug library, run like:
  # make DEBUG=1 LIBCAPSTONE_DIR=/opt/capstone/
@@ -1058,15 +1058,15 @@ else
    NO_PERF_READ_VDSOX32 := 1
  endif
 
-ifndef NO_LIBBABELTRACE
-  $(call feature_check,libbabeltrace)
-  ifeq ($(feature-libbabeltrace), 1)
-    CFLAGS += -DHAVE_LIBBABELTRACE_SUPPORT $(LIBBABELTRACE_CFLAGS)
-    LDFLAGS += $(LIBBABELTRACE_LDFLAGS)
-    EXTLIBS += -lbabeltrace-ctf
-    $(call detected,CONFIG_LIBBABELTRACE)
+ifndef NO_BABELTRACE2
+  $(call feature_check,babeltrace2-ctf-writer)
+  ifeq ($(feature-babeltrace2-ctf-writer), 1)
+    CFLAGS += -DHAVE_BABELTRACE2_SUPPORT $(shell $(PKG_CONFIG) --cflags babeltrace2-ctf-writer)
+    LDFLAGS += $(shell $(PKG_CONFIG) --libs-only-L babeltrace2-ctf-writer)
+    EXTLIBS += $(shell $(PKG_CONFIG) --libs-only-l babeltrace2-ctf-writer)
+    $(call detected,CONFIG_BABELTRACE2)
    else
-    $(warning No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev)
+    $(warning No babeltrace2 found, disables 'perf data' CTF format support, please install libbabeltrace2-dev[el])
    endif
  endif
 
tools/perf/Makefile.perf +1 -1
index f7b936deeaa2..1f4e84a8472e 100644
@@ -79,7 +79,7 @@ include ../scripts/utilities.mak
  #
  # Define NO_ZLIB if you do not want to support compressed kernel modules
  #
-# Define NO_LIBBABELTRACE if you do not want libbabeltrace support
+# Define NO_BABELTRACE2 if you do not want babeltrace2-ctf-writer support
  # for CTF data format.
  #
  # Define NO_CAPSTONE if you do not want libcapstone support
tools/perf/builtin-check.c +1 -1
index 3641d263b345..e9d14a960a03 100644
@@ -43,7 +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("babeltrace2-ctf-writer", HAVE_BABELTRACE2_SUPPORT),
         FEATURE_STATUS("libbpf-strings", HAVE_LIBBPF_STRINGS_SUPPORT),
         FEATURE_STATUS("libcapstone", HAVE_LIBCAPSTONE_SUPPORT),
         FEATURE_STATUS("libdw-dwarf-unwind", HAVE_LIBDW_SUPPORT),
tools/perf/builtin-data.c +4 -14
index 85f59886b5cf..260d74476439 100644
@@ -40,10 +40,8 @@ const struct option data_options[] = {
                 OPT_INCR('v', "verbose", &verbose, "be more verbose"),
                 OPT_STRING('i', "input", &input_name, "file", "input file name"),
                 OPT_STRING(0, "to-json", &to_json, NULL, "Convert to JSON format"),
-#ifdef HAVE_LIBBABELTRACE_SUPPORT
                 OPT_STRING(0, "to-ctf", &to_ctf, NULL, "Convert to CTF format"),
                 OPT_BOOLEAN(0, "tod", &opts.tod, "Convert time to wall clock time"),
-#endif
                 OPT_BOOLEAN('f', "force", &opts.force, "don't complain, do it"),
                 OPT_BOOLEAN(0, "all", &opts.all, "Convert all events"),
                 OPT_STRING(0, "time", &opts.time_str, "str",
@@ -65,29 +63,21 @@ 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_LIBBABELTRACE_SUPPORT
         if (!to_json && !to_ctf) {
                 pr_err("You must specify one of --to-ctf or --to-json.\n");
                 return -1;
         }
-#else
-       if (!to_json) {
-               pr_err("You must specify --to-json.\n");
-       return -1;
-}
-#endif
 
         if (to_json)
                 return bt_convert__perf2json(input_name, to_json, &opts);
 
         if (to_ctf) {
-#if defined(HAVE_LIBBABELTRACE_SUPPORT) && defined(HAVE_LIBTRACEEVENT)
+#if defined(HAVE_BABELTRACE2_SUPPORT) && defined(HAVE_LIBTRACEEVENT)
                 return bt_convert__perf2ctf(input_name, to_ctf, &opts);
  #else
-               pr_err("The libbabeltrace support is not compiled in. perf should be "
-                      "compiled with environment variables LIBBABELTRACE=1 and "
-                      "LIBBABELTRACE_DIR=/path/to/libbabeltrace/.\n"
-                      "Check also if libbtraceevent devel files are available.\n");
+               pr_err("The babeltrace2 support is not compiled in. Ensure you have both\n"
+                       "libbabeltrace2-dev[el] and libtraceevent-dev[el] installed or set\n"
+                       "PKG_CONFIG_PATH to find a local installation of those libraries.\n");
                 return -1;
  #endif
         }
tools/perf/tests/make +2 -2
index 6587dc326d1b..04f9b686cec0 100644
@@ -93,7 +93,7 @@ make_no_libbpf            := NO_LIBBPF=1
  make_libbpf_dynamic := LIBBPF_DYNAMIC=1
  make_no_libbpf_DEBUG := NO_LIBBPF=1 DEBUG=1
  make_no_libllvm     := NO_LIBLLVM=1
-make_with_babeltrace:= LIBBABELTRACE=1
+make_with_babeltrace2 := BABELTRACE2=1
  make_with_coresight := CORESIGHT=1
  make_no_sdt        := NO_SDT=1
  make_no_libpfm4     := NO_LIBPFM4=1
@@ -170,7 +170,7 @@ run += make_no_libbpf_DEBUG
  run += make_no_libllvm
  run += make_no_sdt
  run += make_no_syscall_tbl
-run += make_with_babeltrace
+run += make_with_babeltrace2
  run += make_with_coresight
  run += make_with_clangllvm
  run += make_no_libpfm4
tools/perf/tests/shell/test_perf_data_converter_ctf.sh +4 -4
index 334eebc9945e..65d49a10c028 100755
@@ -24,11 +24,11 @@ trap_cleanup()
  }
  trap trap_cleanup exit term int
 
-check_babeltrace_support()
+check_babeltrace2_support()
  {
-       if ! perf check feature libbabeltrace
+       if ! perf check feature babeltrace2-ctf-writer
         then
-               echo "perf not linked with libbabeltrace, skipping test"
+               echo "perf not linked with libbabeltrace2-ctf-writer, skipping test"
                 exit 2
         fi
  }
@@ -97,7 +97,7 @@ test_ctf_converter_pipe()
         fi
  }
 
-check_babeltrace_support
+check_babeltrace2_support
  test_ctf_converter_file
  test_ctf_converter_pipe
 
tools/perf/util/Build +1 -1
index bcccad7487a9..7f3b67c8eeab 100644
@@ -233,7 +233,7 @@ perf-util-$(CONFIG_LIBUNWIND_X86)      += libunwind/x86_32.o
  perf-util-$(CONFIG_LIBUNWIND_AARCH64)  += libunwind/arm64.o
 
  ifeq ($(CONFIG_LIBTRACEEVENT),y)
-  perf-util-$(CONFIG_LIBBABELTRACE) += data-convert-bt.o
+  perf-util-$(CONFIG_BABELTRACE2) += data-convert-bt.o
  endif
 
  perf-util-y += data-convert-json.o
tools/perf/util/data-convert-bt.c +4 -8
index ba1c8e48d495..91d8cdc9e8c7 100644
@@ -11,14 +11,13 @@
  #include <linux/compiler.h>
  #include <linux/kernel.h>
  #include <linux/zalloc.h>
-#include <babeltrace/ctf-writer/writer.h>
-#include <babeltrace/ctf-writer/clock.h>
-#include <babeltrace/ctf-writer/stream.h>
-#include <babeltrace/ctf-writer/event.h>
-#include <babeltrace/ctf-writer/event-types.h>
-#include <babeltrace/ctf-writer/event-fields.h>
-#include <babeltrace/ctf-ir/utils.h>
-#include <babeltrace/ctf/events.h>
+#include <babeltrace2-ctf-writer/writer.h>
+#include <babeltrace2-ctf-writer/clock.h>
+#include <babeltrace2-ctf-writer/stream.h>
+#include <babeltrace2-ctf-writer/event.h>
Quoted 8 lines

tools/perf/util/data-convert-bt.c line 20

Quoted 3 lines
tools/perf/util/data-convert-bt.c +3 -0
+#include <babeltrace2-ctf-writer/event-types.h>
+#include <babeltrace2-ctf-writer/event-fields.h>
+#include <babeltrace2-ctf-writer/utils.h>

This is cool, I'm surprised at how non-invasive the change is. I'd done a similar thing but keeping both babeltrace 1 and 2. I'll post my WIP in reply just as a heads up, but I have to do much more heavy engineering.

I think I can rework this to try babeltrace2-ctf-writer first and fall back on libbabeltrace1. The change is non-invasive because bt2-ctf-writer is basically just a compat API for the ctf-writer of bt1 but it doesn't expose any of the new features of bt2.

Your WIP patch that uses the proper libbabeltrace2 API is definitely the way to go for the long term. In the meantime would you like a v2 of this patch?

Cheers,

Michael

Quoted 101 lines

Thanks,
Ian

Quoted 97 lines
tools/perf/util/data-convert-bt.c +9 -9
  #include "asm/bug.h"
  #include "data-convert.h"
  #include "session.h"
@@ -121,13 +120,13 @@ static int value_set(struct bt_ctf_field_type *type,
         }
 
         if (sign) {
-               ret = bt_ctf_field_signed_integer_set_value(field, val);
+               ret = bt_ctf_field_integer_signed_set_value(field, val);
                 if (ret) {
                         pr_err("failed to set field value %s\n", name);
                         goto err;
                 }
         } else {
-               ret = bt_ctf_field_unsigned_integer_set_value(field, val);
+               ret = bt_ctf_field_integer_unsigned_set_value(field, val);
                 if (ret) {
                         pr_err("failed to set field value %s\n", name);
                         goto err;
@@ -374,10 +373,10 @@ static int add_tracepoint_field_value(struct ctf_writer *cw,
                                         data + offset + i * len, len);
 
                         if (!(flags & TEP_FIELD_IS_SIGNED))
-                               ret = bt_ctf_field_unsigned_integer_set_value(
+                               ret = bt_ctf_field_integer_unsigned_set_value(
                                                 field, value_int);
                         else
-                               ret = bt_ctf_field_signed_integer_set_value(
+                               ret = bt_ctf_field_integer_signed_set_value(
                                                 field, adjust_signedness(value_int, len));
                 }
 
@@ -471,7 +470,7 @@ add_bpf_output_values(struct bt_ctf_event_class *event_class,
                 goto put_len_type;
         }
 
-       ret = bt_ctf_field_unsigned_integer_set_value(len_field, nr_elements);
+       ret = bt_ctf_field_integer_unsigned_set_value(len_field, nr_elements);
         if (ret) {
                 pr_err("failed to set field value for raw_len\n");
                 goto put_len_field;
@@ -500,7 +499,7 @@ add_bpf_output_values(struct bt_ctf_event_class *event_class,
                 struct bt_ctf_field *elem_field =
                         bt_ctf_field_sequence_get_field(seq_field, i);
 
-               ret = bt_ctf_field_unsigned_integer_set_value(elem_field,
+               ret = bt_ctf_field_integer_unsigned_set_value(elem_field,
                                 ((u32 *)(sample->raw_data))[i]);
 
                 bt_ctf_field_put(elem_field);
@@ -545,7 +544,7 @@ add_callchain_output_values(struct bt_ctf_event_class *event_class,
                 goto put_len_type;
         }
 
-       ret = bt_ctf_field_unsigned_integer_set_value(len_field, nr_elements);
+       ret = bt_ctf_field_integer_unsigned_set_value(len_field, nr_elements);
         if (ret) {
                 pr_err("failed to set field value for perf_callchain_size\n");
                 goto put_len_field;
@@ -575,7 +574,7 @@ add_callchain_output_values(struct bt_ctf_event_class *event_class,
                 struct bt_ctf_field *elem_field =
                         bt_ctf_field_sequence_get_field(seq_field, i);
 
-               ret = bt_ctf_field_unsigned_integer_set_value(elem_field,
+               ret = bt_ctf_field_integer_unsigned_set_value(elem_field,
                                 ((u64 *)(callchain->ips))[i]);
 
                 bt_ctf_field_put(elem_field);
@@ -728,7 +727,7 @@ static struct ctf_stream *ctf_stream__create(struct ctf_writer *cw, int cpu)
                 goto out;
         }
 
-       ret = bt_ctf_field_unsigned_integer_set_value(cpu_field, (u32) cpu);
+       ret = bt_ctf_field_integer_unsigned_set_value(cpu_field, (u32) cpu);
         if (ret) {
                 pr_err("Failed to update CPU number\n");
                 goto out;
tools/perf/util/data-convert.h +2 -3
index ee651fa680a1..d174e6f2729d 100644
@@ -11,10 +11,10 @@ struct perf_data_convert_opts {
         const char *time_str;
  };
 
-#ifdef HAVE_LIBBABELTRACE_SUPPORT
+#ifdef HAVE_BABELTRACE2_SUPPORT
  int bt_convert__perf2ctf(const char *input_name, const char *to_ctf,
                          struct perf_data_convert_opts *opts);
-#endif /* HAVE_LIBBABELTRACE_SUPPORT */
+#endif /* HAVE_BABELTRACE2_SUPPORT */
 
  int bt_convert__perf2json(const char *input_name, const char *to_ctf,
                          struct perf_data_convert_opts *opts);
--

2.47.3

reviewer
#6 lore raw
Quoted 386 lines · Michael Jeanson
Quoted 113 lines · Ian Rogers
Quoted 112 lines · Michael Jeanson

The 1.x branch of Babeltrace has been superseded by 2.x in 2020 and has been unmaintained since 2022, efforts have started to remove it from popular distributions.

Babeltrace 2.x offers a very similar 'ctf-writer' library that can be used with minimal changes for the '--to-ctf' feature and has been packaged since Debian 11 and Fedora 32.

This patch replaces the 'libbabeltrace' build feature with 'babeltrace2-ctf-writer' using pkgconfig detection, adjusts the naming of the public headers and applies minor API cleanups.

No changes to the output ctf traces, this API still implements version 1.8 of the CTF specification that can be read by either Babeltrace 1 / 2 or any CTF compliant reader.

Also remove some ifdefs in the cli option parsing to allow printing the helpful error message with '--to-ctf' when built without babeltrace2.

Cc Adrian Hunter <[email protected]>
Cc Alexander Shishkin <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Derek Foreman <[email protected]>
Cc Ian Rogers <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc James Clark <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Mathieu Desnoyers <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Peter Zijlstra <[email protected]>
---
  tools/build/Makefile.feature                  |  5 +--
  tools/build/feature/Makefile                  |  6 ++--
  tools/build/feature/test-all.c                | 13 ++------
  ...ltrace.c => test-babeltrace2-ctf-writer.c} |  3 +-
  tools/perf/Makefile.config                    | 28 ++++++++--------
  tools/perf/Makefile.perf                      |  2 +-
  tools/perf/builtin-check.c                    |  2 +-
  tools/perf/builtin-data.c                     | 18 +++-------
  tools/perf/tests/make                         |  4 +--
  .../shell/test_perf_data_converter_ctf.sh     |  8 ++---
  tools/perf/util/Build                         |  2 +-
  tools/perf/util/data-convert-bt.c             | 33 +++++++++----------
  tools/perf/util/data-convert.h                |  4 +--
  13 files changed, 55 insertions(+), 73 deletions(-)

rename tools/build/feature/{test-libbabeltrace.c => test-babeltrace2-ctf-writer.c} (59%)

tools/build/Makefile.feature +3 -2
index 0b7a7c38cb88..9e097144817e 100644
@@ -113,7 +113,7 @@ FEATURE_TESTS_EXTRA :=                  \
           gtk2                           \
           gtk2-infobar                   \
           hello                          \
-         libbabeltrace                  \
+         babeltrace2-ctf-writer         \
           libcapstone                    \
           libbfd-liberty                 \
           libbfd-liberty-z               \
@@ -162,6 +162,7 @@ FEATURE_GROUP_MEMBERS-libbfd = libbfd-liberty libbfd-liberty-z
  # Declare list of feature dependency packages that provide pkg-config files.
  #
  FEATURE_PKG_CONFIG ?=           \
+        babeltrace2-ctf-writer \
           libtraceevent          \
           libtracefs
 
@@ -208,7 +209,7 @@ ifeq ($(feature-all), 1)
    $(call feature_check,compile-32)
    $(call feature_check,compile-x32)
    $(call feature_check,bionic)
-  $(call feature_check,libbabeltrace)
+  $(call feature_check,babeltrace2-ctf-writer)
  else
    $(foreach feat,$(FEATURE_TESTS),$(call feature_check,$(feat)))
  endif
tools/build/feature/Makefile +3 -3
index 1fbcb3ce74d2..7735e257c263 100644
@@ -48,7 +48,7 @@ FILES=                                          \
           test-pthread-barrier.bin              \
           test-stackprotector-all.bin            \
           test-timerfd.bin                       \
-         test-libbabeltrace.bin                 \
+         test-babeltrace2-ctf-writer.bin        \
           test-libcapstone.bin                  \
           test-compile-32.bin                    \
           test-compile-x32.bin                   \
@@ -301,8 +301,8 @@ $(OUTPUT)test-backtrace.bin:
  $(OUTPUT)test-timerfd.bin:
         $(BUILD)
 
-$(OUTPUT)test-libbabeltrace.bin:
-       $(BUILD) # -lbabeltrace provided by $(FEATURE_CHECK_LDFLAGS-libbabeltrace)
+$(OUTPUT)test-babeltrace2-ctf-writer.bin:
+       $(BUILD) # -lbabeltrace2-ctf-writer provided by $(FEATURE_CHECK_LDFLAGS-babeltrace2-ctf-writer)
 
  $(OUTPUT)test-libcapstone.bin:
         $(BUILD) # -lcapstone provided by $(FEATURE_CHECK_LDFLAGS-libcapstone)
tools/build/feature/test-all.c +0 -0
index 1488bf6e6078..145abdee049d 100644
@@ -98,17 +98,9 @@
  # include "test-sched_getcpu.c"
  #undef main
 
Quoted 16 lines

tools/build/feature/test-all.c line 102

Quoted 11 lines
tools/build/feature/test-all.c +2 -9
-# if 0
-/*
- * Disable libbabeltrace check for test-all, because the requested
- * library version is not released yet in most distributions. Will
- * reenable later.
- */
-
-#define main main_test_libbabeltrace
-# include "test-libbabeltrace.c"
+#define main main_test_babeltrace2_ctf_writer
+# include "test-babeltrace2-ctf-writer.c"

So I still think the comment about libbabeltrace is probably valid:
most distributions won't have it by default, so a separate test is likely better than testing with test-all. You also need to update FEATURE_TESTS_BASIFEATURE_TESTS_BASIC.

I went by the comment in 'Makefile.feature' that says features in FEATURE_TESTS_EXTRA should be included in 'test-all.c'. I'll remove it.

Quoted 37 lines
Quoted 37 lines
tools/build/feature/test-all.c +1 -1
  #undef main
-#endif
 
  #define main main_test_lzma
  # include "test-lzma.c"
@@ -178,6 +170,7 @@ int main(int argc, char *argv[])
         main_test_libzstd();
         main_test_libtraceevent();
         main_test_libopenssl();
+       main_test_babeltrace2_ctf_writer();
 
         return 0;
  }
tools/build/feature/test-babeltrace2-ctf-writer.c renamed from tools/build/feature/test-libbabeltrace.c +1 -2
similarity index 59%
rename from tools/build/feature/test-libbabeltrace.c
rename to tools/build/feature/test-babeltrace2-ctf-writer.c
index 10bb69d55694..9c89082e9f88 100644
@@ -1,7 +1,6 @@
  // SPDX-License-Identifier: GPL-2.0
 
-#include <babeltrace/ctf-writer/writer.h>
-#include <babeltrace/ctf-ir/stream-class.h>
+#include <babeltrace2-ctf-writer/writer.h>
 
  int main(void)
  {
tools/perf/Makefile.config +0 -0
index 15fbba9f4ca8..f2f5051c94e3 100644
@@ -196,13 +196,13 @@ FEATURE_CHECK_CFLAGS-libdw := $(LIBDW_CFLAGS)
  FEATURE_CHECK_LDFLAGS-libdw := $(LIBDW_LDFLAGS) $(DWARFLIBS)
 
Quoted 8 lines

tools/perf/Makefile.config FEATURE_CHECK_CFLAGS-libdw := $(LIBDW_CFLAGS) · line 199

Quoted 6 lines
tools/perf/Makefile.config +1 -4
  # for linking with debug library, run like:
-# make DEBUG=1 LIBBABELTRACE_DIR=/opt/libbabeltrace/
-ifdef LIBBABELTRACE_DIR
-  LIBBABELTRACE_CFLAGS  := -I$(LIBBABELTRACE_DIR)/include
-  LIBBABELTRACE_LDFLAGS := -L$(LIBBABELTRACE_DIR)/lib
+# make DEBUG=1 PKG_CONFIG_PATH=/opt/babeltrace2/(lib|lib64)/pkgconfig

Delete?

Sure.

Quoted 194 lines
Quoted 194 lines
tools/perf/Makefile.config +13 -10
+
+ifneq ($(NO_BABELTRACE2),1)
+  ifeq ($(call get-executable,$(PKG_CONFIG)),)
+    $(error Error: $(PKG_CONFIG) needed by babeltrace2 is missing on this system, please install it)
+  endif
  endif
-FEATURE_CHECK_CFLAGS-libbabeltrace := $(LIBBABELTRACE_CFLAGS)
-FEATURE_CHECK_LDFLAGS-libbabeltrace := $(LIBBABELTRACE_LDFLAGS) -lbabeltrace-ctf
 
  # for linking with debug library, run like:
  # make DEBUG=1 LIBCAPSTONE_DIR=/opt/capstone/
@@ -1058,15 +1058,15 @@ else
    NO_PERF_READ_VDSOX32 := 1
  endif
 
-ifndef NO_LIBBABELTRACE
-  $(call feature_check,libbabeltrace)
-  ifeq ($(feature-libbabeltrace), 1)
-    CFLAGS += -DHAVE_LIBBABELTRACE_SUPPORT $(LIBBABELTRACE_CFLAGS)
-    LDFLAGS += $(LIBBABELTRACE_LDFLAGS)
-    EXTLIBS += -lbabeltrace-ctf
-    $(call detected,CONFIG_LIBBABELTRACE)
+ifndef NO_BABELTRACE2
+  $(call feature_check,babeltrace2-ctf-writer)
+  ifeq ($(feature-babeltrace2-ctf-writer), 1)
+    CFLAGS += -DHAVE_BABELTRACE2_SUPPORT $(shell $(PKG_CONFIG) --cflags babeltrace2-ctf-writer)
+    LDFLAGS += $(shell $(PKG_CONFIG) --libs-only-L babeltrace2-ctf-writer)
+    EXTLIBS += $(shell $(PKG_CONFIG) --libs-only-l babeltrace2-ctf-writer)
+    $(call detected,CONFIG_BABELTRACE2)
    else
-    $(warning No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev)
+    $(warning No babeltrace2 found, disables 'perf data' CTF format support, please install libbabeltrace2-dev[el])
    endif
  endif
 
tools/perf/Makefile.perf +1 -1
index f7b936deeaa2..1f4e84a8472e 100644
@@ -79,7 +79,7 @@ include ../scripts/utilities.mak
  #
  # Define NO_ZLIB if you do not want to support compressed kernel modules
  #
-# Define NO_LIBBABELTRACE if you do not want libbabeltrace support
+# Define NO_BABELTRACE2 if you do not want babeltrace2-ctf-writer support
  # for CTF data format.
  #
  # Define NO_CAPSTONE if you do not want libcapstone support
tools/perf/builtin-check.c +1 -1
index 3641d263b345..e9d14a960a03 100644
@@ -43,7 +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("babeltrace2-ctf-writer", HAVE_BABELTRACE2_SUPPORT),
         FEATURE_STATUS("libbpf-strings", HAVE_LIBBPF_STRINGS_SUPPORT),
         FEATURE_STATUS("libcapstone", HAVE_LIBCAPSTONE_SUPPORT),
         FEATURE_STATUS("libdw-dwarf-unwind", HAVE_LIBDW_SUPPORT),
tools/perf/builtin-data.c +4 -14
index 85f59886b5cf..260d74476439 100644
@@ -40,10 +40,8 @@ const struct option data_options[] = {
                 OPT_INCR('v', "verbose", &verbose, "be more verbose"),
                 OPT_STRING('i', "input", &input_name, "file", "input file name"),
                 OPT_STRING(0, "to-json", &to_json, NULL, "Convert to JSON format"),
-#ifdef HAVE_LIBBABELTRACE_SUPPORT
                 OPT_STRING(0, "to-ctf", &to_ctf, NULL, "Convert to CTF format"),
                 OPT_BOOLEAN(0, "tod", &opts.tod, "Convert time to wall clock time"),
-#endif
                 OPT_BOOLEAN('f', "force", &opts.force, "don't complain, do it"),
                 OPT_BOOLEAN(0, "all", &opts.all, "Convert all events"),
                 OPT_STRING(0, "time", &opts.time_str, "str",
@@ -65,29 +63,21 @@ 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_LIBBABELTRACE_SUPPORT
         if (!to_json && !to_ctf) {
                 pr_err("You must specify one of --to-ctf or --to-json.\n");
                 return -1;
         }
-#else
-       if (!to_json) {
-               pr_err("You must specify --to-json.\n");
-       return -1;
-}
-#endif
 
         if (to_json)
                 return bt_convert__perf2json(input_name, to_json, &opts);
 
         if (to_ctf) {
-#if defined(HAVE_LIBBABELTRACE_SUPPORT) && defined(HAVE_LIBTRACEEVENT)
+#if defined(HAVE_BABELTRACE2_SUPPORT) && defined(HAVE_LIBTRACEEVENT)
                 return bt_convert__perf2ctf(input_name, to_ctf, &opts);
  #else
-               pr_err("The libbabeltrace support is not compiled in. perf should be "
-                      "compiled with environment variables LIBBABELTRACE=1 and "
-                      "LIBBABELTRACE_DIR=/path/to/libbabeltrace/.\n"
-                      "Check also if libbtraceevent devel files are available.\n");
+               pr_err("The babeltrace2 support is not compiled in. Ensure you have both\n"
+                       "libbabeltrace2-dev[el] and libtraceevent-dev[el] installed or set\n"
+                       "PKG_CONFIG_PATH to find a local installation of those libraries.\n");
                 return -1;
  #endif
         }
tools/perf/tests/make +2 -2
index 6587dc326d1b..04f9b686cec0 100644
@@ -93,7 +93,7 @@ make_no_libbpf            := NO_LIBBPF=1
  make_libbpf_dynamic := LIBBPF_DYNAMIC=1
  make_no_libbpf_DEBUG := NO_LIBBPF=1 DEBUG=1
  make_no_libllvm     := NO_LIBLLVM=1
-make_with_babeltrace:= LIBBABELTRACE=1
+make_with_babeltrace2 := BABELTRACE2=1
  make_with_coresight := CORESIGHT=1
  make_no_sdt        := NO_SDT=1
  make_no_libpfm4     := NO_LIBPFM4=1
@@ -170,7 +170,7 @@ run += make_no_libbpf_DEBUG
  run += make_no_libllvm
  run += make_no_sdt
  run += make_no_syscall_tbl
-run += make_with_babeltrace
+run += make_with_babeltrace2
  run += make_with_coresight
  run += make_with_clangllvm
  run += make_no_libpfm4
tools/perf/tests/shell/test_perf_data_converter_ctf.sh +4 -4
index 334eebc9945e..65d49a10c028 100755
@@ -24,11 +24,11 @@ trap_cleanup()
  }
  trap trap_cleanup exit term int
 
-check_babeltrace_support()
+check_babeltrace2_support()
  {
-       if ! perf check feature libbabeltrace
+       if ! perf check feature babeltrace2-ctf-writer
         then
-               echo "perf not linked with libbabeltrace, skipping test"
+               echo "perf not linked with libbabeltrace2-ctf-writer, skipping test"
                 exit 2
         fi
  }
@@ -97,7 +97,7 @@ test_ctf_converter_pipe()
         fi
  }
 
-check_babeltrace_support
+check_babeltrace2_support
  test_ctf_converter_file
  test_ctf_converter_pipe
 
tools/perf/util/Build +1 -1
index bcccad7487a9..7f3b67c8eeab 100644
@@ -233,7 +233,7 @@ perf-util-$(CONFIG_LIBUNWIND_X86)      += libunwind/x86_32.o
  perf-util-$(CONFIG_LIBUNWIND_AARCH64)  += libunwind/arm64.o
 
  ifeq ($(CONFIG_LIBTRACEEVENT),y)
-  perf-util-$(CONFIG_LIBBABELTRACE) += data-convert-bt.o
+  perf-util-$(CONFIG_BABELTRACE2) += data-convert-bt.o
  endif
 
  perf-util-y += data-convert-json.o
tools/perf/util/data-convert-bt.c +4 -8
index ba1c8e48d495..91d8cdc9e8c7 100644
@@ -11,14 +11,13 @@
  #include <linux/compiler.h>
  #include <linux/kernel.h>
  #include <linux/zalloc.h>
-#include <babeltrace/ctf-writer/writer.h>
-#include <babeltrace/ctf-writer/clock.h>
-#include <babeltrace/ctf-writer/stream.h>
-#include <babeltrace/ctf-writer/event.h>
-#include <babeltrace/ctf-writer/event-types.h>
-#include <babeltrace/ctf-writer/event-fields.h>
-#include <babeltrace/ctf-ir/utils.h>
-#include <babeltrace/ctf/events.h>
+#include <babeltrace2-ctf-writer/writer.h>
+#include <babeltrace2-ctf-writer/clock.h>
+#include <babeltrace2-ctf-writer/stream.h>
+#include <babeltrace2-ctf-writer/event.h>
Quoted 8 lines

tools/perf/util/data-convert-bt.c line 20

Quoted 3 lines
tools/perf/util/data-convert-bt.c +3 -0
+#include <babeltrace2-ctf-writer/event-types.h>
+#include <babeltrace2-ctf-writer/event-fields.h>
+#include <babeltrace2-ctf-writer/utils.h>

This is cool, I'm surprised at how non-invasive the change is. I'd done a similar thing but keeping both babeltrace 1 and 2. I'll post my WIP in reply just as a heads up, but I have to do much more heavy engineering.

Quoted 8 lines

I think I can rework this to try babeltrace2-ctf-writer first and fall back on libbabeltrace1. The change is non-invasive because bt2-ctf-writer is basically just a compat API for the ctf-writer of bt1 but it doesn't expose any of the new features of bt2.

Your WIP patch that uses the proper libbabeltrace2 API is definitely the way to go for the long term. In the meantime would you like a v2 of this patch?

We have a problem with the perf tool in that it carries too much baggage due to its library dependencies, so I'd prefer we stick with v2 support and your cleaner/simpler patch. I'm also hugely appreciative of the work you've put in! I'm too busy to review my own work right now, and cleaning this up ASAP offers an advantage.

Thanks,
Ian

* We support libbfd although libbfd is GPLv3 and license incompatible with perf, which is mainly GPLv2. We carry around libunwind support but that project appears unmaintained. We have LLVM support but the LLVM dependency is huge in terms of size and dependencies it brings in, so people avoid building with it, etc.

Quoted 106 lines

Cheers,

Michael

Quoted 101 lines

Thanks,
Ian

Quoted 97 lines
tools/perf/util/data-convert-bt.c +9 -9
  #include "asm/bug.h"
  #include "data-convert.h"
  #include "session.h"
@@ -121,13 +120,13 @@ static int value_set(struct bt_ctf_field_type *type,
         }
 
         if (sign) {
-               ret = bt_ctf_field_signed_integer_set_value(field, val);
+               ret = bt_ctf_field_integer_signed_set_value(field, val);
                 if (ret) {
                         pr_err("failed to set field value %s\n", name);
                         goto err;
                 }
         } else {
-               ret = bt_ctf_field_unsigned_integer_set_value(field, val);
+               ret = bt_ctf_field_integer_unsigned_set_value(field, val);
                 if (ret) {
                         pr_err("failed to set field value %s\n", name);
                         goto err;
@@ -374,10 +373,10 @@ static int add_tracepoint_field_value(struct ctf_writer *cw,
                                         data + offset + i * len, len);
 
                         if (!(flags & TEP_FIELD_IS_SIGNED))
-                               ret = bt_ctf_field_unsigned_integer_set_value(
+                               ret = bt_ctf_field_integer_unsigned_set_value(
                                                 field, value_int);
                         else
-                               ret = bt_ctf_field_signed_integer_set_value(
+                               ret = bt_ctf_field_integer_signed_set_value(
                                                 field, adjust_signedness(value_int, len));
                 }
 
@@ -471,7 +470,7 @@ add_bpf_output_values(struct bt_ctf_event_class *event_class,
                 goto put_len_type;
         }
 
-       ret = bt_ctf_field_unsigned_integer_set_value(len_field, nr_elements);
+       ret = bt_ctf_field_integer_unsigned_set_value(len_field, nr_elements);
         if (ret) {
                 pr_err("failed to set field value for raw_len\n");
                 goto put_len_field;
@@ -500,7 +499,7 @@ add_bpf_output_values(struct bt_ctf_event_class *event_class,
                 struct bt_ctf_field *elem_field =
                         bt_ctf_field_sequence_get_field(seq_field, i);
 
-               ret = bt_ctf_field_unsigned_integer_set_value(elem_field,
+               ret = bt_ctf_field_integer_unsigned_set_value(elem_field,
                                 ((u32 *)(sample->raw_data))[i]);
 
                 bt_ctf_field_put(elem_field);
@@ -545,7 +544,7 @@ add_callchain_output_values(struct bt_ctf_event_class *event_class,
                 goto put_len_type;
         }
 
-       ret = bt_ctf_field_unsigned_integer_set_value(len_field, nr_elements);
+       ret = bt_ctf_field_integer_unsigned_set_value(len_field, nr_elements);
         if (ret) {
                 pr_err("failed to set field value for perf_callchain_size\n");
                 goto put_len_field;
@@ -575,7 +574,7 @@ add_callchain_output_values(struct bt_ctf_event_class *event_class,
                 struct bt_ctf_field *elem_field =
                         bt_ctf_field_sequence_get_field(seq_field, i);
 
-               ret = bt_ctf_field_unsigned_integer_set_value(elem_field,
+               ret = bt_ctf_field_integer_unsigned_set_value(elem_field,
                                 ((u64 *)(callchain->ips))[i]);
 
                 bt_ctf_field_put(elem_field);
@@ -728,7 +727,7 @@ static struct ctf_stream *ctf_stream__create(struct ctf_writer *cw, int cpu)
                 goto out;
         }
 
-       ret = bt_ctf_field_unsigned_integer_set_value(cpu_field, (u32) cpu);
+       ret = bt_ctf_field_integer_unsigned_set_value(cpu_field, (u32) cpu);
         if (ret) {
                 pr_err("Failed to update CPU number\n");
                 goto out;
tools/perf/util/data-convert.h +2 -3
index ee651fa680a1..d174e6f2729d 100644
@@ -11,10 +11,10 @@ struct perf_data_convert_opts {
         const char *time_str;
  };
 
-#ifdef HAVE_LIBBABELTRACE_SUPPORT
+#ifdef HAVE_BABELTRACE2_SUPPORT
  int bt_convert__perf2ctf(const char *input_name, const char *to_ctf,
                          struct perf_data_convert_opts *opts);
-#endif /* HAVE_LIBBABELTRACE_SUPPORT */
+#endif /* HAVE_BABELTRACE2_SUPPORT */
 
  int bt_convert__perf2json(const char *input_name, const char *to_ctf,
                          struct perf_data_convert_opts *opts);
--

2.47.3

reviewer
#7 lore raw
Quoted 21 lines · Ian Rogers
Quoted 6 lines · Michael Jeanson
Quoted 4 lines · Ian Rogers

This is cool, I'm surprised at how non-invasive the change is. I'd done a similar thing but keeping both babeltrace 1 and 2. I'll post my WIP in reply just as a heads up, but I have to do much more heavy engineering.

Quoted 8 lines

I think I can rework this to try babeltrace2-ctf-writer first and fall back on libbabeltrace1. The change is non-invasive because bt2-ctf-writer is basically just a compat API for the ctf-writer of bt1 but it doesn't expose any of the new features of bt2.

Your WIP patch that uses the proper libbabeltrace2 API is definitely the way to go for the long term. In the meantime would you like a v2 of this patch?

We have a problem with the perf tool in that it carries too much baggage due to its library dependencies, so I'd prefer we stick with v2 support and your cleaner/simpler patch. I'm also hugely appreciative of the work you've put in! I'm too busy to review my own work right now, and cleaning this up ASAP offers an advantage.

...

Quoted 6 lines

* We support libbfd although libbfd is GPLv3 and license incompatible with perf, which is mainly GPLv2. We carry around libunwind support but that project appears unmaintained. We have LLVM support but the LLVM dependency is huge in terms of size and dependencies it brings in, so people avoid building with it, etc.

What's the plan here? I'd prefer to carry the v1 patch, ie let's lose libbabeltrace (version 1) as a dependency.

Thanks,
Ian

#8 lore raw
Quoted 24 lines · Ian Rogers
Quoted 21 lines · Ian Rogers
Quoted 6 lines · Michael Jeanson
Quoted 4 lines · Ian Rogers

This is cool, I'm surprised at how non-invasive the change is. I'd done a similar thing but keeping both babeltrace 1 and 2. I'll post my WIP in reply just as a heads up, but I have to do much more heavy engineering.

Quoted 8 lines

I think I can rework this to try babeltrace2-ctf-writer first and fall back on libbabeltrace1. The change is non-invasive because bt2-ctf-writer is basically just a compat API for the ctf-writer of bt1 but it doesn't expose any of the new features of bt2.

Your WIP patch that uses the proper libbabeltrace2 API is definitely the way to go for the long term. In the meantime would you like a v2 of this patch?

We have a problem with the perf tool in that it carries too much baggage due to its library dependencies, so I'd prefer we stick with v2 support and your cleaner/simpler patch. I'm also hugely appreciative of the work you've put in! I'm too busy to review my own work right now, and cleaning this up ASAP offers an advantage.

...

Quoted 1 line
Quoted 8 lines
Quoted 5 lines

* We support libbfd although libbfd is GPLv3 and license incompatible with perf, which is mainly GPLv2. We carry around libunwind support but that project appears unmaintained. We have LLVM support but the LLVM dependency is huge in terms of size and dependencies it brings in, so people avoid building with it, etc.

What's the plan here? I'd prefer to carry the v1 patch, ie let's lose libbabeltrace (version 1) as a dependency.

I think I misunderstood you, I thought you wanted to keep the bt1 support as a fallback. I'm fine with either version of the patch being merged.

I can send an updated version of the v1 patch addressing your review comments.

Cheers,

Michael

reviewer
#9 lore raw
Quoted 35 lines · Michael Jeanson
Quoted 24 lines · Ian Rogers
Quoted 21 lines · Ian Rogers
Quoted 6 lines · Michael Jeanson
Quoted 4 lines · Ian Rogers

This is cool, I'm surprised at how non-invasive the change is. I'd done a similar thing but keeping both babeltrace 1 and 2. I'll post my WIP in reply just as a heads up, but I have to do much more heavy engineering.

Quoted 8 lines

I think I can rework this to try babeltrace2-ctf-writer first and fall back on libbabeltrace1. The change is non-invasive because bt2-ctf-writer is basically just a compat API for the ctf-writer of bt1 but it doesn't expose any of the new features of bt2.

Your WIP patch that uses the proper libbabeltrace2 API is definitely the way to go for the long term. In the meantime would you like a v2 of this patch?

We have a problem with the perf tool in that it carries too much baggage due to its library dependencies, so I'd prefer we stick with v2 support and your cleaner/simpler patch. I'm also hugely appreciative of the work you've put in! I'm too busy to review my own work right now, and cleaning this up ASAP offers an advantage.

...

Quoted 1 line
Quoted 8 lines
Quoted 5 lines

* We support libbfd although libbfd is GPLv3 and license incompatible with perf, which is mainly GPLv2. We carry around libunwind support but that project appears unmaintained. We have LLVM support but the LLVM dependency is huge in terms of size and dependencies it brings in, so people avoid building with it, etc.

What's the plan here? I'd prefer to carry the v1 patch, ie let's lose libbabeltrace (version 1) as a dependency.

Quoted 6 lines

I think I misunderstood you, I thought you wanted to keep the bt1 support as a fallback. I'm fine with either version of the patch being merged.

I can send an updated version of the v1 patch addressing your review comments.

Arnaldo, Namhyung, do you mind losing libbabeltrace v1 support? As the commit message states:

The 1.x branch of Babeltrace has been superseded by 2.x in 2020 and has been unmaintained since 2022, efforts have started to remove it from popular distributions.

My choice would be to go with the v1 patch with the few fixes I'd mentioned.

Thanks,
Ian

Quoted 3 lines

Cheers,

Michael

#10 lore raw
Quoted 43 lines · Ian Rogers
Quoted 35 lines · Michael Jeanson
Quoted 24 lines · Ian Rogers
Quoted 21 lines · Ian Rogers
Quoted 6 lines · Michael Jeanson
Quoted 4 lines · Ian Rogers

This is cool, I'm surprised at how non-invasive the change is. I'd done a similar thing but keeping both babeltrace 1 and 2. I'll post my WIP in reply just as a heads up, but I have to do much more heavy engineering.

Quoted 8 lines

I think I can rework this to try babeltrace2-ctf-writer first and fall back on libbabeltrace1. The change is non-invasive because bt2-ctf-writer is basically just a compat API for the ctf-writer of bt1 but it doesn't expose any of the new features of bt2.

Your WIP patch that uses the proper libbabeltrace2 API is definitely the way to go for the long term. In the meantime would you like a v2 of this patch?

We have a problem with the perf tool in that it carries too much baggage due to its library dependencies, so I'd prefer we stick with v2 support and your cleaner/simpler patch. I'm also hugely appreciative of the work you've put in! I'm too busy to review my own work right now, and cleaning this up ASAP offers an advantage.

...

Quoted 1 line
Quoted 8 lines
Quoted 5 lines

* We support libbfd although libbfd is GPLv3 and license incompatible with perf, which is mainly GPLv2. We carry around libunwind support but that project appears unmaintained. We have LLVM support but the LLVM dependency is huge in terms of size and dependencies it brings in, so people avoid building with it, etc.

What's the plan here? I'd prefer to carry the v1 patch, ie let's lose libbabeltrace (version 1) as a dependency.

Quoted 6 lines

I think I misunderstood you, I thought you wanted to keep the bt1 support as a fallback. I'm fine with either version of the patch being merged.

I can send an updated version of the v1 patch addressing your review comments.

Quoted 8 lines

Arnaldo, Namhyung, do you mind losing libbabeltrace v1 support? As the commit message states:

The 1.x branch of Babeltrace has been superseded by 2.x in 2020 and has been unmaintained since 2022, efforts have started to remove it from popular distributions.

My choice would be to go with the v1 patch with the few fixes I'd mentioned.

Right, this is from the people working directly in babeltrace, so I'll take their advice, Michael, can you please address Ian's comments, check that it applies cleanly to perf-tools-next and resubmit, please?

- Arnaldo

#11 lore raw

PATCH v2 1/1 perf data ctf: replace libbabeltrace with babeltrace2-ctf-writer

In reply to Michael Jeanson

The 1.x branch of Babeltrace has been superseded by 2.x in 2020 and has been unmaintained since 2022, efforts have started to remove it from popular distributions.

Babeltrace 2.x offers a very similar 'ctf-writer' library that can be used with minimal changes for the '--to-ctf' feature and has been packaged since Debian 11 and Fedora 32.

This patch add a 'babeltrace2-ctf-writer' build feature using pkgconfig detection with a fallback to 'libbabeltrace'. There's a minor change to the API that is handled with simple preprocessor defines.

There is no changes to the output ctf traces, the ctf-writer API still implements version 1.8 of the CTF specification that can be read by either Babeltrace 1 / 2 or any CTF compliant reader.

Also remove some ifdefs in the cli option parsing to allow printing the helpful error message with '--to-ctf' when built without babeltrace.

Cc Adrian Hunter <[email protected]>
Cc Alexander Shishkin <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Derek Foreman <[email protected]>
Cc Ian Rogers <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc James Clark <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Mathieu Desnoyers <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Peter Zijlstra <[email protected]>

---
Changes since v1:
* Keep babeltrace 1 support as fallback

---
 tools/build/Makefile.feature                  |  3 ++
 tools/build/feature/Makefile                  |  4 ++
 .../feature/test-babeltrace2-ctf-writer.c     |  9 ++++
 tools/perf/Makefile.config                    | 24 +++++++---
 tools/perf/builtin-check.c                    |  1 +
 tools/perf/builtin-data.c                     | 20 +++-----
 .../shell/test_perf_data_converter_ctf.sh     |  9 ++--
 tools/perf/util/Build                         |  2 +-
 tools/perf/util/data-convert-bt.c             | 48 ++++++++++++-------
 tools/perf/util/data-convert.h                |  4 +-
 10 files changed, 80 insertions(+), 44 deletions(-)
 create mode 100644 tools/build/feature/test-babeltrace2-ctf-writer.c
tools/build/Makefile.feature +3 -0
index 0b7a7c38cb88..ce0bbbfa5d6c 100644
@@ -114,6 +114,7 @@ FEATURE_TESTS_EXTRA :=                  \
          gtk2-infobar                   \
          hello                          \
          libbabeltrace                  \
+         babeltrace2-ctf-writer         \
          libcapstone                    \
          libbfd-liberty                 \
          libbfd-liberty-z               \
@@ -162,6 +163,7 @@ FEATURE_GROUP_MEMBERS-libbfd = libbfd-liberty libbfd-liberty-z
 # Declare list of feature dependency packages that provide pkg-config files.
 #
 FEATURE_PKG_CONFIG ?=           \
+	 babeltrace2-ctf-writer \
          libtraceevent          \
          libtracefs
 
@@ -209,6 +211,7 @@ ifeq ($(feature-all), 1)
   $(call feature_check,compile-x32)
   $(call feature_check,bionic)
   $(call feature_check,libbabeltrace)
+  $(call feature_check,babeltrace2-ctf-writer)
 else
   $(foreach feat,$(FEATURE_TESTS),$(call feature_check,$(feat)))
 endif
tools/build/feature/Makefile +4 -0
index 1fbcb3ce74d2..314ff4c6f14b 100644
@@ -49,6 +49,7 @@ FILES=                                          \
          test-stackprotector-all.bin            \
          test-timerfd.bin                       \
          test-libbabeltrace.bin                 \
+         test-babeltrace2-ctf-writer.bin        \
          test-libcapstone.bin			\
          test-compile-32.bin                    \
          test-compile-x32.bin                   \
@@ -304,6 +305,9 @@ $(OUTPUT)test-timerfd.bin:
 $(OUTPUT)test-libbabeltrace.bin:
 	$(BUILD) # -lbabeltrace provided by $(FEATURE_CHECK_LDFLAGS-libbabeltrace)
 
+$(OUTPUT)test-babeltrace2-ctf-writer.bin:
+	$(BUILD) # -lbabeltrace2-ctf-writer provided by $(FEATURE_CHECK_LDFLAGS-babeltrace2-ctf-writer)
+
 $(OUTPUT)test-libcapstone.bin:
 	$(BUILD) # -lcapstone provided by $(FEATURE_CHECK_LDFLAGS-libcapstone)
 
tools/build/feature/test-babeltrace2-ctf-writer.c new file +9 -0
new file mode 100644
index 000000000000..9c89082e9f88
@@ -0,0 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <babeltrace2-ctf-writer/writer.h>
+
+int main(void)
+{
+	bt_ctf_stream_class_get_packet_context_type((void *) 0);
+	return 0;
+}
tools/perf/Makefile.config +17 -7
index 15fbba9f4ca8..e3d248bf2b46 100644
@@ -1059,14 +1059,24 @@ else
 endif
 
 ifndef NO_LIBBABELTRACE
-  $(call feature_check,libbabeltrace)
-  ifeq ($(feature-libbabeltrace), 1)
-    CFLAGS += -DHAVE_LIBBABELTRACE_SUPPORT $(LIBBABELTRACE_CFLAGS)
-    LDFLAGS += $(LIBBABELTRACE_LDFLAGS)
-    EXTLIBS += -lbabeltrace-ctf
-    $(call detected,CONFIG_LIBBABELTRACE)
+  # First check for babeltrace2-ctf-writer
+  $(call feature_check,babeltrace2-ctf-writer)
+  ifeq ($(feature-babeltrace2-ctf-writer), 1)
+    CFLAGS += -DHAVE_BABELTRACE2_CTF_WRITER_SUPPORT $(shell $(PKG_CONFIG) --cflags babeltrace2-ctf-writer)
+    LDFLAGS += $(shell $(PKG_CONFIG) --libs-only-L babeltrace2-ctf-writer)
+    EXTLIBS += $(shell $(PKG_CONFIG) --libs-only-l babeltrace2-ctf-writer)
+    $(call detected,CONFIG_BABELTRACE_CTF_WRITER)
   else
-    $(warning No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev)
+    # If we didn't find babeltrace2-ctf-writer, try for libbabeltrace1
+    $(call feature_check,libbabeltrace)
+    ifeq ($(feature-libbabeltrace), 1)
+      CFLAGS += -DHAVE_LIBBABELTRACE_SUPPORT $(LIBBABELTRACE_CFLAGS)
+      LDFLAGS += $(LIBBABELTRACE_LDFLAGS)
+      EXTLIBS += -lbabeltrace-ctf
+      $(call detected,CONFIG_BABELTRACE_CTF_WRITER)
+    else
+      $(warning No libbabeltrace or babeltrace2-ctf-writer found, disables 'perf data' CTF format support, please install libbabeltrace2-dev[el] or libbabeltrace-dev[el]/libbabeltrace-ctf-dev)
+    endif
   endif
 endif
 
tools/perf/builtin-check.c +1 -0
index 3641d263b345..c0837513f9ed 100644
@@ -44,6 +44,7 @@ struct feature_status supported_features[] = {
 	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("babeltrace2-ctf-writer", HAVE_BABELTRACE2_CTF_WRITER_SUPPORT),
 	FEATURE_STATUS("libbpf-strings", HAVE_LIBBPF_STRINGS_SUPPORT),
 	FEATURE_STATUS("libcapstone", HAVE_LIBCAPSTONE_SUPPORT),
 	FEATURE_STATUS("libdw-dwarf-unwind", HAVE_LIBDW_SUPPORT),
tools/perf/builtin-data.c +6 -14
index 85f59886b5cf..9e8eacbaea74 100644
@@ -40,10 +40,8 @@ const struct option data_options[] = {
 		OPT_INCR('v', "verbose", &verbose, "be more verbose"),
 		OPT_STRING('i', "input", &input_name, "file", "input file name"),
 		OPT_STRING(0, "to-json", &to_json, NULL, "Convert to JSON format"),
-#ifdef HAVE_LIBBABELTRACE_SUPPORT
 		OPT_STRING(0, "to-ctf", &to_ctf, NULL, "Convert to CTF format"),
 		OPT_BOOLEAN(0, "tod", &opts.tod, "Convert time to wall clock time"),
-#endif
 		OPT_BOOLEAN('f', "force", &opts.force, "don't complain, do it"),
 		OPT_BOOLEAN(0, "all", &opts.all, "Convert all events"),
 		OPT_STRING(0, "time", &opts.time_str, "str",
@@ -65,29 +63,23 @@ 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_LIBBABELTRACE_SUPPORT
 	if (!to_json && !to_ctf) {
 		pr_err("You must specify one of --to-ctf or --to-json.\n");
 		return -1;
 	}
-#else
-	if (!to_json) {
-		pr_err("You must specify --to-json.\n");
-	return -1;
-}
-#endif
 
 	if (to_json)
 		return bt_convert__perf2json(input_name, to_json, &opts);
 
 	if (to_ctf) {
-#if defined(HAVE_LIBBABELTRACE_SUPPORT) && defined(HAVE_LIBTRACEEVENT)
+#if (defined(HAVE_BABELTRACE2_CTF_WRITER_SUPPORT) || defined(HAVE_LIBBABELTRACE_SUPPORT)) \
+	&& defined(HAVE_LIBTRACEEVENT)
 		return bt_convert__perf2ctf(input_name, to_ctf, &opts);
 #else
-		pr_err("The libbabeltrace support is not compiled in. perf should be "
-		       "compiled with environment variables LIBBABELTRACE=1 and "
-		       "LIBBABELTRACE_DIR=/path/to/libbabeltrace/.\n"
-		       "Check also if libbtraceevent devel files are available.\n");
+		pr_err("The babeltrace ctf support is not compiled in. Ensure you have either\n"
+		       "libbabeltrace2-dev[el] or libbabeltrace-dev[el] installed and also\n"
+		       "libtraceevent-dev[el] or set PKG_CONFIG_PATH to find a local\n"
+		       "installation of those libraries.\n");
 		return -1;
 #endif
 	}
tools/perf/tests/shell/test_perf_data_converter_ctf.sh +6 -3
index 334eebc9945e..1bcffbadf279 100755
@@ -26,10 +26,13 @@ trap trap_cleanup exit term int
 
 check_babeltrace_support()
 {
-	if ! perf check feature libbabeltrace
+	if ! perf check feature babeltrace2-ctf-writer
 	then
-		echo "perf not linked with libbabeltrace, skipping test"
-		exit 2
+		if ! perf check feature libbabeltrace
+		then
+			echo "perf not linked with libbabeltrace2-ctf-writer or libbabeltrace, skipping test"
+			exit 2
+		fi
 	fi
 }
 
tools/perf/util/Build +1 -1
index bcccad7487a9..ba222abbd3e3 100644
@@ -233,7 +233,7 @@ perf-util-$(CONFIG_LIBUNWIND_X86)      += libunwind/x86_32.o
 perf-util-$(CONFIG_LIBUNWIND_AARCH64)  += libunwind/arm64.o
 
 ifeq ($(CONFIG_LIBTRACEEVENT),y)
-  perf-util-$(CONFIG_LIBBABELTRACE) += data-convert-bt.o
+  perf-util-$(CONFIG_BABELTRACE_CTF_WRITER) += data-convert-bt.o
 endif
 
 perf-util-y += data-convert-json.o
tools/perf/util/data-convert-bt.c +31 -17

109 lines not on this page · raw message

tools/perf/util/data-convert.h +2 -2
index ee651fa680a1..febfc0b05268 100644
@@ -11,10 +11,10 @@ struct perf_data_convert_opts {
 	const char *time_str;
 };
 
-#ifdef HAVE_LIBBABELTRACE_SUPPORT
+#if defined(HAVE_BABELTRACE2_CTF_WRITER_SUPPORT) || defined(HAVE_LIBBABELTRACE_SUPPORT)
 int bt_convert__perf2ctf(const char *input_name, const char *to_ctf,
 			 struct perf_data_convert_opts *opts);
-#endif /* HAVE_LIBBABELTRACE_SUPPORT */
+#endif
 
 int bt_convert__perf2json(const char *input_name, const char *to_ctf,
 			 struct perf_data_convert_opts *opts);
Signature · 1 line
2.47.3
#12 lore raw

PATCH v3 1/1 perf data ctf: replace libbabeltrace with babeltrace2-ctf-writer

In reply to Michael Jeanson

The 1.x branch of Babeltrace has been superseded by 2.x in 2020 and has been unmaintained since 2022, efforts have started to remove it from popular distributions.

Babeltrace 2.x offers a very similar 'ctf-writer' library that can be used with minimal changes for the '--to-ctf' feature and has been packaged since Debian 11 and Fedora 32.

This patch replaces the 'libbabeltrace' build feature with 'babeltrace2-ctf-writer' using pkgconfig detection, adjusts the naming of the public headers and applies minor API cleanups.

There is no changes to the output ctf traces, the ctf-writer API still implements version 1.8 of the CTF specification that can be read by either Babeltrace 1 / 2 or any CTF compliant reader.

Also remove some ifdefs in the cli option parsing to allow printing the helpful error message with '--to-ctf' when built without babeltrace2.

Cc Adrian Hunter <[email protected]>
Cc Alexander Shishkin <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Derek Foreman <[email protected]>
Cc Ian Rogers <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc James Clark <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Mathieu Desnoyers <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Peter Zijlstra <[email protected]>

---
Changes since v2:
* Revert babeltrace 1 fallback
* Rebase on perf-tools-next
Changes since v1:
* Keep babeltrace 1 support as fallback

---
 tools/build/Makefile.feature                  |  5 +--
 tools/build/feature/Makefile                  |  6 ++--
 tools/build/feature/test-all.c                |  6 ++--
 ...ltrace.c => test-babeltrace2-ctf-writer.c} |  3 +-
 tools/perf/Makefile.config                    | 27 +++++++--------
 tools/perf/Makefile.perf                      |  2 +-
 tools/perf/builtin-check.c                    |  2 +-
 tools/perf/builtin-data.c                     | 18 +++-------
 tools/perf/tests/make                         |  4 +--
 .../shell/test_perf_data_converter_ctf.sh     |  8 ++---
 tools/perf/util/Build                         |  2 +-
 tools/perf/util/data-convert-bt.c             | 33 +++++++++----------
 tools/perf/util/data-convert.h                |  4 +--
 13 files changed, 53 insertions(+), 67 deletions(-)
 rename tools/build/feature/{test-libbabeltrace.c => test-babeltrace2-ctf-writer.c} (59%)
tools/build/Makefile.feature +3 -2
index 0b7a7c38cb88..9e097144817e 100644
@@ -113,7 +113,7 @@ FEATURE_TESTS_EXTRA :=                  \
          gtk2                           \
          gtk2-infobar                   \
          hello                          \
-         libbabeltrace                  \
+         babeltrace2-ctf-writer         \
          libcapstone                    \
          libbfd-liberty                 \
          libbfd-liberty-z               \
@@ -162,6 +162,7 @@ FEATURE_GROUP_MEMBERS-libbfd = libbfd-liberty libbfd-liberty-z
 # Declare list of feature dependency packages that provide pkg-config files.
 #
 FEATURE_PKG_CONFIG ?=           \
+	 babeltrace2-ctf-writer \
          libtraceevent          \
          libtracefs
 
@@ -208,7 +209,7 @@ ifeq ($(feature-all), 1)
   $(call feature_check,compile-32)
   $(call feature_check,compile-x32)
   $(call feature_check,bionic)
-  $(call feature_check,libbabeltrace)
+  $(call feature_check,babeltrace2-ctf-writer)
 else
   $(foreach feat,$(FEATURE_TESTS),$(call feature_check,$(feat)))
 endif
tools/build/feature/Makefile +3 -3
index 1fbcb3ce74d2..7735e257c263 100644
@@ -48,7 +48,7 @@ FILES=                                          \
          test-pthread-barrier.bin		\
          test-stackprotector-all.bin            \
          test-timerfd.bin                       \
-         test-libbabeltrace.bin                 \
+         test-babeltrace2-ctf-writer.bin        \
          test-libcapstone.bin			\
          test-compile-32.bin                    \
          test-compile-x32.bin                   \
@@ -301,8 +301,8 @@ $(OUTPUT)test-backtrace.bin:
 $(OUTPUT)test-timerfd.bin:
 	$(BUILD)
 
-$(OUTPUT)test-libbabeltrace.bin:
-	$(BUILD) # -lbabeltrace provided by $(FEATURE_CHECK_LDFLAGS-libbabeltrace)
+$(OUTPUT)test-babeltrace2-ctf-writer.bin:
+	$(BUILD) # -lbabeltrace2-ctf-writer provided by $(FEATURE_CHECK_LDFLAGS-babeltrace2-ctf-writer)
 
 $(OUTPUT)test-libcapstone.bin:
 	$(BUILD) # -lcapstone provided by $(FEATURE_CHECK_LDFLAGS-libcapstone)
tools/build/feature/test-all.c +3 -3
index 1488bf6e6078..544563d62950 100644
@@ -100,13 +100,13 @@
 
 # if 0
 /*
- * Disable libbabeltrace check for test-all, because the requested
+ * Disable babeltrace2-ctf-writer check for test-all, because the requested
  * library version is not released yet in most distributions. Will
  * reenable later.
  */
 
-#define main main_test_libbabeltrace
-# include "test-libbabeltrace.c"
+#define main main_test_babeltrace2_ctf_writer
+# include "test-babeltrace2-ctf-writer.c"
 #undef main
 #endif
 
tools/build/feature/test-babeltrace2-ctf-writer.c renamed from tools/build/feature/test-libbabeltrace.c +1 -2
similarity index 59%
rename from tools/build/feature/test-libbabeltrace.c
rename to tools/build/feature/test-babeltrace2-ctf-writer.c
index 10bb69d55694..9c89082e9f88 100644
@@ -1,7 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 
-#include <babeltrace/ctf-writer/writer.h>
-#include <babeltrace/ctf-ir/stream-class.h>
+#include <babeltrace2-ctf-writer/writer.h>
 
 int main(void)
 {
tools/perf/Makefile.config +12 -15
index a8dc72cfe48e..856d2831d53c 100644
@@ -195,14 +195,11 @@ endif
 FEATURE_CHECK_CFLAGS-libdw := $(LIBDW_CFLAGS)
 FEATURE_CHECK_LDFLAGS-libdw := $(LIBDW_LDFLAGS) $(DWARFLIBS)
 
-# for linking with debug library, run like:
-# make DEBUG=1 LIBBABELTRACE_DIR=/opt/libbabeltrace/
-ifdef LIBBABELTRACE_DIR
-  LIBBABELTRACE_CFLAGS  := -I$(LIBBABELTRACE_DIR)/include
-  LIBBABELTRACE_LDFLAGS := -L$(LIBBABELTRACE_DIR)/lib
+ifneq ($(NO_BABELTRACE2),1)
+  ifeq ($(call get-executable,$(PKG_CONFIG)),)
+    $(error Error: $(PKG_CONFIG) needed by babeltrace2 is missing on this system, please install it)
+  endif
 endif
-FEATURE_CHECK_CFLAGS-libbabeltrace := $(LIBBABELTRACE_CFLAGS)
-FEATURE_CHECK_LDFLAGS-libbabeltrace := $(LIBBABELTRACE_LDFLAGS) -lbabeltrace-ctf
 
 # for linking with debug library, run like:
 # make DEBUG=1 LIBCAPSTONE_DIR=/opt/capstone/
@@ -1058,15 +1055,15 @@ else
   NO_PERF_READ_VDSOX32 := 1
 endif
 
-ifndef NO_LIBBABELTRACE
-  $(call feature_check,libbabeltrace)
-  ifeq ($(feature-libbabeltrace), 1)
-    CFLAGS += -DHAVE_LIBBABELTRACE_SUPPORT $(LIBBABELTRACE_CFLAGS)
-    LDFLAGS += $(LIBBABELTRACE_LDFLAGS)
-    EXTLIBS += -lbabeltrace-ctf
-    $(call detected,CONFIG_LIBBABELTRACE)
+ifndef NO_BABELTRACE2
+  $(call feature_check,babeltrace2-ctf-writer)
+  ifeq ($(feature-babeltrace2-ctf-writer), 1)
+    CFLAGS += -DHAVE_BABELTRACE2_CTF_WRITER_SUPPORT $(shell $(PKG_CONFIG) --cflags babeltrace2-ctf-writer)
+    LDFLAGS += $(shell $(PKG_CONFIG) --libs-only-L babeltrace2-ctf-writer)
+    EXTLIBS += $(shell $(PKG_CONFIG) --libs-only-l babeltrace2-ctf-writer)
+    $(call detected,CONFIG_BABELTRACE2_CTF_WRITER)
   else
-    $(warning No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev)
+    $(warning No babeltrace2 found, disables 'perf data' CTF format support, please install libbabeltrace2-dev[el])
   endif
 endif
 
tools/perf/Makefile.perf +1 -1
index 11b63bafdb23..ea830c07b952 100644
@@ -79,7 +79,7 @@ include ../scripts/utilities.mak
 #
 # Define NO_ZLIB if you do not want to support compressed kernel modules
 #
-# Define NO_LIBBABELTRACE if you do not want libbabeltrace support
+# Define NO_BABELTRACE2 if you do not want babeltrace2-ctf-writer support
 # for CTF data format.
 #
 # Define NO_CAPSTONE if you do not want libcapstone support
tools/perf/builtin-check.c +1 -1
index 3641d263b345..60437650c50f 100644
@@ -43,7 +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("babeltrace2-ctf-writer", HAVE_BABELTRACE2_CTF_WRITER_SUPPORT),
 	FEATURE_STATUS("libbpf-strings", HAVE_LIBBPF_STRINGS_SUPPORT),
 	FEATURE_STATUS("libcapstone", HAVE_LIBCAPSTONE_SUPPORT),
 	FEATURE_STATUS("libdw-dwarf-unwind", HAVE_LIBDW_SUPPORT),
tools/perf/builtin-data.c +4 -14
index 85f59886b5cf..d4fdb0d97a29 100644
@@ -40,10 +40,8 @@ const struct option data_options[] = {
 		OPT_INCR('v', "verbose", &verbose, "be more verbose"),
 		OPT_STRING('i', "input", &input_name, "file", "input file name"),
 		OPT_STRING(0, "to-json", &to_json, NULL, "Convert to JSON format"),
-#ifdef HAVE_LIBBABELTRACE_SUPPORT
 		OPT_STRING(0, "to-ctf", &to_ctf, NULL, "Convert to CTF format"),
 		OPT_BOOLEAN(0, "tod", &opts.tod, "Convert time to wall clock time"),
-#endif
 		OPT_BOOLEAN('f', "force", &opts.force, "don't complain, do it"),
 		OPT_BOOLEAN(0, "all", &opts.all, "Convert all events"),
 		OPT_STRING(0, "time", &opts.time_str, "str",
@@ -65,29 +63,21 @@ 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_LIBBABELTRACE_SUPPORT
 	if (!to_json && !to_ctf) {
 		pr_err("You must specify one of --to-ctf or --to-json.\n");
 		return -1;
 	}
-#else
-	if (!to_json) {
-		pr_err("You must specify --to-json.\n");
-	return -1;
-}
-#endif
 
 	if (to_json)
 		return bt_convert__perf2json(input_name, to_json, &opts);
 
 	if (to_ctf) {
-#if defined(HAVE_LIBBABELTRACE_SUPPORT) && defined(HAVE_LIBTRACEEVENT)
+#if defined(HAVE_BABELTRACE2_CTF_WRITER_SUPPORT) && defined(HAVE_LIBTRACEEVENT)
 		return bt_convert__perf2ctf(input_name, to_ctf, &opts);
 #else
-		pr_err("The libbabeltrace support is not compiled in. perf should be "
-		       "compiled with environment variables LIBBABELTRACE=1 and "
-		       "LIBBABELTRACE_DIR=/path/to/libbabeltrace/.\n"
-		       "Check also if libbtraceevent devel files are available.\n");
+		pr_err("The babeltrace2 ctf support is not compiled in. Ensure you have both\n"
+			"libbabeltrace2-dev[el] and libtraceevent-dev[el] installed or set\n"
+			"PKG_CONFIG_PATH to find a local installation of those libraries.\n");
 		return -1;
 #endif
 	}
tools/perf/tests/make +2 -2
index 6587dc326d1b..cc0138fa6d67 100644
@@ -93,7 +93,7 @@ make_no_libbpf	    := NO_LIBBPF=1
 make_libbpf_dynamic := LIBBPF_DYNAMIC=1
 make_no_libbpf_DEBUG := NO_LIBBPF=1 DEBUG=1
 make_no_libllvm     := NO_LIBLLVM=1
-make_with_babeltrace:= LIBBABELTRACE=1
+make_no_babeltrace2 := NO_BABELTRACE2=1
 make_with_coresight := CORESIGHT=1
 make_no_sdt	    := NO_SDT=1
 make_no_libpfm4     := NO_LIBPFM4=1
@@ -170,7 +170,7 @@ run += make_no_libbpf_DEBUG
 run += make_no_libllvm
 run += make_no_sdt
 run += make_no_syscall_tbl
-run += make_with_babeltrace
+run += make_no_babeltrace2
 run += make_with_coresight
 run += make_with_clangllvm
 run += make_no_libpfm4
tools/perf/tests/shell/test_perf_data_converter_ctf.sh +4 -4
index 334eebc9945e..bc58a8dabf4c 100755
@@ -24,11 +24,11 @@ trap_cleanup()
 }
 trap trap_cleanup exit term int
 
-check_babeltrace_support()
+check_babeltrace2_support()
 {
-	if ! perf check feature libbabeltrace
+	if ! perf check feature babeltrace2-ctf-writer
 	then
-		echo "perf not linked with libbabeltrace, skipping test"
+		echo "perf not linked with babeltrace2-ctf-writer, skipping test"
 		exit 2
 	fi
 }
@@ -97,7 +97,7 @@ test_ctf_converter_pipe()
 	fi
 }
 
-check_babeltrace_support
+check_babeltrace2_support
 test_ctf_converter_file
 test_ctf_converter_pipe
 
tools/perf/util/Build +1 -1
index bcccad7487a9..782f208cf30f 100644
@@ -233,7 +233,7 @@ perf-util-$(CONFIG_LIBUNWIND_X86)      += libunwind/x86_32.o
 perf-util-$(CONFIG_LIBUNWIND_AARCH64)  += libunwind/arm64.o
 
 ifeq ($(CONFIG_LIBTRACEEVENT),y)
-  perf-util-$(CONFIG_LIBBABELTRACE) += data-convert-bt.o
+  perf-util-$(CONFIG_BABELTRACE2_CTF_WRITER) += data-convert-bt.o
 endif
 
 perf-util-y += data-convert-json.o
tools/perf/util/data-convert-bt.c +16 -17
index ba1c8e48d495..91d8cdc9e8c7 100644
@@ -11,14 +11,13 @@
 #include <linux/compiler.h>
 #include <linux/kernel.h>
 #include <linux/zalloc.h>
-#include <babeltrace/ctf-writer/writer.h>
-#include <babeltrace/ctf-writer/clock.h>
-#include <babeltrace/ctf-writer/stream.h>
-#include <babeltrace/ctf-writer/event.h>
-#include <babeltrace/ctf-writer/event-types.h>
-#include <babeltrace/ctf-writer/event-fields.h>
-#include <babeltrace/ctf-ir/utils.h>
-#include <babeltrace/ctf/events.h>
+#include <babeltrace2-ctf-writer/writer.h>
+#include <babeltrace2-ctf-writer/clock.h>
+#include <babeltrace2-ctf-writer/stream.h>
+#include <babeltrace2-ctf-writer/event.h>
+#include <babeltrace2-ctf-writer/event-types.h>
+#include <babeltrace2-ctf-writer/event-fields.h>
+#include <babeltrace2-ctf-writer/utils.h>
 #include "asm/bug.h"
 #include "data-convert.h"
 #include "session.h"
@@ -121,13 +120,13 @@ static int value_set(struct bt_ctf_field_type *type,
 	}
 
 	if (sign) {
-		ret = bt_ctf_field_signed_integer_set_value(field, val);
+		ret = bt_ctf_field_integer_signed_set_value(field, val);
 		if (ret) {
 			pr_err("failed to set field value %s\n", name);
 			goto err;
 		}
 	} else {
-		ret = bt_ctf_field_unsigned_integer_set_value(field, val);
+		ret = bt_ctf_field_integer_unsigned_set_value(field, val);
 		if (ret) {
 			pr_err("failed to set field value %s\n", name);
 			goto err;
@@ -374,10 +373,10 @@ static int add_tracepoint_field_value(struct ctf_writer *cw,
 					data + offset + i * len, len);
 
 			if (!(flags & TEP_FIELD_IS_SIGNED))
-				ret = bt_ctf_field_unsigned_integer_set_value(
+				ret = bt_ctf_field_integer_unsigned_set_value(
 						field, value_int);
 			else
-				ret = bt_ctf_field_signed_integer_set_value(
+				ret = bt_ctf_field_integer_signed_set_value(
 						field, adjust_signedness(value_int, len));
 		}
 
@@ -471,7 +470,7 @@ add_bpf_output_values(struct bt_ctf_event_class *event_class,
 		goto put_len_type;
 	}
 
-	ret = bt_ctf_field_unsigned_integer_set_value(len_field, nr_elements);
+	ret = bt_ctf_field_integer_unsigned_set_value(len_field, nr_elements);
 	if (ret) {
 		pr_err("failed to set field value for raw_len\n");
 		goto put_len_field;
@@ -500,7 +499,7 @@ add_bpf_output_values(struct bt_ctf_event_class *event_class,
 		struct bt_ctf_field *elem_field =
 			bt_ctf_field_sequence_get_field(seq_field, i);
 
-		ret = bt_ctf_field_unsigned_integer_set_value(elem_field,
+		ret = bt_ctf_field_integer_unsigned_set_value(elem_field,
 				((u32 *)(sample->raw_data))[i]);
 
 		bt_ctf_field_put(elem_field);
@@ -545,7 +544,7 @@ add_callchain_output_values(struct bt_ctf_event_class *event_class,
 		goto put_len_type;
 	}
 
-	ret = bt_ctf_field_unsigned_integer_set_value(len_field, nr_elements);
+	ret = bt_ctf_field_integer_unsigned_set_value(len_field, nr_elements);
 	if (ret) {
 		pr_err("failed to set field value for perf_callchain_size\n");
 		goto put_len_field;
@@ -575,7 +574,7 @@ add_callchain_output_values(struct bt_ctf_event_class *event_class,
 		struct bt_ctf_field *elem_field =
 			bt_ctf_field_sequence_get_field(seq_field, i);
 
-		ret = bt_ctf_field_unsigned_integer_set_value(elem_field,
+		ret = bt_ctf_field_integer_unsigned_set_value(elem_field,
 				((u64 *)(callchain->ips))[i]);
 
 		bt_ctf_field_put(elem_field);
@@ -728,7 +727,7 @@ static struct ctf_stream *ctf_stream__create(struct ctf_writer *cw, int cpu)
 		goto out;
 	}
 
-	ret = bt_ctf_field_unsigned_integer_set_value(cpu_field, (u32) cpu);
+	ret = bt_ctf_field_integer_unsigned_set_value(cpu_field, (u32) cpu);
 	if (ret) {
 		pr_err("Failed to update CPU number\n");
 		goto out;
tools/perf/util/data-convert.h +2 -2
index ee651fa680a1..a96240f15671 100644
@@ -11,10 +11,10 @@ struct perf_data_convert_opts {
 	const char *time_str;
 };
 
-#ifdef HAVE_LIBBABELTRACE_SUPPORT
+#ifdef HAVE_BABELTRACE2_CTF_WRITER_SUPPORT
 int bt_convert__perf2ctf(const char *input_name, const char *to_ctf,
 			 struct perf_data_convert_opts *opts);
-#endif /* HAVE_LIBBABELTRACE_SUPPORT */
+#endif /* HAVE_BABELTRACE2_CTF_WRITER_SUPPORT */
 
 int bt_convert__perf2json(const char *input_name, const char *to_ctf,
 			 struct perf_data_convert_opts *opts);
Signature · 1 line
2.47.3
reviewer Reviewed-by on v3 1/1
#13 lore raw
Quoted 20 lines · Michael Jeanson

The 1.x branch of Babeltrace has been superseded by 2.x in 2020 and has been unmaintained since 2022, efforts have started to remove it from popular distributions.

Babeltrace 2.x offers a very similar 'ctf-writer' library that can be used with minimal changes for the '--to-ctf' feature and has been packaged since Debian 11 and Fedora 32.

This patch replaces the 'libbabeltrace' build feature with 'babeltrace2-ctf-writer' using pkgconfig detection, adjusts the naming of the public headers and applies minor API cleanups.

There is no changes to the output ctf traces, the ctf-writer API still implements version 1.8 of the CTF specification that can be read by either Babeltrace 1 / 2 or any CTF compliant reader.

Also remove some ifdefs in the cli option parsing to allow printing the helpful error message with '--to-ctf' when built without babeltrace2.

Quoted 13 lines
Cc Adrian Hunter <[email protected]>
Cc Alexander Shishkin <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Derek Foreman <[email protected]>
Cc Ian Rogers <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc James Clark <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Mathieu Desnoyers <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Peter Zijlstra <[email protected]>

Thanks!
Ian

Quoted 419 lines

---
Changes since v2:
* Revert babeltrace 1 fallback
* Rebase on perf-tools-next
Changes since v1:
* Keep babeltrace 1 support as fallback

---
 tools/build/Makefile.feature                  |  5 +--
 tools/build/feature/Makefile                  |  6 ++--
 tools/build/feature/test-all.c                |  6 ++--
 ...ltrace.c => test-babeltrace2-ctf-writer.c} |  3 +-
 tools/perf/Makefile.config                    | 27 +++++++--------
 tools/perf/Makefile.perf                      |  2 +-
 tools/perf/builtin-check.c                    |  2 +-
 tools/perf/builtin-data.c                     | 18 +++-------
 tools/perf/tests/make                         |  4 +--
 .../shell/test_perf_data_converter_ctf.sh     |  8 ++---
 tools/perf/util/Build                         |  2 +-
 tools/perf/util/data-convert-bt.c             | 33 +++++++++----------
 tools/perf/util/data-convert.h                |  4 +--
 13 files changed, 53 insertions(+), 67 deletions(-)
 rename tools/build/feature/{test-libbabeltrace.c => test-babeltrace2-ctf-writer.c} (59%)
tools/build/Makefile.feature +3 -2
index 0b7a7c38cb88..9e097144817e 100644
@@ -113,7 +113,7 @@ FEATURE_TESTS_EXTRA :=                  \
          gtk2                           \
          gtk2-infobar                   \
          hello                          \
-         libbabeltrace                  \
+         babeltrace2-ctf-writer         \
          libcapstone                    \
          libbfd-liberty                 \
          libbfd-liberty-z               \
@@ -162,6 +162,7 @@ FEATURE_GROUP_MEMBERS-libbfd = libbfd-liberty libbfd-liberty-z
 # Declare list of feature dependency packages that provide pkg-config files.
 #
 FEATURE_PKG_CONFIG ?=           \
+        babeltrace2-ctf-writer \
          libtraceevent          \
          libtracefs
 
@@ -208,7 +209,7 @@ ifeq ($(feature-all), 1)
   $(call feature_check,compile-32)
   $(call feature_check,compile-x32)
   $(call feature_check,bionic)
-  $(call feature_check,libbabeltrace)
+  $(call feature_check,babeltrace2-ctf-writer)
 else
   $(foreach feat,$(FEATURE_TESTS),$(call feature_check,$(feat)))
 endif
tools/build/feature/Makefile +3 -3
index 1fbcb3ce74d2..7735e257c263 100644
@@ -48,7 +48,7 @@ FILES=                                          \
          test-pthread-barrier.bin              \
          test-stackprotector-all.bin            \
          test-timerfd.bin                       \
-         test-libbabeltrace.bin                 \
+         test-babeltrace2-ctf-writer.bin        \
          test-libcapstone.bin                  \
          test-compile-32.bin                    \
          test-compile-x32.bin                   \
@@ -301,8 +301,8 @@ $(OUTPUT)test-backtrace.bin:
 $(OUTPUT)test-timerfd.bin:
        $(BUILD)
 
-$(OUTPUT)test-libbabeltrace.bin:
-       $(BUILD) # -lbabeltrace provided by $(FEATURE_CHECK_LDFLAGS-libbabeltrace)
+$(OUTPUT)test-babeltrace2-ctf-writer.bin:
+       $(BUILD) # -lbabeltrace2-ctf-writer provided by $(FEATURE_CHECK_LDFLAGS-babeltrace2-ctf-writer)
 
 $(OUTPUT)test-libcapstone.bin:
        $(BUILD) # -lcapstone provided by $(FEATURE_CHECK_LDFLAGS-libcapstone)
tools/build/feature/test-all.c +3 -3
index 1488bf6e6078..544563d62950 100644
@@ -100,13 +100,13 @@
 
 # if 0
 /*
- * Disable libbabeltrace check for test-all, because the requested
+ * Disable babeltrace2-ctf-writer check for test-all, because the requested
  * library version is not released yet in most distributions. Will
  * reenable later.
  */
 
-#define main main_test_libbabeltrace
-# include "test-libbabeltrace.c"
+#define main main_test_babeltrace2_ctf_writer
+# include "test-babeltrace2-ctf-writer.c"
 #undef main
 #endif
 
tools/build/feature/test-babeltrace2-ctf-writer.c renamed from tools/build/feature/test-libbabeltrace.c +1 -2
similarity index 59%
rename from tools/build/feature/test-libbabeltrace.c
rename to tools/build/feature/test-babeltrace2-ctf-writer.c
index 10bb69d55694..9c89082e9f88 100644
@@ -1,7 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 
-#include <babeltrace/ctf-writer/writer.h>
-#include <babeltrace/ctf-ir/stream-class.h>
+#include <babeltrace2-ctf-writer/writer.h>
 
 int main(void)
 {
tools/perf/Makefile.config +12 -15
index a8dc72cfe48e..856d2831d53c 100644
@@ -195,14 +195,11 @@ endif
 FEATURE_CHECK_CFLAGS-libdw := $(LIBDW_CFLAGS)
 FEATURE_CHECK_LDFLAGS-libdw := $(LIBDW_LDFLAGS) $(DWARFLIBS)
 
-# for linking with debug library, run like:
-# make DEBUG=1 LIBBABELTRACE_DIR=/opt/libbabeltrace/
-ifdef LIBBABELTRACE_DIR
-  LIBBABELTRACE_CFLAGS  := -I$(LIBBABELTRACE_DIR)/include
-  LIBBABELTRACE_LDFLAGS := -L$(LIBBABELTRACE_DIR)/lib
+ifneq ($(NO_BABELTRACE2),1)
+  ifeq ($(call get-executable,$(PKG_CONFIG)),)
+    $(error Error: $(PKG_CONFIG) needed by babeltrace2 is missing on this system, please install it)
+  endif
 endif
-FEATURE_CHECK_CFLAGS-libbabeltrace := $(LIBBABELTRACE_CFLAGS)
-FEATURE_CHECK_LDFLAGS-libbabeltrace := $(LIBBABELTRACE_LDFLAGS) -lbabeltrace-ctf
 
 # for linking with debug library, run like:
 # make DEBUG=1 LIBCAPSTONE_DIR=/opt/capstone/
@@ -1058,15 +1055,15 @@ else
   NO_PERF_READ_VDSOX32 := 1
 endif
 
-ifndef NO_LIBBABELTRACE
-  $(call feature_check,libbabeltrace)
-  ifeq ($(feature-libbabeltrace), 1)
-    CFLAGS += -DHAVE_LIBBABELTRACE_SUPPORT $(LIBBABELTRACE_CFLAGS)
-    LDFLAGS += $(LIBBABELTRACE_LDFLAGS)
-    EXTLIBS += -lbabeltrace-ctf
-    $(call detected,CONFIG_LIBBABELTRACE)
+ifndef NO_BABELTRACE2
+  $(call feature_check,babeltrace2-ctf-writer)
+  ifeq ($(feature-babeltrace2-ctf-writer), 1)
+    CFLAGS += -DHAVE_BABELTRACE2_CTF_WRITER_SUPPORT $(shell $(PKG_CONFIG) --cflags babeltrace2-ctf-writer)
+    LDFLAGS += $(shell $(PKG_CONFIG) --libs-only-L babeltrace2-ctf-writer)
+    EXTLIBS += $(shell $(PKG_CONFIG) --libs-only-l babeltrace2-ctf-writer)
+    $(call detected,CONFIG_BABELTRACE2_CTF_WRITER)
   else
-    $(warning No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev)
+    $(warning No babeltrace2 found, disables 'perf data' CTF format support, please install libbabeltrace2-dev[el])
   endif
 endif
 
tools/perf/Makefile.perf +1 -1
index 11b63bafdb23..ea830c07b952 100644
@@ -79,7 +79,7 @@ include ../scripts/utilities.mak
 #
 # Define NO_ZLIB if you do not want to support compressed kernel modules
 #
-# Define NO_LIBBABELTRACE if you do not want libbabeltrace support
+# Define NO_BABELTRACE2 if you do not want babeltrace2-ctf-writer support
 # for CTF data format.
 #
 # Define NO_CAPSTONE if you do not want libcapstone support
tools/perf/builtin-check.c +1 -1
index 3641d263b345..60437650c50f 100644
@@ -43,7 +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("babeltrace2-ctf-writer", HAVE_BABELTRACE2_CTF_WRITER_SUPPORT),
        FEATURE_STATUS("libbpf-strings", HAVE_LIBBPF_STRINGS_SUPPORT),
        FEATURE_STATUS("libcapstone", HAVE_LIBCAPSTONE_SUPPORT),
        FEATURE_STATUS("libdw-dwarf-unwind", HAVE_LIBDW_SUPPORT),
tools/perf/builtin-data.c +4 -14
index 85f59886b5cf..d4fdb0d97a29 100644
@@ -40,10 +40,8 @@ const struct option data_options[] = {
                OPT_INCR('v', "verbose", &verbose, "be more verbose"),
                OPT_STRING('i', "input", &input_name, "file", "input file name"),
                OPT_STRING(0, "to-json", &to_json, NULL, "Convert to JSON format"),
-#ifdef HAVE_LIBBABELTRACE_SUPPORT
                OPT_STRING(0, "to-ctf", &to_ctf, NULL, "Convert to CTF format"),
                OPT_BOOLEAN(0, "tod", &opts.tod, "Convert time to wall clock time"),
-#endif
                OPT_BOOLEAN('f', "force", &opts.force, "don't complain, do it"),
                OPT_BOOLEAN(0, "all", &opts.all, "Convert all events"),
                OPT_STRING(0, "time", &opts.time_str, "str",
@@ -65,29 +63,21 @@ 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_LIBBABELTRACE_SUPPORT
        if (!to_json && !to_ctf) {
                pr_err("You must specify one of --to-ctf or --to-json.\n");
                return -1;
        }
-#else
-       if (!to_json) {
-               pr_err("You must specify --to-json.\n");
-       return -1;
-}
-#endif
 
        if (to_json)
                return bt_convert__perf2json(input_name, to_json, &opts);
 
        if (to_ctf) {
-#if defined(HAVE_LIBBABELTRACE_SUPPORT) && defined(HAVE_LIBTRACEEVENT)
+#if defined(HAVE_BABELTRACE2_CTF_WRITER_SUPPORT) && defined(HAVE_LIBTRACEEVENT)
                return bt_convert__perf2ctf(input_name, to_ctf, &opts);
 #else
-               pr_err("The libbabeltrace support is not compiled in. perf should be "
-                      "compiled with environment variables LIBBABELTRACE=1 and "
-                      "LIBBABELTRACE_DIR=/path/to/libbabeltrace/.\n"
-                      "Check also if libbtraceevent devel files are available.\n");
+               pr_err("The babeltrace2 ctf support is not compiled in. Ensure you have both\n"
+                       "libbabeltrace2-dev[el] and libtraceevent-dev[el] installed or set\n"
+                       "PKG_CONFIG_PATH to find a local installation of those libraries.\n");
                return -1;
 #endif
        }
tools/perf/tests/make +2 -2
index 6587dc326d1b..cc0138fa6d67 100644
@@ -93,7 +93,7 @@ make_no_libbpf            := NO_LIBBPF=1
 make_libbpf_dynamic := LIBBPF_DYNAMIC=1
 make_no_libbpf_DEBUG := NO_LIBBPF=1 DEBUG=1
 make_no_libllvm     := NO_LIBLLVM=1
-make_with_babeltrace:= LIBBABELTRACE=1
+make_no_babeltrace2 := NO_BABELTRACE2=1
 make_with_coresight := CORESIGHT=1
 make_no_sdt        := NO_SDT=1
 make_no_libpfm4     := NO_LIBPFM4=1
@@ -170,7 +170,7 @@ run += make_no_libbpf_DEBUG
 run += make_no_libllvm
 run += make_no_sdt
 run += make_no_syscall_tbl
-run += make_with_babeltrace
+run += make_no_babeltrace2
 run += make_with_coresight
 run += make_with_clangllvm
 run += make_no_libpfm4
tools/perf/tests/shell/test_perf_data_converter_ctf.sh +4 -4
index 334eebc9945e..bc58a8dabf4c 100755
@@ -24,11 +24,11 @@ trap_cleanup()
 }
 trap trap_cleanup exit term int
 
-check_babeltrace_support()
+check_babeltrace2_support()
 {
-       if ! perf check feature libbabeltrace
+       if ! perf check feature babeltrace2-ctf-writer
        then
-               echo "perf not linked with libbabeltrace, skipping test"
+               echo "perf not linked with babeltrace2-ctf-writer, skipping test"
                exit 2
        fi
 }
@@ -97,7 +97,7 @@ test_ctf_converter_pipe()
        fi
 }
 
-check_babeltrace_support
+check_babeltrace2_support
 test_ctf_converter_file
 test_ctf_converter_pipe
 
tools/perf/util/Build +1 -1
index bcccad7487a9..782f208cf30f 100644
@@ -233,7 +233,7 @@ perf-util-$(CONFIG_LIBUNWIND_X86)      += libunwind/x86_32.o
 perf-util-$(CONFIG_LIBUNWIND_AARCH64)  += libunwind/arm64.o
 
 ifeq ($(CONFIG_LIBTRACEEVENT),y)
-  perf-util-$(CONFIG_LIBBABELTRACE) += data-convert-bt.o
+  perf-util-$(CONFIG_BABELTRACE2_CTF_WRITER) += data-convert-bt.o
 endif
 
 perf-util-y += data-convert-json.o
tools/perf/util/data-convert-bt.c +16 -17
index ba1c8e48d495..91d8cdc9e8c7 100644
@@ -11,14 +11,13 @@
 #include <linux/compiler.h>
 #include <linux/kernel.h>
 #include <linux/zalloc.h>
-#include <babeltrace/ctf-writer/writer.h>
-#include <babeltrace/ctf-writer/clock.h>
-#include <babeltrace/ctf-writer/stream.h>
-#include <babeltrace/ctf-writer/event.h>
-#include <babeltrace/ctf-writer/event-types.h>
-#include <babeltrace/ctf-writer/event-fields.h>
-#include <babeltrace/ctf-ir/utils.h>
-#include <babeltrace/ctf/events.h>
+#include <babeltrace2-ctf-writer/writer.h>
+#include <babeltrace2-ctf-writer/clock.h>
+#include <babeltrace2-ctf-writer/stream.h>
+#include <babeltrace2-ctf-writer/event.h>
+#include <babeltrace2-ctf-writer/event-types.h>
+#include <babeltrace2-ctf-writer/event-fields.h>
+#include <babeltrace2-ctf-writer/utils.h>
 #include "asm/bug.h"
 #include "data-convert.h"
 #include "session.h"
@@ -121,13 +120,13 @@ static int value_set(struct bt_ctf_field_type *type,
        }
 
        if (sign) {
-               ret = bt_ctf_field_signed_integer_set_value(field, val);
+               ret = bt_ctf_field_integer_signed_set_value(field, val);
                if (ret) {
                        pr_err("failed to set field value %s\n", name);
                        goto err;
                }
        } else {
-               ret = bt_ctf_field_unsigned_integer_set_value(field, val);
+               ret = bt_ctf_field_integer_unsigned_set_value(field, val);
                if (ret) {
                        pr_err("failed to set field value %s\n", name);
                        goto err;
@@ -374,10 +373,10 @@ static int add_tracepoint_field_value(struct ctf_writer *cw,
                                        data + offset + i * len, len);
 
                        if (!(flags & TEP_FIELD_IS_SIGNED))
-                               ret = bt_ctf_field_unsigned_integer_set_value(
+                               ret = bt_ctf_field_integer_unsigned_set_value(
                                                field, value_int);
                        else
-                               ret = bt_ctf_field_signed_integer_set_value(
+                               ret = bt_ctf_field_integer_signed_set_value(
                                                field, adjust_signedness(value_int, len));
                }
 
@@ -471,7 +470,7 @@ add_bpf_output_values(struct bt_ctf_event_class *event_class,
                goto put_len_type;
        }
 
-       ret = bt_ctf_field_unsigned_integer_set_value(len_field, nr_elements);
+       ret = bt_ctf_field_integer_unsigned_set_value(len_field, nr_elements);
        if (ret) {
                pr_err("failed to set field value for raw_len\n");
                goto put_len_field;
@@ -500,7 +499,7 @@ add_bpf_output_values(struct bt_ctf_event_class *event_class,
                struct bt_ctf_field *elem_field =
                        bt_ctf_field_sequence_get_field(seq_field, i);
 
-               ret = bt_ctf_field_unsigned_integer_set_value(elem_field,
+               ret = bt_ctf_field_integer_unsigned_set_value(elem_field,
                                ((u32 *)(sample->raw_data))[i]);
 
                bt_ctf_field_put(elem_field);
@@ -545,7 +544,7 @@ add_callchain_output_values(struct bt_ctf_event_class *event_class,
                goto put_len_type;
        }
 
-       ret = bt_ctf_field_unsigned_integer_set_value(len_field, nr_elements);
+       ret = bt_ctf_field_integer_unsigned_set_value(len_field, nr_elements);
        if (ret) {
                pr_err("failed to set field value for perf_callchain_size\n");
                goto put_len_field;
@@ -575,7 +574,7 @@ add_callchain_output_values(struct bt_ctf_event_class *event_class,
                struct bt_ctf_field *elem_field =
                        bt_ctf_field_sequence_get_field(seq_field, i);
 
-               ret = bt_ctf_field_unsigned_integer_set_value(elem_field,
+               ret = bt_ctf_field_integer_unsigned_set_value(elem_field,
                                ((u64 *)(callchain->ips))[i]);
 
                bt_ctf_field_put(elem_field);
@@ -728,7 +727,7 @@ static struct ctf_stream *ctf_stream__create(struct ctf_writer *cw, int cpu)
                goto out;
        }
 
-       ret = bt_ctf_field_unsigned_integer_set_value(cpu_field, (u32) cpu);
+       ret = bt_ctf_field_integer_unsigned_set_value(cpu_field, (u32) cpu);
        if (ret) {
                pr_err("Failed to update CPU number\n");
                goto out;
tools/perf/util/data-convert.h +2 -3
index ee651fa680a1..a96240f15671 100644
@@ -11,10 +11,10 @@ struct perf_data_convert_opts {
        const char *time_str;
 };
 
-#ifdef HAVE_LIBBABELTRACE_SUPPORT
+#ifdef HAVE_BABELTRACE2_CTF_WRITER_SUPPORT
 int bt_convert__perf2ctf(const char *input_name, const char *to_ctf,
                         struct perf_data_convert_opts *opts);
-#endif /* HAVE_LIBBABELTRACE_SUPPORT */
+#endif /* HAVE_BABELTRACE2_CTF_WRITER_SUPPORT */
 
 int bt_convert__perf2json(const char *input_name, const char *to_ctf,
                         struct perf_data_convert_opts *opts);
--

2.47.3

#14 lore raw
Quoted 35 lines · Ian Rogers
Quoted 20 lines · Michael Jeanson

The 1.x branch of Babeltrace has been superseded by 2.x in 2020 and has been unmaintained since 2022, efforts have started to remove it from popular distributions.

Babeltrace 2.x offers a very similar 'ctf-writer' library that can be used with minimal changes for the '--to-ctf' feature and has been packaged since Debian 11 and Fedora 32.

This patch replaces the 'libbabeltrace' build feature with 'babeltrace2-ctf-writer' using pkgconfig detection, adjusts the naming of the public headers and applies minor API cleanups.

There is no changes to the output ctf traces, the ctf-writer API still implements version 1.8 of the CTF specification that can be read by either Babeltrace 1 / 2 or any CTF compliant reader.

Also remove some ifdefs in the cli option parsing to allow printing the helpful error message with '--to-ctf' when built without babeltrace2.

Quoted 13 lines
Cc Adrian Hunter <[email protected]>
Cc Alexander Shishkin <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Derek Foreman <[email protected]>
Cc Ian Rogers <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc James Clark <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Mathieu Desnoyers <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Peter Zijlstra <[email protected]>
Quoted 1 line

Its not applying to perf-tools-next, Michael, can you please take a look?

Thanks,

- Arnaldo

#15 lore raw
Quoted 36 lines · Arnaldo Carvalho de Melo
Quoted 35 lines · Ian Rogers
Quoted 33 lines · Michael Jeanson

The 1.x branch of Babeltrace has been superseded by 2.x in 2020 and has been unmaintained since 2022, efforts have started to remove it from popular distributions.

Babeltrace 2.x offers a very similar 'ctf-writer' library that can be used with minimal changes for the '--to-ctf' feature and has been packaged since Debian 11 and Fedora 32.

This patch replaces the 'libbabeltrace' build feature with 'babeltrace2-ctf-writer' using pkgconfig detection, adjusts the naming of the public headers and applies minor API cleanups.

There is no changes to the output ctf traces, the ctf-writer API still implements version 1.8 of the CTF specification that can be read by either Babeltrace 1 / 2 or any CTF compliant reader.

Also remove some ifdefs in the cli option parsing to allow printing the helpful error message with '--to-ctf' when built without babeltrace2.

Cc Adrian Hunter <[email protected]>
Cc Alexander Shishkin <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Derek Foreman <[email protected]>
Cc Ian Rogers <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc James Clark <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Mathieu Desnoyers <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Peter Zijlstra <[email protected]>
Quoted 4 lines
Quoted 1 line

Its not applying to perf-tools-next, Michael, can you please take a look?

Not sure what happenend, I rebased it on current perf-tools-next and sent it again as v4. Sorry for the noise.

Michael

Quoted 4 lines

Thanks,

- Arnaldo

#16 lore raw

PATCH v4 1/1 perf data ctf: replace libbabeltrace with babeltrace2-ctf-writer

In reply to Michael Jeanson

The 1.x branch of Babeltrace has been superseded by 2.x in 2020 and has been unmaintained since 2022, efforts have started to remove it from popular distributions.

Babeltrace 2.x offers a very similar 'ctf-writer' library that can be used with minimal changes for the '--to-ctf' feature and has been packaged since Debian 11 and Fedora 32.

This patch replaces the 'libbabeltrace' build feature with 'babeltrace2-ctf-writer' using pkgconfig detection, adjusts the naming of the public headers and applies minor API cleanups.

There is no changes to the output ctf traces, the ctf-writer API still implements version 1.8 of the CTF specification that can be read by either Babeltrace 1 / 2 or any CTF compliant reader.

Also remove some ifdefs in the cli option parsing to allow printing the helpful error message with '--to-ctf' when built without babeltrace2.

Cc Adrian Hunter <[email protected]>
Cc Alexander Shishkin <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Derek Foreman <[email protected]>
Cc Ian Rogers <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc James Clark <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Mathieu Desnoyers <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Peter Zijlstra <[email protected]>

---
Changes since v3:
* Rebase on current perf-tools-next
Changes since v2:
* Revert babeltrace 1 fallback
* Rebase on perf-tools-next
Changes since v1:
* Keep babeltrace 1 support as fallback

---
 tools/build/Makefile.feature                  |  5 +--
 tools/build/feature/Makefile                  |  6 ++--
 tools/build/feature/test-all.c                |  6 ++--
 ...ltrace.c => test-babeltrace2-ctf-writer.c} |  3 +-
 tools/perf/Makefile.config                    | 27 +++++++--------
 tools/perf/Makefile.perf                      |  2 +-
 tools/perf/builtin-check.c                    |  2 +-
 tools/perf/builtin-data.c                     | 18 +++-------
 tools/perf/tests/make                         |  4 +--
 .../shell/test_perf_data_converter_ctf.sh     |  8 ++---
 tools/perf/util/Build                         |  2 +-
 tools/perf/util/data-convert-bt.c             | 33 +++++++++----------
 tools/perf/util/data-convert.h                |  4 +--
 13 files changed, 53 insertions(+), 67 deletions(-)
 rename tools/build/feature/{test-libbabeltrace.c => test-babeltrace2-ctf-writer.c} (59%)
tools/build/Makefile.feature +3 -2
index af79c6cf0229..ed1374af31c1 100644
@@ -116,7 +116,7 @@ FEATURE_TESTS_EXTRA :=                  \
          gtk2                           \
          gtk2-infobar                   \
          hello                          \
-         libbabeltrace                  \
+         babeltrace2-ctf-writer         \
          libcapstone                    \
          libcheck                       \
          libbfd-liberty                 \
@@ -169,6 +169,7 @@ FEATURE_GROUP_MEMBERS-libbfd = libbfd-liberty libbfd-liberty-z
 # Declare list of feature dependency packages that provide pkg-config files.
 #
 FEATURE_PKG_CONFIG ?=           \
+	 babeltrace2-ctf-writer \
          libtraceevent          \
          libtracefs
 
@@ -217,7 +218,7 @@ ifeq ($(feature-all), 1)
   $(call feature_check,compile-32)
   $(call feature_check,compile-x32)
   $(call feature_check,bionic)
-  $(call feature_check,libbabeltrace)
+  $(call feature_check,babeltrace2-ctf-writer)
   $(call feature_check,libunwind)
   $(call feature_check,libunwind-debug-frame)
   $(foreach arch,$(LIBUNWIND_ARCHS),$(call feature_check,libunwind-$(arch)))
tools/build/feature/Makefile +3 -3
index 4e4a92ef5e1e..fac5d82c2a58 100644
@@ -45,7 +45,7 @@ FILES=                                          \
          test-pthread-barrier.bin		\
          test-stackprotector-all.bin            \
          test-timerfd.bin                       \
-         test-libbabeltrace.bin                 \
+         test-babeltrace2-ctf-writer.bin        \
          test-libcapstone.bin			\
          test-libcheck.bin			\
          test-compile-32.bin                    \
@@ -304,8 +304,8 @@ $(OUTPUT)test-backtrace.bin:
 $(OUTPUT)test-timerfd.bin:
 	$(BUILD)
 
-$(OUTPUT)test-libbabeltrace.bin:
-	$(BUILD) # -lbabeltrace provided by $(FEATURE_CHECK_LDFLAGS-libbabeltrace)
+$(OUTPUT)test-babeltrace2-ctf-writer.bin:
+	$(BUILD) # -lbabeltrace2-ctf-writer provided by $(FEATURE_CHECK_LDFLAGS-babeltrace2-ctf-writer)
 
 $(OUTPUT)test-libcapstone.bin:
 	$(BUILD) # -lcapstone provided by $(FEATURE_CHECK_LDFLAGS-libcapstone)
tools/build/feature/test-all.c +3 -3
index 1488bf6e6078..544563d62950 100644
@@ -100,13 +100,13 @@
 
 # if 0
 /*
- * Disable libbabeltrace check for test-all, because the requested
+ * Disable babeltrace2-ctf-writer check for test-all, because the requested
  * library version is not released yet in most distributions. Will
  * reenable later.
  */
 
-#define main main_test_libbabeltrace
-# include "test-libbabeltrace.c"
+#define main main_test_babeltrace2_ctf_writer
+# include "test-babeltrace2-ctf-writer.c"
 #undef main
 #endif
 
tools/build/feature/test-babeltrace2-ctf-writer.c renamed from tools/build/feature/test-libbabeltrace.c +1 -2
similarity index 59%
rename from tools/build/feature/test-libbabeltrace.c
rename to tools/build/feature/test-babeltrace2-ctf-writer.c
index 10bb69d55694..9c89082e9f88 100644
@@ -1,7 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 
-#include <babeltrace/ctf-writer/writer.h>
-#include <babeltrace/ctf-ir/stream-class.h>
+#include <babeltrace2-ctf-writer/writer.h>
 
 int main(void)
 {
tools/perf/Makefile.config +12 -15
index c531b9315609..6e7b15fab2ec 100644
@@ -184,14 +184,11 @@ endif
 FEATURE_CHECK_CFLAGS-libdw := $(LIBDW_CFLAGS)
 FEATURE_CHECK_LDFLAGS-libdw := $(LIBDW_LDFLAGS) $(DWARFLIBS)
 
-# for linking with debug library, run like:
-# make DEBUG=1 LIBBABELTRACE_DIR=/opt/libbabeltrace/
-ifdef LIBBABELTRACE_DIR
-  LIBBABELTRACE_CFLAGS  := -I$(LIBBABELTRACE_DIR)/include
-  LIBBABELTRACE_LDFLAGS := -L$(LIBBABELTRACE_DIR)/lib
+ifneq ($(NO_BABELTRACE2),1)
+  ifeq ($(call get-executable,$(PKG_CONFIG)),)
+    $(error Error: $(PKG_CONFIG) needed by babeltrace2 is missing on this system, please install it)
+  endif
 endif
-FEATURE_CHECK_CFLAGS-libbabeltrace := $(LIBBABELTRACE_CFLAGS)
-FEATURE_CHECK_LDFLAGS-libbabeltrace := $(LIBBABELTRACE_LDFLAGS) -lbabeltrace-ctf
 
 # for linking with debug library, run like:
 # make DEBUG=1 LIBCAPSTONE_DIR=/opt/capstone/
@@ -1035,15 +1032,15 @@ else
   NO_PERF_READ_VDSOX32 := 1
 endif
 
-ifndef NO_LIBBABELTRACE
-  $(call feature_check,libbabeltrace)
-  ifeq ($(feature-libbabeltrace), 1)
-    CFLAGS += -DHAVE_LIBBABELTRACE_SUPPORT $(LIBBABELTRACE_CFLAGS)
-    LDFLAGS += $(LIBBABELTRACE_LDFLAGS)
-    EXTLIBS += -lbabeltrace-ctf
-    $(call detected,CONFIG_LIBBABELTRACE)
+ifndef NO_BABELTRACE2
+  $(call feature_check,babeltrace2-ctf-writer)
+  ifeq ($(feature-babeltrace2-ctf-writer), 1)
+    CFLAGS += -DHAVE_BABELTRACE2_CTF_WRITER_SUPPORT $(shell $(PKG_CONFIG) --cflags babeltrace2-ctf-writer)
+    LDFLAGS += $(shell $(PKG_CONFIG) --libs-only-L babeltrace2-ctf-writer)
+    EXTLIBS += $(shell $(PKG_CONFIG) --libs-only-l babeltrace2-ctf-writer)
+    $(call detected,CONFIG_BABELTRACE2_CTF_WRITER)
   else
-    $(warning No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev)
+    $(warning No babeltrace2 found, disables 'perf data' CTF format support, please install libbabeltrace2-dev[el])
   endif
 endif
 
tools/perf/Makefile.perf +1 -1
index 4ac2a0cec9ee..ab661a1d271c 100644
@@ -79,7 +79,7 @@ include ../scripts/utilities.mak
 #
 # Define NO_ZLIB if you do not want to support compressed kernel modules
 #
-# Define NO_LIBBABELTRACE if you do not want libbabeltrace support
+# Define NO_BABELTRACE2 if you do not want babeltrace2-ctf-writer support
 # for CTF data format.
 #
 # Define NO_CAPSTONE if you do not want libcapstone support
tools/perf/builtin-check.c +1 -1
index 3641d263b345..60437650c50f 100644
@@ -43,7 +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("babeltrace2-ctf-writer", HAVE_BABELTRACE2_CTF_WRITER_SUPPORT),
 	FEATURE_STATUS("libbpf-strings", HAVE_LIBBPF_STRINGS_SUPPORT),
 	FEATURE_STATUS("libcapstone", HAVE_LIBCAPSTONE_SUPPORT),
 	FEATURE_STATUS("libdw-dwarf-unwind", HAVE_LIBDW_SUPPORT),
tools/perf/builtin-data.c +4 -14
index 4c08ccb8c06b..1dd73ed6bdcb 100644
@@ -40,10 +40,8 @@ static const struct option data_options[] = {
 		OPT_INCR('v', "verbose", &verbose, "be more verbose"),
 		OPT_STRING('i', "input", &input_name, "file", "input file name"),
 		OPT_STRING(0, "to-json", &to_json, NULL, "Convert to JSON format"),
-#ifdef HAVE_LIBBABELTRACE_SUPPORT
 		OPT_STRING(0, "to-ctf", &to_ctf, NULL, "Convert to CTF format"),
 		OPT_BOOLEAN(0, "tod", &opts.tod, "Convert time to wall clock time"),
-#endif
 		OPT_BOOLEAN('f', "force", &opts.force, "don't complain, do it"),
 		OPT_BOOLEAN(0, "all", &opts.all, "Convert all events"),
 		OPT_STRING(0, "time", &opts.time_str, "str",
@@ -65,29 +63,21 @@ 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_LIBBABELTRACE_SUPPORT
 	if (!to_json && !to_ctf) {
 		pr_err("You must specify one of --to-ctf or --to-json.\n");
 		return -1;
 	}
-#else
-	if (!to_json) {
-		pr_err("You must specify --to-json.\n");
-	return -1;
-}
-#endif
 
 	if (to_json)
 		return bt_convert__perf2json(input_name, to_json, &opts);
 
 	if (to_ctf) {
-#if defined(HAVE_LIBBABELTRACE_SUPPORT) && defined(HAVE_LIBTRACEEVENT)
+#if defined(HAVE_BABELTRACE2_CTF_WRITER_SUPPORT) && defined(HAVE_LIBTRACEEVENT)
 		return bt_convert__perf2ctf(input_name, to_ctf, &opts);
 #else
-		pr_err("The libbabeltrace support is not compiled in. perf should be "
-		       "compiled with environment variables LIBBABELTRACE=1 and "
-		       "LIBBABELTRACE_DIR=/path/to/libbabeltrace/.\n"
-		       "Check also if libbtraceevent devel files are available.\n");
+		pr_err("The babeltrace2 ctf support is not compiled in. Ensure you have both\n"
+			"libbabeltrace2-dev[el] and libtraceevent-dev[el] installed or set\n"
+			"PKG_CONFIG_PATH to find a local installation of those libraries.\n");
 		return -1;
 #endif
 	}
tools/perf/tests/make +2 -2
index dbd7c86a2dcc..d2c2f526e1db 100644
@@ -91,7 +91,7 @@ make_no_libbpf	    := NO_LIBBPF=1
 make_libbpf_dynamic := LIBBPF_DYNAMIC=1
 make_no_libbpf_DEBUG := NO_LIBBPF=1 DEBUG=1
 make_no_libllvm     := NO_LIBLLVM=1
-make_with_babeltrace:= LIBBABELTRACE=1
+make_no_babeltrace2 := NO_BABELTRACE2=1
 make_with_coresight := CORESIGHT=1
 make_no_sdt	    := NO_SDT=1
 make_no_libpfm4     := NO_LIBPFM4=1
@@ -166,7 +166,7 @@ run += make_no_libbpf_DEBUG
 run += make_no_libllvm
 run += make_no_sdt
 run += make_no_syscall_tbl
-run += make_with_babeltrace
+run += make_no_babeltrace2
 run += make_with_coresight
 run += make_with_clangllvm
 run += make_no_libpfm4
tools/perf/tests/shell/test_perf_data_converter_ctf.sh +4 -4
index 334eebc9945e..bc58a8dabf4c 100755
@@ -24,11 +24,11 @@ trap_cleanup()
 }
 trap trap_cleanup exit term int
 
-check_babeltrace_support()
+check_babeltrace2_support()
 {
-	if ! perf check feature libbabeltrace
+	if ! perf check feature babeltrace2-ctf-writer
 	then
-		echo "perf not linked with libbabeltrace, skipping test"
+		echo "perf not linked with babeltrace2-ctf-writer, skipping test"
 		exit 2
 	fi
 }
@@ -97,7 +97,7 @@ test_ctf_converter_pipe()
 	fi
 }
 
-check_babeltrace_support
+check_babeltrace2_support
 test_ctf_converter_file
 test_ctf_converter_pipe
 
tools/perf/util/Build +1 -1
index 4bbc78b1f741..b22cdc24082a 100644
@@ -230,7 +230,7 @@ perf-util-$(CONFIG_LIBUNWIND)          += unwind-libunwind.o
 perf-util-$(CONFIG_LIBUNWIND)          += libunwind-arch/
 
 ifeq ($(CONFIG_LIBTRACEEVENT),y)
-  perf-util-$(CONFIG_LIBBABELTRACE) += data-convert-bt.o
+  perf-util-$(CONFIG_BABELTRACE2_CTF_WRITER) += data-convert-bt.o
 endif
 
 perf-util-y += data-convert-json.o
tools/perf/util/data-convert-bt.c +16 -17
index b3f745cff2a7..d74423b57bbd 100644
@@ -11,14 +11,13 @@
 #include <linux/compiler.h>
 #include <linux/kernel.h>
 #include <linux/zalloc.h>
-#include <babeltrace/ctf-writer/writer.h>
-#include <babeltrace/ctf-writer/clock.h>
-#include <babeltrace/ctf-writer/stream.h>
-#include <babeltrace/ctf-writer/event.h>
-#include <babeltrace/ctf-writer/event-types.h>
-#include <babeltrace/ctf-writer/event-fields.h>
-#include <babeltrace/ctf-ir/utils.h>
-#include <babeltrace/ctf/events.h>
+#include <babeltrace2-ctf-writer/writer.h>
+#include <babeltrace2-ctf-writer/clock.h>
+#include <babeltrace2-ctf-writer/stream.h>
+#include <babeltrace2-ctf-writer/event.h>
+#include <babeltrace2-ctf-writer/event-types.h>
+#include <babeltrace2-ctf-writer/event-fields.h>
+#include <babeltrace2-ctf-writer/utils.h>
 #include "asm/bug.h"
 #include "data-convert.h"
 #include "session.h"
@@ -121,13 +120,13 @@ static int value_set(struct bt_ctf_field_type *type,
 	}
 
 	if (sign) {
-		ret = bt_ctf_field_signed_integer_set_value(field, val);
+		ret = bt_ctf_field_integer_signed_set_value(field, val);
 		if (ret) {
 			pr_err("failed to set field value %s\n", name);
 			goto err;
 		}
 	} else {
-		ret = bt_ctf_field_unsigned_integer_set_value(field, val);
+		ret = bt_ctf_field_integer_unsigned_set_value(field, val);
 		if (ret) {
 			pr_err("failed to set field value %s\n", name);
 			goto err;
@@ -374,10 +373,10 @@ static int add_tracepoint_field_value(struct ctf_writer *cw,
 					data + offset + i * len, len);
 
 			if (!(flags & TEP_FIELD_IS_SIGNED))
-				ret = bt_ctf_field_unsigned_integer_set_value(
+				ret = bt_ctf_field_integer_unsigned_set_value(
 						field, value_int);
 			else
-				ret = bt_ctf_field_signed_integer_set_value(
+				ret = bt_ctf_field_integer_signed_set_value(
 						field, adjust_signedness(value_int, len));
 		}
 
@@ -471,7 +470,7 @@ add_bpf_output_values(struct bt_ctf_event_class *event_class,
 		goto put_len_type;
 	}
 
-	ret = bt_ctf_field_unsigned_integer_set_value(len_field, nr_elements);
+	ret = bt_ctf_field_integer_unsigned_set_value(len_field, nr_elements);
 	if (ret) {
 		pr_err("failed to set field value for raw_len\n");
 		goto put_len_field;
@@ -500,7 +499,7 @@ add_bpf_output_values(struct bt_ctf_event_class *event_class,
 		struct bt_ctf_field *elem_field =
 			bt_ctf_field_sequence_get_field(seq_field, i);
 
-		ret = bt_ctf_field_unsigned_integer_set_value(elem_field,
+		ret = bt_ctf_field_integer_unsigned_set_value(elem_field,
 				((u32 *)(sample->raw_data))[i]);
 
 		bt_ctf_field_put(elem_field);
@@ -545,7 +544,7 @@ add_callchain_output_values(struct bt_ctf_event_class *event_class,
 		goto put_len_type;
 	}
 
-	ret = bt_ctf_field_unsigned_integer_set_value(len_field, nr_elements);
+	ret = bt_ctf_field_integer_unsigned_set_value(len_field, nr_elements);
 	if (ret) {
 		pr_err("failed to set field value for perf_callchain_size\n");
 		goto put_len_field;
@@ -575,7 +574,7 @@ add_callchain_output_values(struct bt_ctf_event_class *event_class,
 		struct bt_ctf_field *elem_field =
 			bt_ctf_field_sequence_get_field(seq_field, i);
 
-		ret = bt_ctf_field_unsigned_integer_set_value(elem_field,
+		ret = bt_ctf_field_integer_unsigned_set_value(elem_field,
 				((u64 *)(callchain->ips))[i]);
 
 		bt_ctf_field_put(elem_field);
@@ -728,7 +727,7 @@ static struct ctf_stream *ctf_stream__create(struct ctf_writer *cw, int cpu)
 		goto out;
 	}
 
-	ret = bt_ctf_field_unsigned_integer_set_value(cpu_field, (u32) cpu);
+	ret = bt_ctf_field_integer_unsigned_set_value(cpu_field, (u32) cpu);
 	if (ret) {
 		pr_err("Failed to update CPU number\n");
 		goto out;
tools/perf/util/data-convert.h +2 -2
index ee651fa680a1..a96240f15671 100644
@@ -11,10 +11,10 @@ struct perf_data_convert_opts {
 	const char *time_str;
 };
 
-#ifdef HAVE_LIBBABELTRACE_SUPPORT
+#ifdef HAVE_BABELTRACE2_CTF_WRITER_SUPPORT
 int bt_convert__perf2ctf(const char *input_name, const char *to_ctf,
 			 struct perf_data_convert_opts *opts);
-#endif /* HAVE_LIBBABELTRACE_SUPPORT */
+#endif /* HAVE_BABELTRACE2_CTF_WRITER_SUPPORT */
 
 int bt_convert__perf2json(const char *input_name, const char *to_ctf,
 			 struct perf_data_convert_opts *opts);
Signature · 1 line
2.47.3
#17 lore raw
Quoted 7 lines · Michael Jeanson

The 1.x branch of Babeltrace has been superseded by 2.x in 2020 and has been unmaintained since 2022, efforts have started to remove it from popular distributions.

Babeltrace 2.x offers a very similar 'ctf-writer' library that can be used with minimal changes for the '--to-ctf' feature and has been packaged since Debian 11 and Fedora 32.

I think Ian provided a Reviewed-by for thee previous version of this patch, right? I'm tentatively adding it for this one as well, please advise.

- Arnaldo

Quoted 446 lines

This patch replaces the 'libbabeltrace' build feature with 'babeltrace2-ctf-writer' using pkgconfig detection, adjusts the naming of the public headers and applies minor API cleanups.

There is no changes to the output ctf traces, the ctf-writer API still implements version 1.8 of the CTF specification that can be read by either Babeltrace 1 / 2 or any CTF compliant reader.

Also remove some ifdefs in the cli option parsing to allow printing the helpful error message with '--to-ctf' when built without babeltrace2.

Cc Adrian Hunter <[email protected]>
Cc Alexander Shishkin <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Derek Foreman <[email protected]>
Cc Ian Rogers <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc James Clark <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Mathieu Desnoyers <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Peter Zijlstra <[email protected]>

---
Changes since v3:
* Rebase on current perf-tools-next
Changes since v2:
* Revert babeltrace 1 fallback
* Rebase on perf-tools-next
Changes since v1:
* Keep babeltrace 1 support as fallback

---
 tools/build/Makefile.feature                  |  5 +--
 tools/build/feature/Makefile                  |  6 ++--
 tools/build/feature/test-all.c                |  6 ++--
 ...ltrace.c => test-babeltrace2-ctf-writer.c} |  3 +-
 tools/perf/Makefile.config                    | 27 +++++++--------
 tools/perf/Makefile.perf                      |  2 +-
 tools/perf/builtin-check.c                    |  2 +-
 tools/perf/builtin-data.c                     | 18 +++-------
 tools/perf/tests/make                         |  4 +--
 .../shell/test_perf_data_converter_ctf.sh     |  8 ++---
 tools/perf/util/Build                         |  2 +-
 tools/perf/util/data-convert-bt.c             | 33 +++++++++----------
 tools/perf/util/data-convert.h                |  4 +--
 13 files changed, 53 insertions(+), 67 deletions(-)
 rename tools/build/feature/{test-libbabeltrace.c => test-babeltrace2-ctf-writer.c} (59%)
tools/build/Makefile.feature +3 -2
index af79c6cf0229..ed1374af31c1 100644
@@ -116,7 +116,7 @@ FEATURE_TESTS_EXTRA :=                  \
          gtk2                           \
          gtk2-infobar                   \
          hello                          \
-         libbabeltrace                  \
+         babeltrace2-ctf-writer         \
          libcapstone                    \
          libcheck                       \
          libbfd-liberty                 \
@@ -169,6 +169,7 @@ FEATURE_GROUP_MEMBERS-libbfd = libbfd-liberty libbfd-liberty-z
 # Declare list of feature dependency packages that provide pkg-config files.
 #
 FEATURE_PKG_CONFIG ?=           \
+	 babeltrace2-ctf-writer \
          libtraceevent          \
          libtracefs
 
@@ -217,7 +218,7 @@ ifeq ($(feature-all), 1)
   $(call feature_check,compile-32)
   $(call feature_check,compile-x32)
   $(call feature_check,bionic)
-  $(call feature_check,libbabeltrace)
+  $(call feature_check,babeltrace2-ctf-writer)
   $(call feature_check,libunwind)
   $(call feature_check,libunwind-debug-frame)
   $(foreach arch,$(LIBUNWIND_ARCHS),$(call feature_check,libunwind-$(arch)))
tools/build/feature/Makefile +3 -3
index 4e4a92ef5e1e..fac5d82c2a58 100644
@@ -45,7 +45,7 @@ FILES=                                          \
          test-pthread-barrier.bin		\
          test-stackprotector-all.bin            \
          test-timerfd.bin                       \
-         test-libbabeltrace.bin                 \
+         test-babeltrace2-ctf-writer.bin        \
          test-libcapstone.bin			\
          test-libcheck.bin			\
          test-compile-32.bin                    \
@@ -304,8 +304,8 @@ $(OUTPUT)test-backtrace.bin:
 $(OUTPUT)test-timerfd.bin:
 	$(BUILD)
 
-$(OUTPUT)test-libbabeltrace.bin:
-	$(BUILD) # -lbabeltrace provided by $(FEATURE_CHECK_LDFLAGS-libbabeltrace)
+$(OUTPUT)test-babeltrace2-ctf-writer.bin:
+	$(BUILD) # -lbabeltrace2-ctf-writer provided by $(FEATURE_CHECK_LDFLAGS-babeltrace2-ctf-writer)
 
 $(OUTPUT)test-libcapstone.bin:
 	$(BUILD) # -lcapstone provided by $(FEATURE_CHECK_LDFLAGS-libcapstone)
tools/build/feature/test-all.c +3 -3
index 1488bf6e6078..544563d62950 100644
@@ -100,13 +100,13 @@
 
 # if 0
 /*
- * Disable libbabeltrace check for test-all, because the requested
+ * Disable babeltrace2-ctf-writer check for test-all, because the requested
  * library version is not released yet in most distributions. Will
  * reenable later.
  */
 
-#define main main_test_libbabeltrace
-# include "test-libbabeltrace.c"
+#define main main_test_babeltrace2_ctf_writer
+# include "test-babeltrace2-ctf-writer.c"
 #undef main
 #endif
 
tools/build/feature/test-babeltrace2-ctf-writer.c renamed from tools/build/feature/test-libbabeltrace.c +1 -2
similarity index 59%
rename from tools/build/feature/test-libbabeltrace.c
rename to tools/build/feature/test-babeltrace2-ctf-writer.c
index 10bb69d55694..9c89082e9f88 100644
@@ -1,7 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 
-#include <babeltrace/ctf-writer/writer.h>
-#include <babeltrace/ctf-ir/stream-class.h>
+#include <babeltrace2-ctf-writer/writer.h>
 
 int main(void)
 {
tools/perf/Makefile.config +12 -15
index c531b9315609..6e7b15fab2ec 100644
@@ -184,14 +184,11 @@ endif
 FEATURE_CHECK_CFLAGS-libdw := $(LIBDW_CFLAGS)
 FEATURE_CHECK_LDFLAGS-libdw := $(LIBDW_LDFLAGS) $(DWARFLIBS)
 
-# for linking with debug library, run like:
-# make DEBUG=1 LIBBABELTRACE_DIR=/opt/libbabeltrace/
-ifdef LIBBABELTRACE_DIR
-  LIBBABELTRACE_CFLAGS  := -I$(LIBBABELTRACE_DIR)/include
-  LIBBABELTRACE_LDFLAGS := -L$(LIBBABELTRACE_DIR)/lib
+ifneq ($(NO_BABELTRACE2),1)
+  ifeq ($(call get-executable,$(PKG_CONFIG)),)
+    $(error Error: $(PKG_CONFIG) needed by babeltrace2 is missing on this system, please install it)
+  endif
 endif
-FEATURE_CHECK_CFLAGS-libbabeltrace := $(LIBBABELTRACE_CFLAGS)
-FEATURE_CHECK_LDFLAGS-libbabeltrace := $(LIBBABELTRACE_LDFLAGS) -lbabeltrace-ctf
 
 # for linking with debug library, run like:
 # make DEBUG=1 LIBCAPSTONE_DIR=/opt/capstone/
@@ -1035,15 +1032,15 @@ else
   NO_PERF_READ_VDSOX32 := 1
 endif
 
-ifndef NO_LIBBABELTRACE
-  $(call feature_check,libbabeltrace)
-  ifeq ($(feature-libbabeltrace), 1)
-    CFLAGS += -DHAVE_LIBBABELTRACE_SUPPORT $(LIBBABELTRACE_CFLAGS)
-    LDFLAGS += $(LIBBABELTRACE_LDFLAGS)
-    EXTLIBS += -lbabeltrace-ctf
-    $(call detected,CONFIG_LIBBABELTRACE)
+ifndef NO_BABELTRACE2
+  $(call feature_check,babeltrace2-ctf-writer)
+  ifeq ($(feature-babeltrace2-ctf-writer), 1)
+    CFLAGS += -DHAVE_BABELTRACE2_CTF_WRITER_SUPPORT $(shell $(PKG_CONFIG) --cflags babeltrace2-ctf-writer)
+    LDFLAGS += $(shell $(PKG_CONFIG) --libs-only-L babeltrace2-ctf-writer)
+    EXTLIBS += $(shell $(PKG_CONFIG) --libs-only-l babeltrace2-ctf-writer)
+    $(call detected,CONFIG_BABELTRACE2_CTF_WRITER)
   else
-    $(warning No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev)
+    $(warning No babeltrace2 found, disables 'perf data' CTF format support, please install libbabeltrace2-dev[el])
   endif
 endif
 
tools/perf/Makefile.perf +1 -1
index 4ac2a0cec9ee..ab661a1d271c 100644
@@ -79,7 +79,7 @@ include ../scripts/utilities.mak
 #
 # Define NO_ZLIB if you do not want to support compressed kernel modules
 #
-# Define NO_LIBBABELTRACE if you do not want libbabeltrace support
+# Define NO_BABELTRACE2 if you do not want babeltrace2-ctf-writer support
 # for CTF data format.
 #
 # Define NO_CAPSTONE if you do not want libcapstone support
tools/perf/builtin-check.c +1 -1
index 3641d263b345..60437650c50f 100644
@@ -43,7 +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("babeltrace2-ctf-writer", HAVE_BABELTRACE2_CTF_WRITER_SUPPORT),
 	FEATURE_STATUS("libbpf-strings", HAVE_LIBBPF_STRINGS_SUPPORT),
 	FEATURE_STATUS("libcapstone", HAVE_LIBCAPSTONE_SUPPORT),
 	FEATURE_STATUS("libdw-dwarf-unwind", HAVE_LIBDW_SUPPORT),
tools/perf/builtin-data.c +4 -14
index 4c08ccb8c06b..1dd73ed6bdcb 100644
@@ -40,10 +40,8 @@ static const struct option data_options[] = {
 		OPT_INCR('v', "verbose", &verbose, "be more verbose"),
 		OPT_STRING('i', "input", &input_name, "file", "input file name"),
 		OPT_STRING(0, "to-json", &to_json, NULL, "Convert to JSON format"),
-#ifdef HAVE_LIBBABELTRACE_SUPPORT
 		OPT_STRING(0, "to-ctf", &to_ctf, NULL, "Convert to CTF format"),
 		OPT_BOOLEAN(0, "tod", &opts.tod, "Convert time to wall clock time"),
-#endif
 		OPT_BOOLEAN('f', "force", &opts.force, "don't complain, do it"),
 		OPT_BOOLEAN(0, "all", &opts.all, "Convert all events"),
 		OPT_STRING(0, "time", &opts.time_str, "str",
@@ -65,29 +63,21 @@ 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_LIBBABELTRACE_SUPPORT
 	if (!to_json && !to_ctf) {
 		pr_err("You must specify one of --to-ctf or --to-json.\n");
 		return -1;
 	}
-#else
-	if (!to_json) {
-		pr_err("You must specify --to-json.\n");
-	return -1;
-}
-#endif
 
 	if (to_json)
 		return bt_convert__perf2json(input_name, to_json, &opts);
 
 	if (to_ctf) {
-#if defined(HAVE_LIBBABELTRACE_SUPPORT) && defined(HAVE_LIBTRACEEVENT)
+#if defined(HAVE_BABELTRACE2_CTF_WRITER_SUPPORT) && defined(HAVE_LIBTRACEEVENT)
 		return bt_convert__perf2ctf(input_name, to_ctf, &opts);
 #else
-		pr_err("The libbabeltrace support is not compiled in. perf should be "
-		       "compiled with environment variables LIBBABELTRACE=1 and "
-		       "LIBBABELTRACE_DIR=/path/to/libbabeltrace/.\n"
-		       "Check also if libbtraceevent devel files are available.\n");
+		pr_err("The babeltrace2 ctf support is not compiled in. Ensure you have both\n"
+			"libbabeltrace2-dev[el] and libtraceevent-dev[el] installed or set\n"
+			"PKG_CONFIG_PATH to find a local installation of those libraries.\n");
 		return -1;
 #endif
 	}
tools/perf/tests/make +2 -2
index dbd7c86a2dcc..d2c2f526e1db 100644
@@ -91,7 +91,7 @@ make_no_libbpf	    := NO_LIBBPF=1
 make_libbpf_dynamic := LIBBPF_DYNAMIC=1
 make_no_libbpf_DEBUG := NO_LIBBPF=1 DEBUG=1
 make_no_libllvm     := NO_LIBLLVM=1
-make_with_babeltrace:= LIBBABELTRACE=1
+make_no_babeltrace2 := NO_BABELTRACE2=1
 make_with_coresight := CORESIGHT=1
 make_no_sdt	    := NO_SDT=1
 make_no_libpfm4     := NO_LIBPFM4=1
@@ -166,7 +166,7 @@ run += make_no_libbpf_DEBUG
 run += make_no_libllvm
 run += make_no_sdt
 run += make_no_syscall_tbl
-run += make_with_babeltrace
+run += make_no_babeltrace2
 run += make_with_coresight
 run += make_with_clangllvm
 run += make_no_libpfm4
tools/perf/tests/shell/test_perf_data_converter_ctf.sh +4 -4
index 334eebc9945e..bc58a8dabf4c 100755
@@ -24,11 +24,11 @@ trap_cleanup()
 }
 trap trap_cleanup exit term int
 
-check_babeltrace_support()
+check_babeltrace2_support()
 {
-	if ! perf check feature libbabeltrace
+	if ! perf check feature babeltrace2-ctf-writer
 	then
-		echo "perf not linked with libbabeltrace, skipping test"
+		echo "perf not linked with babeltrace2-ctf-writer, skipping test"
 		exit 2
 	fi
 }
@@ -97,7 +97,7 @@ test_ctf_converter_pipe()
 	fi
 }
 
-check_babeltrace_support
+check_babeltrace2_support
 test_ctf_converter_file
 test_ctf_converter_pipe
 
tools/perf/util/Build +1 -1
index 4bbc78b1f741..b22cdc24082a 100644
@@ -230,7 +230,7 @@ perf-util-$(CONFIG_LIBUNWIND)          += unwind-libunwind.o
 perf-util-$(CONFIG_LIBUNWIND)          += libunwind-arch/
 
 ifeq ($(CONFIG_LIBTRACEEVENT),y)
-  perf-util-$(CONFIG_LIBBABELTRACE) += data-convert-bt.o
+  perf-util-$(CONFIG_BABELTRACE2_CTF_WRITER) += data-convert-bt.o
 endif
 
 perf-util-y += data-convert-json.o
tools/perf/util/data-convert-bt.c +16 -17
index b3f745cff2a7..d74423b57bbd 100644
@@ -11,14 +11,13 @@
 #include <linux/compiler.h>
 #include <linux/kernel.h>
 #include <linux/zalloc.h>
-#include <babeltrace/ctf-writer/writer.h>
-#include <babeltrace/ctf-writer/clock.h>
-#include <babeltrace/ctf-writer/stream.h>
-#include <babeltrace/ctf-writer/event.h>
-#include <babeltrace/ctf-writer/event-types.h>
-#include <babeltrace/ctf-writer/event-fields.h>
-#include <babeltrace/ctf-ir/utils.h>
-#include <babeltrace/ctf/events.h>
+#include <babeltrace2-ctf-writer/writer.h>
+#include <babeltrace2-ctf-writer/clock.h>
+#include <babeltrace2-ctf-writer/stream.h>
+#include <babeltrace2-ctf-writer/event.h>
+#include <babeltrace2-ctf-writer/event-types.h>
+#include <babeltrace2-ctf-writer/event-fields.h>
+#include <babeltrace2-ctf-writer/utils.h>
 #include "asm/bug.h"
 #include "data-convert.h"
 #include "session.h"
@@ -121,13 +120,13 @@ static int value_set(struct bt_ctf_field_type *type,
 	}
 
 	if (sign) {
-		ret = bt_ctf_field_signed_integer_set_value(field, val);
+		ret = bt_ctf_field_integer_signed_set_value(field, val);
 		if (ret) {
 			pr_err("failed to set field value %s\n", name);
 			goto err;
 		}
 	} else {
-		ret = bt_ctf_field_unsigned_integer_set_value(field, val);
+		ret = bt_ctf_field_integer_unsigned_set_value(field, val);
 		if (ret) {
 			pr_err("failed to set field value %s\n", name);
 			goto err;
@@ -374,10 +373,10 @@ static int add_tracepoint_field_value(struct ctf_writer *cw,
 					data + offset + i * len, len);
 
 			if (!(flags & TEP_FIELD_IS_SIGNED))
-				ret = bt_ctf_field_unsigned_integer_set_value(
+				ret = bt_ctf_field_integer_unsigned_set_value(
 						field, value_int);
 			else
-				ret = bt_ctf_field_signed_integer_set_value(
+				ret = bt_ctf_field_integer_signed_set_value(
 						field, adjust_signedness(value_int, len));
 		}
 
@@ -471,7 +470,7 @@ add_bpf_output_values(struct bt_ctf_event_class *event_class,
 		goto put_len_type;
 	}
 
-	ret = bt_ctf_field_unsigned_integer_set_value(len_field, nr_elements);
+	ret = bt_ctf_field_integer_unsigned_set_value(len_field, nr_elements);
 	if (ret) {
 		pr_err("failed to set field value for raw_len\n");
 		goto put_len_field;
@@ -500,7 +499,7 @@ add_bpf_output_values(struct bt_ctf_event_class *event_class,
 		struct bt_ctf_field *elem_field =
 			bt_ctf_field_sequence_get_field(seq_field, i);
 
-		ret = bt_ctf_field_unsigned_integer_set_value(elem_field,
+		ret = bt_ctf_field_integer_unsigned_set_value(elem_field,
 				((u32 *)(sample->raw_data))[i]);
 
 		bt_ctf_field_put(elem_field);
@@ -545,7 +544,7 @@ add_callchain_output_values(struct bt_ctf_event_class *event_class,
 		goto put_len_type;
 	}
 
-	ret = bt_ctf_field_unsigned_integer_set_value(len_field, nr_elements);
+	ret = bt_ctf_field_integer_unsigned_set_value(len_field, nr_elements);
 	if (ret) {
 		pr_err("failed to set field value for perf_callchain_size\n");
 		goto put_len_field;
@@ -575,7 +574,7 @@ add_callchain_output_values(struct bt_ctf_event_class *event_class,
 		struct bt_ctf_field *elem_field =
 			bt_ctf_field_sequence_get_field(seq_field, i);
 
-		ret = bt_ctf_field_unsigned_integer_set_value(elem_field,
+		ret = bt_ctf_field_integer_unsigned_set_value(elem_field,
 				((u64 *)(callchain->ips))[i]);
 
 		bt_ctf_field_put(elem_field);
@@ -728,7 +727,7 @@ static struct ctf_stream *ctf_stream__create(struct ctf_writer *cw, int cpu)
 		goto out;
 	}
 
-	ret = bt_ctf_field_unsigned_integer_set_value(cpu_field, (u32) cpu);
+	ret = bt_ctf_field_integer_unsigned_set_value(cpu_field, (u32) cpu);
 	if (ret) {
 		pr_err("Failed to update CPU number\n");
 		goto out;
tools/perf/util/data-convert.h +2 -2
index ee651fa680a1..a96240f15671 100644
@@ -11,10 +11,10 @@ struct perf_data_convert_opts {
 	const char *time_str;
 };
 
-#ifdef HAVE_LIBBABELTRACE_SUPPORT
+#ifdef HAVE_BABELTRACE2_CTF_WRITER_SUPPORT
 int bt_convert__perf2ctf(const char *input_name, const char *to_ctf,
 			 struct perf_data_convert_opts *opts);
-#endif /* HAVE_LIBBABELTRACE_SUPPORT */
+#endif /* HAVE_BABELTRACE2_CTF_WRITER_SUPPORT */
 
 int bt_convert__perf2json(const char *input_name, const char *to_ctf,
 			 struct perf_data_convert_opts *opts);
Signature · 1 line
2.47.3