24 #ifndef PXR_BASE_TF_DIAGNOSTIC_MGR_H
25 #define PXR_BASE_TF_DIAGNOSTIC_MGR_H
35 #include "pxr/base/tf/status.h"
37 #include "pxr/base/tf/warning.h"
40 #include "pxr/base/tf/api.h"
46 #include <tbb/enumerable_thread_specific.h>
47 #include <tbb/spin_rw_mutex.h>
55 PXR_NAMESPACE_OPEN_SCOPE
58 TF_LOG_STACK_TRACE_ON_ERROR,
59 TF_LOG_STACK_TRACE_ON_WARNING,
60 TF_ERROR_MARK_TRACKING,
61 TF_PRINT_ALL_POSTED_ERRORS_TO_STDERR
76 typedef std::list<TfError> ErrorList;
108 const TfCallContext &context,
const std::string &msg,
109 const TfDiagnosticInfo &info);
139 std::string
const &msg) = 0;
212 TfCallContext
const &context,
213 const std::string& commentary, TfDiagnosticInfo info,
230 TfCallContext
const &context, std::string
const &commentary,
231 TfDiagnosticInfo info,
bool quiet)
const;
246 TfCallContext
const &context, std::string
const &commentary,
247 TfDiagnosticInfo info,
bool quiet)
const;
262 std::string
const &msg)
const;
268 #if !defined(doxygen)
275 ErrorHelper(TfCallContext
const &context,
TfEnum errorCode,
276 const char* errorCodeString)
277 : _context(context), _errorCode(errorCode),
278 _errorCodeString(errorCodeString)
283 void Post(
const char* fmt, ...) const
287 void PostQuietly(const
char* fmt, ...) const
291 void Post(const std::
string& msg) const;
295 const std::
string& msg,
296 TfDiagnosticInfo info = TfDiagnosticInfo()) const;
299 void PostQuietly(const std::
string& msg,
300 TfDiagnosticInfo info = TfDiagnosticInfo()) const;
303 TfCallContext _context;
305 const
char *_errorCodeString;
308 struct WarningHelper {
309 WarningHelper(TfCallContext
const &context,
TfEnum warningCode,
310 const char *warningCodeString)
311 : _context(context), _warningCode(warningCode),
312 _warningCodeString(warningCodeString)
317 void Post(
const char* fmt, ...) const
318 ARCH_PRINTF_FUNCTION(2,3);
321 void PostQuietly(const
char* fmt, ...) const
322 ARCH_PRINTF_FUNCTION(2,3);
325 void Post(const std::
string &str) const;
329 const std::
string& msg,
330 TfDiagnosticInfo info = TfDiagnosticInfo()) const;
333 void PostQuietly(const std::
string& msg) const;
336 TfCallContext _context;
338 const
char *_warningCodeString;
341 struct StatusHelper {
342 StatusHelper(TfCallContext
const &context,
TfEnum statusCode,
343 const char *statusCodeString)
344 : _context(context), _statusCode(statusCode),
345 _statusCodeString(statusCodeString)
350 void Post(
const char* fmt, ...) const
351 ARCH_PRINTF_FUNCTION(2,3);
354 void PostQuietly(const
char* fmt, ...) const
355 ARCH_PRINTF_FUNCTION(2,3);
358 void Post(const std::
string &str) const;
362 const std::
string& msg,
363 TfDiagnosticInfo info = TfDiagnosticInfo()) const;
366 void PostQuietly(const std::
string& msg) const;
369 TfCallContext _context;
371 const
char *_statusCodeString;
375 FatalHelper(TfCallContext
const &context,
TfEnum statusCode)
377 _statusCode(statusCode)
381 void Post(
const std::string &str)
const {
385 TfCallContext _context;
400 ErrorIterator _GetErrorMarkBegin(
size_t mark,
size_t *nErrors);
403 inline void _CreateErrorMark() { ++_errorMarkCounts.local(); }
406 inline bool _DestroyErrorMark() {
return --_errorMarkCounts.local() == 0; }
410 void _ReportError(
const TfError &err);
415 void _SpliceErrors(ErrorList &src);
422 void _RebuildErrorLogText();
425 void _SetLogInfoForErrors(std::vector<std::string>
const &logText)
const;
429 mutable tbb::enumerable_thread_specific<bool> _reentrantGuard;
432 std::vector<Delegate*> _delegates;
434 mutable tbb::spin_rw_mutex _delegatesMutex;
437 std::atomic<size_t> _nextSerial;
440 tbb::enumerable_thread_specific<ErrorList> _errorList;
447 std::pair<std::vector<std::string>,
448 std::vector<std::string>> texts;
451 void _AppendAndPublishImpl(
bool clear,
454 tbb::enumerable_thread_specific<_LogText> _logText;
458 tbb::enumerable_thread_specific<
459 size_t, tbb::cache_aligned_allocator<size_t>,
460 tbb::ets_key_per_instance> _errorMarkCounts;
471 PXR_NAMESPACE_CLOSE_SCOPE
473 #endif // PXR_BASE_TF_DIAGNOSTIC_MGR_H
Manage a single instance of an object.
Manage a single instance of an object (see.
Singleton class through which all errors and diagnostics pass.
virtual void IssueStatus(TfStatus const &status)=0
Called when a TF_STATUS() is issued.
Functions for recording call locations.
Conditional debugging output class and macros.
TF_API void PostFatal(TfCallContext const &context, TfEnum statusCode, std::string const &msg) const
This method will issue a fatal error to all delegates.
Define preprocessor function name macros.
virtual void IssueWarning(TfWarning const &warning)=0
Called when a TF_WARNING() is issued.
TF_API void SetQuiet(bool quiet)
Set whether errors, warnings and status messages should be printed out to the terminal.
Define function attributes.
static TF_API std::string GetCodeName(const TfEnum &code)
Returns the name of the given diagnostic code.
Definitions of basic string utilities in tf.
An enum class that records both enum type and enum value.
ErrorIterator GetErrorEnd()
Return an iterator to the end of this thread's error list.
static TF_API This & GetInstance()
Return the singleton instance.
Pointer storage with deletion detection.
static TF_API std::string FormatDiagnostic(const TfEnum &code, const TfCallContext &context, const std::string &msg, const TfDiagnosticInfo &info)
Return a human-readable diagnostic message.
#define TF_DEBUG_CODES(...)
Define debugging symbols.
bool HasActiveErrorMark()
Return true if an instance of TfErrorMark exists in the current thread of execution, false otherwise.
TF_API void AddDelegate(Delegate *delegate)
Add the delegate delegate to the list of current delegates.
Represents the base class of an object representing a diagnostic message.
ErrorIterator GetErrorBegin()
Return an iterator to the beginning of this thread's error list.
TF_API ErrorIterator EraseRange(ErrorIterator first, ErrorIterator last)
Remove all the errors in [first, last) from this thread's error stream.
Class used to record the end of the error-list.
#define ARCH_PRINTF_FUNCTION(_fmt, _firstArg)
Macro used to indicate a function takes a printf-like specification.
Represents an object that contains information about a status message.
TF_API void PostWarning(TfEnum warningCode, const char *warningCodeString, TfCallContext const &context, std::string const &commentary, TfDiagnosticInfo info, bool quiet) const
This method will create a TfWarning and pass it to all delegates.
static T & GetInstance()
Return a reference to an object of type T, creating it if necessary.
TF_API ErrorIterator EraseError(ErrorIterator i)
Remove error specified by iterator i.
Represents an object that contains error information.
virtual void IssueError(TfError const &err)=0
Called when a TfError is posted.
TF_API void PostStatus(TfEnum statusCode, const char *statusCodeString, TfCallContext const &context, std::string const &commentary, TfDiagnosticInfo info, bool quiet) const
This method will create a TfStatus and pass it to all delegates.
TF_API void _UnhandledAbort() const
Abort the program, but avoid the session logging mechanism.
TF_API void PostError(TfEnum errorCode, const char *errorCodeString, TfCallContext const &context, const std::string &commentary, TfDiagnosticInfo info, bool quiet)
This method will create a TfError, append it to the error list, and pass it to all delegates...
TF_API void RemoveDelegate(Delegate *delegate)
Removes all delegates equal to delegate from the current delegates.
Provide facilities for error handling in script.
Enable a concrete base class for use with TfWeakPtr.
Represents an object that contains information about a warning.
ErrorList::iterator ErrorIterator
Synonym for standard STL iterator to traverse the error list.
One may set a delegate with the TfDiagnosticMgr which will be called to respond to errors and diagnos...
virtual void IssueFatalError(TfCallContext const &context, std::string const &msg)=0
Called when a TF_FATAL_ERROR is issued (or a failed TF_AXIOM).
A facility for transporting errors from thread to thread.
TF_API void AppendError(TfError const &e)
Append an error to the list of active errors.
Stripped down version of diagnostic.h that doesn't define std::string.