From abbe1441fa7ca480224341c64dbb69a78cd79f91 Mon Sep 17 00:00:00 2001 From: Thilina Ratnayaka Date: Fri, 28 Feb 2025 01:56:20 +0000 Subject: [PATCH 01/34] Generate traces for thapi_start() and thapi_end() --- utils/Makefile.am | 16 ++++++++++++++++ utils/thapi_toggle_tracepoints.tp | 13 +++++++++++++ utils/toggle_tracer.c | 9 +++++++++ 3 files changed, 38 insertions(+) create mode 100644 utils/thapi_toggle_tracepoints.tp create mode 100644 utils/toggle_tracer.c diff --git a/utils/Makefile.am b/utils/Makefile.am index 8e27fa9c3..f5487d633 100644 --- a/utils/Makefile.am +++ b/utils/Makefile.am @@ -43,6 +43,22 @@ dlinfo_wrapper_CFLAGS = -Wall -Wextra bin_PROGRAMS += thapi_metadata +toggledir = $(pkglibdir)/toggle +toggle_LTLIBRARIES = libtoggle.la + +BUILT_SOURCES += \ + thapi_toggle_tracepoints.h \ + thapi_toggle_tracepoints.c + +nodist_libtoggle_la_SOURCES = \ + thapi_toggle_tracepoints.h \ + thapi_toggle_tracepoints.c + +libtoggle_la_SOURCES = toggle_tracer.c + +libtoggle_la_CFLAGS = $(LTTNG_FLAGS) $(LTTNG_UST_CFLAGS) +libtoggle_la_LDFLAGS = $(LTTNG_UST_LIBS) + bin_SCRIPTS = \ babeltrace_thapi diff --git a/utils/thapi_toggle_tracepoints.tp b/utils/thapi_toggle_tracepoints.tp new file mode 100644 index 000000000..e4c78b490 --- /dev/null +++ b/utils/thapi_toggle_tracepoints.tp @@ -0,0 +1,13 @@ +TRACEPOINT_EVENT( + lttng_ust_thapi, + start, + TP_ARGS(), + TP_FIELDS() +) + +TRACEPOINT_EVENT( + lttng_ust_thapi, + stop, + TP_ARGS(), + TP_FIELDS() +) diff --git a/utils/toggle_tracer.c b/utils/toggle_tracer.c new file mode 100644 index 000000000..b4c1697ff --- /dev/null +++ b/utils/toggle_tracer.c @@ -0,0 +1,9 @@ +#include "thapi_toggle_tracepoints.h" + +void thapi_start(void) { + tracepoint(lttng_ust_thapi, start); +} + +void thapi_stop(void) { + tracepoint(lttng_ust_thapi, stop); +} From 849500194e7c52b67cbc914c9883b14c0e5531de Mon Sep 17 00:00:00 2001 From: Thilina Ratnayaka Date: Mon, 3 Mar 2025 22:02:51 +0000 Subject: [PATCH 02/34] Call thapi_stop() if libtoggle is linked This is done by adding `__attribute((constructor))__` to `thapi_stop()`. Added an autotools check to see if the compiler supports `__attribute((constructor))__`. --- configure.ac | 17 +++++++++++++++++ utils/toggle_tracer.c | 2 ++ 2 files changed, 19 insertions(+) diff --git a/configure.ac b/configure.ac index ee8c71aba..44728f1ce 100644 --- a/configure.ac +++ b/configure.ac @@ -137,6 +137,23 @@ AC_FUNC_MMAP AC_FUNC_REALLOC AC_CHECK_FUNCS([clock_gettime ftruncate memmove memset strdup strstr strtoull strlen strchr]) +# Check if __attribute__((constructor)) works. Source: +# https://github.com/openucx/ucx/blob/72ae40c607067b6dfadf0d208f6811171bbf36b6/config/m4/ucs.m4#L140 +AC_DEFUN([CHECK_CROSS_COMP], [ + AC_RUN_IFELSE([$1], [$2], [$3], + [AC_LINK_IFELSE([$1], [$2], [$3])]) +]) + +AC_MSG_CHECKING([__attribute__((constructor))]) +CHECK_CROSS_COMP([AC_LANG_SOURCE([static int rc = 1; + static void constructor_test() __attribute__((constructor)); + static void constructor_test() { rc = 0; } + int main(int argc, char** argv) { return rc; }])], + [AC_MSG_RESULT([yes])], + [AC_MSG_ERROR([Cannot continue. Please use compiler that + supports __attribute__((constructor))])] + ) + AC_CONFIG_FILES([ Makefile xprof/Makefile diff --git a/utils/toggle_tracer.c b/utils/toggle_tracer.c index b4c1697ff..a68f448f0 100644 --- a/utils/toggle_tracer.c +++ b/utils/toggle_tracer.c @@ -1,5 +1,7 @@ #include "thapi_toggle_tracepoints.h" +void thapi_stop() __attribute__((constructor)); + void thapi_start(void) { tracepoint(lttng_ust_thapi, start); } From 4646b79f9c35854013e76fe86d35888cbc17d9fb Mon Sep 17 00:00:00 2001 From: Thilina Ratnayaka Date: Mon, 3 Mar 2025 22:40:31 +0000 Subject: [PATCH 03/34] Rename toggle to ThapiProfiler and install `thapi_profiler.h` header files to provied declarations of `thapi_start()` and `thapi_stop()`. --- utils/Makefile.am | 22 ++++++++++--------- utils/{toggle_tracer.c => thapi_profiler.c} | 2 +- utils/thapi_profiler.h | 7 ++++++ ...oints.tp => thapi_profiler_tracepoints.tp} | 0 4 files changed, 20 insertions(+), 11 deletions(-) rename utils/{toggle_tracer.c => thapi_profiler.c} (81%) create mode 100644 utils/thapi_profiler.h rename utils/{thapi_toggle_tracepoints.tp => thapi_profiler_tracepoints.tp} (100%) diff --git a/utils/Makefile.am b/utils/Makefile.am index f5487d633..3a71c359a 100644 --- a/utils/Makefile.am +++ b/utils/Makefile.am @@ -43,21 +43,23 @@ dlinfo_wrapper_CFLAGS = -Wall -Wextra bin_PROGRAMS += thapi_metadata -toggledir = $(pkglibdir)/toggle -toggle_LTLIBRARIES = libtoggle.la +include_HEADERS = thapi_profiler.h + +ThapiProfilerdir = $(pkglibdir) +ThapiProfiler_LTLIBRARIES = libThapiProfiler.la BUILT_SOURCES += \ - thapi_toggle_tracepoints.h \ - thapi_toggle_tracepoints.c + thapi_profiler_tracepoints.h \ + thapi_profiler_tracepoints.c -nodist_libtoggle_la_SOURCES = \ - thapi_toggle_tracepoints.h \ - thapi_toggle_tracepoints.c +nodist_libThapiProfiler_la_SOURCES = \ + thapi_profiler_tracepoints.h \ + thapi_profiler_tracepoints.c -libtoggle_la_SOURCES = toggle_tracer.c +libThapiProfiler_la_SOURCES = thapi_profiler.c -libtoggle_la_CFLAGS = $(LTTNG_FLAGS) $(LTTNG_UST_CFLAGS) -libtoggle_la_LDFLAGS = $(LTTNG_UST_LIBS) +libThapiProfiler_la_CFLAGS = $(LTTNG_FLAGS) $(LTTNG_UST_CFLAGS) +libThapiProfiler_la_LDFLAGS = $(LTTNG_UST_LIBS) bin_SCRIPTS = \ babeltrace_thapi diff --git a/utils/toggle_tracer.c b/utils/thapi_profiler.c similarity index 81% rename from utils/toggle_tracer.c rename to utils/thapi_profiler.c index a68f448f0..f5ddd7dd9 100644 --- a/utils/toggle_tracer.c +++ b/utils/thapi_profiler.c @@ -1,4 +1,4 @@ -#include "thapi_toggle_tracepoints.h" +#include "thapi_profiler_tracepoints.h" void thapi_stop() __attribute__((constructor)); diff --git a/utils/thapi_profiler.h b/utils/thapi_profiler.h new file mode 100644 index 000000000..d7999c88f --- /dev/null +++ b/utils/thapi_profiler.h @@ -0,0 +1,7 @@ +#if !defined(THAPI_PROFILER) +#define THAPI_PROFILER + +void thapi_stop(); +void thapi_start(); + +#endif // THAPI_PROFILER diff --git a/utils/thapi_toggle_tracepoints.tp b/utils/thapi_profiler_tracepoints.tp similarity index 100% rename from utils/thapi_toggle_tracepoints.tp rename to utils/thapi_profiler_tracepoints.tp From 6dc7280f76f71c5e879d01eb94ffacbeb383dd44 Mon Sep 17 00:00:00 2001 From: Thilina Ratnayaka Date: Mon, 3 Mar 2025 22:46:54 +0000 Subject: [PATCH 04/34] Add `profiler_` to ThapiProfiler symbols --- utils/thapi_profiler.c | 10 +++++----- utils/thapi_profiler.h | 4 ++-- utils/thapi_profiler_tracepoints.tp | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/utils/thapi_profiler.c b/utils/thapi_profiler.c index f5ddd7dd9..aa8c21ac1 100644 --- a/utils/thapi_profiler.c +++ b/utils/thapi_profiler.c @@ -1,11 +1,11 @@ #include "thapi_profiler_tracepoints.h" -void thapi_stop() __attribute__((constructor)); +void thapi_profiler_stop() __attribute__((constructor)); -void thapi_start(void) { - tracepoint(lttng_ust_thapi, start); +void thapi_profiler_start(void) { + tracepoint(lttng_ust_profiler, start); } -void thapi_stop(void) { - tracepoint(lttng_ust_thapi, stop); +void thapi_profiler_stop(void) { + tracepoint(lttng_ust_profiler, stop); } diff --git a/utils/thapi_profiler.h b/utils/thapi_profiler.h index d7999c88f..664ed7bab 100644 --- a/utils/thapi_profiler.h +++ b/utils/thapi_profiler.h @@ -1,7 +1,7 @@ #if !defined(THAPI_PROFILER) #define THAPI_PROFILER -void thapi_stop(); -void thapi_start(); +void thapi_profiler_start(); +void thapi_profiler_stop(); #endif // THAPI_PROFILER diff --git a/utils/thapi_profiler_tracepoints.tp b/utils/thapi_profiler_tracepoints.tp index e4c78b490..5d74b2be4 100644 --- a/utils/thapi_profiler_tracepoints.tp +++ b/utils/thapi_profiler_tracepoints.tp @@ -1,12 +1,12 @@ TRACEPOINT_EVENT( - lttng_ust_thapi, + lttng_ust_profiler, start, TP_ARGS(), TP_FIELDS() ) TRACEPOINT_EVENT( - lttng_ust_thapi, + lttng_ust_profiler, stop, TP_ARGS(), TP_FIELDS() From d9f119002f465a7a4833407119d0af8c46afbd95 Mon Sep 17 00:00:00 2001 From: Thilina Ratnayaka Date: Thu, 6 Mar 2025 01:13:56 +0000 Subject: [PATCH 05/34] Fix `make distcheck` failure --- utils/Makefile.am | 1 + 1 file changed, 1 insertion(+) diff --git a/utils/Makefile.am b/utils/Makefile.am index 3a71c359a..fde37d599 100644 --- a/utils/Makefile.am +++ b/utils/Makefile.am @@ -92,6 +92,7 @@ EXTRA_DIST = \ gen_library_base.rb \ dump_trace_format.rb \ thapi_metadata_tracepoints.tp \ + thapi_profiler_tracepoints.tp \ command.rb \ meta_parameters.rb \ optparse_thapi.rb \ From 435f7cbd03a36f2804514baf89f4809158654ac6 Mon Sep 17 00:00:00 2001 From: Thilina Ratnayaka Date: Thu, 6 Mar 2025 01:30:59 +0000 Subject: [PATCH 06/34] Remove profiler from symbols --- utils/Makefile.am | 24 +++++++++---------- utils/thapi.c | 11 +++++++++ utils/thapi.h | 7 ++++++ utils/thapi_profiler.c | 11 --------- utils/thapi_profiler.h | 7 ------ ...er_tracepoints.tp => thapi_tracepoints.tp} | 4 ++-- 6 files changed, 32 insertions(+), 32 deletions(-) create mode 100644 utils/thapi.c create mode 100644 utils/thapi.h delete mode 100644 utils/thapi_profiler.c delete mode 100644 utils/thapi_profiler.h rename utils/{thapi_profiler_tracepoints.tp => thapi_tracepoints.tp} (71%) diff --git a/utils/Makefile.am b/utils/Makefile.am index fde37d599..51885a64e 100644 --- a/utils/Makefile.am +++ b/utils/Makefile.am @@ -43,23 +43,23 @@ dlinfo_wrapper_CFLAGS = -Wall -Wextra bin_PROGRAMS += thapi_metadata -include_HEADERS = thapi_profiler.h +include_HEADERS = thapi.h -ThapiProfilerdir = $(pkglibdir) -ThapiProfiler_LTLIBRARIES = libThapiProfiler.la +Thapidir = $(pkglibdir) +Thapi_LTLIBRARIES = libThapi.la BUILT_SOURCES += \ - thapi_profiler_tracepoints.h \ - thapi_profiler_tracepoints.c + thapi_tracepoints.h \ + thapi_tracepoints.c -nodist_libThapiProfiler_la_SOURCES = \ - thapi_profiler_tracepoints.h \ - thapi_profiler_tracepoints.c +nodist_libThapi_la_SOURCES = \ + thapi_tracepoints.h \ + thapi_tracepoints.c -libThapiProfiler_la_SOURCES = thapi_profiler.c +libThapi_la_SOURCES = thapi.c -libThapiProfiler_la_CFLAGS = $(LTTNG_FLAGS) $(LTTNG_UST_CFLAGS) -libThapiProfiler_la_LDFLAGS = $(LTTNG_UST_LIBS) +libThapi_la_CFLAGS = $(LTTNG_FLAGS) $(LTTNG_UST_CFLAGS) +libThapi_la_LDFLAGS = $(LTTNG_UST_LIBS) bin_SCRIPTS = \ babeltrace_thapi @@ -92,7 +92,7 @@ EXTRA_DIST = \ gen_library_base.rb \ dump_trace_format.rb \ thapi_metadata_tracepoints.tp \ - thapi_profiler_tracepoints.tp \ + thapi_tracepoints.tp \ command.rb \ meta_parameters.rb \ optparse_thapi.rb \ diff --git a/utils/thapi.c b/utils/thapi.c new file mode 100644 index 000000000..ffb6ce3bc --- /dev/null +++ b/utils/thapi.c @@ -0,0 +1,11 @@ +#include "thapi_tracepoints.h" + +void thapi_stop() __attribute__((constructor)); + +void thapi_start(void) { + tracepoint(lttng_ust_toggle, start); +} + +void thapi_stop(void) { + tracepoint(lttng_ust_toggle, stop); +} diff --git a/utils/thapi.h b/utils/thapi.h new file mode 100644 index 000000000..5436c1133 --- /dev/null +++ b/utils/thapi.h @@ -0,0 +1,7 @@ +#if !defined(THAPI) +#define THAPI + +void thapi_start(); +void thapi_stop(); + +#endif // THAPI diff --git a/utils/thapi_profiler.c b/utils/thapi_profiler.c deleted file mode 100644 index aa8c21ac1..000000000 --- a/utils/thapi_profiler.c +++ /dev/null @@ -1,11 +0,0 @@ -#include "thapi_profiler_tracepoints.h" - -void thapi_profiler_stop() __attribute__((constructor)); - -void thapi_profiler_start(void) { - tracepoint(lttng_ust_profiler, start); -} - -void thapi_profiler_stop(void) { - tracepoint(lttng_ust_profiler, stop); -} diff --git a/utils/thapi_profiler.h b/utils/thapi_profiler.h deleted file mode 100644 index 664ed7bab..000000000 --- a/utils/thapi_profiler.h +++ /dev/null @@ -1,7 +0,0 @@ -#if !defined(THAPI_PROFILER) -#define THAPI_PROFILER - -void thapi_profiler_start(); -void thapi_profiler_stop(); - -#endif // THAPI_PROFILER diff --git a/utils/thapi_profiler_tracepoints.tp b/utils/thapi_tracepoints.tp similarity index 71% rename from utils/thapi_profiler_tracepoints.tp rename to utils/thapi_tracepoints.tp index 5d74b2be4..83fc7fac0 100644 --- a/utils/thapi_profiler_tracepoints.tp +++ b/utils/thapi_tracepoints.tp @@ -1,12 +1,12 @@ TRACEPOINT_EVENT( - lttng_ust_profiler, + lttng_ust_toggle, start, TP_ARGS(), TP_FIELDS() ) TRACEPOINT_EVENT( - lttng_ust_profiler, + lttng_ust_toggle, stop, TP_ARGS(), TP_FIELDS() From 784e6e549afbd9aa18957d5ffd0ecbbcda75290e Mon Sep 17 00:00:00 2001 From: Thilina Ratnayaka Date: Thu, 6 Mar 2025 02:14:25 +0000 Subject: [PATCH 07/34] Use AX_GCC_FUNC_ATTRIBUTE to check constructor support --- configure.ac | 17 +-- m4/ax_gcc_func_attribute.m4 | 242 ++++++++++++++++++++++++++++++++++++ 2 files changed, 243 insertions(+), 16 deletions(-) create mode 100644 m4/ax_gcc_func_attribute.m4 diff --git a/configure.ac b/configure.ac index 44728f1ce..c0f171fe9 100644 --- a/configure.ac +++ b/configure.ac @@ -137,22 +137,7 @@ AC_FUNC_MMAP AC_FUNC_REALLOC AC_CHECK_FUNCS([clock_gettime ftruncate memmove memset strdup strstr strtoull strlen strchr]) -# Check if __attribute__((constructor)) works. Source: -# https://github.com/openucx/ucx/blob/72ae40c607067b6dfadf0d208f6811171bbf36b6/config/m4/ucs.m4#L140 -AC_DEFUN([CHECK_CROSS_COMP], [ - AC_RUN_IFELSE([$1], [$2], [$3], - [AC_LINK_IFELSE([$1], [$2], [$3])]) -]) - -AC_MSG_CHECKING([__attribute__((constructor))]) -CHECK_CROSS_COMP([AC_LANG_SOURCE([static int rc = 1; - static void constructor_test() __attribute__((constructor)); - static void constructor_test() { rc = 0; } - int main(int argc, char** argv) { return rc; }])], - [AC_MSG_RESULT([yes])], - [AC_MSG_ERROR([Cannot continue. Please use compiler that - supports __attribute__((constructor))])] - ) +AX_GCC_FUNC_ATTRIBUTE(constructor) AC_CONFIG_FILES([ Makefile diff --git a/m4/ax_gcc_func_attribute.m4 b/m4/ax_gcc_func_attribute.m4 new file mode 100644 index 000000000..fa4e089d6 --- /dev/null +++ b/m4/ax_gcc_func_attribute.m4 @@ -0,0 +1,242 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_gcc_func_attribute.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_GCC_FUNC_ATTRIBUTE(ATTRIBUTE) +# +# DESCRIPTION +# +# This macro checks if the compiler supports one of GCC's function +# attributes; many other compilers also provide function attributes with +# the same syntax. Compiler warnings are used to detect supported +# attributes as unsupported ones are ignored by default so quieting +# warnings when using this macro will yield false positives. +# +# The ATTRIBUTE parameter holds the name of the attribute to be checked. +# +# If ATTRIBUTE is supported define HAVE_FUNC_ATTRIBUTE_. +# +# The macro caches its result in the ax_cv_have_func_attribute_ +# variable. +# +# The macro currently supports the following function attributes: +# +# alias +# aligned +# alloc_size +# always_inline +# artificial +# cold +# const +# constructor +# constructor_priority for constructor attribute with priority +# deprecated +# destructor +# dllexport +# dllimport +# error +# externally_visible +# fallthrough +# flatten +# format +# format_arg +# gnu_format +# gnu_inline +# hot +# ifunc +# leaf +# malloc +# noclone +# noinline +# nonnull +# noreturn +# nothrow +# optimize +# pure +# sentinel +# sentinel_position +# unused +# used +# visibility +# warning +# warn_unused_result +# weak +# weakref +# +# Unsupported function attributes will be tested with a prototype +# returning an int and not accepting any arguments and the result of the +# check might be wrong or meaningless so use with care. +# +# LICENSE +# +# Copyright (c) 2013 Gabriele Svelto +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 13 + +AC_DEFUN([AX_GCC_FUNC_ATTRIBUTE], [ + AS_VAR_PUSHDEF([ac_var], [ax_cv_have_func_attribute_$1]) + + AC_CACHE_CHECK([for __attribute__(($1))], [ac_var], [ + AC_LINK_IFELSE([AC_LANG_PROGRAM([ + m4_case([$1], + [alias], [ + int foo( void ) { return 0; } + int bar( void ) __attribute__(($1("foo"))); + ], + [aligned], [ + int foo( void ) __attribute__(($1(32))); + ], + [alloc_size], [ + void *foo(int a) __attribute__(($1(1))); + ], + [always_inline], [ + inline __attribute__(($1)) int foo( void ) { return 0; } + ], + [artificial], [ + inline __attribute__(($1)) int foo( void ) { return 0; } + ], + [cold], [ + int foo( void ) __attribute__(($1)); + ], + [const], [ + int foo( void ) __attribute__(($1)); + ], + [constructor_priority], [ + int foo( void ) __attribute__((__constructor__(65535/2))); + ], + [constructor], [ + int foo( void ) __attribute__(($1)); + ], + [deprecated], [ + int foo( void ) __attribute__(($1(""))); + ], + [destructor], [ + int foo( void ) __attribute__(($1)); + ], + [dllexport], [ + __attribute__(($1)) int foo( void ) { return 0; } + ], + [dllimport], [ + int foo( void ) __attribute__(($1)); + ], + [error], [ + int foo( void ) __attribute__(($1(""))); + ], + [externally_visible], [ + int foo( void ) __attribute__(($1)); + ], + [fallthrough], [ + void foo( int x ) {switch (x) { case 1: __attribute__(($1)); case 2: break ; }}; + ], + [flatten], [ + int foo( void ) __attribute__(($1)); + ], + [format], [ + int foo(const char *p, ...) __attribute__(($1(printf, 1, 2))); + ], + [gnu_format], [ + int foo(const char *p, ...) __attribute__((format(gnu_printf, 1, 2))); + ], + [format_arg], [ + char *foo(const char *p) __attribute__(($1(1))); + ], + [gnu_inline], [ + inline __attribute__(($1)) int foo( void ) { return 0; } + ], + [hot], [ + int foo( void ) __attribute__(($1)); + ], + [ifunc], [ + int my_foo( void ) { return 0; } + static int (*resolve_foo(void))(void) { return my_foo; } + int foo( void ) __attribute__(($1("resolve_foo"))); + ], + [leaf], [ + __attribute__(($1)) int foo( void ) { return 0; } + ], + [malloc], [ + void *foo( void ) __attribute__(($1)); + ], + [noclone], [ + int foo( void ) __attribute__(($1)); + ], + [noinline], [ + __attribute__(($1)) int foo( void ) { return 0; } + ], + [nonnull], [ + int foo(char *p) __attribute__(($1(1))); + ], + [noreturn], [ + void foo( void ) __attribute__(($1)); + ], + [nothrow], [ + int foo( void ) __attribute__(($1)); + ], + [optimize], [ + __attribute__(($1(3))) int foo( void ) { return 0; } + ], + [pure], [ + int foo( void ) __attribute__(($1)); + ], + [sentinel], [ + int foo(void *p, ...) __attribute__(($1)); + ], + [sentinel_position], [ + int foo(void *p, ...) __attribute__(($1(1))); + ], + [returns_nonnull], [ + void *foo( void ) __attribute__(($1)); + ], + [unused], [ + int foo( void ) __attribute__(($1)); + ], + [used], [ + int foo( void ) __attribute__(($1)); + ], + [visibility], [ + int foo_def( void ) __attribute__(($1("default"))); + int foo_hid( void ) __attribute__(($1("hidden"))); + int foo_int( void ) __attribute__(($1("internal"))); + int foo_pro( void ) __attribute__(($1("protected"))); + ], + [warning], [ + int foo( void ) __attribute__(($1(""))); + ], + [warn_unused_result], [ + int foo( void ) __attribute__(($1)); + ], + [weak], [ + int foo( void ) __attribute__(($1)); + ], + [weakref], [ + static int foo( void ) { return 0; } + static int bar( void ) __attribute__(($1("foo"))); + ], + [ + m4_warn([syntax], [Unsupported attribute $1, the test may fail]) + int foo( void ) __attribute__(($1)); + ] + )], []) + ], + dnl GCC doesn't exit with an error if an unknown attribute is + dnl provided but only outputs a warning, so accept the attribute + dnl only if no warning were issued. + [AS_IF([grep -- -Wattributes conftest.err], + [AS_VAR_SET([ac_var], [no])], + [AS_VAR_SET([ac_var], [yes])])], + [AS_VAR_SET([ac_var], [no])]) + ]) + + AS_IF([test yes = AS_VAR_GET([ac_var])], + [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_FUNC_ATTRIBUTE_$1), 1, + [Define to 1 if the system has the `$1' function attribute])], []) + + AS_VAR_POPDEF([ac_var]) +]) From 26b53f132a6ab29cd2ae8814cbc90bdb3aab639d Mon Sep 17 00:00:00 2001 From: Thilina Ratnayaka Date: Thu, 6 Mar 2025 02:43:35 +0000 Subject: [PATCH 08/34] Install libThapi.so in lib instead of lib/thapi --- utils/Makefile.am | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/utils/Makefile.am b/utils/Makefile.am index 51885a64e..f41baaf8a 100644 --- a/utils/Makefile.am +++ b/utils/Makefile.am @@ -45,9 +45,6 @@ bin_PROGRAMS += thapi_metadata include_HEADERS = thapi.h -Thapidir = $(pkglibdir) -Thapi_LTLIBRARIES = libThapi.la - BUILT_SOURCES += \ thapi_tracepoints.h \ thapi_tracepoints.c @@ -57,10 +54,11 @@ nodist_libThapi_la_SOURCES = \ thapi_tracepoints.c libThapi_la_SOURCES = thapi.c - libThapi_la_CFLAGS = $(LTTNG_FLAGS) $(LTTNG_UST_CFLAGS) libThapi_la_LDFLAGS = $(LTTNG_UST_LIBS) +lib_LTLIBRARIES = libThapi.la + bin_SCRIPTS = \ babeltrace_thapi From 105a3767e984fc2b50b3c8919adcb58865fca9ad Mon Sep 17 00:00:00 2001 From: Thilina Ratnayaka Date: Thu, 6 Mar 2025 15:24:03 +0000 Subject: [PATCH 09/34] Add an integration test --- integration_tests/general.bats | 12 ++++++++++++ integration_tests/thapi_start_stop.c | 6 ++++++ 2 files changed, 18 insertions(+) create mode 100644 integration_tests/thapi_start_stop.c diff --git a/integration_tests/general.bats b/integration_tests/general.bats index 3c49cff41..eb8911bd8 100644 --- a/integration_tests/general.bats +++ b/integration_tests/general.bats @@ -103,3 +103,15 @@ teardown_file() { run bats_pipe echo "FOO" \| $IPROF cat [[ "$output" =~ "FOO" ]] } + +@test "thapi_start_stop" { + cc -I${THAPI_INC_DIR} ./integration_tests/thapi_start_stop.c -o thapi_start_stop \ + -Wl,-rpath,${THAPI_LIB_DIR} -L${THAPI_LIB_DIR} -lThapi + $IPROF --no-analysis -- ./thapi_start_stop + + start_count=`babeltrace2 $THAPI_HOME/thapi-traces | grep lttng_ust_toggle:start | wc -l` + [ "$start_count" -eq 1 ] + + stop_count=`babeltrace2 $THAPI_HOME/thapi-traces | grep lttng_ust_toggle:stop | wc -l` + [ "$stop_count" -eq 2 ] +} diff --git a/integration_tests/thapi_start_stop.c b/integration_tests/thapi_start_stop.c new file mode 100644 index 000000000..4a366e57c --- /dev/null +++ b/integration_tests/thapi_start_stop.c @@ -0,0 +1,6 @@ +#include "thapi.h" + +int main(int argc, char *argv[]) { + thapi_start(); + thapi_stop(); +} From 3dc7a3f2ec76fc4941ca970e6fe5ba88b291bd25 Mon Sep 17 00:00:00 2001 From: Thilina Ratnayaka Date: Thu, 6 Mar 2025 17:27:53 +0000 Subject: [PATCH 10/34] Minor changes in utils/thapi.[ch] --- utils/thapi.c | 3 +-- utils/thapi.h | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/utils/thapi.c b/utils/thapi.c index ffb6ce3bc..0c3f877da 100644 --- a/utils/thapi.c +++ b/utils/thapi.c @@ -1,6 +1,5 @@ #include "thapi_tracepoints.h" - -void thapi_stop() __attribute__((constructor)); +#include "thapi.h" void thapi_start(void) { tracepoint(lttng_ust_toggle, start); diff --git a/utils/thapi.h b/utils/thapi.h index 5436c1133..d81d21ec1 100644 --- a/utils/thapi.h +++ b/utils/thapi.h @@ -1,7 +1,7 @@ #if !defined(THAPI) #define THAPI -void thapi_start(); -void thapi_stop(); +void thapi_start(void); +void thapi_stop(void) __attribute__((constructor)); #endif // THAPI From 8057f7f6d6663cbef949592e2585189c3b470fc9 Mon Sep 17 00:00:00 2001 From: Thilina Ratnayaka Date: Tue, 18 Mar 2025 02:56:32 +0000 Subject: [PATCH 11/34] Fix the failing integration test --- integration_tests/general.bats | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/integration_tests/general.bats b/integration_tests/general.bats index eb8911bd8..d427648f0 100644 --- a/integration_tests/general.bats +++ b/integration_tests/general.bats @@ -107,11 +107,11 @@ teardown_file() { @test "thapi_start_stop" { cc -I${THAPI_INC_DIR} ./integration_tests/thapi_start_stop.c -o thapi_start_stop \ -Wl,-rpath,${THAPI_LIB_DIR} -L${THAPI_LIB_DIR} -lThapi - $IPROF --no-analysis -- ./thapi_start_stop + $IPROF --trace-output trace_toggle --no-analysis -- ./thapi_start_stop - start_count=`babeltrace2 $THAPI_HOME/thapi-traces | grep lttng_ust_toggle:start | wc -l` + start_count=`babeltrace2 trace_toggle | grep lttng_ust_toggle:start | wc -l` [ "$start_count" -eq 1 ] - stop_count=`babeltrace2 $THAPI_HOME/thapi-traces | grep lttng_ust_toggle:stop | wc -l` + stop_count=`babeltrace2 trace_toggle | grep lttng_ust_toggle:stop | wc -l` [ "$stop_count" -eq 2 ] } From 1f2e500d808274a1a92f6bc0315fee8b5d85051c Mon Sep 17 00:00:00 2001 From: Thilina Ratnayaka Date: Tue, 18 Mar 2025 14:24:33 +0000 Subject: [PATCH 12/34] thapi.c->thapi_toggle.c & use toggle over profiler --- utils/Makefile.am | 2 +- utils/{thapi.c => thapi_toggle.c} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename utils/{thapi.c => thapi_toggle.c} (100%) diff --git a/utils/Makefile.am b/utils/Makefile.am index f41baaf8a..8f7004a43 100644 --- a/utils/Makefile.am +++ b/utils/Makefile.am @@ -53,7 +53,7 @@ nodist_libThapi_la_SOURCES = \ thapi_tracepoints.h \ thapi_tracepoints.c -libThapi_la_SOURCES = thapi.c +libThapi_la_SOURCES = thapi_toggle.c libThapi_la_CFLAGS = $(LTTNG_FLAGS) $(LTTNG_UST_CFLAGS) libThapi_la_LDFLAGS = $(LTTNG_UST_LIBS) diff --git a/utils/thapi.c b/utils/thapi_toggle.c similarity index 100% rename from utils/thapi.c rename to utils/thapi_toggle.c From bf25a27e08ca239e5f58cc73ec8886c3f1c8919f Mon Sep 17 00:00:00 2001 From: Thilina Ratnayaka Date: Tue, 18 Mar 2025 14:38:51 +0000 Subject: [PATCH 13/34] Use constructor priority for thapi_stop() --- utils/thapi.h | 2 +- utils/thapi_toggle.c | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/utils/thapi.h b/utils/thapi.h index d81d21ec1..bd0f9af16 100644 --- a/utils/thapi.h +++ b/utils/thapi.h @@ -2,6 +2,6 @@ #define THAPI void thapi_start(void); -void thapi_stop(void) __attribute__((constructor)); +void thapi_stop(void); #endif // THAPI diff --git a/utils/thapi_toggle.c b/utils/thapi_toggle.c index 0c3f877da..0e363c2f6 100644 --- a/utils/thapi_toggle.c +++ b/utils/thapi_toggle.c @@ -1,10 +1,14 @@ #include "thapi_tracepoints.h" #include "thapi.h" +#ifndef LTTNG_UST_CONSTRUCTOR_PRIO +#error "LTTNG_UST_CONSTRUCTOR_PRIO not defined." +#endif + void thapi_start(void) { tracepoint(lttng_ust_toggle, start); } -void thapi_stop(void) { +void __attribute__((constructor(LTTNG_UST_CONSTRUCTOR_PRIO + 1))) thapi_stop(void) { tracepoint(lttng_ust_toggle, stop); } From b27c15c3f2c3f8f908dfd94982bfb0278b7617dc Mon Sep 17 00:00:00 2001 From: Thilina Ratnayaka Date: Tue, 18 Mar 2025 14:46:40 +0000 Subject: [PATCH 14/34] Set minimum lttng-ust version We need one which supports __attribute__((constructor)) in user code. --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index c0f171fe9..d08d3197f 100644 --- a/configure.ac +++ b/configure.ac @@ -102,7 +102,7 @@ AC_SUBST([ENABLE_CLANG_PARSER]) PKG_CHECK_MODULES([LIBFFI], [libffi >= 3.2]) PKG_CHECK_MODULES([BABELTRACE2], [babeltrace2 >= 2.0]) -PKG_CHECK_MODULES([LTTNG_UST], [lttng-ust >= 2.10]) +PKG_CHECK_MODULES([LTTNG_UST], [lttng-ust >= 2.12.8]) PKG_CHECK_MODULES([PROTOBUF], [protobuf >= 3.0]) AX_RUBY_EXTENSION([cast-to-yaml], [yes]) From a6799a7599e8c08a6bdc115da3770ff56be75bb9 Mon Sep 17 00:00:00 2001 From: Thilina Ratnayaka Date: Tue, 25 Mar 2025 22:38:13 +0000 Subject: [PATCH 15/34] Check if the header is included by a CXX compiler --- utils/thapi.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/utils/thapi.h b/utils/thapi.h index bd0f9af16..b94918a4c 100644 --- a/utils/thapi.h +++ b/utils/thapi.h @@ -1,7 +1,15 @@ #if !defined(THAPI) #define THAPI +#ifdef __cplusplus +extern "C" { +#endif + void thapi_start(void); void thapi_stop(void); +#ifdef __cplusplus +} +#endif + #endif // THAPI From 0b7e607aaa91997b719efd7cfcaef1f1540832b2 Mon Sep 17 00:00:00 2001 From: Thilina Ratnayaka Date: Wed, 2 Apr 2025 04:32:55 +0000 Subject: [PATCH 16/34] Plugin to filter traces based on thapi_start/stop --- utils/Makefile.am | 33 +++++++++++++++++++++++++++------ utils/btx_thapi.yaml | 27 +++++++++++++++++++++++++++ utils/thapi_callbacks.c | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 6 deletions(-) create mode 100644 utils/btx_thapi.yaml create mode 100644 utils/thapi_callbacks.c diff --git a/utils/Makefile.am b/utils/Makefile.am index 8f7004a43..672d88856 100644 --- a/utils/Makefile.am +++ b/utils/Makefile.am @@ -45,19 +45,38 @@ bin_PROGRAMS += thapi_metadata include_HEADERS = thapi.h -BUILT_SOURCES += \ - thapi_tracepoints.h \ - thapi_tracepoints.c - +lib_LTLIBRARIES = libThapi.la nodist_libThapi_la_SOURCES = \ thapi_tracepoints.h \ thapi_tracepoints.c - libThapi_la_SOURCES = thapi_toggle.c libThapi_la_CFLAGS = $(LTTNG_FLAGS) $(LTTNG_UST_CFLAGS) libThapi_la_LDFLAGS = $(LTTNG_UST_LIBS) -lib_LTLIBRARIES = libThapi.la +BTX_THAPI_GENERATED = \ + btx_thapi/metababel/metababel.h \ + btx_thapi/metababel/btx_component.h \ + btx_thapi/metababel/btx_component.c \ + btx_thapi/metababel/btx_upstream.h \ + btx_thapi/metababel/btx_upstream.c \ + btx_thapi/metababel/btx_downstream.h \ + btx_thapi/metababel/btx_downstream.c \ + btx_thapi/btx_main.c + +$(BTX_THAPI_GENERATED): btx_thapi.yaml thapi_callbacks.c + $(METABABEL) --enable-callbacks on_downstream --component-type FILTER \ + --upstream $(top_srcdir)/utils/btx_thapi.yaml --downstream $(top_srcdir)/utils/btx_thapi.yaml \ + -o btx_thapi + +noinst_LTLIBRARIES = libThapiPlugin.la +nodist_libThapiPlugin_la_SOURCES = $(BTX_THAPI_GENERATED) +libThapiPlugin_la_SOURCES = thapi_callbacks.c +libThapiPlugin_la_CFLAGS = -fPIC -shared -Wall -Wextra -Wno-unused-parameter $(BABELTRACE2_CFLAGS) -I./btx_thapi -I$(top_srcdir)/utils/include + +BUILT_SOURCES += \ + thapi_tracepoints.h \ + thapi_tracepoints.c \ + $(BTX_THAPI_GENERATED) bin_SCRIPTS = \ babeltrace_thapi @@ -78,6 +97,7 @@ CLEANFILES = \ version \ optparse_thapi.rb \ lttng/tracepoint_gen.h \ + $(BTX_THAPI_GENERATED) \ $(BUILT_SOURCES) EXTRA_DIST = \ @@ -91,6 +111,7 @@ EXTRA_DIST = \ dump_trace_format.rb \ thapi_metadata_tracepoints.tp \ thapi_tracepoints.tp \ + btx_thapi.yaml \ command.rb \ meta_parameters.rb \ optparse_thapi.rb \ diff --git a/utils/btx_thapi.yaml b/utils/btx_thapi.yaml new file mode 100644 index 000000000..bc908b991 --- /dev/null +++ b/utils/btx_thapi.yaml @@ -0,0 +1,27 @@ +:stream_classes: +- :name: thapi_toggle + :default_clock_class: {} + :packet_context_field_class: + :type: structure + :members: + - :name: cpu_id + :field_class: + :type: integer_unsigned + :cast_type: uint64_t + :field_value_range: 32 + :event_common_context_field_class: + :type: structure + :members: + - :name: vpid + :field_class: + :type: integer_signed + :field_value_range: 32 + :cast_type: int + - :name: vtid + :field_class: + :type: integer_signed + :field_value_range: 32 + :cast_type: int + :event_classes: + - :name: lttng_ust_toggle:start + - :name: lttng_ust_toggle:stop diff --git a/utils/thapi_callbacks.c b/utils/thapi_callbacks.c new file mode 100644 index 000000000..ea500dfc7 --- /dev/null +++ b/utils/thapi_callbacks.c @@ -0,0 +1,35 @@ +#include + +static void init(void **data) { *data = calloc(1, sizeof(int)); } + +static void finalize(void *data) { free(data); } + +static void thapi_start_callback(void *btx_handle, void *push, long int cpuid, + int vpid, int vtid) { + *((int *)push) = 1; +} + +static void thapi_stop_callback(void *btx_handle, void *push, long int cpuid, + int vpid, int vtid) { + *((int *)push) = 0; +} + +static void push_downstream(void *btx_handle, void *push, + const bt_message *msg) { + if (*((int *)push) == 1) + btx_push_message(btx_handle, msg); + else + bt_message_put_ref(msg); +} + +void btx_register_usr_callbacks(void *btx_handle) { + btx_register_callbacks_initialize_component(btx_handle, &init); + btx_register_callbacks_finalize_component(btx_handle, &finalize); + + btx_register_callbacks_lttng_ust_toggle_start(btx_handle, + &thapi_start_callback); + btx_register_callbacks_lttng_ust_toggle_stop(btx_handle, + &thapi_stop_callback); + + btx_register_on_downstream_message_callback(btx_handle, &push_downstream); +} From f32aab6bfb391f9786bc70e3dd4a67537e211ec1 Mon Sep 17 00:00:00 2001 From: Thilina Ratnayaka Date: Wed, 2 Apr 2025 06:10:06 +0000 Subject: [PATCH 17/34] Format utils/thapi_toggle.c --- utils/thapi_toggle.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/utils/thapi_toggle.c b/utils/thapi_toggle.c index 0e363c2f6..65d812110 100644 --- a/utils/thapi_toggle.c +++ b/utils/thapi_toggle.c @@ -1,14 +1,13 @@ -#include "thapi_tracepoints.h" #include "thapi.h" +#include "thapi_tracepoints.h" #ifndef LTTNG_UST_CONSTRUCTOR_PRIO -#error "LTTNG_UST_CONSTRUCTOR_PRIO not defined." +#error "LTTNG_UST_CONSTRUCTOR_PRIO is not defined." #endif -void thapi_start(void) { - tracepoint(lttng_ust_toggle, start); -} +void thapi_start(void) { tracepoint(lttng_ust_toggle, start); } -void __attribute__((constructor(LTTNG_UST_CONSTRUCTOR_PRIO + 1))) thapi_stop(void) { +void __attribute__((constructor(LTTNG_UST_CONSTRUCTOR_PRIO + 1))) +thapi_stop(void) { tracepoint(lttng_ust_toggle, stop); } From a85f3136c253f979092c11acc806d8ef2fe0916f Mon Sep 17 00:00:00 2001 From: Thilina Ratnayaka Date: Tue, 24 Jun 2025 16:09:42 +0000 Subject: [PATCH 18/34] Prefix files related to toggle with `thapi_toggle` Also, minor refactoring in utils/Makefile.am. --- integration_tests/general.bats | 6 +-- .../{thapi_start_stop.c => thapi_toggle.c} | 2 +- utils/Makefile.am | 52 ++++++++++--------- .../{btx_thapi.yaml => btx_thapi_toggle.yaml} | 0 utils/thapi_toggle.c | 2 +- ...i_callbacks.c => thapi_toggle_callbacks.c} | 9 ++-- ...epoints.tp => thapi_toggle_tracepoints.tp} | 0 7 files changed, 35 insertions(+), 36 deletions(-) rename integration_tests/{thapi_start_stop.c => thapi_toggle.c} (78%) rename utils/{btx_thapi.yaml => btx_thapi_toggle.yaml} (100%) rename utils/{thapi_callbacks.c => thapi_toggle_callbacks.c} (79%) rename utils/{thapi_tracepoints.tp => thapi_toggle_tracepoints.tp} (100%) diff --git a/integration_tests/general.bats b/integration_tests/general.bats index d427648f0..7db42965f 100644 --- a/integration_tests/general.bats +++ b/integration_tests/general.bats @@ -104,10 +104,10 @@ teardown_file() { [[ "$output" =~ "FOO" ]] } -@test "thapi_start_stop" { - cc -I${THAPI_INC_DIR} ./integration_tests/thapi_start_stop.c -o thapi_start_stop \ +@test "thapi_toggle" { + cc -I${THAPI_INC_DIR} ./integration_tests/thapi_toggle.c -o thapi_toggle \ -Wl,-rpath,${THAPI_LIB_DIR} -L${THAPI_LIB_DIR} -lThapi - $IPROF --trace-output trace_toggle --no-analysis -- ./thapi_start_stop + $IPROF --trace-output trace_toggle --no-analysis -- ./thapi_toggle start_count=`babeltrace2 trace_toggle | grep lttng_ust_toggle:start | wc -l` [ "$start_count" -eq 1 ] diff --git a/integration_tests/thapi_start_stop.c b/integration_tests/thapi_toggle.c similarity index 78% rename from integration_tests/thapi_start_stop.c rename to integration_tests/thapi_toggle.c index 4a366e57c..bc1e1e900 100644 --- a/integration_tests/thapi_start_stop.c +++ b/integration_tests/thapi_toggle.c @@ -1,4 +1,4 @@ -#include "thapi.h" +#include int main(int argc, char *argv[]) { thapi_start(); diff --git a/utils/Makefile.am b/utils/Makefile.am index 672d88856..afc17da54 100644 --- a/utils/Makefile.am +++ b/utils/Makefile.am @@ -18,7 +18,8 @@ lttng/tracepoint_gen.h: $(srcdir)/tracepoint_gen.rb mkdir -p lttng $(RUBY) $< 25 > $@ -LTTNG_FLAGS=-fPIC -Wall -Wextra -Wno-unused-parameter -Wno-type-limits -Wno-sign-compare $(WERROR) -I$(top_srcdir)/utils -I$(top_srcdir)/utils/include -I./ +LTTNG_FLAGS= -fPIC -Wall -Wextra -Wno-unused-parameter -Wno-type-limits -Wno-sign-compare $(WERROR) \ + -I$(top_srcdir)/utils -I$(top_srcdir)/utils/include -I./ %.h %.c: %.tp lttng/tracepoint_gen.h $(LTTNG_GEN_TP) $< -o $*.c -o $*.h @@ -47,36 +48,37 @@ include_HEADERS = thapi.h lib_LTLIBRARIES = libThapi.la nodist_libThapi_la_SOURCES = \ - thapi_tracepoints.h \ - thapi_tracepoints.c + thapi_toggle_tracepoints.h \ + thapi_toggle_tracepoints.c libThapi_la_SOURCES = thapi_toggle.c libThapi_la_CFLAGS = $(LTTNG_FLAGS) $(LTTNG_UST_CFLAGS) libThapi_la_LDFLAGS = $(LTTNG_UST_LIBS) -BTX_THAPI_GENERATED = \ - btx_thapi/metababel/metababel.h \ - btx_thapi/metababel/btx_component.h \ - btx_thapi/metababel/btx_component.c \ - btx_thapi/metababel/btx_upstream.h \ - btx_thapi/metababel/btx_upstream.c \ - btx_thapi/metababel/btx_downstream.h \ - btx_thapi/metababel/btx_downstream.c \ - btx_thapi/btx_main.c - -$(BTX_THAPI_GENERATED): btx_thapi.yaml thapi_callbacks.c +BTX_THAPI_TOGGLE_GENERATED = \ + btx_thapi_toggle/metababel/metababel.h \ + btx_thapi_toggle/metababel/btx_component.h \ + btx_thapi_toggle/metababel/btx_component.c \ + btx_thapi_toggle/metababel/btx_upstream.h \ + btx_thapi_toggle/metababel/btx_upstream.c \ + btx_thapi_toggle/metababel/btx_downstream.h \ + btx_thapi_toggle/metababel/btx_downstream.c \ + btx_thapi_toggle/btx_main.c + +$(BTX_THAPI_TOGGLE_GENERATED): btx_thapi_toggle.yaml thapi_toggle_callbacks.c $(METABABEL) --enable-callbacks on_downstream --component-type FILTER \ - --upstream $(top_srcdir)/utils/btx_thapi.yaml --downstream $(top_srcdir)/utils/btx_thapi.yaml \ - -o btx_thapi + --upstream $(top_srcdir)/utils/btx_thapi_toggle.yaml --downstream $(top_srcdir)/utils/btx_thapi_toggle.yaml \ + -o btx_thapi_toggle noinst_LTLIBRARIES = libThapiPlugin.la -nodist_libThapiPlugin_la_SOURCES = $(BTX_THAPI_GENERATED) -libThapiPlugin_la_SOURCES = thapi_callbacks.c -libThapiPlugin_la_CFLAGS = -fPIC -shared -Wall -Wextra -Wno-unused-parameter $(BABELTRACE2_CFLAGS) -I./btx_thapi -I$(top_srcdir)/utils/include +nodist_libThapiPlugin_la_SOURCES = $(BTX_THAPI_TOGGLE_GENERATED) +libThapiPlugin_la_SOURCES = thapi_toggle_callbacks.c +libThapiPlugin_la_CFLAGS = -fPIC -shared -Wall -Wextra -Wno-unused-parameter $(BABELTRACE2_CFLAGS) \ + -I./btx_thapi_toggle -I$(top_srcdir)/utils/include BUILT_SOURCES += \ - thapi_tracepoints.h \ - thapi_tracepoints.c \ - $(BTX_THAPI_GENERATED) + thapi_toggle_tracepoints.h \ + thapi_toggle_tracepoints.c \ + $(BTX_THAPI_TOGGLE_GENERATED) bin_SCRIPTS = \ babeltrace_thapi @@ -97,7 +99,7 @@ CLEANFILES = \ version \ optparse_thapi.rb \ lttng/tracepoint_gen.h \ - $(BTX_THAPI_GENERATED) \ + $(BTX_THAPI_TOGGLE_GENERATED) \ $(BUILT_SOURCES) EXTRA_DIST = \ @@ -110,8 +112,8 @@ EXTRA_DIST = \ gen_library_base.rb \ dump_trace_format.rb \ thapi_metadata_tracepoints.tp \ - thapi_tracepoints.tp \ - btx_thapi.yaml \ + thapi_toggle_tracepoints.tp \ + btx_thapi_toggle.yaml \ command.rb \ meta_parameters.rb \ optparse_thapi.rb \ diff --git a/utils/btx_thapi.yaml b/utils/btx_thapi_toggle.yaml similarity index 100% rename from utils/btx_thapi.yaml rename to utils/btx_thapi_toggle.yaml diff --git a/utils/thapi_toggle.c b/utils/thapi_toggle.c index 65d812110..0fedca261 100644 --- a/utils/thapi_toggle.c +++ b/utils/thapi_toggle.c @@ -1,5 +1,5 @@ #include "thapi.h" -#include "thapi_tracepoints.h" +#include "thapi_toggle_tracepoints.h" #ifndef LTTNG_UST_CONSTRUCTOR_PRIO #error "LTTNG_UST_CONSTRUCTOR_PRIO is not defined." diff --git a/utils/thapi_callbacks.c b/utils/thapi_toggle_callbacks.c similarity index 79% rename from utils/thapi_callbacks.c rename to utils/thapi_toggle_callbacks.c index ea500dfc7..4c1145c0c 100644 --- a/utils/thapi_callbacks.c +++ b/utils/thapi_toggle_callbacks.c @@ -4,18 +4,15 @@ static void init(void **data) { *data = calloc(1, sizeof(int)); } static void finalize(void *data) { free(data); } -static void thapi_start_callback(void *btx_handle, void *push, long int cpuid, - int vpid, int vtid) { +static void thapi_start_callback(void *btx_handle, void *push, long int cpuid, int vpid, int vtid) { *((int *)push) = 1; } -static void thapi_stop_callback(void *btx_handle, void *push, long int cpuid, - int vpid, int vtid) { +static void thapi_stop_callback(void *btx_handle, void *push, long int cpuid, int vpid, int vtid) { *((int *)push) = 0; } -static void push_downstream(void *btx_handle, void *push, - const bt_message *msg) { +static void push_downstream(void *btx_handle, void *push, const bt_message *msg) { if (*((int *)push) == 1) btx_push_message(btx_handle, msg); else diff --git a/utils/thapi_tracepoints.tp b/utils/thapi_toggle_tracepoints.tp similarity index 100% rename from utils/thapi_tracepoints.tp rename to utils/thapi_toggle_tracepoints.tp From ab51d264cdb2bb5c02b787884e3b185427174cb1 Mon Sep 17 00:00:00 2001 From: Thilina Ratnayaka Date: Tue, 24 Jun 2025 16:10:12 +0000 Subject: [PATCH 19/34] Check hostname and vpid when using toggle --- utils/Makefile.am | 8 ++-- utils/btx_thapi_toggle.yaml | 15 ++++---- utils/thapi_toggle_callbacks.c | 32 ---------------- utils/thapi_toggle_callbacks.cpp | 65 ++++++++++++++++++++++++++++++++ 4 files changed, 78 insertions(+), 42 deletions(-) delete mode 100644 utils/thapi_toggle_callbacks.c create mode 100644 utils/thapi_toggle_callbacks.cpp diff --git a/utils/Makefile.am b/utils/Makefile.am index afc17da54..e46372ce3 100644 --- a/utils/Makefile.am +++ b/utils/Makefile.am @@ -64,16 +64,18 @@ BTX_THAPI_TOGGLE_GENERATED = \ btx_thapi_toggle/metababel/btx_downstream.c \ btx_thapi_toggle/btx_main.c -$(BTX_THAPI_TOGGLE_GENERATED): btx_thapi_toggle.yaml thapi_toggle_callbacks.c +$(BTX_THAPI_TOGGLE_GENERATED): $(srcdir)/btx_thapi_toggle.yaml $(srcdir)/thapi_toggle_callbacks.cpp $(METABABEL) --enable-callbacks on_downstream --component-type FILTER \ - --upstream $(top_srcdir)/utils/btx_thapi_toggle.yaml --downstream $(top_srcdir)/utils/btx_thapi_toggle.yaml \ + --upstream $(srcdir)/btx_thapi_toggle.yaml --downstream $(srcdir)/btx_thapi_toggle.yaml \ -o btx_thapi_toggle noinst_LTLIBRARIES = libThapiPlugin.la nodist_libThapiPlugin_la_SOURCES = $(BTX_THAPI_TOGGLE_GENERATED) -libThapiPlugin_la_SOURCES = thapi_toggle_callbacks.c +libThapiPlugin_la_SOURCES = thapi_toggle_callbacks.cpp libThapiPlugin_la_CFLAGS = -fPIC -shared -Wall -Wextra -Wno-unused-parameter $(BABELTRACE2_CFLAGS) \ -I./btx_thapi_toggle -I$(top_srcdir)/utils/include +libThapiPlugin_la_CXXFLAGS = -fPIC -shared -Wall -Wextra -Wno-unused-parameter $(BABELTRACE2_CFLAGS) \ + -I./btx_thapi_toggle -I$(top_srcdir)/utils/include BUILT_SOURCES += \ thapi_toggle_tracepoints.h \ diff --git a/utils/btx_thapi_toggle.yaml b/utils/btx_thapi_toggle.yaml index bc908b991..53266a1c0 100644 --- a/utils/btx_thapi_toggle.yaml +++ b/utils/btx_thapi_toggle.yaml @@ -1,3 +1,7 @@ +:environment: + :entries: + - :name: hostname + :type: string :stream_classes: - :name: thapi_toggle :default_clock_class: {} @@ -6,22 +10,19 @@ :members: - :name: cpu_id :field_class: - :type: integer_unsigned - :cast_type: uint64_t - :field_value_range: 32 + :type: integer_signed + :cast_type: int64_t :event_common_context_field_class: :type: structure :members: - :name: vpid :field_class: :type: integer_signed - :field_value_range: 32 - :cast_type: int + :cast_type: int64_t - :name: vtid :field_class: :type: integer_signed - :field_value_range: 32 - :cast_type: int + :cast_type: int64_t :event_classes: - :name: lttng_ust_toggle:start - :name: lttng_ust_toggle:stop diff --git a/utils/thapi_toggle_callbacks.c b/utils/thapi_toggle_callbacks.c deleted file mode 100644 index 4c1145c0c..000000000 --- a/utils/thapi_toggle_callbacks.c +++ /dev/null @@ -1,32 +0,0 @@ -#include - -static void init(void **data) { *data = calloc(1, sizeof(int)); } - -static void finalize(void *data) { free(data); } - -static void thapi_start_callback(void *btx_handle, void *push, long int cpuid, int vpid, int vtid) { - *((int *)push) = 1; -} - -static void thapi_stop_callback(void *btx_handle, void *push, long int cpuid, int vpid, int vtid) { - *((int *)push) = 0; -} - -static void push_downstream(void *btx_handle, void *push, const bt_message *msg) { - if (*((int *)push) == 1) - btx_push_message(btx_handle, msg); - else - bt_message_put_ref(msg); -} - -void btx_register_usr_callbacks(void *btx_handle) { - btx_register_callbacks_initialize_component(btx_handle, &init); - btx_register_callbacks_finalize_component(btx_handle, &finalize); - - btx_register_callbacks_lttng_ust_toggle_start(btx_handle, - &thapi_start_callback); - btx_register_callbacks_lttng_ust_toggle_stop(btx_handle, - &thapi_stop_callback); - - btx_register_on_downstream_message_callback(btx_handle, &push_downstream); -} diff --git a/utils/thapi_toggle_callbacks.cpp b/utils/thapi_toggle_callbacks.cpp new file mode 100644 index 000000000..00e6c183d --- /dev/null +++ b/utils/thapi_toggle_callbacks.cpp @@ -0,0 +1,65 @@ +#include +#include +#include +#include + +#include +#include + +#include + +using ToggleKey = std::tuple; +using ToggleMap = std::map; + +static char hostname_s[HOST_NAME_MAX + 1]; + +static void init(void **data) { *data = new ToggleMap; } + +static void finalize(void *data) { delete static_cast(data); } + +static void thapi_start_callback(void *btx_handle, void *tmap, int64_t cpuid, const char *hostname, + int64_t vpid, int64_t vtid) { + auto map = static_cast(tmap); + auto key = ToggleKey{std::string(hostname), vpid}; + (*map)[key] = true; + strncpy(hostname_s, hostname, HOST_NAME_MAX); +} + +static void thapi_stop_callback(void *btx_handle, void *tmap, int64_t cpuid, const char *hostname, + int64_t vpid, int64_t vtid) { + auto map = static_cast(tmap); + auto key = ToggleKey{std::string(hostname), vpid}; + (*map)[key] = false; +} + +static void push_downstream(void *btx_handle, void *tmap, const bt_message *msg) { + bool push_msg = true; + + if (bt_message_get_type(msg) == BT_MESSAGE_TYPE_EVENT) { + const bt_event *event = bt_message_event_borrow_event_const(msg); + const bt_field *ccf = bt_event_borrow_common_context_field_const(event); + const bt_field *vpid = bt_field_structure_borrow_member_field_by_name_const(ccf, "vpid"); + uint64_t vpid_v = bt_field_integer_signed_get_value(vpid); + + auto map = static_cast(tmap); + auto key = ToggleKey{std::string(hostname_s), vpid_v}; + push_msg = (*map)[key]; + } + + if (push_msg) { + btx_push_message(btx_handle, msg); + } else { + bt_message_put_ref(msg); + } +} + +void btx_register_usr_callbacks(void *btx_handle) { + btx_register_callbacks_initialize_component(btx_handle, &init); + btx_register_callbacks_lttng_ust_toggle_start(btx_handle, + &thapi_start_callback); + btx_register_callbacks_lttng_ust_toggle_stop(btx_handle, + &thapi_stop_callback); + btx_register_callbacks_finalize_component(btx_handle, &finalize); + + btx_register_on_downstream_message_callback(btx_handle, &push_downstream); +} From 4c8e6f1836bfdb082ac6298eb157f34efa27ef94 Mon Sep 17 00:00:00 2001 From: Thilina Ratnayaka Date: Tue, 1 Jul 2025 19:31:49 +0000 Subject: [PATCH 20/34] Install ThapiToggle plugin --- utils/Makefile.am | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/utils/Makefile.am b/utils/Makefile.am index e46372ce3..1d8b89fdf 100644 --- a/utils/Makefile.am +++ b/utils/Makefile.am @@ -64,17 +64,17 @@ BTX_THAPI_TOGGLE_GENERATED = \ btx_thapi_toggle/metababel/btx_downstream.c \ btx_thapi_toggle/btx_main.c -$(BTX_THAPI_TOGGLE_GENERATED): $(srcdir)/btx_thapi_toggle.yaml $(srcdir)/thapi_toggle_callbacks.cpp +$(BTX_THAPI_TOGGLE_GENERATED): $(srcdir)/btx_thapi_toggle.yaml $(METABABEL) --enable-callbacks on_downstream --component-type FILTER \ --upstream $(srcdir)/btx_thapi_toggle.yaml --downstream $(srcdir)/btx_thapi_toggle.yaml \ -o btx_thapi_toggle -noinst_LTLIBRARIES = libThapiPlugin.la -nodist_libThapiPlugin_la_SOURCES = $(BTX_THAPI_TOGGLE_GENERATED) -libThapiPlugin_la_SOURCES = thapi_toggle_callbacks.cpp -libThapiPlugin_la_CFLAGS = -fPIC -shared -Wall -Wextra -Wno-unused-parameter $(BABELTRACE2_CFLAGS) \ +lib_LTLIBRARIES += libThapiToggle.la +nodist_libThapiToggle_la_SOURCES = $(BTX_THAPI_TOGGLE_GENERATED) +libThapiToggle_la_SOURCES = thapi_toggle_callbacks.cpp +libThapiToggle_la_CFLAGS = -fPIC -shared -Wall -Wextra -Wno-unused-parameter $(BABELTRACE2_CFLAGS) \ -I./btx_thapi_toggle -I$(top_srcdir)/utils/include -libThapiPlugin_la_CXXFLAGS = -fPIC -shared -Wall -Wextra -Wno-unused-parameter $(BABELTRACE2_CFLAGS) \ +libThapiToggle_la_CXXFLAGS = -fPIC -shared -Wall -Wextra -Wno-unused-parameter $(BABELTRACE2_CFLAGS) \ -I./btx_thapi_toggle -I$(top_srcdir)/utils/include BUILT_SOURCES += \ From 326e37b830938ee9eccc1594529c1fade07c78f4 Mon Sep 17 00:00:00 2001 From: Thilina Ratnayaka Date: Tue, 1 Jul 2025 16:36:56 +0000 Subject: [PATCH 21/34] Add integration tests for ThapiToggle --- integration_tests/general.bats | 30 ++++++++++++++++++++++++++++ integration_tests/thapi_toggle_mpi.c | 30 ++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 integration_tests/thapi_toggle_mpi.c diff --git a/integration_tests/general.bats b/integration_tests/general.bats index 7db42965f..2198a6eae 100644 --- a/integration_tests/general.bats +++ b/integration_tests/general.bats @@ -115,3 +115,33 @@ teardown_file() { stop_count=`babeltrace2 trace_toggle | grep lttng_ust_toggle:stop | wc -l` [ "$stop_count" -eq 2 ] } + +toggle_count_traces() { + trace_metadata_file=`find toggle_traces -iname metadata` + trace_metadata_dir=$(dirname "${trace_metadata_file}") + + traces=$(babeltrace2 --plugin-path=${THAPI_LIB_DIR} \ + --component source:source.ctf.fs --params "inputs=[\"${trace_metadata_dir}\"]" \ + --component=filter:filter.metababel_filter.btx \ + --component=sink:sink.text.pretty) + rm -rf toggle_traces + + echo $traces | sed -e "s/ \[/@[/g" | sed "s/@/\n/g" | grep . | wc -l +} + +@test "toggle_plugin_mpi_np_1" { + mpicc -I${THAPI_INC_DIR} ./integration_tests/thapi_toggle_mpi.c -o thapi_toggle_mpi \ + -Wl,-rpath,${THAPI_LIB_DIR} -L${THAPI_LIB_DIR} -lThapi + + THAPI_SYNC_DAEMON=fs THAPI_JOBID=0 timeout 40s $MPIRUN -n 1 $IPROF --trace-output toggle_traces --no-analysis -- ./thapi_toggle_mpi 0 + count_0=$(toggle_count_traces) + + THAPI_SYNC_DAEMON=fs THAPI_JOBID=0 timeout 40s $MPIRUN -n 1 $IPROF --trace-output toggle_traces --no-analysis -- ./thapi_toggle_mpi 1 + count_1=$(toggle_count_traces) + + THAPI_SYNC_DAEMON=fs THAPI_JOBID=0 timeout 40s $MPIRUN -n 1 $IPROF --trace-output toggle_traces --no-analysis -- ./thapi_toggle_mpi 2 + count_2=$(toggle_count_traces) + + [ "$count_2" -eq 0 ] + [ "$count_0" -gt "$count_1" ] +} diff --git a/integration_tests/thapi_toggle_mpi.c b/integration_tests/thapi_toggle_mpi.c new file mode 100644 index 000000000..d98fc77cf --- /dev/null +++ b/integration_tests/thapi_toggle_mpi.c @@ -0,0 +1,30 @@ +#include +#include + +#include + +int main(int argc, char *argv[]) { + int variant = (argc > 1) ? atoi(argv[1]) : 0; + + MPI_Init(&argc, &argv); + + int rank, size; + + switch (variant) { + case 0: + thapi_start(); + case 1: + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + if (rank == 0) thapi_start(); + MPI_Comm_size(MPI_COMM_WORLD, &size); + break; + default: + break; + } + + thapi_stop(); + + MPI_Finalize(); + + return 0; +} From 3c66473d4c5e7441674837e173b87c5905ac3641 Mon Sep 17 00:00:00 2001 From: Thilina Ratnayaka Date: Wed, 2 Jul 2025 04:25:18 +0000 Subject: [PATCH 22/34] Add integration tests with np=2 for ThapiToggle --- integration_tests/general.bats | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/integration_tests/general.bats b/integration_tests/general.bats index 2198a6eae..827e6f5dc 100644 --- a/integration_tests/general.bats +++ b/integration_tests/general.bats @@ -145,3 +145,23 @@ toggle_count_traces() { [ "$count_2" -eq 0 ] [ "$count_0" -gt "$count_1" ] } + +toggle_count_vpids() { + vpids=$(babeltrace2 toggle_traces | sed -e "s/, { vpid = /\nvpid,/g" | grep vpid | awk '{ split($0,a,","); print a[2] }' | sort | uniq | wc -l) + rm -rf toggle_traces + echo $vpids +} + +@test "toggle_plugin_mpi_np_2" { + mpicc -I${THAPI_INC_DIR} ./integration_tests/thapi_toggle_mpi.c -o thapi_toggle_mpi \ + -Wl,-rpath,${THAPI_LIB_DIR} -L${THAPI_LIB_DIR} -lThapi + + THAPI_SYNC_DAEMON=fs THAPI_JOBID=0 timeout 40s $MPIRUN -n 2 $IPROF --trace-output toggle_traces --no-analysis -- ./thapi_toggle_mpi 0 + count_0=$(toggle_count_vpids) + + THAPI_SYNC_DAEMON=fs THAPI_JOBID=0 timeout 40s $MPIRUN -n 2 $IPROF --trace-output toggle_traces --no-analysis -- ./thapi_toggle_mpi 1 + count_1=$(toggle_count_vpids) + + [ "$count_0" -eq 2 ] + [ "$count_1" -eq 1 ] +} From 642bdf131b990efc1ebe9f00f55ce8fa2a0c6733 Mon Sep 17 00:00:00 2001 From: Thilina Ratnayaka Date: Wed, 2 Jul 2025 04:32:29 +0000 Subject: [PATCH 23/34] Fix typos and refactor toggle tests --- integration_tests/general.bats | 48 ++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/integration_tests/general.bats b/integration_tests/general.bats index 827e6f5dc..04f048580 100644 --- a/integration_tests/general.bats +++ b/integration_tests/general.bats @@ -104,28 +104,37 @@ teardown_file() { [[ "$output" =~ "FOO" ]] } -@test "thapi_toggle" { +@test "toggle_api" { + rm -rf toggle_traces 2> /dev/null + cc -I${THAPI_INC_DIR} ./integration_tests/thapi_toggle.c -o thapi_toggle \ -Wl,-rpath,${THAPI_LIB_DIR} -L${THAPI_LIB_DIR} -lThapi - $IPROF --trace-output trace_toggle --no-analysis -- ./thapi_toggle + $IPROF --trace-output toggle_traces --no-analysis -- ./thapi_toggle - start_count=`babeltrace2 trace_toggle | grep lttng_ust_toggle:start | wc -l` + start_count=`babeltrace2 toggle_traces | grep lttng_ust_toggle:start | wc -l` [ "$start_count" -eq 1 ] - stop_count=`babeltrace2 trace_toggle | grep lttng_ust_toggle:stop | wc -l` + stop_count=`babeltrace2 toggle_traces | grep lttng_ust_toggle:stop | wc -l` [ "$stop_count" -eq 2 ] } -toggle_count_traces() { +toggle_count_base() { + rm -rf toggle_traces 2> /dev/null + + THAPI_SYNC_DAEMON=fs THAPI_JOBID=$3 timeout 40s $MPIRUN -n $1 $IPROF --trace-output toggle_traces --no-analysis -- ./thapi_toggle_mpi $2 + trace_metadata_file=`find toggle_traces -iname metadata` trace_metadata_dir=$(dirname "${trace_metadata_file}") - traces=$(babeltrace2 --plugin-path=${THAPI_LIB_DIR} \ --component source:source.ctf.fs --params "inputs=[\"${trace_metadata_dir}\"]" \ --component=filter:filter.metababel_filter.btx \ --component=sink:sink.text.pretty) - rm -rf toggle_traces + echo $traces +} + +toggle_count_traces() { + traces=$(toggle_count_base $1 $2 $3) echo $traces | sed -e "s/ \[/@[/g" | sed "s/@/\n/g" | grep . | wc -l } @@ -133,35 +142,28 @@ toggle_count_traces() { mpicc -I${THAPI_INC_DIR} ./integration_tests/thapi_toggle_mpi.c -o thapi_toggle_mpi \ -Wl,-rpath,${THAPI_LIB_DIR} -L${THAPI_LIB_DIR} -lThapi - THAPI_SYNC_DAEMON=fs THAPI_JOBID=0 timeout 40s $MPIRUN -n 1 $IPROF --trace-output toggle_traces --no-analysis -- ./thapi_toggle_mpi 0 - count_0=$(toggle_count_traces) - - THAPI_SYNC_DAEMON=fs THAPI_JOBID=0 timeout 40s $MPIRUN -n 1 $IPROF --trace-output toggle_traces --no-analysis -- ./thapi_toggle_mpi 1 - count_1=$(toggle_count_traces) - - THAPI_SYNC_DAEMON=fs THAPI_JOBID=0 timeout 40s $MPIRUN -n 1 $IPROF --trace-output toggle_traces --no-analysis -- ./thapi_toggle_mpi 2 - count_2=$(toggle_count_traces) + count_0=$(toggle_count_traces 1 0 100) + count_1=$(toggle_count_traces 1 1 101) + count_2=$(toggle_count_traces 1 2 102) [ "$count_2" -eq 0 ] [ "$count_0" -gt "$count_1" ] } toggle_count_vpids() { - vpids=$(babeltrace2 toggle_traces | sed -e "s/, { vpid = /\nvpid,/g" | grep vpid | awk '{ split($0,a,","); print a[2] }' | sort | uniq | wc -l) - rm -rf toggle_traces - echo $vpids + traces=$(toggle_count_base $1 $2 $3) + echo $traces | sed -e "s/ - /, /g" | sed -e "s/,/\n/g" | grep vpid | sort | uniq | wc -l } @test "toggle_plugin_mpi_np_2" { mpicc -I${THAPI_INC_DIR} ./integration_tests/thapi_toggle_mpi.c -o thapi_toggle_mpi \ -Wl,-rpath,${THAPI_LIB_DIR} -L${THAPI_LIB_DIR} -lThapi - THAPI_SYNC_DAEMON=fs THAPI_JOBID=0 timeout 40s $MPIRUN -n 2 $IPROF --trace-output toggle_traces --no-analysis -- ./thapi_toggle_mpi 0 - count_0=$(toggle_count_vpids) - - THAPI_SYNC_DAEMON=fs THAPI_JOBID=0 timeout 40s $MPIRUN -n 2 $IPROF --trace-output toggle_traces --no-analysis -- ./thapi_toggle_mpi 1 - count_1=$(toggle_count_vpids) + count_0=$(toggle_count_vpids 2 0 200) + count_1=$(toggle_count_vpids 2 1 201) + count_2=$(toggle_count_vpids 2 2 202) [ "$count_0" -eq 2 ] [ "$count_1" -eq 1 ] + [ "$count_2" -eq 0 ] } From 5f7ee1f8cec0b1a5e008e4cae51e0e98c9832dc7 Mon Sep 17 00:00:00 2001 From: Thilina Ratnayaka Date: Thu, 3 Jul 2025 16:31:25 +0000 Subject: [PATCH 24/34] Move toggle tests into toggle.bats --- integration_tests/general.bats | 64 -------------------------- integration_tests/toggle.bats | 84 ++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 64 deletions(-) create mode 100644 integration_tests/toggle.bats diff --git a/integration_tests/general.bats b/integration_tests/general.bats index 04f048580..3c49cff41 100644 --- a/integration_tests/general.bats +++ b/integration_tests/general.bats @@ -103,67 +103,3 @@ teardown_file() { run bats_pipe echo "FOO" \| $IPROF cat [[ "$output" =~ "FOO" ]] } - -@test "toggle_api" { - rm -rf toggle_traces 2> /dev/null - - cc -I${THAPI_INC_DIR} ./integration_tests/thapi_toggle.c -o thapi_toggle \ - -Wl,-rpath,${THAPI_LIB_DIR} -L${THAPI_LIB_DIR} -lThapi - $IPROF --trace-output toggle_traces --no-analysis -- ./thapi_toggle - - start_count=`babeltrace2 toggle_traces | grep lttng_ust_toggle:start | wc -l` - [ "$start_count" -eq 1 ] - - stop_count=`babeltrace2 toggle_traces | grep lttng_ust_toggle:stop | wc -l` - [ "$stop_count" -eq 2 ] -} - -toggle_count_base() { - rm -rf toggle_traces 2> /dev/null - - THAPI_SYNC_DAEMON=fs THAPI_JOBID=$3 timeout 40s $MPIRUN -n $1 $IPROF --trace-output toggle_traces --no-analysis -- ./thapi_toggle_mpi $2 - - trace_metadata_file=`find toggle_traces -iname metadata` - trace_metadata_dir=$(dirname "${trace_metadata_file}") - traces=$(babeltrace2 --plugin-path=${THAPI_LIB_DIR} \ - --component source:source.ctf.fs --params "inputs=[\"${trace_metadata_dir}\"]" \ - --component=filter:filter.metababel_filter.btx \ - --component=sink:sink.text.pretty) - - echo $traces -} - -toggle_count_traces() { - traces=$(toggle_count_base $1 $2 $3) - echo $traces | sed -e "s/ \[/@[/g" | sed "s/@/\n/g" | grep . | wc -l -} - -@test "toggle_plugin_mpi_np_1" { - mpicc -I${THAPI_INC_DIR} ./integration_tests/thapi_toggle_mpi.c -o thapi_toggle_mpi \ - -Wl,-rpath,${THAPI_LIB_DIR} -L${THAPI_LIB_DIR} -lThapi - - count_0=$(toggle_count_traces 1 0 100) - count_1=$(toggle_count_traces 1 1 101) - count_2=$(toggle_count_traces 1 2 102) - - [ "$count_2" -eq 0 ] - [ "$count_0" -gt "$count_1" ] -} - -toggle_count_vpids() { - traces=$(toggle_count_base $1 $2 $3) - echo $traces | sed -e "s/ - /, /g" | sed -e "s/,/\n/g" | grep vpid | sort | uniq | wc -l -} - -@test "toggle_plugin_mpi_np_2" { - mpicc -I${THAPI_INC_DIR} ./integration_tests/thapi_toggle_mpi.c -o thapi_toggle_mpi \ - -Wl,-rpath,${THAPI_LIB_DIR} -L${THAPI_LIB_DIR} -lThapi - - count_0=$(toggle_count_vpids 2 0 200) - count_1=$(toggle_count_vpids 2 1 201) - count_2=$(toggle_count_vpids 2 2 202) - - [ "$count_0" -eq 2 ] - [ "$count_1" -eq 1 ] - [ "$count_2" -eq 0 ] -} diff --git a/integration_tests/toggle.bats b/integration_tests/toggle.bats new file mode 100644 index 000000000..ed04563ba --- /dev/null +++ b/integration_tests/toggle.bats @@ -0,0 +1,84 @@ +#!/usr/bin/env bats + +setup_file() { + export THAPI_HOME=${THAPI_HOME:-${PWD}} + export THAPI_INSTALL_DIR=${THAPI_INSTALL_DIR:-${PWD}/build/ici/} + export THAPI_BIN_DIR=${THAPI_BIN_DIR:-${THAPI_INSTALL_DIR}/bin} + export THAPI_INC_DIR=${THAPI_INC_DIR:-${THAPI_INSTALL_DIR}/include} + export THAPI_LIB_DIR=${THAPI_LIB_DIR:-${THAPI_INSTALL_DIR}/lib} + + export IPROF=$THAPI_BIN_DIR/iprof + export MPIRUN=${MPIRUN:-mpirun} +} + +teardown_file() { + rm -rf $THAPI_HOME/thapi-traces +} + +get_unique_jobid() { + echo ${BATS_TEST_NAME}.${RANDOM} +} + +@test "toggle_api" { + rm -rf toggle_traces 2> /dev/null + + cc -I${THAPI_INC_DIR} ./integration_tests/thapi_toggle.c -o thapi_toggle \ + -Wl,-rpath,${THAPI_LIB_DIR} -L${THAPI_LIB_DIR} -lThapi + $IPROF --trace-output toggle_traces --no-analysis -- ./thapi_toggle + + start_count=`babeltrace2 toggle_traces | grep lttng_ust_toggle:start | wc -l` + [ "$start_count" -eq 1 ] + + stop_count=`babeltrace2 toggle_traces | grep lttng_ust_toggle:stop | wc -l` + [ "$stop_count" -eq 2 ] +} + +toggle_count_base() { + rm -rf toggle_traces 2> /dev/null + + THAPI_SYNC_DAEMON=fs THAPI_JOBID=$(get_unique_jobid) timeout 40s $MPIRUN -n $1 $IPROF --trace-output toggle_traces --no-analysis -- ./thapi_toggle_mpi $2 + + trace_metadata_file=`find toggle_traces -iname metadata` + trace_metadata_dir=$(dirname "${trace_metadata_file}") + traces=$(babeltrace2 --plugin-path=${THAPI_LIB_DIR} \ + --component source:source.ctf.fs --params "inputs=[\"${trace_metadata_dir}\"]" \ + --component=filter:filter.metababel_filter.btx \ + --component=sink:sink.text.pretty) + + echo $traces +} + +toggle_count_traces() { + traces=$(toggle_count_base $1 $2) + echo $traces | sed -e "s/ \[/@[/g" | sed "s/@/\n/g" | grep . | wc -l +} + +@test "toggle_plugin_mpi_np_1" { + mpicc -I${THAPI_INC_DIR} ./integration_tests/thapi_toggle_mpi.c -o thapi_toggle_mpi \ + -Wl,-rpath,${THAPI_LIB_DIR} -L${THAPI_LIB_DIR} -lThapi + + count_0=$(toggle_count_traces 1 0) + count_1=$(toggle_count_traces 1 1) + count_2=$(toggle_count_traces 1 2) + + [ "$count_2" -eq 0 ] + [ "$count_0" -gt "$count_1" ] +} + +toggle_count_vpids() { + traces=$(toggle_count_base $1 $2) + echo $traces | sed -e "s/ - /, /g" | sed -e "s/,/\n/g" | grep vpid | sort | uniq | wc -l +} + +@test "toggle_plugin_mpi_np_2" { + mpicc -I${THAPI_INC_DIR} ./integration_tests/thapi_toggle_mpi.c -o thapi_toggle_mpi \ + -Wl,-rpath,${THAPI_LIB_DIR} -L${THAPI_LIB_DIR} -lThapi + + count_0=$(toggle_count_vpids 2 0) + count_1=$(toggle_count_vpids 2 1) + count_2=$(toggle_count_vpids 2 2) + + [ "$count_0" -eq 2 ] + [ "$count_1" -eq 1 ] + [ "$count_2" -eq 0 ] +} From 72855798bad04c5270dc3e396caa10ab36a52576 Mon Sep 17 00:00:00 2001 From: Thilina Ratnayaka Date: Thu, 3 Jul 2025 16:47:27 +0000 Subject: [PATCH 25/34] Use babeltrace_thapi instead of babeltrace2 --- integration_tests/toggle.bats | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/integration_tests/toggle.bats b/integration_tests/toggle.bats index ed04563ba..d997a8b48 100644 --- a/integration_tests/toggle.bats +++ b/integration_tests/toggle.bats @@ -9,6 +9,7 @@ setup_file() { export IPROF=$THAPI_BIN_DIR/iprof export MPIRUN=${MPIRUN:-mpirun} + export BBT=${THAPI_BIN_DIR}/babeltrace_thapi } teardown_file() { @@ -24,12 +25,14 @@ get_unique_jobid() { cc -I${THAPI_INC_DIR} ./integration_tests/thapi_toggle.c -o thapi_toggle \ -Wl,-rpath,${THAPI_LIB_DIR} -L${THAPI_LIB_DIR} -lThapi + $IPROF --trace-output toggle_traces --no-analysis -- ./thapi_toggle + dir=$(ls -d -1 ./toggle_traces/*/) - start_count=`babeltrace2 toggle_traces | grep lttng_ust_toggle:start | wc -l` + start_count=`$BBT -c $dir | grep lttng_ust_toggle:start | wc -l` [ "$start_count" -eq 1 ] - stop_count=`babeltrace2 toggle_traces | grep lttng_ust_toggle:stop | wc -l` + stop_count=`$BBT -c $dir | grep lttng_ust_toggle:stop | wc -l` [ "$stop_count" -eq 2 ] } From 0c026cb163183fa07e59be4bda25704d212ba115 Mon Sep 17 00:00:00 2001 From: Thilina Ratnayaka Date: Thu, 3 Jul 2025 17:22:50 +0000 Subject: [PATCH 26/34] Simplify trace counting --- integration_tests/toggle.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration_tests/toggle.bats b/integration_tests/toggle.bats index d997a8b48..766099683 100644 --- a/integration_tests/toggle.bats +++ b/integration_tests/toggle.bats @@ -53,7 +53,7 @@ toggle_count_base() { toggle_count_traces() { traces=$(toggle_count_base $1 $2) - echo $traces | sed -e "s/ \[/@[/g" | sed "s/@/\n/g" | grep . | wc -l + echo $traces | sed -e "s/ \[/\n[/g" | grep . | wc -l } @test "toggle_plugin_mpi_np_1" { From 65def13bbbb368aac5c50c3c99331eac8eed4d10 Mon Sep 17 00:00:00 2001 From: Thilina Ratnayaka Date: Mon, 14 Jul 2025 17:31:51 +0000 Subject: [PATCH 27/34] Set and use the env vars from setup_suite.bash --- .github/workflows/presubmit.yml | 2 +- integration_tests/setup_suite.bash | 5 ++++- integration_tests/toggle.bats | 12 ------------ 3 files changed, 5 insertions(+), 14 deletions(-) diff --git a/.github/workflows/presubmit.yml b/.github/workflows/presubmit.yml index d3b0d433a..d898cfdff 100644 --- a/.github/workflows/presubmit.yml +++ b/.github/workflows/presubmit.yml @@ -132,7 +132,7 @@ jobs: if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }} - name: Integration test run: | - THAPI_BIN_DIR=./build/ici/bin bats integration_tests/ + THAPI_INSTALL_DIR=./build/ici bats integration_tests/ build-in-tree-and-check: needs: efficios_dep diff --git a/integration_tests/setup_suite.bash b/integration_tests/setup_suite.bash index e01a9c4c0..5e9d26d61 100644 --- a/integration_tests/setup_suite.bash +++ b/integration_tests/setup_suite.bash @@ -2,7 +2,10 @@ setup_suite() { export THAPI_HOME=${THAPI_HOME:-${PWD}} - export THAPI_BIN_DIR=${THAPI_BIN_DIR:-${THAPI_HOME}/install/bin} + export THAPI_INSTALL_DIR=${THAPI_INSTALL_DIR:-${THAPI_HOME}/install} + export THAPI_BIN_DIR=${THAPI_BIN_DIR:-${THAPI_INSTALL_DIR}/bin} + export THAPI_INC_DIR=${THAPI_INC_DIR:-${THAPI_INSTALL_DIR}/include} + export THAPI_LIB_DIR=${THAPI_LIB_DIR:-${THAPI_INSTALL_DIR}/lib} export THAPI_TEST_BIN=${THAPI_TEST_BIN:-clinfo} export IPROF=${IPROF:-${THAPI_BIN_DIR}/iprof} diff --git a/integration_tests/toggle.bats b/integration_tests/toggle.bats index 766099683..880b80771 100644 --- a/integration_tests/toggle.bats +++ b/integration_tests/toggle.bats @@ -1,17 +1,5 @@ #!/usr/bin/env bats -setup_file() { - export THAPI_HOME=${THAPI_HOME:-${PWD}} - export THAPI_INSTALL_DIR=${THAPI_INSTALL_DIR:-${PWD}/build/ici/} - export THAPI_BIN_DIR=${THAPI_BIN_DIR:-${THAPI_INSTALL_DIR}/bin} - export THAPI_INC_DIR=${THAPI_INC_DIR:-${THAPI_INSTALL_DIR}/include} - export THAPI_LIB_DIR=${THAPI_LIB_DIR:-${THAPI_INSTALL_DIR}/lib} - - export IPROF=$THAPI_BIN_DIR/iprof - export MPIRUN=${MPIRUN:-mpirun} - export BBT=${THAPI_BIN_DIR}/babeltrace_thapi -} - teardown_file() { rm -rf $THAPI_HOME/thapi-traces } From 64df7de1996893575905a098508ce78d668bf76f Mon Sep 17 00:00:00 2001 From: Thilina Ratnayaka Date: Mon, 14 Jul 2025 18:33:15 +0000 Subject: [PATCH 28/34] Rename the filter to `toggle` --- integration_tests/toggle.bats | 2 +- utils/Makefile.am | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/integration_tests/toggle.bats b/integration_tests/toggle.bats index 880b80771..0dfeaa6bf 100644 --- a/integration_tests/toggle.bats +++ b/integration_tests/toggle.bats @@ -33,7 +33,7 @@ toggle_count_base() { trace_metadata_dir=$(dirname "${trace_metadata_file}") traces=$(babeltrace2 --plugin-path=${THAPI_LIB_DIR} \ --component source:source.ctf.fs --params "inputs=[\"${trace_metadata_dir}\"]" \ - --component=filter:filter.metababel_filter.btx \ + --component=filter:filter.toggle.btx \ --component=sink:sink.text.pretty) echo $traces diff --git a/utils/Makefile.am b/utils/Makefile.am index 1d8b89fdf..45c4b4778 100644 --- a/utils/Makefile.am +++ b/utils/Makefile.am @@ -65,7 +65,7 @@ BTX_THAPI_TOGGLE_GENERATED = \ btx_thapi_toggle/btx_main.c $(BTX_THAPI_TOGGLE_GENERATED): $(srcdir)/btx_thapi_toggle.yaml - $(METABABEL) --enable-callbacks on_downstream --component-type FILTER \ + $(METABABEL) --enable-callbacks on_downstream --component-type FILTER -p toggle \ --upstream $(srcdir)/btx_thapi_toggle.yaml --downstream $(srcdir)/btx_thapi_toggle.yaml \ -o btx_thapi_toggle From 69f6c627b76cdfb2fe34068a362d66101da4ca28 Mon Sep 17 00:00:00 2001 From: Thilina Ratnayaka Date: Mon, 14 Jul 2025 18:34:44 +0000 Subject: [PATCH 29/34] Rename `thapi_toggle_* -> toggle_* in tests --- integration_tests/toggle.bats | 11 ++++++----- integration_tests/{thapi_toggle.c => toggle.c} | 0 .../{thapi_toggle_mpi.c => toggle_mpi.c} | 0 3 files changed, 6 insertions(+), 5 deletions(-) rename integration_tests/{thapi_toggle.c => toggle.c} (100%) rename integration_tests/{thapi_toggle_mpi.c => toggle_mpi.c} (100%) diff --git a/integration_tests/toggle.bats b/integration_tests/toggle.bats index 0dfeaa6bf..4a7b74471 100644 --- a/integration_tests/toggle.bats +++ b/integration_tests/toggle.bats @@ -11,10 +11,10 @@ get_unique_jobid() { @test "toggle_api" { rm -rf toggle_traces 2> /dev/null - cc -I${THAPI_INC_DIR} ./integration_tests/thapi_toggle.c -o thapi_toggle \ + cc -I${THAPI_INC_DIR} ./integration_tests/toggle.c -o toggle \ -Wl,-rpath,${THAPI_LIB_DIR} -L${THAPI_LIB_DIR} -lThapi - $IPROF --trace-output toggle_traces --no-analysis -- ./thapi_toggle + $IPROF --trace-output toggle_traces --no-analysis -- ./toggle dir=$(ls -d -1 ./toggle_traces/*/) start_count=`$BBT -c $dir | grep lttng_ust_toggle:start | wc -l` @@ -27,7 +27,8 @@ get_unique_jobid() { toggle_count_base() { rm -rf toggle_traces 2> /dev/null - THAPI_SYNC_DAEMON=fs THAPI_JOBID=$(get_unique_jobid) timeout 40s $MPIRUN -n $1 $IPROF --trace-output toggle_traces --no-analysis -- ./thapi_toggle_mpi $2 + THAPI_SYNC_DAEMON=fs THAPI_JOBID=$(get_unique_jobid) timeout 40s $MPIRUN -n $1 \ + $IPROF --trace-output toggle_traces --no-analysis -- ./toggle_mpi $2 trace_metadata_file=`find toggle_traces -iname metadata` trace_metadata_dir=$(dirname "${trace_metadata_file}") @@ -45,7 +46,7 @@ toggle_count_traces() { } @test "toggle_plugin_mpi_np_1" { - mpicc -I${THAPI_INC_DIR} ./integration_tests/thapi_toggle_mpi.c -o thapi_toggle_mpi \ + mpicc -I${THAPI_INC_DIR} ./integration_tests/toggle_mpi.c -o toggle_mpi \ -Wl,-rpath,${THAPI_LIB_DIR} -L${THAPI_LIB_DIR} -lThapi count_0=$(toggle_count_traces 1 0) @@ -62,7 +63,7 @@ toggle_count_vpids() { } @test "toggle_plugin_mpi_np_2" { - mpicc -I${THAPI_INC_DIR} ./integration_tests/thapi_toggle_mpi.c -o thapi_toggle_mpi \ + mpicc -I${THAPI_INC_DIR} ./integration_tests/toggle_mpi.c -o toggle_mpi \ -Wl,-rpath,${THAPI_LIB_DIR} -L${THAPI_LIB_DIR} -lThapi count_0=$(toggle_count_vpids 2 0) diff --git a/integration_tests/thapi_toggle.c b/integration_tests/toggle.c similarity index 100% rename from integration_tests/thapi_toggle.c rename to integration_tests/toggle.c diff --git a/integration_tests/thapi_toggle_mpi.c b/integration_tests/toggle_mpi.c similarity index 100% rename from integration_tests/thapi_toggle_mpi.c rename to integration_tests/toggle_mpi.c From 87b2c1002de6bbaad212eeee34ab84fb66035efb Mon Sep 17 00:00:00 2001 From: Thilina Ratnayaka Date: Tue, 15 Jul 2025 17:02:04 +0000 Subject: [PATCH 30/34] Undo spliting LTTNNG_FLAGS --- utils/Makefile.am | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/utils/Makefile.am b/utils/Makefile.am index 45c4b4778..d9c64b5ae 100644 --- a/utils/Makefile.am +++ b/utils/Makefile.am @@ -18,8 +18,7 @@ lttng/tracepoint_gen.h: $(srcdir)/tracepoint_gen.rb mkdir -p lttng $(RUBY) $< 25 > $@ -LTTNG_FLAGS= -fPIC -Wall -Wextra -Wno-unused-parameter -Wno-type-limits -Wno-sign-compare $(WERROR) \ - -I$(top_srcdir)/utils -I$(top_srcdir)/utils/include -I./ +LTTNG_FLAGS=-fPIC -Wall -Wextra -Wno-unused-parameter -Wno-type-limits -Wno-sign-compare $(WERROR) -I$(top_srcdir)/utils -I$(top_srcdir)/utils/include -I./ %.h %.c: %.tp lttng/tracepoint_gen.h $(LTTNG_GEN_TP) $< -o $*.c -o $*.h From 71f50eb4a7f88201a7426c1bb3cf9d4703b67eb8 Mon Sep 17 00:00:00 2001 From: Thilina Ratnayaka Date: Tue, 15 Jul 2025 20:21:02 +0000 Subject: [PATCH 31/34] Comment why lttng-ust version change is required --- configure.ac | 3 +++ 1 file changed, 3 insertions(+) diff --git a/configure.ac b/configure.ac index d08d3197f..464ccbb6b 100644 --- a/configure.ac +++ b/configure.ac @@ -102,6 +102,9 @@ AC_SUBST([ENABLE_CLANG_PARSER]) PKG_CHECK_MODULES([LIBFFI], [libffi >= 3.2]) PKG_CHECK_MODULES([BABELTRACE2], [babeltrace2 >= 2.0]) +# Use of __attribute__((constructor)) requires `lttng-ust >= 2.12.8` to work properly. +# Specifically, the following fix: +# https://github.com/lttng/lttng-ust/commit/a8fafb675a9f580f6a889223e26664ea11cb0c99. PKG_CHECK_MODULES([LTTNG_UST], [lttng-ust >= 2.12.8]) PKG_CHECK_MODULES([PROTOBUF], [protobuf >= 3.0]) From 95f5d4e51aa4099f54cc4089ea3cccc890e3e14f Mon Sep 17 00:00:00 2001 From: Thilina Ratnayaka Date: Mon, 29 Sep 2025 18:52:07 +0000 Subject: [PATCH 32/34] Install libThapiToggle.so in bt2 plugin dir --- integration_tests/toggle.bats | 7 +------ utils/Makefile.am | 4 +++- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/integration_tests/toggle.bats b/integration_tests/toggle.bats index 4a7b74471..0b7060776 100644 --- a/integration_tests/toggle.bats +++ b/integration_tests/toggle.bats @@ -30,12 +30,7 @@ toggle_count_base() { THAPI_SYNC_DAEMON=fs THAPI_JOBID=$(get_unique_jobid) timeout 40s $MPIRUN -n $1 \ $IPROF --trace-output toggle_traces --no-analysis -- ./toggle_mpi $2 - trace_metadata_file=`find toggle_traces -iname metadata` - trace_metadata_dir=$(dirname "${trace_metadata_file}") - traces=$(babeltrace2 --plugin-path=${THAPI_LIB_DIR} \ - --component source:source.ctf.fs --params "inputs=[\"${trace_metadata_dir}\"]" \ - --component=filter:filter.toggle.btx \ - --component=sink:sink.text.pretty) + traces=$($BBT ./toggle_traces) echo $traces } diff --git a/utils/Makefile.am b/utils/Makefile.am index d9c64b5ae..b1d0812fb 100644 --- a/utils/Makefile.am +++ b/utils/Makefile.am @@ -68,7 +68,9 @@ $(BTX_THAPI_TOGGLE_GENERATED): $(srcdir)/btx_thapi_toggle.yaml --upstream $(srcdir)/btx_thapi_toggle.yaml --downstream $(srcdir)/btx_thapi_toggle.yaml \ -o btx_thapi_toggle -lib_LTLIBRARIES += libThapiToggle.la +bt2dir = $(pkglibdir)/bt2 +bt2_LTLIBRARIES = libThapiToggle.la + nodist_libThapiToggle_la_SOURCES = $(BTX_THAPI_TOGGLE_GENERATED) libThapiToggle_la_SOURCES = thapi_toggle_callbacks.cpp libThapiToggle_la_CFLAGS = -fPIC -shared -Wall -Wextra -Wno-unused-parameter $(BABELTRACE2_CFLAGS) \ From 15f1a4feb4e58973056d55038676bf3d7220549b Mon Sep 17 00:00:00 2001 From: Thilina Ratnayaka Date: Wed, 1 Oct 2025 01:41:38 +0000 Subject: [PATCH 33/34] Fix libThapiToggle.so flags --- utils/Makefile.am | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/utils/Makefile.am b/utils/Makefile.am index b1d0812fb..b6a6e9f29 100644 --- a/utils/Makefile.am +++ b/utils/Makefile.am @@ -63,10 +63,10 @@ BTX_THAPI_TOGGLE_GENERATED = \ btx_thapi_toggle/metababel/btx_downstream.c \ btx_thapi_toggle/btx_main.c -$(BTX_THAPI_TOGGLE_GENERATED): $(srcdir)/btx_thapi_toggle.yaml - $(METABABEL) --enable-callbacks on_downstream --component-type FILTER -p toggle \ - --upstream $(srcdir)/btx_thapi_toggle.yaml --downstream $(srcdir)/btx_thapi_toggle.yaml \ - -o btx_thapi_toggle +$(BTX_THAPI_TOGGLE_GENERATED) &: $(srcdir)/btx_thapi_toggle.yaml + $(METABABEL) --enable-callbacks on_downstream -t FILTER -p toggle -c toggle \ + --upstream $(srcdir)/btx_thapi_toggle.yaml --downstream $(srcdir)/btx_thapi_toggle.yaml \ + -o btx_thapi_toggle bt2dir = $(pkglibdir)/bt2 bt2_LTLIBRARIES = libThapiToggle.la @@ -77,6 +77,7 @@ libThapiToggle_la_CFLAGS = -fPIC -shared -Wall -Wextra -Wno-unused-parameter $(B -I./btx_thapi_toggle -I$(top_srcdir)/utils/include libThapiToggle_la_CXXFLAGS = -fPIC -shared -Wall -Wextra -Wno-unused-parameter $(BABELTRACE2_CFLAGS) \ -I./btx_thapi_toggle -I$(top_srcdir)/utils/include +libThapiToggle_la_LDFLAGS = $(BABELTRACE2_LIBS) -avoid-version -module BUILT_SOURCES += \ thapi_toggle_tracepoints.h \ From 7a184b784d7b27ace063ca81ff6f7570d326cc4a Mon Sep 17 00:00:00 2001 From: Thilina Ratnayaka Date: Wed, 1 Oct 2025 01:42:03 +0000 Subject: [PATCH 34/34] Run filter.toggle.toggle during trace command --- utils/babeltrace_thapi.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/babeltrace_thapi.in b/utils/babeltrace_thapi.in index 8a7b9a9db..915e66dbd 100755 --- a/utils/babeltrace_thapi.in +++ b/utils/babeltrace_thapi.in @@ -322,7 +322,7 @@ def bt_graphs(inputs) 'filter.btx_aggreg.aggreg', 'sink.btx_tally.tally'], 'timeline' => ['filter.intervals.interval', 'sink.btx_timeline.timeline'], - 'trace' => ['sink.text.rubypretty'], + 'trace' => ['filter.toggle.toggle', 'sink.text.rubypretty'], 'to_interval' => ['filter.intervals.interval', 'filter.btx_stripper.stripper', 'sink.ctf.fs'], 'to_aggreg' => ['filter.intervals.interval', 'filter.btx_aggreg.aggreg',