CallableTracer: fix namespace and decouple from SMO::OptionsParser

We now have a static local var that informs libspinscale whether or
not to print the callable traces at runtime.
This commit is contained in:
2026-02-17 11:03:52 -04:00
parent 18b632e5bb
commit 130921062c
3 changed files with 17 additions and 15 deletions

View File

@@ -77,6 +77,7 @@ add_library(spinscale SHARED
src/component.cpp src/component.cpp
src/puppetApplication.cpp src/puppetApplication.cpp
src/runtime.cpp src/runtime.cpp
src/callableTracer.cpp
) )
# Conditionally add qutexAcquisitionHistoryTracker.cpp only when debug locks # Conditionally add qutexAcquisitionHistoryTracker.cpp only when debug locks

View File

@@ -8,11 +8,6 @@
#include <cstdint> #include <cstdint>
#include <spinscale/componentThread.h> #include <spinscale/componentThread.h>
// Forward declaration - OptionParser is defined in smocore/include/opts.h
// If you need tracing, include opts.h before including this header
// The code will check for OPTS_H define to see if opts.h has been included
class OptionParser;
namespace sscl { namespace sscl {
/** /**
@@ -50,11 +45,8 @@ public:
void operator()() void operator()()
{ {
// OptionParser::getOptions() requires opts.h to be included #ifdef CONFIG_DEBUG_TRACE_CALLABLES
// Only check traceCallables if opts.h has been included (OPTS_H is defined) if (optTraceCallables)
#ifdef CONFIG_DEBUG_TRACE_CALLABLES
#ifdef OPTS_H
if (OptionParser::getOptions().traceCallables)
{ {
std::cout << "" << __func__ << ": On thread " std::cout << "" << __func__ << ": On thread "
<< (ComponentThread::tlsInitialized() << (ComponentThread::tlsInitialized()
@@ -65,12 +57,14 @@ public:
<< ", return addr 1: " << returnAddr1 << ", return addr 1: " << returnAddr1
<< std::endl; << std::endl;
} }
#endif #endif
#endif
callable(); callable();
} }
public: public:
/// Set by application (e.g. from opts) to enable per-callable trace output
static bool optTraceCallables;
/// Name of the function that created this callable /// Name of the function that created this callable
std::string callerFuncName; std::string callerFuncName;
/// Line number where this callable was created /// Line number where this callable was created
@@ -115,7 +109,7 @@ private:
// e.g., "void smo::SomeClass::method(int, int)" // e.g., "void smo::SomeClass::method(int, int)"
// __builtin_return_address(0) = direct caller // __builtin_return_address(0) = direct caller
// __builtin_return_address(1) = caller before that // __builtin_return_address(1) = caller before that
#define STC(arg) smo::CallableTracer( \ #define STC(arg) sscl::CallableTracer( \
__PRETTY_FUNCTION__, \ __PRETTY_FUNCTION__, \
__LINE__, \ __LINE__, \
__builtin_return_address(0), \ __builtin_return_address(0), \
@@ -126,7 +120,7 @@ private:
// e.g., "void __cdecl smo::SomeClass::method(int, int)" // e.g., "void __cdecl smo::SomeClass::method(int, int)"
// _ReturnAddress() = direct caller (only one level available) // _ReturnAddress() = direct caller (only one level available)
#include <intrin.h> #include <intrin.h>
#define STC(arg) smo::CallableTracer( \ #define STC(arg) sscl::CallableTracer( \
__FUNCSIG__, \ __FUNCSIG__, \
__LINE__, \ __LINE__, \
_ReturnAddress(), \ _ReturnAddress(), \
@@ -135,7 +129,7 @@ private:
#else #else
// Fallback to standard __func__ (unqualified name only) // Fallback to standard __func__ (unqualified name only)
// No return address support // No return address support
#define STC(arg) smo::CallableTracer( \ #define STC(arg) sscl::CallableTracer( \
__func__, \ __func__, \
__LINE__, \ __LINE__, \
nullptr, \ nullptr, \

7
src/callableTracer.cpp Normal file
View File

@@ -0,0 +1,7 @@
#include <spinscale/callableTracer.h>
namespace sscl {
bool CallableTracer::optTraceCallables = false;
} // namespace sscl