HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
coalescingDiagnosticDelegate.h
Go to the documentation of this file.
1 //
2 // Copyright 2017 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_USD_USD_UTILS_COALESCING_DIAGNOSTIC_DELEGATE_H
8 #define PXR_USD_USD_UTILS_COALESCING_DIAGNOSTIC_DELEGATE_H
9 
10 /// \file usdUtils/coalescingDiagnosticDelegate.h
11 ///
12 /// A class which provides aggregation of warnings and statuses
13 /// emitted from Tf's diagnostic management system. These diagnostic
14 /// notifications can be coalesced by invocation point,
15 /// currently defined as the source file, line number and function name,
16 /// to recieve a more concise output.
17 
18 #include "pxr/pxr.h"
19 #include "pxr/usd/usdUtils/api.h"
21 
22 #include <ostream>
23 #include <memory>
24 #include <string>
25 #include <vector>
26 
27 #include <tbb/concurrent_queue.h>
28 
30 
31 /// The shared component in a coalesced result
32 /// This type can be thought of as the key by which we
33 /// coalesce our diagnostics.
36  std::string sourceFunction;
37  std::string sourceFileName;
38 };
39 
40 /// The unshared component in a coalesced result
43  std::string commentary;
44 };
45 
46 /// An item used in coalesced results, containing a shared component:
47 /// the file/function/line number, and a set of unshared components: the
48 /// call context and commentary.
51  std::vector<UsdUtilsCoalescingDiagnosticDelegateUnsharedItem> unsharedItems;
52 };
53 
54 /// A vector of coalesced results, each containing a shared component,
55 /// the file/function/line number, and a set of unshared components, the
56 /// call context and commentary.
57 typedef std::vector<UsdUtilsCoalescingDiagnosticDelegateItem>
59 
60 /// A class which collects warnings and statuses from the
61 /// Tf diagnostic manager system in a thread safe manner.
62 ///
63 /// This class allows clients to get both the unfiltered
64 /// results, as well as a compressed view which deduplicates
65 /// diagnostic events by their source line number, function and file
66 /// from which they occurred.
68 public:
71 
74 
75  /// Methods that implement the interface provided in TfDiagnosticMgr::Delegate
76 
78  virtual void IssueError(const TfError&) override;
79 
81  virtual void IssueStatus(const TfStatus&) override;
82 
84  virtual void IssueWarning(const TfWarning&) override;
85 
87  virtual void IssueFatalError(const TfCallContext&, const std::string &) override;
88 
89  // Methods that provide collection of diagnostics as well as sending
90  // them to a stream(stderr, stdout, a file, etc).
91 
92  /// Print all pending diagnostics in a coalesced form to \p ostr
93  /// \note This method clears the pending diagnostics.
95  void DumpCoalescedDiagnostics(std::ostream& ostr);
96 
97  /// Print all pending diagnostics without any coalescing to \p ostr
98  /// \note This method clears the pending diagnostics.
100  void DumpUncoalescedDiagnostics(std::ostream& ostr);
101 
102  /// Get all pending diagnostics in a coalesced form.
103  /// \note This method clears the pending diagnostics.
106 
107  /// Get all pending diagnostics without any coalescing.
108  /// \note This method clears the pending diagnostics.
110  std::vector<std::unique_ptr<TfDiagnosticBase>> TakeUncoalescedDiagnostics();
111 
112 private:
113  tbb::concurrent_queue<TfDiagnosticBase*> _diagnostics;
114 };
115 
117 
118 #endif // PXR_USD_USD_UTILS_COALESCING_DIAGNOSTIC_DELEGATE_H
The unshared component in a coalesced result.
virtual USDUTILS_API void IssueFatalError(const TfCallContext &, const std::string &) override
virtual USDUTILS_API ~UsdUtilsCoalescingDiagnosticDelegate()
std::vector< UsdUtilsCoalescingDiagnosticDelegateUnsharedItem > unsharedItems
USDUTILS_API void DumpUncoalescedDiagnostics(std::ostream &ostr)
virtual USDUTILS_API void IssueStatus(const TfStatus &) override
Called when a TF_STATUS() is issued.
virtual USDUTILS_API void IssueError(const TfError &) override
Methods that implement the interface provided in TfDiagnosticMgr::Delegate.
USDUTILS_API std::vector< std::unique_ptr< TfDiagnosticBase > > TakeUncoalescedDiagnostics()
UsdUtilsCoalescingDiagnosticDelegateSharedItem sharedItem
Definition: error.h:32
USDUTILS_API UsdUtilsCoalescingDiagnosticDelegateVector TakeCoalescedDiagnostics()
virtual USDUTILS_API void IssueWarning(const TfWarning &) override
Called when a TF_WARNING() is issued.
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
std::vector< UsdUtilsCoalescingDiagnosticDelegateItem > UsdUtilsCoalescingDiagnosticDelegateVector
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
USDUTILS_API void DumpCoalescedDiagnostics(std::ostream &ostr)
#define USDUTILS_API
Definition: api.h:23
USDUTILS_API UsdUtilsCoalescingDiagnosticDelegate()