[llvm] [Offload] Enable more refined debug printing (PR #163431)
Alex Duran via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 17 09:20:37 PDT 2025
adurang wrote:
I put together a bit of code. Messages are constructed in C++ stream fashion can be tagged with a **channel** and **level**.
Then you can filter them by **channel**, **level** or **component** (this TARGET_NAME as omptarget, plugin, ... but could be defined differently).
So the debug messages code could look something like this:
```
OFFLOAD_DEBUG("msg " << 1 <<" (default channel, default debug level)\n");
OFFLOAD_DEBUG("Init", "msg" << 2 <<" (Init channel, default debug level)\n");
OFFLOAD_DEBUG("Init", 2, "msg" << 3 <<" (Init channel, debug level 2)\n");
OFFLOAD_DEBUG("Init", 5, "msg" << 4 <<" (Init channel, debug level 5)\n");
OFFLOAD_DEBUG("PluginManager", "msg " << 5 <<" (PluginManager channel, default debug level)\n");
OFFLOAD_DEBUG("Map", "msg " << 6 <<" (Map channel, default debug level)\n");
// Change component for testing
#undef TARGET_NAME
#define TARGET_NAME Plugin
OFFLOAD_DEBUG("Map", 3, "msg " << 7 <<" (Map channel, debug level 3)\n");
OFFLOAD_DEBUG("RTL", "msg " << 8 <<" (RTL channel, default debug level)\n");
```
Then configuration through LIBOMPTARGET_DEBUG could be something like this:
```
// show no messages
$ LIBOMPTARGET_DEBUG=0 ./a.out
// show all messages at debug level 1
$ LIBOMPTARGET_DEBUG=All ./a.out
omptarget --> msg 1 (default channel, default debug level)
omptarget --> msg2 (Init channel, default debug level)
omptarget --> msg 5 (PluginManager channel, default debug level)
omptarget --> msg 6 (Map channel, default debug level)
Plugin --> msg 8 (RTL channel, default debug level)
// Show all messages at debug level 3 or less
$ LIBOMPTARGET_DEBUG=3 ./a.out
omptarget --> msg 1 (default channel, default debug level)
omptarget --> msg2 (Init channel, default debug level)
omptarget --> msg3 (Init channel, debug level 2)
omptarget --> msg 5 (PluginManager channel, default debug level)
omptarget --> msg 6 (Map channel, default debug level)
Plugin --> msg 7 (Map channel, debug level 3)
Plugin --> msg 8 (RTL channel, default debug level)
// Show all messages fom the Map channel at debug level 1
$ LIBOMPTARGET_DEBUG=Map ./a.out
omptarget --> msg 6 (Map channel, default debug level)
// Show all messages fom the Map channel at debug level 5 or less
$ LIBOMPTARGET_DEBUG=Map:5 ./a.out
omptarget --> msg 6 (Map channel, default debug level)
Plugin --> msg 7 (Map channel, debug level 3)
// Show all messages fmom the Plugin component at debug level 1
$ LIBOMPTARGET_DEBUG=Plugin ./a.out
Plugin --> msg 8 (RTL channel, default debug level)
// Show all messages from the Plugin component at debug level 3 or less
$LIBOMPTARGET_DEBUG=Plugin:3 ./a.out
Plugin --> msg 7 (Map channel, debug level 3)
Plugin --> msg 8 (RTL channel, default debug level)
// Show all messages from the Default and Map channels at level 1 and
// from the Plugin component at level 3 or less
$LIBOMPTARGET_DEBUG=default,map,plugin:3 ./a.out
omptarget --> msg 1 (default channel, default debug level)
omptarget --> msg 6 (Map channel, default debug level)
Plugin --> msg 7 (Map channel, debug level 3)
Plugin --> msg 8 (RTL channel, default debug level)
```
is this the general idea that you were describing @jhuber6 ?
https://github.com/llvm/llvm-project/pull/163431
More information about the llvm-commits
mailing list