7#ifndef PXR_BASE_TF_DIAGNOSTIC_MGR_H
8#define PXR_BASE_TF_DIAGNOSTIC_MGR_H
18#include "pxr/base/tf/status.h"
20#include "pxr/base/tf/warning.h"
23#include "pxr/base/tf/api.h"
29#include <tbb/enumerable_thread_specific.h>
30#include <tbb/spin_rw_mutex.h>
38PXR_NAMESPACE_OPEN_SCOPE
41 TF_LOG_STACK_TRACE_ON_ERROR,
42 TF_LOG_STACK_TRACE_ON_WARNING,
43 TF_ERROR_MARK_TRACKING,
44 TF_PRINT_ALL_POSTED_ERRORS_TO_STDERR
59 typedef std::list<TfError> ErrorList;
91 const TfCallContext &context,
const std::string &msg,
92 const TfDiagnosticInfo &info);
122 std::string
const &msg) = 0;
195 TfCallContext
const &context,
196 const std::string& commentary, TfDiagnosticInfo info,
213 TfCallContext
const &context, std::string
const &commentary,
214 TfDiagnosticInfo info,
bool quiet)
const;
229 TfCallContext
const &context, std::string
const &commentary,
230 TfDiagnosticInfo info,
bool quiet)
const;
246 std::string
const &msg)
const;
259 ErrorHelper(TfCallContext
const &context,
TfEnum errorCode,
260 const char* errorCodeString)
261 : _context(context), _errorCode(errorCode),
262 _errorCodeString(errorCodeString)
267 void Post(
const char* fmt, ...) const
271 void PostQuietly(const
char* fmt, ...) const
275 void Post(const
std::
string& msg) const;
279 const
std::
string& msg,
280 TfDiagnosticInfo info = TfDiagnosticInfo()) const;
283 void PostQuietly(const
std::
string& msg,
284 TfDiagnosticInfo info = TfDiagnosticInfo()) const;
287 TfCallContext _context;
289 const
char *_errorCodeString;
292 struct WarningHelper {
293 WarningHelper(TfCallContext
const &context,
TfEnum warningCode,
294 const char *warningCodeString)
295 : _context(context), _warningCode(warningCode),
296 _warningCodeString(warningCodeString)
301 void Post(
const char* fmt, ...) const
305 void PostQuietly(const
char* fmt, ...) const
309 void Post(const
std::
string &str) const;
313 const
std::
string& msg,
314 TfDiagnosticInfo info = TfDiagnosticInfo()) const;
317 void PostQuietly(const
std::
string& msg) const;
320 TfCallContext _context;
322 const
char *_warningCodeString;
325 struct StatusHelper {
326 StatusHelper(TfCallContext
const &context,
TfEnum statusCode,
327 const char *statusCodeString)
328 : _context(context), _statusCode(statusCode),
329 _statusCodeString(statusCodeString)
334 void Post(
const char* fmt, ...) const
338 void PostQuietly(const
char* fmt, ...) const
342 void Post(const
std::
string &str) const;
346 const
std::
string& msg,
347 TfDiagnosticInfo info = TfDiagnosticInfo()) const;
350 void PostQuietly(const
std::
string& msg) const;
353 TfCallContext _context;
355 const
char *_statusCodeString;
359 FatalHelper(TfCallContext
const &context,
TfEnum statusCode)
361 _statusCode(statusCode)
365 void Post(
const std::string &str)
const {
366 This::GetInstance().PostFatal(_context, _statusCode, str);
369 TfCallContext _context;
384 ErrorIterator _GetErrorMarkBegin(
size_t mark,
size_t *nErrors);
387 inline void _CreateErrorMark() { ++_errorMarkCounts.local(); }
390 inline bool _DestroyErrorMark() {
return --_errorMarkCounts.local() == 0; }
394 void _ReportError(
const TfError &err);
399 void _SpliceErrors(ErrorList &src);
402 void _AppendErrorsToLogText(ErrorIterator i);
406 void _RebuildErrorLogText();
409 void _SetLogInfoForErrors(std::vector<std::string>
const &logText)
const;
413 mutable tbb::enumerable_thread_specific<bool> _reentrantGuard;
416 std::vector<Delegate*> _delegates;
418 mutable tbb::spin_rw_mutex _delegatesMutex;
421 std::atomic<size_t> _nextSerial;
424 tbb::enumerable_thread_specific<ErrorList> _errorList;
428 void AppendAndPublish(ErrorIterator i, ErrorIterator end);
429 void RebuildAndPublish(ErrorIterator i, ErrorIterator end);
431 std::pair<std::vector<std::string>,
432 std::vector<std::string>> texts;
435 void _AppendAndPublishImpl(
bool clear,
436 ErrorIterator i, ErrorIterator end);
438 tbb::enumerable_thread_specific<_LogText> _logText;
442 tbb::enumerable_thread_specific<
443 size_t, tbb::cache_aligned_allocator<size_t>,
444 tbb::ets_key_per_instance> _errorMarkCounts;
455PXR_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.