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