HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UT_PerfMonAutoEvent.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_PerfMonAutoEvent.h ( UT Library, C++)
7  *
8  * COMMENTS:
9  *
10  * Convenience classes for automatically starting and stopping
11  * timed and memory events in the Performance Monitor.
12  *
13  */
14 
15 #ifndef __UT_PerfMonAutoEvent__
16 #define __UT_PerfMonAutoEvent__
17 
18 #include "UT_NonCopyable.h"
19 #include "UT_Performance.h"
20 
21 class SIM_Solver;
22 
23 /// Base class.
24 /// Use one of the derived classes (below) instead.
26 {
27 public:
29  {
30  myTimedEventId = UT_PERFMON_INVALID_ID;
31  myMemoryEventId = UT_PERFMON_INVALID_ID;
32  myShouldStopEvents = true;
33  }
34 
36  {
37  if (!myShouldStopEvents)
38  return;
39 
40  if (myMemoryEventId != UT_PERFMON_INVALID_ID)
41  UTgetPerformance()->stopEvent(myMemoryEventId);
42  if (myTimedEventId != UT_PERFMON_INVALID_ID)
43  UTgetPerformance()->stopEvent(myTimedEventId);
44  }
45 
46  void setExtraInfo(const char *extra_info)
47  {
48  if (myTimedEventId != UT_PERFMON_INVALID_ID)
49  UTgetPerformance()->setEventExtraInfo(myTimedEventId, extra_info);
50 
51  if (myMemoryEventId != UT_PERFMON_INVALID_ID)
52  UTgetPerformance()->setEventExtraInfo(myMemoryEventId, extra_info);
53  }
54 
55  // These exist because the unit tests need them.
56  int getTimedEventId() const { return myTimedEventId; }
57  int getMemoryEventId() const { return myMemoryEventId; }
58 
59 protected:
60  void setTimedEventId_(int event_id) { myTimedEventId = event_id; }
61  void setMemoryEventId_(int event_id) { myMemoryEventId = event_id; }
62  void setShouldBaseClassStopEvents_(bool stop) { myShouldStopEvents = stop; }
63 
64 private:
65  int myTimedEventId;
66  int myMemoryEventId;
67  bool myShouldStopEvents;
68 };
69 
70 /// Convenience class for node cook events.
72 {
73 public:
74  UT_PerfMonAutoCookEvent(int node_id, const char *cook_event_name=NULL)
75  {
77 
78  /// The constructor's signature must match the signature
79  /// of UT_Performance::start*CookEvent().
80  if (perf->isRecordingCookStats())
81  {
83  perf->startTimedCookEvent(node_id, cook_event_name));
84  }
85 
86  if (perf->isRecordingMemoryStats())
87  {
89  perf->startMemoryCookEvent(node_id, cook_event_name));
90  }
91  }
93 };
94 
95 /// Convenience class for DOP solve events.
97 {
98 public:
99  /// The constructor's signature must match the signature
100  /// of UT_Performance::start*SolveEvent().
102  const SIM_Solver *solver, const char *solver_event_name=NULL)
103  {
105 
106  if (perf->isRecordingSolveStats())
107  {
109  perf->startTimedSolveEvent(solver, solver_event_name));
110  }
111 
112  if (perf->isRecordingMemoryStats())
113  {
115  perf->startMemorySolveEvent(solver, solver_event_name));
116  }
117  }
119 };
120 
121 /// Convenience class for object draw events.
123 {
124 public:
125  /// The constructor's signature must match the signature
126  /// of UT_Performance::start*DrawEvent().
128  const char *object, const char *draw_event_name, bool is_gpu_draw=false)
129  {
131 
132  if ((!is_gpu_draw && perf->isRecordingObjectDrawStats())
133  || (is_gpu_draw && perf->isRecordingObjectGPUDrawStats()))
134  {
136  perf->startTimedDrawEvent(object, draw_event_name,
137  is_gpu_draw));
138  }
139 
140  if (perf->isRecordingMemoryStats())
141  {
143  perf->startMemoryDrawEvent(object, draw_event_name,
144  is_gpu_draw));
145  }
146  }
148 };
149 
150 /// Convenience class for viewport draw events.
152 {
153 public:
154  /// The constructor's signature must match the signature
155  /// of UT_Performance::start*DrawEvent().
157  const char *viewport_name, const char *draw_event_name,
158  UT_PerfMonViewportType viewport_type, bool is_gpu_draw=false)
159  {
161 
162  if (perf->isRecordingViewportStats())
163  {
166  viewport_name, draw_event_name, viewport_type,
167  is_gpu_draw));
168  }
169 
170  if (perf->isRecordingMemoryStats())
171  {
174  viewport_name, draw_event_name, viewport_type,
175  is_gpu_draw));
176  }
177  }
179 };
180 
181 /// Convenience class for script events.
183 {
184 public:
185  /// The constructor's signature must match the signature
186  /// of UT_Performance::start*ScriptEvent().
188  const char *code_description, UT_PerfMonScriptType script_type,
189  bool auto_nest_events=true)
190  {
192 
193  if (perf->isRecordingScriptStats())
194  {
196  perf->startTimedScriptEvent(
197  code_description, script_type, auto_nest_events));
198  }
199 
200  if (perf->isRecordingMemoryStats())
201  {
204  code_description, script_type, auto_nest_events));
205  }
206  }
208 };
209 
210 /// Convenience class for render events.
212 {
213 public:
214  /// The constructor's signature must match the signature
215  /// of UT_Performance::start*RenderEvent().
217  const char *renderer, const char *operation,
218  bool is_renderer_a_node, int frame_num, const char *object=NULL)
219  {
221 
222  if (perf->isRecordingRenderStats())
223  {
225  perf->startTimedRenderEvent(
226  renderer, operation, is_renderer_a_node,
227  frame_num, object));
228  }
229 
230  if (perf->isRecordingMemoryStats())
231  {
234  renderer, operation, is_renderer_a_node,
235  frame_num, object));
236  }
237  }
239 };
240 
241 /// Convenience class for node creation events.
243 {
244 public:
245  /// The constructor's signature must match the signature
246  /// of UT_Performance::start*NodeCreationEvent().
248  : myNodeId(-1)
249  , myRecording(false)
250  {
251  // Make sure that the base class does not attempt
252  // to stop the underlying events.
254 
256 
257  if (perf->isRecordingCookStats())
258  {
259  myRecording = true;
262  }
263 
264  if (perf->isRecordingMemoryStats())
265  {
266  myRecording = true;
269  }
270  }
272  {
274  {
276  getTimedEventId(), myNodeId);
277  }
279  {
281  getMemoryEventId(), myNodeId);
282  }
283  };
284 
285  /// Set the node id that should be attached to the underlying
286  /// node creation events. This method should be called
287  /// immediately after the node is created.
288  void setNodeId(int node_id) { myNodeId = node_id; }
289 
290  bool isRecording() const { return myRecording; }
291 
292 private:
293  int myNodeId;
294  bool myRecording;
295 };
296 
297 #endif
298 
UT_PerfMonAutoCookEvent(int node_id, const char *cook_event_name=NULL)
UT_API UT_Performance * UTgetPerformance(bool create=true)
Convenience class for object draw events.
int getMemoryEventId() const
void stopNodeCreationEvent(int event_id, int node_id)
int startTimedViewportDrawEvent(const char *viewport_name, const char *draw_event_name, UT_PerfMonViewportType viewport_type, bool is_gpu_draw=false)
int startTimedRenderEvent(const char *renderer, const char *operation, bool is_renderer_a_node, int frame_num, const char *object=NULL)
UT_PerfMonAutoScriptEvent(const char *code_description, UT_PerfMonScriptType script_type, bool auto_nest_events=true)
bool isRecordingRenderStats() const
Return true if Houdini is recording render stats.
bool isRecordingSolveStats() const
Return true if Houdini is recording simulation solve stats.
UT_PerfMonAutoViewportDrawEvent(const char *viewport_name, const char *draw_event_name, UT_PerfMonViewportType viewport_type, bool is_gpu_draw=false)
int startMemorySolveEvent(const SIM_Solver *solver, const char *solver_event_name=NULL)
bool isRecordingMemoryStats() const
Return true if Houdini is recording memory stats.
void setMemoryEventId_(int event_id)
int startTimedScriptEvent(const char *code_description, UT_PerfMonScriptType script_type, bool auto_nest_events=true)
bool isRecordingCookStats() const
Return true if Houdini is recording cook stats.
Convenience class for DOP solve events.
int startTimedCookEvent(int node_id, const char *cook_event_name=NULL)
bool isRecordingScriptStats() const
Return true if Houdini is recording script stats.
int startTimedDrawEvent(const char *object, const char *draw_event_name, bool is_gpu_draw=false)
Convenience class for viewport draw events.
Convenience class for render events.
bool isRecordingViewportStats() const
Return true if Houdini is recording viewport draw stats.
Convenience class for node creation events.
Convenience class for node cook events.
int startMemoryRenderEvent(const char *renderer, const char *operation, bool is_renderer_a_node, int frame_num, const char *object=NULL)
UT_PerfMonAutoSolveEvent(const SIM_Solver *solver, const char *solver_event_name=NULL)
void setExtraInfo(const char *extra_info)
#define UT_PERFMON_INVALID_ID
fpreal stopEvent(int event_id, bool return_value=false)
UT_PerfMonViewportType
Viewport types recognized by the performance monitor.
void setTimedEventId_(int event_id)
UT_PerfMonAutoDrawEvent(const char *object, const char *draw_event_name, bool is_gpu_draw=false)
bool isRecordingObjectDrawStats() const
Return true if Houdini is recording object draw stats.
Convenience class for script events.
int startMemoryNodeCreationEvent()
bool isRecordingObjectGPUDrawStats() const
Return true if Houdini is recording object draw stats.
int startMemoryScriptEvent(const char *code_description, UT_PerfMonScriptType script_type, bool auto_nest_events=true)
UT_PerfMonScriptType
Script types recognized by the performance monitor.
int startTimedSolveEvent(const SIM_Solver *solver, const char *solver_event_name=NULL)
int startMemoryCookEvent(int node_id, const char *cook_event_name=NULL)
void setEventExtraInfo(int event_id, const char *extra_info) const
int startTimedNodeCreationEvent()
void setShouldBaseClassStopEvents_(bool stop)
UT_PerfMonAutoRenderEvent(const char *renderer, const char *operation, bool is_renderer_a_node, int frame_num, const char *object=NULL)
int getTimedEventId() const
int startMemoryDrawEvent(const char *object, const char *draw_event_name, bool is_gpu_draw=false)
int startMemoryViewportDrawEvent(const char *viewport_name, const char *draw_event_name, UT_PerfMonViewportType viewport_type, bool is_gpu_draw=false)