7 #ifndef PXR_BASE_TF_DEBUG_H
8 #define PXR_BASE_TF_DEBUG_H
31 class Tf_DebugSymbolRegistry;
123 enum _NodeState { _NodeUninitialized, _NodeDisabled, _NodeEnabled };
135 _SetNode(_GetNode(val), Tf_DebugGetEnumName(val),
true);
141 _SetNode(_GetNode(val), Tf_DebugGetEnumName(val),
false);
153 for (
int i = 0; i !=
n; ++i) {
154 T code =
static_cast<T>(i);
155 _SetNode(_GetNode(code), Tf_DebugGetEnumName(code),
true);
163 for (
int i = 0; i !=
n; ++i) {
164 T code =
static_cast<T>(i);
165 _SetNode(_GetNode(code), Tf_DebugGetEnumName(code),
false);
178 "Must declare debug codes with TF_DEBUG_CODES()");
180 _Node &node = _GetNode(val);
181 _NodeState curState = node.
state.load();
183 _InitializeNode(_GetNode(val), Tf_DebugGetEnumName(val));
184 curState = node.
state.load();
186 return curState == _NodeEnabled;
196 "Must declare debug codes with TF_DEBUG_CODES()");
206 "Must declare debug codes with TF_DEBUG_CODES()");
210 #if !defined(doxygen)
212 static TF_API void Msg(
const std::string& msg);
213 static TF_API void Msg(
const char* msg, ...) ARCH_PRINTF_FUNCTION(1,2);
222 TfDebug::_ScopedOutput(
true,
str);
230 TfDebug::_ScopedOutput(
false,
str);
240 ARCH_PRINTF_FUNCTION(3, 4);
296 T enumVal,
char const *
name,
char const *descrip) {
298 "Must declare debug codes with TF_DEBUG_CODES()");
299 const int index =
static_cast<int>(enumVal);
302 _ComplainAboutInvalidSymbol(name);
310 char const *descrip);
324 mutable std::atomic<_NodeState>
state;
336 return _Data<T>::nodes[
static_cast<int>(
val)];
342 static void _InitializeNode(
_Node &node,
char const *
name);
345 static void _ComplainAboutInvalidSymbol(
char const *
name);
351 static void _ScopedOutput(
bool start,
char const *str);
360 ARCH_PRINTF_FUNCTION(3, 4) {
376 #define TF_DEBUG_CODES(...) \
377 TF_CONDITIONALLY_COMPILE_TIME_ENABLED_DEBUG_CODES(true, __VA_ARGS__)
397 #define TF_CONDITIONALLY_COMPILE_TIME_ENABLED_DEBUG_CODES(condition, ...) \
398 enum _TF_DEBUG_ENUM_NAME(__VA_ARGS__) { \
400 TF_PP_CAT( _TF_DEBUG_ENUM_NAME(__VA_ARGS__), __PAST_END) \
403 struct TfDebug::_Traits<_TF_DEBUG_ENUM_NAME(__VA_ARGS__)> { \
404 static constexpr bool IsDeclared = true; \
405 static constexpr int NumCodes = \
406 TF_PP_CAT(_TF_DEBUG_ENUM_NAME(__VA_ARGS__), __PAST_END); \
407 static constexpr bool CompileTimeEnabled = (condition); \
409 inline char const * \
410 Tf_DebugGetEnumName(_TF_DEBUG_ENUM_NAME(__VA_ARGS__) val) { \
411 constexpr char const *CStrings[] = { \
412 TF_PP_FOR_EACH(_TF_DEBUG_MAKE_STRING, __VA_ARGS__) \
414 return CStrings[static_cast<int>(val)]; \
417 #define _TF_DEBUG_MAKE_STRING(x) #x,
422 #define _TF_DEBUG_ENUM_NAME(...) \
423 TF_PP_CAT(_TF_DEBUG_FIRST_CODE(__VA_ARGS__, dummy), __DebugCodes)
425 #define _TF_DEBUG_FIRST_CODE(first, ...) first
449 #define TF_DEBUG_MSG(enumVal, ...) \
450 if (!TfDebug::IsEnabled(enumVal)) ; else TfDebug::Helper().Msg(__VA_ARGS__)
484 #define TF_DEBUG(enumVal) \
485 if (!TfDebug::IsEnabled(enumVal)) ; else TfDebug::Helper()
494 #define TF_INFO(x) TF_DEBUG(x)
523 #define TF_DEBUG_TIMED_SCOPE(enumVal, ...) \
524 TfDebug::TimedScopeHelper< \
526 std::decay<decltype(enumVal)>::type>::CompileTimeEnabled> \
527 TF_PP_CAT(local__TfScopeDebugSwObject, __LINE__)( \
528 TfDebug::IsEnabled(enumVal), __VA_ARGS__)
548 #define TF_DEBUG_ENVIRONMENT_SYMBOL(VAL, descrip) \
549 if (TfDebug::_Traits< \
550 std::decay<decltype(VAL)>::type>::CompileTimeEnabled) { \
551 TF_ADD_ENUM_NAME(VAL); \
552 TfDebug::_RegisterDebugSymbol(VAL, #VAL, descrip); \
static TF_API void SetOutputFile(FILE *file)
static size_t GetNumDebugCodes()
static TF_API std::vector< std::string > SetDebugSymbolsByName(const std::string &pattern, bool value)
static TF_API std::string GetDebugSymbolDescription(const std::string &name)
GLsizei const GLfloat * value
static void Disable(T val)
Mark debugging as disabled for enum value val.
static TF_API void Msg(const std::string &msg)
GLenum GLenum GLsizei const GLuint GLboolean enabled
static TF_API std::string GetDebugSymbolDescriptions()
static void Enable(T val)
friend class Tf_DebugSymbolRegistry
static void _RegisterDebugSymbol(T enumVal, char const *name, char const *descrip)
static constexpr bool IsDeclared
static TF_API void _RegisterDebugSymbolImpl(_Node *addr, char const *enumName, char const *descrip)
GLuint const GLchar * name
static bool IsEnabled(T val)
static bool IsCompileTimeEnabled()
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
#define PXR_NAMESPACE_CLOSE_SCOPE
static TF_API bool IsDebugSymbolNameEnabled(const std::string &name)
True if the specified debug symbol is set.
TimedScopeHelper(bool enabled, const char *fmt,...) ARCH_PRINTF_FUNCTION(3
ScopeHelper(bool enabled, const char *name)
static void DisableAll()
Mark debugging as disabled for all enum values of type T.
std::atomic< _NodeState > state
static TF_API std::vector< std::string > GetDebugSymbolNames()
Get a listing of all debug symbols.