All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
diagnostic.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PCP_DIAGNOSTIC_H
25 #define PCP_DIAGNOSTIC_H
26 
29 
30 #include "pxr/pxr.h"
31 #include "pxr/usd/pcp/api.h"
32 #include "pxr/usd/pcp/debugCodes.h"
33 #include "pxr/usd/pcp/errors.h"
34 
35 #include "pxr/base/arch/hints.h"
36 
37 #include <boost/preprocessor/cat.hpp>
38 
39 #include <string>
40 
41 PXR_NAMESPACE_OPEN_SCOPE
42 
43 class PcpLayerStackSite;
44 class PcpNodeRef;
45 class PcpPrimIndex;
46 class PcpSite;
47 class PcpPrimIndex_StackFrame;
48 
49 PCP_API
50 std::string PcpDump(const PcpPrimIndex& primIndex,
51  bool includeInheritOriginInfo = false,
52  bool includeMaps = false);
53 
54 PCP_API
55 std::string PcpDump(const PcpNodeRef& node,
56  bool includeInheritOriginInfo = false,
57  bool includeMaps = false);
58 
59 PCP_API
60 void PcpDumpDotGraph(const PcpPrimIndex& primIndex,
61  const char *filename,
62  bool includeInheritOriginInfo = true,
63  bool includeMaps = false);
64 
65 PCP_API
66 void PcpDumpDotGraph(const PcpNodeRef& node,
67  const char *filename,
68  bool includeInheritOriginInfo = true,
69  bool includeMaps = false);
70 
71 // Enable this #define for extra runtime validation.
72 // This is normally disabled because it is expensive.
73 // #define PCP_DIAGNOSTIC_VALIDATION
74 
75 // Private helpers.
76 inline PcpPrimIndex const *
77 Pcp_ToIndex(PcpPrimIndex const *index) { return index; }
78 
79 template <class T>
80 inline PcpPrimIndex const *
81 Pcp_ToIndex(T const &obj) { return obj->GetOriginatingIndex(); }
82 
90 
92 #define PCP_INDEXING_PHASE(indexer, node, ...) \
93  auto BOOST_PP_CAT(_pcpIndexingPhase, __LINE__) = \
94  ARCH_UNLIKELY(TfDebug::IsEnabled(PCP_PRIM_INDEX)) ? \
95  Pcp_IndexingPhaseScope(Pcp_ToIndex(indexer), \
96  node, TfStringPrintf(__VA_ARGS__)) : \
97  Pcp_IndexingPhaseScope()
98 
101 #define PCP_INDEXING_UPDATE(indexer, node, ...) \
102  if (ARCH_UNLIKELY(TfDebug::IsEnabled(PCP_PRIM_INDEX))) { \
103  Pcp_IndexingUpdate(Pcp_ToIndex(indexer), node, \
104  TfStringPrintf(__VA_ARGS__)); \
105  }
106 
108 #define PCP_INDEXING_MSG(indexer, ...) \
109  if (ARCH_UNLIKELY(TfDebug::IsEnabled(PCP_PRIM_INDEX))) { \
110  Pcp_IndexingMsg(Pcp_ToIndex(indexer), __VA_ARGS__); \
111  }
112 
114 
117 class Pcp_PrimIndexingDebug {
118 public:
119  Pcp_PrimIndexingDebug(PcpPrimIndex const *index,
120  PcpPrimIndex const *originatingIndex,
121  PcpLayerStackSite const &site)
122  : _index(nullptr)
123  , _originatingIndex(nullptr) {
124  if (ARCH_UNLIKELY(TfDebug::IsEnabled(PCP_PRIM_INDEX))) {
125  _index = index;
126  _originatingIndex = originatingIndex;
127  _PushIndex(site);
128  }
129  }
130 
131  Pcp_PrimIndexingDebug(Pcp_PrimIndexingDebug const &) = delete;
132  Pcp_PrimIndexingDebug &operator=(Pcp_PrimIndexingDebug const &) = delete;
133 
134  inline ~Pcp_PrimIndexingDebug() {
135  if (ARCH_UNLIKELY(_index)) {
136  _PopIndex();
137  }
138  }
139 private:
140  void _PushIndex(PcpLayerStackSite const &site) const;
141  void _PopIndex() const;
142 
143  PcpPrimIndex const *_index;
144  PcpPrimIndex const *_originatingIndex;
145 };
146 
147 // Implementation details; private helper objects and functions for debugging
148 // output. Use the macros above instead.
149 
150 class Pcp_IndexingPhaseScope {
151 public:
152  Pcp_IndexingPhaseScope() : _index(nullptr) {}
153  Pcp_IndexingPhaseScope(PcpPrimIndex const *index,
154  const PcpNodeRef& node, std::string &&msg);
155  Pcp_IndexingPhaseScope(Pcp_IndexingPhaseScope const &) = delete;
156  Pcp_IndexingPhaseScope(Pcp_IndexingPhaseScope &&other)
157  : _index(other._index) {
158  other._index = nullptr;
159  }
160  Pcp_IndexingPhaseScope &operator=(Pcp_IndexingPhaseScope const &) = delete;
161  inline Pcp_IndexingPhaseScope &operator=(Pcp_IndexingPhaseScope &&other) {
162  if (&other != this) {
163  _index = other._index;
164  other._index = nullptr;
165  }
166  return *this;
167  }
168  inline ~Pcp_IndexingPhaseScope() {
169  if (ARCH_UNLIKELY(_index)) {
170  _EndScope();
171  }
172  }
173 private:
174  void _EndScope() const;
175  PcpPrimIndex const *_index;
176 };
177 
178 void
179 Pcp_IndexingMsg(PcpPrimIndex const *index,
180  const PcpNodeRef& a1,
181  char const *fmt, ...) ARCH_PRINTF_FUNCTION(3, 4);
182 void
183 Pcp_IndexingMsg(PcpPrimIndex const *index,
184  const PcpNodeRef& a1, const PcpNodeRef& a2,
185  char const *fmt, ...) ARCH_PRINTF_FUNCTION(4, 5);
186 void
187 Pcp_IndexingUpdate(PcpPrimIndex const *index,
188  const PcpNodeRef& node, std::string &&msg);
189 
190 PCP_API
191 std::string Pcp_FormatSite(const PcpSite& site);
192 PCP_API
193 std::string Pcp_FormatSite(const PcpLayerStackSite& site);
194 
195 PXR_NAMESPACE_CLOSE_SCOPE
196 
197 #endif // PCP_DIAGNOSTIC_H
A site specifies a path in a layer stack of scene description.
Definition: site.h:117
PcpPrimIndex is an index of the all sites of scene description that contribute opinions to a specific...
Definition: primIndex.h:77
PcpNode represents a node in an expression tree for compositing scene description.
Definition: node.h:65
A site specifies a path in a layer stack of scene description.
Definition: site.h:46
static bool IsEnabled(T val)
True if debugging is enabled for the enum value val.
Definition: debug.h:192
#define ARCH_PRINTF_FUNCTION(_fmt, _firstArg)
Macro used to indicate a function takes a printf-like specification.
Definition: attributes.h:51