Skip to content

Add thapi_start() and thapi_stop() - #454

Open
thilinarmtb wants to merge 54 commits into
argonne-lcf:develfrom
thilinarmtb:thapi_on_and_off_v2
Open

Add thapi_start() and thapi_stop()#454
thilinarmtb wants to merge 54 commits into
argonne-lcf:develfrom
thilinarmtb:thapi_on_and_off_v2

Conversation

@thilinarmtb

@thilinarmtb thilinarmtb commented Nov 17, 2025

Copy link
Copy Markdown
Contributor

I created lttng_ust_toggle event category and implemented thapi_start() and thapi_stop()
user APIs (in a similar spirit to cudaProfilerStart() etc.). The library which the user has to link
against is named libThapi.so.

Usage of the API is as follows:

#include <thapi.h>
//
// code
//
thapi_start();
// code to be profiled
thapi_stop();
//
// more code
//

If libThapi.so is linked, thapi_auto_stop() (which is not part of the user API) is called automatically
during the library load time using __attribute__((constructor)). I added a check in configure.ac to
check if the compiler supports __attribute__((constructor)).

If the user runs iprof with --toggle-on, the traces generated by thapi_auto_stop(), thapi_start()
and thapi_stop() will be respected by babeltrace (otherwise there is no change to iprof/babeltrace
behavior). Since thapi_auto_stop() is called automatically, babeltrace will filter out all of the traces
till it see a thapi_start(). Trace filtering out will start again once the user call thapi_stop(). This API
only affects the trace collection of the calling process/thread.

P.S: This feature requires lttng-ust >= 2.12.8. Specifically, this fix.

TODO

  • Respect lttng_ust_profiler_* lttng_ust_toggle_* events when calculating statistics
  • Fix failing checks
  • Add the filter.toggle.toggle to babeltrace graph

@thilinarmtb
thilinarmtb force-pushed the thapi_on_and_off_v2 branch 2 times, most recently from 8120018 to 7a184b7 Compare December 5, 2025 17:38
@thilinarmtb
thilinarmtb force-pushed the thapi_on_and_off_v2 branch 5 times, most recently from 19954ee to 9817061 Compare January 27, 2026 21:32
@thilinarmtb

thilinarmtb commented Jan 29, 2026

Copy link
Copy Markdown
Contributor Author

@TApplencourt : Two tests fail out of the three tests used to check the toggle API. Those two fail
because we have not integrated the toggle plugin to babeltrace_thapi. Once we do that, I think
those two will pass as well.

@TApplencourt

Copy link
Copy Markdown
Collaborator

I can show you how to do it tomorrow : )

@thilinarmtb

Copy link
Copy Markdown
Contributor Author

I can show you how to do it tomorrow : )

Works for me.

@thilinarmtb
thilinarmtb force-pushed the thapi_on_and_off_v2 branch 9 times, most recently from 889b0d5 to 7ae17f3 Compare February 5, 2026 22:49
@thilinarmtb
thilinarmtb force-pushed the thapi_on_and_off_v2 branch 6 times, most recently from fa70166 to c4ebb89 Compare July 16, 2026 17:50
This is done by adding `__attribute((constructor))__` to
`thapi_stop()`. Added an autotools check to see if the
compiler supports `__attribute((constructor))__`.
and install `thapi_profiler.h` header files to provied declarations
of `thapi_start()` and `thapi_stop()`.
@thilinarmtb
thilinarmtb force-pushed the thapi_on_and_off_v2 branch from c4ebb89 to 547ce95 Compare July 16, 2026 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants