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