Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
75f43ba
Generate traces for thapi_start() and thapi_end()
thilinarmtb Feb 28, 2025
3950634
Call thapi_stop() if libtoggle is linked
thilinarmtb Mar 3, 2025
7466d7e
Rename toggle to ThapiProfiler
thilinarmtb Mar 3, 2025
a7af1d6
Add `profiler_` to ThapiProfiler symbols
thilinarmtb Mar 3, 2025
98d4023
Fix `make distcheck` failure
thilinarmtb Mar 6, 2025
e439324
Remove profiler from symbols
thilinarmtb Mar 6, 2025
ff1709e
Use AX_GCC_FUNC_ATTRIBUTE to check constructor support
thilinarmtb Mar 6, 2025
3157cc6
Install libThapi.so in lib instead of lib/thapi
thilinarmtb Mar 6, 2025
39e7fe7
Add an integration test
thilinarmtb Mar 6, 2025
15762b0
Minor changes in utils/thapi.[ch]
thilinarmtb Mar 6, 2025
e83de6b
Fix the failing integration test
thilinarmtb Mar 18, 2025
3003858
thapi.c->thapi_toggle.c & use toggle over profiler
thilinarmtb Mar 18, 2025
68ed663
Use constructor priority for thapi_stop()
thilinarmtb Mar 18, 2025
1320a4b
Set minimum lttng-ust version
thilinarmtb Mar 18, 2025
a420d62
Check if the header is included by a CXX compiler
thilinarmtb Mar 25, 2025
9bc0242
Plugin to filter traces based on thapi_start/stop
thilinarmtb Apr 2, 2025
baf1178
Format utils/thapi_toggle.c
thilinarmtb Apr 2, 2025
9694cad
Prefix files related to toggle with `thapi_toggle`
thilinarmtb Jun 24, 2025
a6bc1f3
Check hostname and vpid when using toggle
thilinarmtb Jun 24, 2025
46ef331
Install ThapiToggle plugin
thilinarmtb Jul 1, 2025
b1178e6
Add integration tests for ThapiToggle
thilinarmtb Jul 1, 2025
ce7c584
Add integration tests with np=2 for ThapiToggle
thilinarmtb Jul 2, 2025
a280e3a
Fix typos and refactor toggle tests
thilinarmtb Jul 2, 2025
4668ad9
Move toggle tests into toggle.bats
thilinarmtb Jul 3, 2025
4dfafdd
Use babeltrace_thapi instead of babeltrace2
thilinarmtb Jul 3, 2025
ea3e1ef
Simplify trace counting
thilinarmtb Jul 3, 2025
35b5491
Set and use the env vars from setup_suite.bash
thilinarmtb Jul 14, 2025
dffdd93
Rename the filter to `toggle`
thilinarmtb Jul 14, 2025
b888ab5
Rename `thapi_toggle_* -> toggle_* in tests
thilinarmtb Jul 14, 2025
8ac24aa
Undo spliting LTTNNG_FLAGS
thilinarmtb Jul 15, 2025
14a280b
Comment why lttng-ust version change is required
thilinarmtb Jul 15, 2025
b8ef402
Install libThapiToggle.so in bt2 plugin dir
thilinarmtb Sep 29, 2025
3475cc8
Fix libThapiToggle.so flags
thilinarmtb Oct 1, 2025
d30db36
Fix `shfmt` errors
thilinarmtb Jan 26, 2026
df095a7
Add `Cflags` and `Libs` to `thapi.pc.in`
thilinarmtb Jan 26, 2026
e6bbf8f
Use `pkg-config` to find thapi include and ldflags
thilinarmtb Jan 26, 2026
9817061
$IPROF -> iprof, $BBT -> babeltrace_thapi
thilinarmtb Jan 27, 2026
4781a3a
Enable toggle events on iprof
thilinarmtb Jan 28, 2026
125325b
$MPIRUN -> mpirun
thilinarmtb Jan 29, 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 @@ -102,7 +102,10 @@ 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])
# 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([cast-to-yaml], [yes])
Expand Down Expand Up @@ -137,6 +140,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
73 changes: 73 additions & 0 deletions integration_tests/toggle.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/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)"
}

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 ${THAPI_INCFLAGS} ./integration_tests/toggle.c -o toggle ${THAPI_LDFLAGS}

iprof --trace-output toggle_traces --no-analysis -- ./toggle
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 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 -- ./toggle_mpi $2

traces=$(babeltrace_thapi ./toggle_traces)

echo $traces
}

toggle_count_traces() {
traces=$(toggle_count_base $1 $2)
echo $traces | sed -e "s/ \[/\n[/g" | grep . | wc -l
}

@test "toggle_plugin_mpi_np_1" {
mpicc ${THAPI_INCFLAGS} ./integration_tests/toggle_mpi.c -o toggle_mpi ${THAPI_LDFLAGS}

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 ${THAPI_INCFLAGS} ./integration_tests/toggle_mpi.c -o toggle_mpi ${THAPI_LDFLAGS}

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 ]
}
6 changes: 6 additions & 0 deletions integration_tests/toggle.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <thapi.h>

int main(int argc, char *argv[]) {
thapi_start();
thapi_stop();
}
30 changes: 30 additions & 0 deletions integration_tests/toggle_mpi.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <stdlib.h>
#include <mpi.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;
}
242 changes: 242 additions & 0 deletions m4/ax_gcc_func_attribute.m4
Original file line number Diff line number Diff line change
@@ -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_<ATTRIBUTE>.
#
# The macro caches its result in the ax_cv_have_func_attribute_<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 <gabriele.svelto@gmail.com>
#
# 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])
])
2 changes: 2 additions & 0 deletions thapi.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ bindir=@bindir@
Name: Thapi
Description: A tracing infrastructure for heterogeneous computing applications.
Version: @PACKAGE_VERSION@
Cflags: -I${includedir}
Libs: -L${libdir} -lThapi
Loading
Loading