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>
55PXR_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;
263 std::string
const &msg)
const;
276 ErrorHelper(TfCallContext
const &context,
TfEnum errorCode,
277 const char* errorCodeString)
278 : _context(context), _errorCode(errorCode),
279 _errorCodeString(errorCodeString)
284 void Post(
const char* fmt, ...) const
288 void PostQuietly(const
char* fmt, ...) const
292 void Post(const
std::
string& msg) const;
296 const
std::
string& msg,
297 TfDiagnosticInfo info = TfDiagnosticInfo()) const;
300 void PostQuietly(const
std::
string& msg,
301 TfDiagnosticInfo info = TfDiagnosticInfo()) const;
304 TfCallContext _context;
306 const
char *_errorCodeString;
309 struct WarningHelper {
310 WarningHelper(TfCallContext
const &context,
TfEnum warningCode,
311 const char *warningCodeString)
312 : _context(context), _warningCode(warningCode),
313 _warningCodeString(warningCodeString)
318 void Post(
const char* fmt, ...) const
322 void PostQuietly(const
char* fmt, ...) const
326 void Post(const
std::
string &str) const;
330 const
std::
string& msg,
331 TfDiagnosticInfo info = TfDiagnosticInfo()) const;
334 void PostQuietly(const
std::
string& msg) const;
337 TfCallContext _context;
339 const
char *_warningCodeString;
342 struct StatusHelper {
343 StatusHelper(TfCallContext
const &context,
TfEnum statusCode,
344 const char *statusCodeString)
345 : _context(context), _statusCode(statusCode),
346 _statusCodeString(statusCodeString)
351 void Post(
const char* fmt, ...) const
355 void PostQuietly(const
char* fmt, ...) const
359 void Post(const
std::
string &str) const;
363 const
std::
string& msg,
364 TfDiagnosticInfo info = TfDiagnosticInfo()) const;
367 void PostQuietly(const
std::
string& msg) const;
370 TfCallContext _context;
372 const
char *_statusCodeString;
376 FatalHelper(TfCallContext
const &context,
TfEnum statusCode)
378 _statusCode(statusCode)
382 void Post(
const std::string &str)
const {
383 This::GetInstance().PostFatal(_context, _statusCode, str);
386 TfCallContext _context;
401 ErrorIterator _GetErrorMarkBegin(
size_t mark,
size_t *nErrors);
404 inline void _CreateErrorMark() { ++_errorMarkCounts.local(); }
407 inline bool _DestroyErrorMark() {
return --_errorMarkCounts.local() == 0; }
411 void _ReportError(
const TfError &err);
416 void _SpliceErrors(ErrorList &src);
419 void _AppendErrorsToLogText(ErrorIterator i);
423 void _RebuildErrorLogText();
426 void _SetLogInfoForErrors(std::vector<std::string>
const &logText)
const;
430 mutable tbb::enumerable_thread_specific<bool> _reentrantGuard;
433 std::vector<Delegate*> _delegates;
435 mutable tbb::spin_rw_mutex _delegatesMutex;
438 std::atomic<size_t> _nextSerial;
441 tbb::enumerable_thread_specific<ErrorList> _errorList;
445 void AppendAndPublish(ErrorIterator i, ErrorIterator end);
446 void RebuildAndPublish(ErrorIterator i, ErrorIterator end);
448 std::pair<std::vector<std::string>,
449 std::vector<std::string>> texts;
452 void _AppendAndPublishImpl(
bool clear,
453 ErrorIterator i, ErrorIterator end);
455 tbb::enumerable_thread_specific<_LogText> _logText;
459 tbb::enumerable_thread_specific<
460 size_t, tbb::cache_aligned_allocator<size_t>,
461 tbb::ets_key_per_instance> _errorMarkCounts;
472PXR_NAMESPACE_CLOSE_SCOPE
Define function attributes.
#define ARCH_PRINTF_FUNCTION(_fmt, _firstArg)
Macro used to indicate a function takes a printf-like specification.
Functions for recording call locations.
Represents the base class of an object representing a diagnostic message.
One may set a delegate with the TfDiagnosticMgr which will be called to respond to errors and diagnos...
virtual void IssueStatus(TfStatus const &status)=0
Called when a TF_STATUS() is issued.
virtual void IssueError(TfError const &err)=0
Called when a TfError is posted.
TF_API void _UnhandledAbort() const
Abort the program, but avoid the session logging mechanism.
virtual void IssueWarning(TfWarning const &warning)=0
Called when a TF_WARNING() is issued.
virtual void IssueFatalError(TfCallContext const &context, std::string const &msg)=0
Called when a TF_FATAL_ERROR is issued (or a failed TF_AXIOM).
Singleton class through which all errors and diagnostics pass.
TF_API void RemoveDelegate(Delegate *delegate)
Removes all delegates equal to delegate from the current delegates.
TF_API void PostError(const TfDiagnosticBase &diagnostic)
This method will create a TfError, append it to the error list, and pass it to all delegates.
TF_API void AddDelegate(Delegate *delegate)
Add the delegate delegate to the list of current delegates.
TF_API void SetQuiet(bool quiet)
Set whether errors, warnings and status messages should be printed out to the terminal.
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 ErrorIterator EraseError(ErrorIterator i)
Remove error specified by iterator i.
static TF_API This & GetInstance()
Return the singleton instance.
TF_API void PostFatal(TfCallContext const &context, TfEnum statusCode, std::string const &msg) const
This method will issue a fatal error to all delegates.
ErrorIterator GetErrorEnd()
Return an iterator to the end of this thread's error list.
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.
TF_API void PostStatus(const TfDiagnosticBase &diagnostic) const
This method will create a TfStatus and pass it to all delegates.
TF_API void AppendError(TfError const &e)
Append an error to the list of active errors.
TF_API ErrorIterator EraseRange(ErrorIterator first, ErrorIterator last)
Remove all the errors in [first, last) from this thread's error stream.
bool HasActiveErrorMark()
Return true if an instance of TfErrorMark exists in the current thread of execution,...
TF_API void PostWarning(const TfDiagnosticBase &diagnostic) const
This method will create a TfWarning and pass it to all delegates.
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.
ErrorList::iterator ErrorIterator
Synonym for standard STL iterator to traverse the error list.
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.
ErrorIterator GetErrorBegin()
Return an iterator to the beginning of this thread's error list.
static TF_API std::string GetCodeName(const TfEnum &code)
Returns the name of the given diagnostic code.
An enum class that records both enum type and enum value.
Represents an object that contains error information.
Class used to record the end of the error-list.
A facility for transporting errors from thread to thread.
Manage a single instance of an object (see.
static T & GetInstance()
Return a reference to an object of type T, creating it if necessary.
Represents an object that contains information about a status message.
Represents an object that contains information about a warning.
Enable a concrete base class for use with TfWeakPtr.
Conditional debugging output class and macros.
Stripped down version of diagnostic.h that doesn't define std::string.
Define preprocessor function name macros.
#define TF_DEBUG_CODES(...)
Define debugging symbols.
Manage a single instance of an object.
Definitions of basic string utilities in tf.
Provide facilities for error handling in script.
Pointer storage with deletion detection.