HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_Performance.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_Performance.h ( UT Library, C++)
7  *
8  * COMMENTS:
9  *
10  * The performance monitor.
11  */
12 
13 #ifndef __UT_Performance__
14 #define __UT_Performance__
15 
16 #include "UT_API.h"
17 
18 #include "UT_Condition.h"
19 #include "UT_Lock.h"
20 #include "UT_Map.h"
21 #include "UT_PerfMonProfile.h"
22 #include "UT_PerfMonTimedEvent.h"
23 #include "UT_PerfMonTypes.h"
24 #include "UT_Color.h"
25 #include "UT_Ramp.h"
26 #include "UT_ThreadSpecificValue.h"
27 #include <SYS/SYS_AtomicInt.h>
28 
29 #include <tbb/spin_rw_mutex.h>
30 
31 #define UT_PERFMON_INVALID_ID -1
32 
34 {
45 };
46 
49 
50 typedef void (*UT_PerfMonEventCB)
51  (void *callee, const UT_PerfMonEvent *event);
52 
53 class OP_Node;
54 class SIM_Solver;
55 class UT_NetSocket;
56 class UT_PerfMonEvent;
57 class UT_PerfMonProfile;
58 class UT_PerfMonStats;
59 class ut_PerfMonProfileInterest;
60 class ut_PerfMonEventInterest;
61 class UT_WorkBuffer;
62 
64 {
65 public:
67  virtual ~UT_Performance();
68 
69  /// ********************************************************
70  /// EVENT MANAGEMENT
71  /// ********************************************************
72 
73  /// Start a generic timed event or memory event. For custom monitoring.
74  /// Check if there are more specific startTimed*() and startMemory*()
75  /// methods below that you can call instead before using these methods.
76  ///
77  /// Return the event id, or UT_PERFMON_INVALID_ID if the event
78  /// was not recorded (i.e. no profile has been started).
79  /// If `auto_nest_events` is true, then any other events
80  /// that are started and stopped before this event is stopped
81  /// will be treated as dependencies on this event.
82  int startTimedEvent(
83  const char *event,
84  const char *object,
85  bool auto_nest_events=true);
86  int startMemoryEvent(
87  const char *object,
88  bool auto_nest_events=true);
89 
90  /// Start a timed event or memory event for OP cooks.
91  /// Return the event id, or UT_PERFMON_INVALID_ID if the event
92  /// was not recorded (i.e. no profile has been started).
93  int startTimedCookEvent(
94  int node_id,
95  const char *cook_event_name=NULL);
96  int startMemoryCookEvent(
97  int node_id,
98  const char *cook_event_name=NULL);
99 
100  /// Add a new timed cook event.
101  /// Instead of starting and stopping the event,
102  /// immediately set the event's run time to `time`. The event is
103  /// added to any interested profiles and observers.
104  void addTimedCookEvent(
105  int node_id,
106  fpreal time,
107  const char *cook_event_name=NULL);
108 
109  /// Start a timed event or memory event for DOP solves.
110  /// Return the event id, or UT_PERFMON_INVALID_ID if the event
111  /// was not recorded (i.e. no profile has been started).
112  int startTimedSolveEvent(
113  const SIM_Solver *solver,
114  const char *solver_event_name=NULL);
115  int startMemorySolveEvent(
116  const SIM_Solver *solver,
117  const char *solver_event_name=NULL);
118 
119  /// Start a timed event or memory event for a generic draw event.
120  /// Set `is_gpu_draw` to true if the draw event occurred on the GPU.
121  /// Return the event id, or UT_PERFMON_INVALID_ID if the event
122  /// was not recorded (i.e. no profile has been started).
123  int startTimedDrawEvent(
124  const char *object,
125  const char *draw_event_name,
126  bool is_gpu_draw=false);
127  int startMemoryDrawEvent(
128  const char *object,
129  const char *draw_event_name,
130  bool is_gpu_draw=false);
131 
132  /// Start a timed event or memory event for viewport draws.
133  /// Set `is_gpu_draw` to true if the draw event occurred on the GPU.
134  /// Return the event id, or UT_PERFMON_INVALID_ID if the event
135  /// was not recorded (i.e. no profile has been started).
136  int startTimedViewportDrawEvent(
137  const char *viewport_name,
138  const char *draw_event_name,
139  UT_PerfMonViewportType viewport_type,
140  bool is_gpu_draw=false);
141  int startMemoryViewportDrawEvent(
142  const char *viewport_name,
143  const char *draw_event_name,
144  UT_PerfMonViewportType viewport_type,
145  bool is_gpu_draw=false);
146 
147  /// Add a new timed draw event.
148  /// Instead of starting and stopping the event,
149  /// immediately set the event's run time to `time`. The event is
150  /// added to any interested profiles and observers.
151  void addTimedDrawEvent(
152  const char *object,
153  const char *draw_event_name,
154  fpreal time,
155  bool is_gpu_draw=false);
156 
157  /// Add a new timed viewport draw event.
158  /// Instead of starting and stopping the event,
159  /// immediately set the event's run time to `time`. The event is
160  /// added to any interested profiles and observers.
161  void addTimedViewportDrawEvent(
162  const char *object,
163  const char *draw_event_name,
164  UT_PerfMonViewportType viewport_type,
165  fpreal time,
166  bool is_gpu_draw=false);
167 
168  /// Start a timed script event or memory script event.
169  /// Return the event id, or UT_PERFMON_INVALID_ID if the event
170  /// was not recorded (i.e. no profile has been started).
171  int startTimedScriptEvent(
172  const char *code_description,
173  UT_PerfMonScriptType script_type,
174  bool auto_nest_events=true);
175  int startMemoryScriptEvent(
176  const char *code_description,
177  UT_PerfMonScriptType script_type,
178  bool auto_nest_events=true);
179 
180  /// Start a timed render event or a memory render event.
181  /// Return the event id, or UT_PERFMON_INVALID_ID if the event
182  /// was not recorded (i.e. no profile has been started).
183  int startTimedRenderEvent(
184  const char *renderer,
185  const char *operation,
186  bool is_renderer_a_node,
187  int frame_num,
188  const char *object=NULL);
189  int startMemoryRenderEvent(
190  const char *renderer,
191  const char *operation,
192  bool is_renderer_a_node,
193  int frame_num,
194  const char *object=NULL);
195 
196  /// Add a new timed or memory render event.
197  /// Instead of starting and stopping the event,
198  /// immediately set the event's run time or memory.
199  /// The event is added to any interested profiles and observers.
200  void addTimedRenderEvent(
201  const char *object,
202  bool is_renderer_a_node,
203  int frame_num,
204  fpreal time);
205  void addMemoryRenderEvent(
206  const char *object,
207  bool is_renderer_a_node,
208  int frame_num,
209  fpreal value);
210 
211  /// Start a timed or memory frame event.
212  /// Return the event id, or UT_PERFMON_INVALID_ID if the event
213  /// was not recorded.
214  int startTimedFrameEvent(fpreal frame);
215  int startMemoryFrameEvent(fpreal frame);
216 
217  /// Stop a running event.
218  /// Return the event's (self) value if `return_value` is set to true.
219  /// If the event defined by `event_id` does not exist, or is not running,
220  /// or if `return_value` is set to false, then return 0.
221  /// Note that calculating the event's value can be expensive.
222  fpreal stopEvent(int event_id, bool return_value=false);
223 
224  /// These methods start and stop events that are specifically designed
225  /// to measure the creation of nodes.
226  int startTimedNodeCreationEvent();
227  int startMemoryNodeCreationEvent();
228  void stopNodeCreationEvent(int event_id, int node_id);
229 
230  /// Cancel a running event. The event is stopped but is not added
231  /// to any profiles nor is it broadcast to any observers.
232  /// Do nothing if the event does not exist or if it is not running.
233  void cancelEvent(int event_id);
234 
235  /// Log a generic message event.
236  void logMessage(const char *message);
237 
238  /// Return the specified event. (read-only)
239  /// Return NULL if the requested event does not exist.
240  const UT_PerfMonEvent *getEvent(int event_id) const;
241 
242  /// Return the specified timed event. (read-only)
243  /// Return NULL if the requested event does not exist
244  /// or is not a timed event.
245  const UT_PerfMonTimedEvent *getTimedEvent(int event_id) const;
246 
247  /// Start timing the given task scope.
248  /// Return the id of the event that the task is attached to.
249  /// Return UT_PERMON_INVALID_ID if no such event exists.
250  /// This method should only be called in UT_TaskScope's constructor.
251  virtual int startTaskScope(const UT_TaskScope* task_scope);
252 
253  /// Stop timing the given task scope.
254  /// This method should only be called in UT_TaskScope's destructor.
255  virtual void stopTaskScope(
256  const UT_TaskScope* task_scope,
257  int event_id);
258 
259  /// Set extra information that will appear with the event in the
260  /// stats and event log.
261  void setEventExtraInfo(
262  int event_id, const char *extra_info) const;
263 
264  /// Return the port that the performance monitor is listening on
265  /// for remote events. Return 0 if the performance monitor
266  /// is currently not listening for events.
267  int getEventListenPort() const;
268 
269  /// ********************************************************
270  /// PROFILE MANAGEMENT
271  /// ********************************************************
272 
273  /// Start a new profile and capture timed and memory events.
274  /// When the profile is stopped, the events are processed
275  /// to produce a statistical report.
276  /// Return the unique id for the new profile.
277  int startProfile(
278  const char *title,
279  const UT_PerfMonRecordOptions *options=NULL);
280 
281  /// Stop the specified profile. Tabulate timings.
282  /// Do nothing if the profile does not exist or has already stopped.
283  void stopProfile(int profile_id);
284 
285  /// Cancel the specified profile. Do nothing if the profile
286  /// does not exist or is not profiling.
287  void cancelProfile(int profile_id);
288 
289  /// Pause the specified profile. Do nothing if the profile
290  /// does not exist, or if it is not profiling,
291  /// or if it is already paused.
292  void pauseProfile(int profile_id);
293 
294  /// Resume the specified profile. Do nothing if the profile
295  /// does not exist, or if it is not profiling,
296  /// or if it is not paused.
297  void resumeProfile(int profile_id);
298 
299  /// Load a profile from disk. Return the id of the loaded profile.
300  /// Return UT_PERFMON_INVALID_ID if the load failed.
301  int loadProfile(
302  const char *file_path,
303  UT_StringArray &errors);
304 
305  /// Delete the specified profile and unregister it from
306  /// the performance monitor. Do nothing if the profile does not exist.
307  void removeProfile(int profile_id);
308 
309  /// Rename the specified profile.
310  void renameProfile(
311  int profile_id,
312  const char *profile_name);
313 
314  /// Change the recording options for the specified profile.
315  void changeProfileRecordOptions(
316  int profile_id,
317  const UT_PerfMonRecordOptions &options);
318 
319  /// Clear the stats for the given profile.
320  void clearProfileStats(int profile_id);
321 
322  /// Return the specified profile. (read-only)
323  /// Return NULL if the requested profile does not exist.
324  const UT_PerfMonProfile *getProfile(int profile_id) const;
325 
326  /// Return the id of the active profile.
327  /// Return UT_PERFMON_INVALID_ID if there is no active profile.
328  int getActiveProfileId() const
329  { return myActiveProfileId; }
330 
331  /// Set the active profile to the given id
332  void setActiveProfileId(int profile_id);
333 
334  /// Return the number of completed profiles that the performance monitor
335  /// is storing. A completed profile is a profile that is no longer
336  /// recording events and has generated stats.
337  int numCompletedProfiles() const;
338 
339  /// Return the completed profile at the specified index.
340  /// A completed profile is a profile that is no longer recording events
341  /// and has generated stats.
342  const UT_PerfMonProfile *getCompletedProfile(int index) const;
343 
344  /// Add an interest for profile events.
345  /// Do nothing if the interest has been previously added.
346  void addProfileInterest(
347  void *callee,
349 
350  /// Remove an interest for profile events.
351  /// Do nothing if the specified interest does not exist.
352  void removeProfileInterest(
353  void *callee,
355 
356  /// Return true if the performance monitor already
357  /// has the given profile interest. Return false otherwise.
358  bool hasProfileInterest(
359  void *callee,
361 
362  /// Add an interest for running events.
363  /// You can pass in a set of record options to define the types of events
364  /// that you are interested in.
365  void addEventInterest(
366  void *callee,
367  UT_PerfMonEventCB callback,
368  const UT_PerfMonRecordOptions &options);
369 
370  /// Update the recording options for the specified event interest.
371  void changeEventInterestRecordOptions(
372  void *callee,
373  UT_PerfMonEventCB callback,
374  const UT_PerfMonRecordOptions &options);
375 
376  /// Remove an interest for events.
377  void removeEventInterest(
378  void *callee,
379  UT_PerfMonEventCB callback);
380 
381  /// Return true if the performance monitor already
382  /// has the given profile interest. Return false otherwise.
383  bool hasEventInterest(
384  void *callee,
385  UT_PerfMonEventCB callback);
386 
387  /// Create a new profile that stores difference in stats between profiles
388  /// Return the unique id for the new profile.
389  int createDiffProfile(int id1, int id2);
390 
391  /// ********************************************************
392  /// RECORDING METHODS
393  /// ********************************************************
394 
395  /// Return true if the performance monitor is recording Houdini events.
396  /// Return false otherwise.
397  bool isRecording() const {
398  return myIsRecordingCount.load() > 0
399  || getDisplayNodeInfo();
400  }
401 
402  /// Return true if Houdini is recording cook stats.
403  bool isRecordingCookStats() const {
404  return myRecordCookStatsCount.load() > 0
405  || getDisplayNodeInfo();
406  }
407 
408  /// Return true if Houdini is recording simulation solve stats.
409  bool isRecordingSolveStats() const {
410  return myRecordSolveStatsCount.load() > 0;
411  }
412 
413  /// Return true if Houdini is recording object draw stats.
415  return
416  myRecordObjectDrawStatsCount.load() > 0;
417  }
418 
419  /// Return true if Houdini is recording object draw stats.
421  return
422  myRecordObjectGPUDrawStatsCount.load() > 0;
423  }
424 
425  /// Return true if Houdini is recording viewport draw stats.
427  return myRecordViewportStatsCount.load() > 0;
428  }
429 
430  /// Return true if Houdini is recording script stats.
431  bool isRecordingScriptStats() const {
432  return myRecordScriptStatsCount.load() > 0;
433  }
434 
435  /// Return true if Houdini is recording render stats.
436  bool isRecordingRenderStats() const {
437  return myRecordRenderStatsCount.load() > 0;
438  }
439 
440  /// Return true if Houdini is recording thread stats.
441  bool isRecordingThreadStats() const {
442  return myRecordThreadStatsCount.load() > 0;
443  }
444 
445  /// Return true if Houdini is recording frame stats.
446  bool isRecordingFrameStats() const {
447  return myRecordFrameStatsCount.load() > 0;
448  }
449 
450  /// Return true if Houdini is recording memory stats.
451  bool isRecordingMemoryStats() const {
452  return myRecordMemoryStatsCount.load() > 0;
453  }
454 
455  /// Return true if Houdini is recording errors.
456  bool isRecordingErrors() const {
457  return myRecordErrorsCount.load() > 0;
458  }
459 
460  /// Returns true if the particular node passed is allowed to
461  /// participate in recording of the statistics, false otherwise.
462  /// This is currently used for disallowing recording of the contents
463  /// of compiled nodes.
464  virtual bool isRecordingAllowedFor(OP_Node* node) const;
465 
466  /// ********************************************************
467  /// FRAME STATISTIC METHODS
468  /// ********************************************************
469 
470  /// Return the number of timed frame events
471  /// recorded by the performance monitor.
473  { return myTimedFrameEventCounter; }
474 
475  /// Return the number of memory frame events
476  /// recorded by the performance monitor.
478  { return myMemoryFrameEventCounter; }
479 
480  /// Return the total time spent in the frame events
481  /// recorded by the performance monitor.
483  { return myTotalFrameTime; }
484 
485  /// Return the total memory accumulation in the frame events
486  /// recorded by the performance monitor.
488  { return myTotalFrameMemory; }
489 
490  /// Reset the performance monitor's accumulated frame statistics.
491  void resetCumulativeFrameStats();
492 
493  /// ********************************************************
494  /// MISCELLANEOUS
495  /// ********************************************************
496 
497  /// Return the icon name to use for the given stats object.
498  /// Return NULL if there is no known icon to use for the object.
499  /// Subclasses can override this method to set up their own mappings
500  /// of stats objects to icons.
501  virtual const char *getStatsIcon(const UT_PerfMonStats *stats) const;
502 
503  /// ********************************************************
504  /// DISPLAY OPTIONS
505  /// ********************************************************
506 
507  /// Toggle whether or not the performance info is displayed in
508  /// the Node info.
509  void setDisplayNodeInfo(bool display);
510  bool getDisplayNodeInfo() const
511  { return myDisplayNodeInfo; }
512 
513  /// Thresholds for displaying various colours in the network editor and
514  /// in the Spreadsheet.
515  void getPerformanceColor(fpreal pos, UT_Color &c);
516 
517  /// Return the ramp color scheme used by the performance monitor.
518  const UT_Ramp &getRampColorScheme() const;
519 
520  /// Set the performance monitor's ramp color scheme.
521  void setRampColorScheme(const UT_Ramp &src_ramp);
522 
523  /// Load the ramp color scheme from the given string representation.
524  void loadRampColorScheme(const char *str_color_scheme);
525 
526  /// Save a representation of the ramp color scheme to the given string.
527  void saveRampColorScheme(UT_String &str_color_scheme);
528 
529  /// Return the default ramp color scheme.
530  const UT_Ramp &getDefaultColorRampScheme();
531 
532  /// ********************************************************
533  /// MAINTENANCE
534  /// ********************************************************
535 
536  /// Reset the state of the performance monitor.
537  /// Reset counters and delete events and profiles.
538  /// This method should never be called. It is handy for testing purposes.
539  void reset();
540 
541 protected:
542 
543  /// Return the current frame.
544  virtual int getCurrentFrameSubclass_();
545 
546  /// Return a pointer to the node specified by the given id.
547  virtual OP_Node *getNodeSubclass_(int node_id) const;
548 
549  /// Return a pointer to the node that is bound to the given SIM solver.
550  virtual OP_Node *getNodeFromSolverSubclass_(
551  const SIM_Solver *solver) const;
552 
553  /// Pass back an object path that can be tied to a UT_PerfMonStats object.
554  /// The path is generated from the given node and event name.
555  virtual void getObjectPathFromNodeSubclass_(
556  OP_Node *node, const char *event_name,
557  UT_WorkBuffer &object_path) const;
558 
559  /// Pass back an object path that can be tied to a UT_PerfMonStats object.
560  /// The path is generated from the given solver, node and event name.
561  virtual void getObjectPathFromSolverAndNodeSubclass_(
562  const SIM_Solver *solver, OP_Node *node,
563  const char *event_name, UT_WorkBuffer &object_path)
564  const;
565 
566  /// Pass back extra info that can be tied to a UT_PerfMonStats object.
567  /// The extra info is generated from the given node.
568  virtual void getExtraInfoFromNodeSubclass_(
569  OP_Node *node, UT_WorkBuffer &extra_info) const;
570 
571 private:
572 
573  int newEventId_();
574  int newProfileId_();
575 
576 
577  /// Return the specified timed event.
578  /// Return NULL if the requested event does not exist
579  /// or is not a timed event.
580  UT_PerfMonTimedEvent *getTimedEvent_(int event_id) const;
581 
582  /// Return the specified event.
583  /// Return NULL if the requested event does not exist.
584  UT_PerfMonEvent *getEvent_(int event_id) const;
585 
586  /// Start a event.
587  /// Subclasses must call this method when starting their own events.
588  int startEvent_(
589  const char *event,
590  const char *object,
591  bool auto_nest_events,
592  UT_PerfMonCategory category,
594  UT_PerfMonObjectType object_type,
595  const char *object_icon,
596  int *frame_num=NULL,
597  const char *extra_info=NULL);
598 
599  /// Start a cook event.
600  int startCookEvent_(
602  int node_id, const char *cook_event_name);
603 
604  /// Start a solve event.
605  int startSolveEvent_(
607  const SIM_Solver *solver,
608  const char *solver_event_name);
609 
610  /// Start a draw event.
611  int startDrawEvent_(
613  const char *object,
614  const char *draw_event_name,
615  bool is_gpu_draw);
616 
617  /// Start a viewport draw event.
618  int startViewportDrawEvent_(
620  const char *viewport_name,
621  const char *draw_event_name,
622  UT_PerfMonViewportType viewport_type,
623  bool is_gpu_draw);
624 
625  /// Start a generic draw event.
626  int startGenericDrawEvent_(
628  const char *object,
629  const char *draw_event_name,
630  UT_PerfMonObjectType object_type,
631  const char *object_icon,
632  bool is_gpu_draw);
633 
634  /// Start a script event.
635  int startScriptEvent_(
637  const char *code_description,
638  UT_PerfMonScriptType script_type,
639  bool auto_nest_events);
640 
641  /// Start a render event.
642  int startRenderEvent_(
644  const char *renderer,
645  const char *operation,
646  bool is_renderer_a_node,
647  int frame_num,
648  const char *object);
649 
650  /// Return the specified profile.
651  /// Return NULL if the requested profile does not exist.
652  UT_PerfMonProfile *getProfile_(int profile_id) const;
653 
654  /// Activate profile.
655  void activateProfile_(UT_PerfMonProfile *profile);
656 
657  /// De-activate profile.
658  void deactivateProfile_(UT_PerfMonProfile *profile);
659 
660  /// Increment recording counters based on the specified options.
661  void incrementRecordingCounters_(
662  const UT_PerfMonRecordOptions &options);
663 
664  /// Decrement recording counters based on the specified options.
665  void decrementRecordingCounters_(
666  const UT_PerfMonRecordOptions &options);
667 
668  /// Remove and delete the specified profile. Returns the profile id
669  int removeProfile_(UT_PerfMonProfile *profile);
670 
671  /// Notify that given profile id has been destroyed
672  void notifyRemovedProfile_(int profile_id);
673 
674  /// Remove the event. Delete it if it is a top-level event.
675  void removeEvent_(
676  int event_id,
677  UT_PerfMonEvent *event,
678  bool is_cancelled=false);
679 
680  // Find the running parent event (if any) of the given event
681  // and create a link between them.
682  void findAndLinkToRunningParentEvent_(
683  UT_PerfMonEvent *event);
684 
685  UT_PerfMonEvent *findRunningParentEvent_(
686  const UT_TaskScope *task,
687  bool for_memory_event,
688  bool require_auto_nest);
689 
690  /// Return the list of running events for the given task.
691  /// The most recently started event will appear at the end of the list.
692  /// This method will create a new list if no such list already exists.
693  UT_PerfMonEventList *getOrCreateRunningEventList_(
694  const UT_TaskScope *task,
695  bool for_memory_event);
696 
697  /// Return the list of running events for the given task.
698  /// Return NULL if no such list exists.
699  /// It is up to the caller to acquire the appropriate thread events lock.
700  UT_PerfMonEventList *getRunningEventList_(
701  const UT_TaskScope *task,
702  bool for_memory_event) const;
703 
704  /// Remove the specified event from the running events list
705  /// associated with the given task.
706  /// It is up to the caller to acquire the appropriate thread events lock.
707  void removeFromRunningEventList_(
708  const UT_TaskScope *task,
709  UT_PerfMonEvent *event);
710 
711  /// Add the specified event to the running events list
712  /// associated with the given task.
713  void addToRunningEventList_(
714  const UT_TaskScope *task,
715  UT_PerfMonEvent *event);
716 
717  /// Reset the thread tasks to running event lists data structure.
718  void resetRunningEventLists_();
719 
720  /// Contribute the event's data to any interested profiles.
721  void contributeEventToProfiles_(UT_PerfMonEvent *event);
722 
723  /// Return the index of the profile interest that matches the given
724  /// callee and callback. Return -1 if no such interest exists.
725  int findProfileInterest_(void *callee,
726  UT_PerfMonProfileEventMethod callback) const;
727 
728  /// Notify interests that the given profile event has taken place.
729  void notifyProfileInterests_(
730  UT_PerfMonProfileEventType event_type,
731  int profile_id) const;
732 
733  /// Return the index of the event interest that matches the given
734  /// callee and callback. Return -1 if no such interest exists.
735  int findEventInterest_(void *callee,
736  UT_PerfMonEventCB callback) const;
737 
738  /// Notify interests that the given event has been stopped.
739  void notifyEventInterests_(
740  const UT_PerfMonEvent *event) const;
741 
742  using RWLock = tbb::spin_rw_mutex;
743 
744  /// Return the lock to use for the given task's running events list.
745  RWLock &getRunningEventsLock_(
746  const UT_TaskScope *task,
747  bool for_memory_event);
748 
749  /// Return true if the given options are interested in recording
750  /// the passed-in event.
751  bool areOptionsInterestedInEvent_(
752  const UT_PerfMonRecordOptions &options,
753  const UT_PerfMonEvent *event) const;
754 
755  /// Helper method for stopEvent().
756  /// Update cumulative frame statistics with the given frame value.
757  void addToCumulativeFrameStats_(
758  fpreal frame_value, bool is_memory_value);
759 
760  /// Start and initialize a thread to listen for incoming events
761  /// from remote processes. Do nothing if the listen thread has already
762  /// been started.
763  void initAndStartEventListenThread_();
764 
765  /// Stop the thread that is listening for incoming events from remote
766  /// processes. Do nothing if there is no listen thread.
767  void stopEventListenThread_();
768 
769  /// Block until the event listen thread has signaled that it is initialized.
770  /// Return immediately If there is no event listen thread.
771  void ensureEventListenThreadIsInitialized_();
772 
773  /// Initialize the default color ramp scheme.
774  void initDefaultColorRampScheme_();
775 
776  /// Keep track of the active profile.
777  int myActiveProfileId;
778 
779  /// Option that determines whether performance information is displayed
780  /// with Node info.
781  bool myDisplayNodeInfo;
782 
783  UT_Ramp myColorRamp;
784  UT_Ramp myDefaultColorRamp;
785 
786  // Members dealing with events.
787  SYS_AtomicInt32 myEventIdCounter;
789 
790  // Members dealing with profiles.
791  SYS_AtomicInt32 myProfileIdCounter;
793  UT_PerfMonProfileList myRecordingProfiles;
794  UT_PerfMonProfileList myCompletedProfiles;
795 
796  // These locks protect the performance monitor's events and profiles.
797  // If you plan to use both locks in a method, be sure to
798  // lock the profiles lock first, then the events lock.
799  mutable RWLock myEventsLock;
800  mutable RWLock myProfilesLock;
801  mutable RWLock myProfileInterestsLock;
802  mutable RWLock myEventInterestsLock;
803 
804  /// A map of task scopes to running timed event lists for each thread.
805  typedef UT_Map<const UT_TaskScope *, UT_PerfMonEventList *> TaskToEventListMap;
806  UT_ThreadSpecificValue<TaskToEventListMap *> myTasksToRunningTimedEvents;
807  UT_ThreadSpecificValue<RWLock> myTasksToRunningTimedEventsLock;
808 
809  /// A map of task scopes to running memory event lists for each thread.
810  UT_ThreadSpecificValue<TaskToEventListMap *> myTasksToRunningMemoryEvents;
811  UT_ThreadSpecificValue<RWLock> myTasksToRunningMemoryEventsLock;
812 
813  /// A list of interests on profile events.
814  UT_ValArray<ut_PerfMonProfileInterest *> myProfileInterests;
815 
816  /// A list of interests on events.
818 
819  /// Socket for listening on incoming events from other processes
820  /// (i.e. Mantra).
821  UT_NetSocket *myEventSocket;
822  UT_Thread *myEventListenThread;
823  bool myListenThreadIsInitialized;
824  UT_Lock myListenThreadIsInitializedLock;
825  UT_Condition myListenThreadIsInitializedCond;
826 
827  // Recording counters.
828  SYS_AtomicInt32 myIsRecordingCount;
829  SYS_AtomicInt32 myRecordCookStatsCount;
830  SYS_AtomicInt32 myRecordSolveStatsCount;
831  SYS_AtomicInt32 myRecordObjectDrawStatsCount;
832  SYS_AtomicInt32 myRecordObjectGPUDrawStatsCount;
833  SYS_AtomicInt32 myRecordViewportStatsCount;
834  SYS_AtomicInt32 myRecordScriptStatsCount;
835  SYS_AtomicInt32 myRecordRenderStatsCount;
836  SYS_AtomicInt32 myRecordThreadStatsCount;
837  SYS_AtomicInt32 myRecordFrameStatsCount;
838  SYS_AtomicInt32 myRecordMemoryStatsCount;
839  SYS_AtomicInt32 myRecordErrorsCount;
840 
841  // Frame stat counters.
842  fpreal myTotalFrameTime;
843  fpreal myTotalFrameMemory;
844  int myTimedFrameEventCounter;
845  int myMemoryFrameEventCounter;
846 
847  static void * listenForRemoteEvents_(void *data);
848 };
849 
850 UT_API UT_Performance *UTgetPerformance(bool create=true);
851 UT_API void UTsetPerformance(UT_Performance *perfmon);
852 
853 #endif
854 
png_infop png_charpp int png_charpp profile
Definition: png.h:2467
UT_PerfMonEventType
Event types.
int getNumRecordedMemoryFrameEvents() const
UT_API UT_Performance * UTgetPerformance(bool create=true)
GT_API const UT_StringHolder time
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
#define UT_API
Definition: UT_API.h:13
bool isRecordingRenderStats() const
Return true if Houdini is recording render stats.
bool isRecordingSolveStats() const
Return true if Houdini is recording simulation solve stats.
bool isRecordingErrors() const
Return true if Houdini is recording errors.
bool isRecordingMemoryStats() const
Return true if Houdini is recording memory stats.
struct _cl_event * event
Definition: glcorearb.h:2960
bool isRecordingCookStats() const
Return true if Houdini is recording cook stats.
void(* UT_PerfMonProfileEventMethod)(void *callee, UT_PerfMonProfileEventType type, int profile_id)
bool isRecordingScriptStats() const
Return true if Houdini is recording script stats.
bool isRecordingViewportStats() const
Return true if Houdini is recording viewport draw stats.
bool getDisplayNodeInfo() const
UT_PerfMonObjectType
Object types.
fpreal getTotalRecordedFrameEventTime() const
UT_PerfMonCategory
Categories.
UT_PerfMonProfileEventType
UT_PerfMonViewportType
Viewport types recognized by the performance monitor.
GLboolean * data
Definition: glcorearb.h:130
A collection of statistics for a particular object (i.e. node, viewport).
int getNumRecordedTimedFrameEvents() const
GLuint GLsizei const GLchar * message
Definition: glcorearb.h:2542
bool isRecording() const
GLsizei const GLfloat * value
Definition: glcorearb.h:823
double fpreal
Definition: SYS_Types.h:270
bool isRecordingObjectDrawStats() const
Return true if Houdini is recording object draw stats.
Utility class for containing a color ramp.
Definition: UT_Ramp.h:84
GLuint index
Definition: glcorearb.h:785
int getActiveProfileId() const
void(* UT_PerfMonEventCB)(void *callee, const UT_PerfMonEvent *event)
GT_API const UT_StringHolder profile_id
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
bool isRecordingObjectGPUDrawStats() const
Return true if Houdini is recording object draw stats.
bool isRecordingFrameStats() const
Return true if Houdini is recording frame stats.
UT_PerfMonScriptType
Script types recognized by the performance monitor.
fpreal getTotalRecordedFrameEventMemory() const
UT_API void UTsetPerformance(UT_Performance *perfmon)
bool isRecordingThreadStats() const
Return true if Houdini is recording thread stats.