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