123 enum _NodeState { _NodeUninitialized, _NodeDisabled, _NodeEnabled };
135 _SetNode(_GetNode(val), Tf_DebugGetEnumName(val),
true);
141 _SetNode(_GetNode(val), Tf_DebugGetEnumName(val),
false);
152 const int n = _Traits<T>::NumCodes;
153 for (
int i = 0; i != n; ++i) {
154 T code =
static_cast<T
>(i);
155 _SetNode(_GetNode(code), Tf_DebugGetEnumName(code),
true);
162 const int n = _Traits<T>::NumCodes;
163 for (
int i = 0; i != n; ++i) {
164 T code =
static_cast<T
>(i);
165 _SetNode(_GetNode(code), Tf_DebugGetEnumName(code),
false);
177 static_assert(_Traits<T>::IsDeclared,
178 "Must declare debug codes with TF_DEBUG_CODES()");
179 if (_Traits<T>::CompileTimeEnabled) {
180 _Node &node = _GetNode(val);
181 _NodeState curState = node.state.load();
182 if (ARCH_UNLIKELY(curState == _NodeUninitialized)) {
183 _InitializeNode(_GetNode(val), Tf_DebugGetEnumName(val));
184 curState = node.state.load();
186 return curState == _NodeEnabled;
195 static_assert(_Traits<T>::IsDeclared,
196 "Must declare debug codes with TF_DEBUG_CODES()");
197 return _Traits<T>::CompileTimeEnabled;
205 static_assert(_Traits<T>::IsDeclared,
206 "Must declare debug codes with TF_DEBUG_CODES()");
207 return _Traits<T>::NumCodes;
213 template <
class Enum>
214 explicit _Helper(Enum val) : _enumName(Tf_DebugGetEnumName(val)) {}
215 TF_API
void Msg(
const std::string& msg)
const;
218 char const * const _enumName = "<< no debug code >>";
222 template <
class A1,
class ...Args>
223 static void Msg(
char const *fmt, A1 &&a1, Args && ...args) {
224 return _Helper().Msg(
225 fmt, std::forward<A1>(a1), std::forward<Args>(args)...);
227 static void Msg(
const std::string &msg) {
228 return _Helper().Msg(msg);
235 ScopeHelper(
bool enabled,
const char* name) {
236 if ((active = enabled)) {
238 TfDebug::_ScopedOutput(
true, str);
246 TfDebug::_ScopedOutput(
false, str);
254 struct TimedScopeHelper {
255 TimedScopeHelper(
bool enabled,
const char* fmt, ...)
271 static
std::vector<
std::
string> SetDebugSymbolsByName(
272 const
std::
string& pattern,
bool value);
276 static
bool IsDebugSymbolNameEnabled(const
std::
string& name);
283 static
std::
string GetDebugSymbolDescriptions();
287 static
std::vector<
std::
string> GetDebugSymbolNames();
295 static
std::
string GetDebugSymbolDescription(const
std::
string& name);
304 static
void SetOutputFile(FILE *file);
311 static
void _RegisterDebugSymbol(
312 T enumVal,
char const *name,
char const *descrip) {
313 static_assert(_Traits<T>::IsDeclared,
314 "Must declare debug codes with TF_DEBUG_CODES()");
315 const int index =
static_cast<int>(enumVal);
316 const int numCodes = _Traits<T>::NumCodes;
317 if (ARCH_UNLIKELY(index < 0 || index >= numCodes)) {
318 _ComplainAboutInvalidSymbol(name);
321 _RegisterDebugSymbolImpl(&_GetNode(enumVal), name, descrip);
325 static void _RegisterDebugSymbolImpl(_Node *addr,
char const *enumName,
326 char const *descrip);
334 static constexpr bool IsDeclared =
false;
340 mutable std::atomic<_NodeState> state;
347 static _Node nodes[_Traits<T>::NumCodes];
351 static _Node &_GetNode(T val) {
352 return _Data<T>::nodes[
static_cast<int>(val)];
355 friend class Tf_DebugSymbolRegistry;
358 static void _InitializeNode(_Node &node,
char const *name);
361 static void _ComplainAboutInvalidSymbol(
char const *name);
364 static void _SetNode(_Node &node,
char const *name,
bool state);
367 static void _ScopedOutput(
bool start,
char const *str);