Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
ac2be88
Generate traces for thapi_start() and thapi_end()
thilinarmtb Feb 28, 2025
ba3fbfb
Call thapi_stop() if libtoggle is linked
thilinarmtb Mar 3, 2025
6bce142
Rename toggle to ThapiProfiler
thilinarmtb Mar 3, 2025
a7fbbd2
Add `profiler_` to ThapiProfiler symbols
thilinarmtb Mar 3, 2025
3fa640e
Fix `make distcheck` failure
thilinarmtb Mar 6, 2025
aa43ce2
Remove profiler from symbols
thilinarmtb Mar 6, 2025
7648e79
Use AX_GCC_FUNC_ATTRIBUTE to check constructor support
thilinarmtb Mar 6, 2025
feb3163
Install libThapi.so in lib instead of lib/thapi
thilinarmtb Mar 6, 2025
f4dc0ba
Add an integration test
thilinarmtb Mar 6, 2025
c0976f8
Minor changes in utils/thapi.[ch]
thilinarmtb Mar 6, 2025
b5a9d86
Fix the failing integration test
thilinarmtb Mar 18, 2025
21d4b0a
thapi.c->thapi_toggle.c & use toggle over profiler
thilinarmtb Mar 18, 2025
3586789
Use constructor priority for thapi_stop()
thilinarmtb Mar 18, 2025
1895aaa
Set minimum lttng-ust version
thilinarmtb Mar 18, 2025
bfabb96
Check if the header is included by a CXX compiler
thilinarmtb Mar 25, 2025
d6496ff
Plugin to filter traces based on thapi_start/stop
thilinarmtb Apr 2, 2025
96bdf34
Format utils/thapi_toggle.c
thilinarmtb Apr 2, 2025
e051963
Prefix files related to toggle with `thapi_toggle`
thilinarmtb Jun 24, 2025
b944e69
Check hostname and vpid when using toggle
thilinarmtb Jun 24, 2025
541e19b
Install ThapiToggle plugin
thilinarmtb Jul 1, 2025
c9fddfa
Add integration tests for ThapiToggle
thilinarmtb Jul 1, 2025
8089b3f
Add integration tests with np=2 for ThapiToggle
thilinarmtb Jul 2, 2025
e488928
Fix typos and refactor toggle tests
thilinarmtb Jul 2, 2025
453c1e7
Move toggle tests into toggle.bats
thilinarmtb Jul 3, 2025
876d1b2
Use babeltrace_thapi instead of babeltrace2
thilinarmtb Jul 3, 2025
3fa33a1
Simplify trace counting
thilinarmtb Jul 3, 2025
f436019
Set and use the env vars from setup_suite.bash
thilinarmtb Jul 14, 2025
1bbcccb
Rename the filter to `toggle`
thilinarmtb Jul 14, 2025
944ba7c
Rename `thapi_toggle_* -> toggle_* in tests
thilinarmtb Jul 14, 2025
3a8be59
Undo spliting LTTNNG_FLAGS
thilinarmtb Jul 15, 2025
50a81fb
Comment why lttng-ust version change is required
thilinarmtb Jul 15, 2025
f1bff63
Install libThapiToggle.so in bt2 plugin dir
thilinarmtb Sep 29, 2025
f73737e
Fix libThapiToggle.so flags
thilinarmtb Oct 1, 2025
421b849
Fix `shfmt` errors
thilinarmtb Jan 26, 2026
17f57a6
Add `Cflags` and `Libs` to `thapi.pc.in`
thilinarmtb Jan 26, 2026
e05b877
Use `pkg-config` to find thapi include and ldflags
thilinarmtb Jan 26, 2026
f5ed08a
$IPROF -> iprof, $BBT -> babeltrace_thapi
thilinarmtb Jan 27, 2026
cdbc653
Enable toggle events on iprof
thilinarmtb Jan 28, 2026
4a6a04a
$MPIRUN -> mpirun
thilinarmtb Jan 29, 2026
0fc73e6
Add `lttng_ust_toggle:auto_stop`
thilinarmtb Feb 1, 2026
e14ec53
Get rid of THAPI_HOME
thilinarmtb Feb 3, 2026
57baf73
Add a dlopen test for toggle traces
thilinarmtb Feb 2, 2026
e59e4f7
Update the thapi babeltrace plugin
thilinarmtb Feb 5, 2026
9dfae45
clang-format -i thapi_toggle*
thilinarmtb Feb 5, 2026
2b902db
Fix compilation errors
thilinarmtb Feb 5, 2026
7d0d975
Minor fixes
thilinarmtb Mar 4, 2026
67a819f
Split toggle API tests into two tests
thilinarmtb Mar 4, 2026
6d77aed
Add the toggle filter in babeltrace_thapi
thilinarmtb Mar 4, 2026
fc5838d
Remove redundant code due to a bad rebase
thilinarmtb Jul 14, 2026
f6dcf9b
Fix linting errors
thilinarmtb Jul 14, 2026
1468e31
Avoid copying the map
thilinarmtb Jul 15, 2026
7e2f938
Add toggle filter to bt graph if --toggle-on is present
thilinarmtb Jul 16, 2026
547ce95
Update the tests
thilinarmtb Jul 16, 2026
2e63a99
Refactor tests
thilinarmtb Jul 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ AX_COMPARE_VERSION([$H2YAML_VERSION], [ge], [$H2YAML_MIN_VERSION],

PKG_CHECK_MODULES([LIBFFI], [libffi >= 3.2])
PKG_CHECK_MODULES([BABELTRACE2], [babeltrace2 >= 2.0])
PKG_CHECK_MODULES([LTTNG_UST], [lttng-ust >= 2.10])
# 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])

AX_RUBY_EXTENSION([nokogiri], [yes])
Expand Down Expand Up @@ -138,6 +141,8 @@ AC_FUNC_MMAP
AC_FUNC_REALLOC
AC_CHECK_FUNCS([clock_gettime ftruncate memmove memset strdup strstr strtoull strlen strchr])

AX_GCC_FUNC_ATTRIBUTE(constructor)

# Required for configuring thapi.pc.in
PKG_PROG_PKG_CONFIG

Expand Down
1 change: 1 addition & 0 deletions integration_tests/setup_suite.bash
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
setup_suite() {
export MPIRUN=${MPIRUN:-mpirun}

# Set the path to find iprof, babeltrace_thapi, etc.
export PATH=$(pkg-config --variable=bindir thapi):${PATH}

missing_tools=()
Expand Down
97 changes: 97 additions & 0 deletions integration_tests/toggle.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#!/usr/bin/env bats

setup_file() {
export THAPI_INCFLAGS="-I$(pkg-config --variable=includedir thapi)"
export THAPI_LDFLAGS="-Wl,-rpath,$(pkg-config --variable=libdir thapi) $(pkg-config --libs thapi)"
# needed for toggle api dlopen test.
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$(pkg-config --variable=libdir thapi)
}

get_unique_jobid() {
echo ${BATS_TEST_NAME}.${RANDOM}
}

@test "toggle_api" {
rm -rf toggle_traces 2>/dev/null

cc ${THAPI_INCFLAGS} ./integration_tests/toggle.c -o toggle ${THAPI_LDFLAGS}
iprof --trace-output toggle_traces --no-analysis -- ./toggle

# Make sure auto_stop comes before stop.
babeltrace_thapi ./toggle_traces | awk 'BEGIN { seen_auto = 0 }
$0 ~ /lttng_ust_toggle:auto_stop/ { seen_auto = 1 }
$0 ~ /lttng_ust_toggle:stop/ { if (seen_auto == 1) { exit 0 } else { exit 1 } }
'

# Check expected trace counts.
dir=$(ls -d -1 ./toggle_traces/*/)
start_count=$(babeltrace_thapi -c $dir | grep lttng_ust_toggle:start | wc -l)
[ "$start_count" -eq 1 ]

stop_count=$(babeltrace_thapi -c $dir | grep lttng_ust_toggle:stop | wc -l)
[ "$stop_count" -eq 1 ]

auto_stop_count=$(babeltrace_thapi -c $dir | grep lttng_ust_toggle:auto_stop | wc -l)
[ "$auto_stop_count" -eq 1 ]
}

@test "toggle_api_dlopen" {
rm -rf toggle_traces 2>/dev/null

cc ./integration_tests/toggle_dlopen.c -o toggle_dlopen -ldl
iprof --trace-output toggle_traces --no-analysis -- ./toggle_dlopen

# Check expected trace counts.
dir=$(ls -d -1 ./toggle_traces/*/)
start_count=$(babeltrace_thapi -c $dir | grep lttng_ust_toggle:start | wc -l)
[ "$start_count" -eq 2 ]

stop_count=$(babeltrace_thapi -c $dir | grep lttng_ust_toggle:stop | wc -l)
[ "$stop_count" -eq 2 ]

auto_stop_count=$(babeltrace_thapi -c $dir | grep lttng_ust_toggle:auto_stop | wc -l)
[ "$auto_stop_count" -eq 2 ]
}

# Trace and analyse in a single iprof call: `--toggle-on` gates the events on the
# lttng_ust_toggle start/stop tracepoints, and iprof prints the tally to stdout.
count_base() {
rm -rf toggle_traces 2>/dev/null

mpicc ${THAPI_INCFLAGS} ./integration_tests/toggle_mpi.c -o toggle_mpi ${THAPI_LDFLAGS}

THAPI_SYNC_DAEMON=fs THAPI_JOBID=$(get_unique_jobid) timeout 40s mpirun -n $1 \
iprof --toggle-on --trace-output toggle_traces -- ./toggle_mpi $2
}

# Count the number of traced API calls: the tally's `Total` row, whose 4th
# `|`-separated column is the call count (see general.bats `default_summary`).
count_traces() {
count_base $1 $2 | awk -F'|' '/Total/ {c = int($4)} END {print c + 0}'
}

@test "toggle_plugin_mpi_np_1" {
count_0=$(count_traces 1 0)
count_1=$(count_traces 1 1)
count_2=$(count_traces 1 2)

[ "$count_0" -eq 2 ]
[ "$count_1" -eq 1 ]
[ "$count_2" -eq 0 ]
}

# Count the number of processes that emitted traced API calls: the `Processes`
# field of the tally header.
count_processors() {
count_base $1 $2 | grep -oP '\d+(?= Processes)' || echo 0
}

@test "toggle_plugin_mpi_np_2" {
count_0=$(count_processors 2 0)
count_1=$(count_processors 2 1)
count_2=$(count_processors 2 2)

[ "$count_0" -eq 2 ]
[ "$count_1" -eq 1 ]
[ "$count_2" -eq 0 ]
}
7 changes: 7 additions & 0 deletions integration_tests/toggle.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <thapi.h>

int main(void) {
thapi_start();
thapi_stop();
return 0;
}
35 changes: 35 additions & 0 deletions integration_tests/toggle_dlopen.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <dlfcn.h>
#include <stdio.h>
#include <stdlib.h>

#define check_error(ptr_) \
{ \
void *ptr = (void *)ptr_; \
if (!ptr) { \
fprintf(stderr, "%s:%d -- %s\n", __FILE__, __LINE__, dlerror()); \
return 1; \
} \
}

int main(void) {
dlerror();

for (int i = 0; i < 2; i++) {
void *thapi = dlopen("libThapi.so", RTLD_NOW | RTLD_LOCAL);
check_error(thapi);

void (*start)(void) = (void (*)(void))dlsym(thapi, "thapi_start");
check_error(start);

void (*stop)(void) = (void (*)(void))dlsym(thapi, "thapi_stop");
check_error(stop);

(*start)(), (*stop)();

dlclose(thapi);
}

return 0;
}

#undef check_error
31 changes: 31 additions & 0 deletions integration_tests/toggle_mpi.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <mpi.h>
#include <stdlib.h>

#include <thapi.h>

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;
}
Loading
Loading