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_NTUtil.h" // for pid_t and getpid()
22 #include "UT_StringHolder.h"
23 
24 // Tracy implementation.
25 
26 // On-demand profiling.
27 #define TRACY_ON_DEMAND
28 // We manage profiler startup and shutdown.
29 #define TRACY_DELAYED_INIT
30 #define TRACY_MANUAL_LIFETIME
31 
32 // Set up TRACY_API the same way we do for UT_API
33 #if !defined(MAKING_STATIC)
34 #ifdef UT_EXPORTS
35 #define TRACY_EXPORTS
36 #else
37 #define TRACY_IMPORTS
38 #endif
39 #endif
40 
41 #include <tracy/Tracy.hpp>
42 
43 class UT_API utTraceControl
44 {
45 public:
46  // Flags for different types of traces. To add a new type of trace,
47  // add an enum here and a TRACYPARM call in the constructor.
48  enum Flag
49  {
50  NODE_PATHS,
51  CL_KERNELS,
52  CL_MEMORY,
53  NODE_COOKS,
54  DOP_SOLVES,
55  CL_FLUID,
56  VIEWPORT,
57  PYTHON_STATE,
58  EVENT_QUEUE,
59  HOUDINI_ENGINE
60  };
61 
62  utTraceControl();
63  ~utTraceControl();
64 
65  static utTraceControl &get();
66 
67  bool flag(Flag f) const
68  {
69  return m_flags & (1u << f);
70  }
71 
72  uint32_t setFlag(uint32_t idx, uint32_t val)
73  {
74  uint32_t bflag = (1u << idx);
75  m_flags = val ? (m_flags | bflag) : (m_flags & ~bflag);
76  return val;
77  }
78 
79 private:
80 
81  uint32_t m_flags;
82  pid_t m_pid;
83 };
84 
85 // If the specific type of tracing is active.
86 #define utTraceFlag(F) utTraceControl::get().flag(utTraceControl::F)
87 
88 // These macros match the Tracy suffix name:
89 // See the Tracy documentation for more: https://github.com/wolfpld/tracy
90 // N indicates a name
91 // S a stack trace to the specified depth
92 // C a specific color for the zone in the profiler UI
93 
94 // Scoped zone tracing, supply a flag to specify the trace type.
95 #define utZoneScopedFlag(F) ZoneNamed( ___tracy_scoped_zone, utTraceFlag(F) )
96 #define utZoneScopedFlagN(F, name) ZoneNamedN( ___tracy_scoped_zone, name, utTraceFlag(F) )
97 #define utZoneScopedFlagS(F, depth) ZoneNamedS( ___tracy_scoped_zone, depth, utTraceFlag(F) )
98 #define utZoneScopedFlagNS(F, name, depth) ZoneNamedNS( ___tracy_scoped_zone, name, depth, utTraceFlag(F) )
99 #define utZoneScopedBool(b) ZoneNamed( ___tracy_scoped_zone, b )
100 
101 // These zones show up for any trace type.
102 #define utZoneScoped ZoneScoped
103 #define utZoneScopedN(name) ZoneScopedN(name)
104 #define utZoneScopedC(color) ZoneScopedC(color)
105 #define utZoneScopedNC(name,color) ZoneScopedNC(name,color)
106 
107 #define utZoneScopedS(depth) ZoneScopedS(depth)
108 #define utZoneScopedNS(name,depth) ZoneScopedNS(name,depth)
109 #define utZoneScopedCS(color,depth) ZoneScopedCS(color,depth)
110 #define utZoneScopedNCS(name,color,depth) ZoneScopedNCS(name,color,depth)
111 
112 // Attach user text, name, color, or user value to
113 // the current zone.
114 // SH takes a UT_StringHolder (anything that has c_str and length, really)
115 #define utZoneText(txt,size) ZoneText(txt,size)
116 #define utZoneTextSH(sh) ZoneText((sh).c_str(),(sh).length())
117 #define utZoneName(name,size) ZoneName(name,size)
118 #define utZoneNameSH(sh) ZoneName((sh).c_str(),(sh).length())
119 #define utZoneColor(color) ZoneColor(color)
120 #define utZoneValue(value) ZoneValue(value)
121 #define utZoneIsActive ZoneIsActive
122 
123 // Mark a frame, possibly with a type of frame.
124 #define utFrameMark FrameMark
125 #define utFrameMarkNamed(x) FrameMarkNamed(x)
126 
127 #define utTracePlot(name,val) TracyPlot(name,val)
128 // Confifgure plot as num, memory, or percent.
129 #define utTracePlotConfigNum(name) TracyPlotConfig(name,tracy::PlotFormatType::Number)
130 #define utTracePlotConfigMem(name) TracyPlotConfig(name,tracy::PlotFormatType::Memory)
131 #define utTracePlotConfigPct(name) TracyPlotConfig(name,tracy::PlotFormatType::Percentage)
132 
133 // Add a trace message to the profiler, will attach
134 // to the current zone.
135 // L is literal, else you need to supply a size.
136 #define utTraceMessage(txt,size) TracyMessage(txt,size)
137 #define utTraceMessageSH(sh) TracyMessage((sh).c_str(),(sh).length())
138 #define utTraceMessageL(txt) TracyMessageL(txt)
139 #define utTraceMessageC(txt,size,color) TracyMessageC(txt,size,color)
140 #define utTraceMessageSHC(sh,color) TracyMessageC((sh).c_str(),(sh).length(),color)
141 #define utTraceMessageLC(txt,color) TracyMessageLC(txt,color)
142 
143 #define utTraceMessageS(txt,size,depth) TracyMessageS(txt,size,depth)
144 #define utTraceMessageSHS(sh,depth) TracyMessageS((sh).c_str(),(sh).length(),depth)
145 #define utTraceMessageLS(txt,depth) TracyMessageLS(txt,depth)
146 #define utTraceMessageCS(txt,size,color,d) TracyMessageCS(txt,size,color,d)
147 #define utTraceMessageSHCS(sh,color,d) TracyMessageCS((sh).c_str(),(sh).length(),color,d)
148 #define utTraceMessageLCS(txt,color,depth) TracyMessageLCS(txt,color,depth)
149 
150 #define utTraceMessageFlag(F,txt,size) if(utTraceFlag(F)) TracyMessage(txt,size)
151 #define utTraceMessageFlagSH(F,sh) if(utTraceFlag(F)) TracyMessage((sh).c_str(),(sh).length())
152 #define utTraceMessageFlagL(F,txt) if(utTraceFlag(F)) TracyMessageL(txt)
153 #define utTraceMessageFlagLC(F,txt,color) if(utTraceFlag(F)) TracyMessageLC(txt,color)
154 #define utTraceMessageFlagC(F,txt,size,color) if(utTraceFlag(F)) TracyMessageC(txt,size,color)
155 #define utTraceMessageFlagSHC(F,sh,color) if(utTraceFlag(F)) TracyMessageC((sh).c_str(),(sh).length(),color)
156 
157 #define utTraceMessageFlagS(F,txt,size,depth) if(utTraceFlag(F)) TracyMessageS(txt,size,depth)
158 #define utTraceMessageFlagSHS(F,sh,depth) if(utTraceFlag(F)) TracyMessageS((sh).c_str(),(sh).length(),depth)
159 #define utTraceMessageFlagLS(F,txt,depth) if(utTraceFlag(F)) TracyMessageLS(txt,depth)
160 #define utTraceMessageFlagLCS(F,txt,color,depth) if(utTraceFlag(F)) TracyMessageLCS(txt,color,depth)
161 #define utTraceMessageFlagCS(F,txt,size,color,d) if(utTraceFlag(F)) TracyMessageCS(txt,size,color,d)
162 #define utTraceMessageFlagSHCS(F,sh,color,d) if(utTraceFlag(F)) TracyMessageCS((sh).c_str(),(sh).length(),color,d)
163 
164 // Memory tracing.
165 #define utTraceAlloc(ptr,size) TracyAlloc(ptr,size)
166 #define utTraceFree(ptr) TracyFree(ptr)
167 #define utTraceAllocN(ptr,size,name) TracyAllocN(ptr,size,name)
168 #define utTraceFreeN(ptr,name) TracyFreeN(ptr,name)
169 
170 #define utTraceAllocS(ptr,size,depth) TracyAllocS(ptr, size, depth)
171 #define utTraceFreeS(ptr,depth) TracyFreeS(ptr, depth)
172 #define utTraceAllocNS(ptr,size,depth,name) TracyAllocNS(ptr, size, depth, name)
173 #define utTraceFreeNS(ptr,depth,name) TracyFreeNS(ptr, depth, name)
174 
175 // Query if the profiler is connected.
176 #define utTraceIsConnected TracyIsConnected
177 
178 
179 // Set the zone name to the node name
180 #define utZoneScopedNodeFlag(F, node) ZoneNamed( ___tracy_scoped_zone, utTraceFlag(F) ); \
181  if (node) utZoneNameSH(node->getName());
182 // Set the zone name to the node name, optionally setting the zone text to the full path.
183 // Only do if the zone is active (flag true and isconnected) since getFullPath is expensive.
184 #define utZoneScopedNodeFlagP(F, node) utZoneScopedNodeFlag(F, node) \
185  if (utZoneIsActive && node && utTraceFlag(NODE_PATHS)) { \
186  UT_StringHolder ___zonetext = node->getFullPath(); \
187  utZoneTextSH(___zonetext);}
188 
189 #define utTraceViewportDrawEvent(viewport, event) utZoneScopedFlag(VIEWPORT); \
190  if (utZoneIsActive) { \
191  utZoneNameSH(UT_StringHolder(viewport)); \
192  utZoneTextSH(UT_StringHolder(event)); }
193 
194 
195 #else
196 
197 #define utTraceFlag(F) false
198 
199 #define utZoneScopedFlag(F)
200 #define utZoneScopedFlagN(F, name)
201 #define utZoneScopedFlagS(F, depth)
202 #define utZoneScopedFlagNS(F, name, depth)
203 #define utZoneScopedBool(b)
204 
205 #define utZoneScoped
206 #define utZoneScopedN(name)
207 #define utZoneScopedC(color)
208 #define utZoneScopedNC(name,color)
209 
210 #define utZoneScopedS(depth)
211 #define utZoneScopedNS(name,depth)
212 #define utZoneScopedCS(color,depth)
213 #define utZoneScopedNCS(name,color,depth)
214 
215 #define utZoneText(txt,size)
216 #define utZoneTextSH(sh)
217 #define utZoneName(name,size)
218 #define utZoneNameSH(sh)
219 #define utZoneColor(color)
220 #define utZoneValue(value)
221 #define utZoneIsActive false
222 
223 #define utFrameMark
224 #define utFrameMarkNamed(x)
225 
226 #define utTracePlot(name,val)
227 #define utTracePlotConfigNum(name)
228 #define utTracePlotConfigMem(name)
229 #define utTracePlotConfigPct(name)
230 
231 #define utTraceMessage(txt,size)
232 #define utTraceMessageSH(sh)
233 #define utTraceMessageL(txt)
234 #define utTraceMessageC(txt,size,color)
235 #define utTraceMessageSHC(sh,color)
236 #define utTraceMessageLC(txt,color)
237 
238 #define utTraceMessageS(txt,size,depth)
239 #define utTraceMessageSHS(sh,depth)
240 #define utTraceMessageLS(txt,depth)
241 #define utTraceMessageCS(txt,size,color,d)
242 #define utTraceMessageSHCS(sh,color,d)
243 #define utTraceMessageLCS(txt,color,depth)
244 
245 #define utTraceMessageFlag(F,txt,size)
246 #define utTraceMessageFlagSH(F,sh)
247 #define utTraceMessageFlagL(F,txt)
248 #define utTraceMessageFlagLC(F,txt,color)
249 #define utTraceMessageFlagC(F,txt,size,color)
250 #define utTraceMessageFlagSHC(F,sh,color)
251 
252 #define utTraceMessageFlagS(F,txt,size,depth)
253 #define utTraceMessageFlagSHS(F,sh,depth)
254 #define utTraceMessageFlagLS(F,txt,depth)
255 #define utTraceMessageFlagLCS(F,txt,color,depth)
256 #define utTraceMessageFlagCS(F,txt,size,color,d)
257 #define utTraceMessageFlagSHCS(F,sh,color,d)
258 
259 #define utTraceAlloc(ptr,size)
260 #define utTraceFree(ptr)
261 #define utTraceAllocN(ptr,size,name)
262 #define utTraceFreeN(ptr,name)
263 
264 #define utTraceAllocS(ptr,size,depth)
265 #define utTraceFreeS(ptr,depth)
266 #define utTraceAllocNS(ptr,size,depth,name)
267 #define utTraceFreeNS(ptr,depth,name)
268 
269 #define utTraceIsConnected false
270 
271 #define utZoneScopedNodeFlag(F, node)
272 #define utZoneScopedNodeFlagP(F, node)
273 
274 #define utTraceViewportDrawEvent(viewport, event)
275 
276 #endif
277 
278 #endif // UT_ASSERT_H_INCLUDED
#define UT_API
Definition: UT_API.h:14
GLfloat f
Definition: glcorearb.h:1926
GLuint GLfloat * val
Definition: glcorearb.h:1608