Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
abbe144
Generate traces for thapi_start() and thapi_end()
thilinarmtb Feb 28, 2025
8495001
Call thapi_stop() if libtoggle is linked
thilinarmtb Mar 3, 2025
4646b79
Rename toggle to ThapiProfiler
thilinarmtb Mar 3, 2025
6dc7280
Add `profiler_` to ThapiProfiler symbols
thilinarmtb Mar 3, 2025
d9f1190
Fix `make distcheck` failure
thilinarmtb Mar 6, 2025
435f7cb
Remove profiler from symbols
thilinarmtb Mar 6, 2025
784e6e5
Use AX_GCC_FUNC_ATTRIBUTE to check constructor support
thilinarmtb Mar 6, 2025
26b53f1
Install libThapi.so in lib instead of lib/thapi
thilinarmtb Mar 6, 2025
105a376
Add an integration test
thilinarmtb Mar 6, 2025
3dc7a3f
Minor changes in utils/thapi.[ch]
thilinarmtb Mar 6, 2025
8057f7f
Fix the failing integration test
thilinarmtb Mar 18, 2025
1f2e500
thapi.c->thapi_toggle.c & use toggle over profiler
thilinarmtb Mar 18, 2025
bf25a27
Use constructor priority for thapi_stop()
thilinarmtb Mar 18, 2025
b27c15c
Set minimum lttng-ust version
thilinarmtb Mar 18, 2025
a6799a7
Check if the header is included by a CXX compiler
thilinarmtb Mar 25, 2025
0b7e607
Plugin to filter traces based on thapi_start/stop
thilinarmtb Apr 2, 2025
f32aab6
Format utils/thapi_toggle.c
thilinarmtb Apr 2, 2025
a85f313
Prefix files related to toggle with `thapi_toggle`
thilinarmtb Jun 24, 2025
ab51d26
Check hostname and vpid when using toggle
thilinarmtb Jun 24, 2025
4c8e6f1
Install ThapiToggle plugin
thilinarmtb Jul 1, 2025
326e37b
Add integration tests for ThapiToggle
thilinarmtb Jul 1, 2025
3c66473
Add integration tests with np=2 for ThapiToggle
thilinarmtb Jul 2, 2025
642bdf1
Fix typos and refactor toggle tests
thilinarmtb Jul 2, 2025
5f7ee1f
Move toggle tests into toggle.bats
thilinarmtb Jul 3, 2025
7285579
Use babeltrace_thapi instead of babeltrace2
thilinarmtb Jul 3, 2025
0c026cb
Simplify trace counting
thilinarmtb Jul 3, 2025
65def13
Set and use the env vars from setup_suite.bash
thilinarmtb Jul 14, 2025
64df7de
Rename the filter to `toggle`
thilinarmtb Jul 14, 2025
69f6c62
Rename `thapi_toggle_* -> toggle_* in tests
thilinarmtb Jul 14, 2025
87b2c10
Undo spliting LTTNNG_FLAGS
thilinarmtb Jul 15, 2025
71f50eb
Comment why lttng-ust version change is required
thilinarmtb Jul 15, 2025
95f5d4e
Install libThapiToggle.so in bt2 plugin dir
thilinarmtb Sep 29, 2025
15f1a4f
Fix libThapiToggle.so flags
thilinarmtb Oct 1, 2025
7a184b7
Run filter.toggle.toggle during trace command
thilinarmtb Oct 1, 2025
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
2 changes: 1 addition & 1 deletion .github/workflows/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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)

AC_CONFIG_FILES([
Makefile
xprof/Makefile
Expand Down
5 changes: 4 additions & 1 deletion integration_tests/setup_suite.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
71 changes: 71 additions & 0 deletions integration_tests/toggle.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env bats

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/toggle.c -o toggle \
-Wl,-rpath,${THAPI_LIB_DIR} -L${THAPI_LIB_DIR} -lThapi

$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`
[ "$start_count" -eq 1 ]

stop_count=`$BBT -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=$($BBT ./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 -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)
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/toggle_mpi.c -o 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 ]
}
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])
])
Loading
Loading