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