HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_Tracing.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_Tracing header (C++)
7  *
8  * COMMENTS: This class defines tracing macros that can be left
9  * in the source, as they pre-process to nothing if
10  * one of the tracing system macros is undefined.
11  *
12  */
13 
14 #ifndef __UT_Tracing_h__
15 #define __UT_Tracing_h__
16 
17 #include "UT_API.h"
18 
19 #ifdef TRACY_ENABLE
20 
21 #include "UT_NonCopyable.h"
22 #include "UT_NTUtil.h" // for pid_t and getpid()
23 #include "UT_StringHolder.h"
24 
25 // Tracy implementation.
26 
27 // On-demand profiling.
28 #define TRACY_ON_DEMAND
29 // We manage profiler startup and shutdown.
30 #define TRACY_DELAYED_INIT
31 #define TRACY_MANUAL_LIFETIME
32 
33 // Set up TRACY_API the same way we do for UT_API
34 #if !defined(MAKING_STATIC)
35 #ifdef UT_EXPORTS
36 #define TRACY_EXPORTS
37 #else
38 #define TRACY_IMPORTS
39 #endif
40 #endif
41 
42 #include <tracy/tracy/Tracy.hpp>
43 
44 class UT_API ut_TraceControl
45 {
46 public:
47  // Flags for different types of traces. To add a new type of trace,
48  // add an enum here and a TRACYPARM call in the constructor.
49  enum Flag
50  {
51  GENERIC,
52  NODE_PATHS,
53  CL_KERNELS,
54  CL_MEMORY,
55  NODE_COOKS,
56  DOP_SOLVES,
57  CL_FLUID,
58  VIEWPORT,
59  PYTHON_STATE,
60  EVENT_QUEUE,
61  HOUDINI_ENGINE,
62  VK_COMMANDS,
63  };
64 
65  ut_TraceControl();
66  ~ut_TraceControl();
67 
68  UT_NON_COPYABLE(ut_TraceControl)
69 
70  static ut_TraceControl &get();
71 
72  bool flag(Flag f) const
73  {
74  return myFlags & (1u << f);
75  }
76 
77  uint32_t setFlag(uint32_t idx, uint32_t val)
78  {
79  uint32_t bflag = (1u << idx);
80  myFlags = val ? (myFlags | bflag) : (myFlags & ~bflag);
81  return val;
82  }
83 
84  void shutdown();
85 
86 private:
87 
88  uint32_t myFlags;
89  pid_t myPid;
90 };
91 
92 // If the specific type of tracing is active.
93 #define utTraceFlag(F) ut_TraceControl::get().flag(ut_TraceControl::F)
94 
95 // These macros match the Tracy suffix name:
96 // See the Tracy documentation for more: https://github.com/wolfpld/tracy
97 // N indicates a name
98 // S a stack trace to the specified depth
99 // C a specific color for the zone in the profiler UI
100 
101 // Scoped zone tracing, supply a flag to specify the trace type.
102 #define utZoneScopedFlag(F) ZoneNamed( ___tracy_scoped_zone, utTraceFlag(F) )
103 #define utZoneScopedFlagN(F, name) ZoneNamedN( ___tracy_scoped_zone, name, utTraceFlag(F) )
104 #define utZoneScopedFlagS(F, depth) ZoneNamedS( ___tracy_scoped_zone, depth, utTraceFlag(F) )
105 #define utZoneScopedFlagNS(F, name, depth) ZoneNamedNS( ___tracy_scoped_zone, name, depth, utTraceFlag(F) )
106 #define utZoneScopedBool(b) ZoneNamed( ___tracy_scoped_zone, b )
107 
108 // These zones show up for any trace type.
109 #define utZoneScoped utZoneScopedFlag(GENERIC)
110 #define utZoneScopedN(name) utZoneScopedFlagN(GENERIC, name)
111 // #define utZoneScopedC(color) ZoneScopedC(color)
112 // #define utZoneScopedNC(name,color) ZoneScopedNC(name,color)
113 
114 #define utZoneScopedS(depth) utZoneScopedFlagS(GENERIC, depth)
115 #define utZoneScopedNS(name,depth) utZoneScopedFlagNS(GENERIC, name,depth)
116 //#define utZoneScopedCS(color,depth) ZoneScopedCS(color,depth)
117 //#define utZoneScopedNCS(name,color,depth) ZoneScopedNCS(name,color,depth)
118 
119 // Attach user text, name, color, or user value to
120 // the current zone.
121 // SH takes a UT_StringHolder (anything that has c_str and length, really)
122 #define utZoneText(txt,size) ZoneText(txt,size)
123 #define utZoneTextSH(sh) ZoneText((sh).c_str(),(sh).length())
124 #define utZoneName(name,size) ZoneName(name,size)
125 #define utZoneNameSH(sh) ZoneName((sh).c_str(),(sh).length())
126 #define utZoneColor(color) ZoneColor(color)
127 #define utZoneValue(value) ZoneValue(value)
128 #define utZoneIsActive ZoneIsActive
129 
130 // Mark a frame, possibly with a type of frame.
131 #define utFrameMark FrameMark
132 #define utFrameMarkNamed(x) FrameMarkNamed(x)
133 
134 #define utTracePlot(name,val) TracyPlot(name,val)
135 // Confifgure plot as num, memory, or percent.
136 #define utTracePlotConfigNum(name) TracyPlotConfig(name,tracy::PlotFormatType::Number)
137 #define utTracePlotConfigMem(name) TracyPlotConfig(name,tracy::PlotFormatType::Memory)
138 #define utTracePlotConfigPct(name) TracyPlotConfig(name,tracy::PlotFormatType::Percentage)
139 
140 // Add a trace message to the profiler, will attach
141 // to the current zone.
142 // L is literal, else you need to supply a size.
143 #define utTraceMessage(txt,size) TracyMessage(txt,size)
144 #define utTraceMessageSH(sh) TracyMessage((sh).c_str(),(sh).length())
145 #define utTraceMessageL(txt) TracyMessageL(txt)
146 #define utTraceMessageC(txt,size,color) TracyMessageC(txt,size,color)
147 #define utTraceMessageSHC(sh,color) TracyMessageC((sh).c_str(),(sh).length(),color)
148 #define utTraceMessageLC(txt,color) TracyMessageLC(txt,color)
149 
150 #define utTraceMessageS(txt,size,depth) TracyMessageS(txt,size,depth)
151 #define utTraceMessageSHS(sh,depth) TracyMessageS((sh).c_str(),(sh).length(),depth)
152 #define utTraceMessageLS(txt,depth) TracyMessageLS(txt,depth)
153 #define utTraceMessageCS(txt,size,color,d) TracyMessageCS(txt,size,color,d)
154 #define utTraceMessageSHCS(sh,color,d) TracyMessageCS((sh).c_str(),(sh).length(),color,d)
155 #define utTraceMessageLCS(txt,color,depth) TracyMessageLCS(txt,color,depth)
156 
157 #define utTraceMessageFlag(F,txt,size) if(utTraceFlag(F)) TracyMessage(txt,size)
158 #define utTraceMessageFlagSH(F,sh) if(utTraceFlag(F)) TracyMessage((sh).c_str(),(sh).length())
159 #define utTraceMessageFlagL(F,txt) if(utTraceFlag(F)) TracyMessageL(txt)
160 #define utTraceMessageFlagLC(F,txt,color) if(utTraceFlag(F)) TracyMessageLC(txt,color)
161 #define utTraceMessageFlagC(F,txt,size,color) if(utTraceFlag(F)) TracyMessageC(txt,size,color)
162 #define utTraceMessageFlagSHC(F,sh,color) if(utTraceFlag(F)) TracyMessageC((sh).c_str(),(sh).length(),color)
163 
164 #define utTraceMessageFlagS(F,txt,size,depth) if(utTraceFlag(F)) TracyMessageS(txt,size,depth)
165 #define utTraceMessageFlagSHS(F,sh,depth) if(utTraceFlag(F)) TracyMessageS((sh).c_str(),(sh).length(),depth)
166 #define utTraceMessageFlagLS(F,txt,depth) if(utTraceFlag(F)) TracyMessageLS(txt,depth)
167 #define utTraceMessageFlagLCS(F,txt,color,depth) if(utTraceFlag(F)) TracyMessageLCS(txt,color,depth)
168 #define utTraceMessageFlagCS(F,txt,size,color,d) if(utTraceFlag(F)) TracyMessageCS(txt,size,color,d)
169 #define utTraceMessageFlagSHCS(F,sh,color,d) if(utTraceFlag(F)) TracyMessageCS((sh).c_str(),(sh).length(),color,d)
170 
171 // Memory tracing.
172 #define utTraceAlloc(ptr,size) TracyAlloc(ptr,size)
173 #define utTraceFree(ptr) TracyFree(ptr)
174 #define utTraceAllocN(ptr,size,name) TracyAllocN(ptr,size,name)
175 #define utTraceFreeN(ptr,name) TracyFreeN(ptr,name)
176 
177 #define utTraceAllocS(ptr,size,depth) TracyAllocS(ptr, size, depth)
178 #define utTraceFreeS(ptr,depth) TracyFreeS(ptr, depth)
179 #define utTraceAllocNS(ptr,size,depth,name) TracyAllocNS(ptr, size, depth, name)
180 #define utTraceFreeNS(ptr,depth,name) TracyFreeNS(ptr, depth, name)
181 
182 // Query if the profiler is connected.
183 #define utTraceIsConnected TracyIsConnected
184 
185 // Tests if the profiler
186 // has been started at all via tracy::StartupProfiler()
187 // in the static ut_TraceControl constructor.
188 // If a zone might be called during static construction
189 // it should be guarded with
190 // if (utIsStarted)
191 // otherwise its call to tracy::getProfiler might crash
192 // if ut_TraceControl hasn't been constructed yet.
193 #define utTraceIsStarted TracyIsStarted
194 
195 // Set the zone name to the node name
196 #define utZoneScopedNodeFlag(F, node) ZoneNamed( ___tracy_scoped_zone, utTraceFlag(F) ); \
197  if (node) utZoneNameSH(node->getName());
198 // Set the zone name to the node name, optionally setting the zone text to the full path.
199 // Only do if the zone is active (flag true and isconnected) since getFullPath is expensive.
200 #define utZoneScopedNodeFlagP(F, node) utZoneScopedNodeFlag(F, node) \
201  if (utZoneIsActive && node && utTraceFlag(NODE_PATHS)) { \
202  UT_StringHolder ___zonetext = node->getFullPath(); \
203  utZoneTextSH(___zonetext);}
204 
205 #define utTraceViewportDrawEvent(viewport, event) utZoneScopedFlag(VIEWPORT); \
206  if (utZoneIsActive) { \
207  utZoneNameSH(UT_StringHolder(viewport)); \
208  utZoneTextSH(UT_StringHolder(event)); }
209 
210 
211 #else
212 
213 #define utTraceFlag(F) false
214 
215 #define utZoneScopedFlag(F)
216 #define utZoneScopedFlagN(F, name)
217 #define utZoneScopedFlagS(F, depth)
218 #define utZoneScopedFlagNS(F, name, depth)
219 #define utZoneScopedBool(b)
220 
221 #define utZoneScoped
222 #define utZoneScopedN(name)
223 #define utZoneScopedC(color)
224 #define utZoneScopedNC(name,color)
225 
226 #define utZoneScopedS(depth)
227 #define utZoneScopedNS(name,depth)
228 #define utZoneScopedCS(color,depth)
229 #define utZoneScopedNCS(name,color,depth)
230 
231 #define utZoneText(txt,size)
232 #define utZoneTextSH(sh)
233 #define utZoneName(name,size)
234 #define utZoneNameSH(sh)
235 #define utZoneColor(color)
236 #define utZoneValue(value)
237 #define utZoneIsActive false
238 
239 #define utFrameMark
240 #define utFrameMarkNamed(x)
241 
242 #define utTracePlot(name,val)
243 #define utTracePlotConfigNum(name)
244 #define utTracePlotConfigMem(name)
245 #define utTracePlotConfigPct(name)
246 
247 #define utTraceMessage(txt,size)
248 #define utTraceMessageSH(sh)
249 #define utTraceMessageL(txt)
250 #define utTraceMessageC(txt,size,color)
251 #define utTraceMessageSHC(sh,color)
252 #define utTraceMessageLC(txt,color)
253 
254 #define utTraceMessageS(txt,size,depth)
255 #define utTraceMessageSHS(sh,depth)
256 #define utTraceMessageLS(txt,depth)
257 #define utTraceMessageCS(txt,size,color,d)
258 #define utTraceMessageSHCS(sh,color,d)
259 #define utTraceMessageLCS(txt,color,depth)
260 
261 #define utTraceMessageFlag(F,txt,size)
262 #define utTraceMessageFlagSH(F,sh)
263 #define utTraceMessageFlagL(F,txt)
264 #define utTraceMessageFlagLC(F,txt,color)
265 #define utTraceMessageFlagC(F,txt,size,color)
266 #define utTraceMessageFlagSHC(F,sh,color)
267 
268 #define utTraceMessageFlagS(F,txt,size,depth)
269 #define utTraceMessageFlagSHS(F,sh,depth)
270 #define utTraceMessageFlagLS(F,txt,depth)
271 #define utTraceMessageFlagLCS(F,txt,color,depth)
272 #define utTraceMessageFlagCS(F,txt,size,color,d)
273 #define utTraceMessageFlagSHCS(F,sh,color,d)
274 
275 #define utTraceAlloc(ptr,size)
276 #define utTraceFree(ptr)
277 #define utTraceAllocN(ptr,size,name)
278 #define utTraceFreeN(ptr,name)
279 
280 #define utTraceAllocS(ptr,size,depth)
281 #define utTraceFreeS(ptr,depth)
282 #define utTraceAllocNS(ptr,size,depth,name)
283 #define utTraceFreeNS(ptr,depth,name)
284 
285 #define utTraceIsConnected false
286 #define utTraceIsStarted false
287 
288 #define utZoneScopedNodeFlag(F, node)
289 #define utZoneScopedNodeFlagP(F, node)
290 
291 #define utTraceViewportDrawEvent(viewport, event)
292 
293 #endif
294 
295 #endif // UT_ASSERT_H_INCLUDED
#define UT_API
Definition: UT_API.h:14
GLfloat f
Definition: glcorearb.h:1926
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
auto get(const UT_ARTIterator< T > &it) -> decltype(it.key())
Definition: UT_ARTMap.h:1173
GLuint GLfloat * val
Definition: glcorearb.h:1608
OIIO_API void shutdown()