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  /// If `include_recording_profiles` is true, then recording profiles are
366  /// removed as well.
367  void removeAllProfiles(
368  bool include_recording_profiles=true);
369 
370  /// Rename the specified profile.
371  void renameProfile(
372  int profile_id,
373  const char *profile_name);
374 
375  /// Change the recording options for the specified profile.
376  void changeProfileRecordOptions(
377  int profile_id,
378  const UT_PerfMonRecordOptions &options);
379 
380  /// Clear the stats for the given profile.
381  void clearProfileStats(int profile_id);
382 
383  /// Return the specified profile. (read-only)
384  /// Return NULL if the requested profile does not exist.
385  const UT_PerfMonProfile *getProfile(int profile_id) const;
386 
387  /// Return the id of the active profile.
388  /// Return UT_PERFMON_INVALID_ID if there is no active profile.
389  int getActiveProfileId() const
390  { return myActiveProfileId; }
391 
392  /// Set the active profile to the given id
393  void setActiveProfileId(int profile_id);
394 
395  /// Return the number of completed profiles that the performance monitor
396  /// is storing. A completed profile is a profile that is no longer
397  /// recording events and has generated stats.
398  int numCompletedProfiles() const;
399 
400  /// Return the completed profile at the specified index.
401  /// A completed profile is a profile that is no longer recording events
402  /// and has generated stats.
403  const UT_PerfMonProfile *getCompletedProfile(int index) const;
404 
405  /// Return ID of a loaded profile corresponding to the provided file path.
406  /// Return UT_PERFMON_INVALID_ID if no such mapping exists.
407  int getProfileByFilePath(
408  const char *file_path) const;
409 
410  /// Add an interest for profile events.
411  /// Do nothing if the interest has been previously added.
412  void addProfileInterest(
413  void *callee,
415 
416  /// Remove an interest for profile events.
417  /// Do nothing if the specified interest does not exist.
418  void removeProfileInterest(
419  void *callee,
421 
422  /// Return true if the performance monitor already
423  /// has the given profile interest. Return false otherwise.
424  bool hasProfileInterest(
425  void *callee,
427 
428  /// Add an interest for running events.
429  /// You can pass in a set of record options to define the types of events
430  /// that you are interested in.
431  void addEventInterest(
432  void *callee,
433  UT_PerfMonEventCB callback,
434  const UT_PerfMonRecordOptions &options);
435 
436  /// Update the recording options for the specified event interest.
437  void changeEventInterestRecordOptions(
438  void *callee,
439  UT_PerfMonEventCB callback,
440  const UT_PerfMonRecordOptions &options);
441 
442  /// Remove an interest for events.
443  void removeEventInterest(
444  void *callee,
445  UT_PerfMonEventCB callback);
446 
447  /// Return true if the performance monitor already
448  /// has the given profile interest. Return false otherwise.
449  bool hasEventInterest(
450  void *callee,
451  UT_PerfMonEventCB callback);
452 
453  /// Create a new profile that stores difference in stats between profiles
454  /// Return the unique id for the new profile.
455  int createDiffProfile(int id1, int id2);
456 
457  /// ********************************************************
458  /// RECORDING METHODS
459  /// ********************************************************
460 
461  /// Return true if the performance monitor is recording Houdini events.
462  /// When `profile_only` is enabled, only returns true if the performance
463  /// monitor is explicitly recording a profile (settings such as
464  /// getDisplayNodeInfo() still record cook events for the node info window).
465  bool isRecording(bool profile_only = false) const {
466  return myIsRecordingCount.load() > 0 ||
467  (!profile_only && getDisplayNodeInfo());
468  }
469 
470  /// Return true if Houdini is recording cook stats.
471  bool isRecordingCookStats(bool profile_only = false) const {
472  return myRecordCookStatsCount.load() > 0 ||
473  (!profile_only && getDisplayNodeInfo());
474  }
475 
476  /// Return true if Houdini is recording pdg cook stats.
477  bool isRecordingPDGCookStats() const {
478  return myRecordPDGCookStatsCount.load() > 0;
479  }
480 
481  /// Return true if Houdini is recording simulation solve stats.
482  bool isRecordingSolveStats() const {
483  return myRecordSolveStatsCount.load() > 0;
484  }
485 
486  /// Return true if Houdini is recording object draw stats.
488  return
489  myRecordObjectDrawStatsCount.load() > 0;
490  }
491 
492  /// Return true if Houdini is recording object draw stats.
494  return
495  myRecordObjectGPUDrawStatsCount.load() > 0;
496  }
497 
498  /// Return true if Houdini is recording viewport draw stats.
500  return myRecordViewportStatsCount.load() > 0;
501  }
502 
503  /// Return true if Houdini is recording pane related stats.
504  bool isRecordingPaneStats() const {
505  return myRecordPaneStatsCount.load() > 0;
506  }
507 
508  /// Return true if Houdini is recording script stats.
509  bool isRecordingScriptStats() const {
510  return myRecordScriptStatsCount.load() > 0;
511  }
512 
513  /// Return true if Houdini is recording render stats.
514  bool isRecordingRenderStats() const {
515  return myRecordRenderStatsCount.load() > 0;
516  }
517 
518  /// Return true if Houdini is recording thread stats.
519  bool isRecordingThreadStats() const {
520  return myRecordThreadStatsCount.load() > 0;
521  }
522 
523  /// Return true if Houdini is recording frame stats.
524  bool isRecordingFrameStats() const {
525  return myRecordFrameStatsCount.load() > 0;
526  }
527 
528  /// Return true if Houdini is recording memory stats.
529  bool isRecordingMemoryStats() const {
530  return myRecordMemoryStatsCount.load() > 0;
531  }
532 
533  /// Return true if Houdini is recording errors.
534  bool isRecordingErrors() const {
535  return myRecordErrorsCount.load() > 0;
536  }
537 
538  /// Returns true if the particular node passed is allowed to
539  /// participate in recording of the statistics, false otherwise.
540  /// This is currently used for disallowing recording of the contents
541  /// of compiled nodes.
542  virtual bool isRecordingAllowedFor(OP_Node* node) const;
543 
544  /// ********************************************************
545  /// FRAME STATISTIC METHODS
546  /// ********************************************************
547 
548  /// Return the number of timed frame events
549  /// recorded by the performance monitor.
551  { return myTimedFrameEventCounter; }
552 
553  /// Return the number of memory frame events
554  /// recorded by the performance monitor.
556  { return myMemoryFrameEventCounter; }
557 
558  /// Return the total time spent in the frame events
559  /// recorded by the performance monitor.
561  { return myTotalFrameTime; }
562 
563  /// Return the total memory accumulation in the frame events
564  /// recorded by the performance monitor.
566  { return myTotalFrameMemory; }
567 
568  /// Reset the performance monitor's accumulated frame statistics.
569  void resetCumulativeFrameStats();
570 
571  /// ********************************************************
572  /// MISCELLANEOUS
573  /// ********************************************************
574 
575  /// Return the icon name to use for the given stats object.
576  /// Return empty string if there is no known icon to use for the object.
577  /// Subclasses can override this method to set up their own mappings
578  /// of stats objects to icons.
579  virtual UT_StringHolder getStatsIcon(const UT_PerfMonStats *stats) const;
580 
581  /// ********************************************************
582  /// DISPLAY OPTIONS
583  /// ********************************************************
584 
585  /// Toggle whether or not the performance info is displayed in
586  /// the Node info.
587  void setDisplayNodeInfo(bool display);
588  bool getDisplayNodeInfo() const
589  { return myDisplayNodeInfo; }
590 
591  /// Thresholds for displaying various colours in the network editor and
592  /// in the Spreadsheet.
593  void getPerformanceColor(fpreal pos, UT_Color &c);
594 
595  /// Return the ramp color scheme used by the performance monitor.
596  const UT_Ramp &getRampColorScheme() const;
597 
598  /// Set the performance monitor's ramp color scheme.
599  void setRampColorScheme(const UT_Ramp &src_ramp);
600 
601  /// Load the ramp color scheme from the given string representation.
602  void loadRampColorScheme(const char *str_color_scheme);
603 
604  /// Save a representation of the ramp color scheme to the given string.
605  void saveRampColorScheme(UT_String &str_color_scheme);
606 
607  /// Return the default ramp color scheme.
608  const UT_Ramp &getDefaultColorRampScheme();
609 
610  /// ********************************************************
611  /// MAINTENANCE
612  /// ********************************************************
613 
614  /// Reset the state of the performance monitor.
615  /// Reset counters and delete events and profiles.
616  /// This method should never be called. It is handy for testing purposes.
617  void reset();
618 
619 protected:
620  /// Return the current frame.
621  virtual int getCurrentFrameSubclass_();
622 
623  /// Return a pointer to the node specified by the given id.
624  virtual OP_Node *getNodeSubclass_(int node_id) const;
625 
626  /// Return a pointer to the node that is bound to the given SIM solver.
627  virtual OP_Node *getNodeFromSolverSubclass_(
628  const SIM_Solver *solver) const;
629 
630  /// Pass back an object path that can be tied to a UT_PerfMonStats object.
631  /// The path is generated from the given node and event name.
632  virtual void getObjectPathFromNodeSubclass_(
633  OP_Node *node, const char *event_name,
634  UT_WorkBuffer &object_path) const;
635 
636  /// Pass back an object path that can be tied to a UT_PerfMonStats object.
637  /// The path is generated from the given solver, node and event name.
638  virtual void getObjectPathFromSolverAndNodeSubclass_(
639  const SIM_Solver *solver, OP_Node *node,
640  const char *event_name, UT_WorkBuffer &object_path)
641  const;
642 
643  /// Pass back extra info that can be tied to a UT_PerfMonStats object.
644  /// The extra info is generated from the given node.
645  virtual void getExtraInfoFromNodeSubclass_(
646  OP_Node *node, UT_WorkBuffer &extra_info) const;
647 
648  /// Start the remote listener to handle incoming information.
649  virtual void startRemoteListener_() {};
650 
651 private:
652 
653  int newEventId_();
654  int newProfileId_();
655 
656 
657  /// Return the specified timed event.
658  /// Return NULL if the requested event does not exist
659  /// or is not a timed event.
660  UT_PerfMonTimedEvent *getTimedEvent_(int event_id) const;
661 
662  /// Return the specified event.
663  /// Return NULL if the requested event does not exist.
664  UT_PerfMonEvent *getEvent_(int event_id) const;
665 
666  /// Start a event.
667  /// Subclasses must call this method when starting their own events.
668  int startEvent_(
669  const UT_StringHolder &event,
670  const UT_StringHolder &object,
671  bool auto_nest_events,
672  UT_PerfMonCategory category,
674  UT_PerfMonObjectType object_type,
675  const UT_StringHolder &object_icon,
676  int *frame_num=NULL,
678 
679  /// Start a cook event.
680  int startCookEvent_(
682  int node_id, const char *cook_event_name);
683 
684  /// Start a work item event.
685  int startPDGEvent_(
687  const char *path,
688  const char *pdg_event_name);
689 
690  /// Start a solve event.
691  int startSolveEvent_(
693  const SIM_Solver *solver,
694  const char *solver_event_name);
695 
696  /// Start a draw event.
697  int startDrawEvent_(
699  const char *object,
700  const char *draw_event_name,
701  bool is_gpu_draw);
702 
703  /// Start a viewport draw event.
704  int startViewportDrawEvent_(
706  const char *viewport_name,
707  const char *draw_event_name,
708  UT_PerfMonViewportType viewport_type,
709  bool is_gpu_draw);
710 
711  /// Start a generic draw event.
712  int startGenericDrawEvent_(
714  const char *object,
715  const char *draw_event_name,
716  UT_PerfMonObjectType object_type,
717  const char *object_icon,
718  bool is_gpu_draw);
719 
720  /// Start a script event.
721  int startScriptEvent_(
723  const char *code_description,
724  UT_PerfMonScriptType script_type,
725  bool auto_nest_events,
726  OP_Node *node);
727 
728  /// Start a render event.
729  int startRenderEvent_(
731  const char *renderer,
732  const char *operation,
733  bool is_renderer_a_node,
734  int frame_num,
735  const char *object);
736 
737  /// Start a pane event.
738  int startPaneEvent_(
740  const char *pane_type,
741  const char *operation);
742 
743  /// Return the specified profile.
744  /// Return NULL if the requested profile does not exist.
745  UT_PerfMonProfile *getProfile_(int profile_id) const;
746 
747  /// Activate profile.
748  void activateProfile_(UT_PerfMonProfile *profile);
749 
750  /// De-activate profile.
751  void deactivateProfile_(UT_PerfMonProfile *profile);
752 
753  /// Increment recording counters based on the specified options.
754  void incrementRecordingCounters_(
755  const UT_PerfMonRecordOptions &options);
756 
757  /// Decrement recording counters based on the specified options.
758  void decrementRecordingCounters_(
759  const UT_PerfMonRecordOptions &options);
760 
761  /// Remove and delete the specified profile. Returns the profile id
762  int removeProfile_(UT_PerfMonProfile *profile);
763 
764  /// Notify that given profile id has been destroyed
765  void notifyRemovedProfile_(int profile_id);
766 
767  /// Return ID of a loaded profile corresponding to the provided file path.
768  /// Return UT_PERFMON_INVALID_ID if no such mapping exists.
769  /// It is up to the caller to acquire the appropriate profile mutex lock.
770  int getProfileByFilePath_(const char *file_path) const;
771 
772  /// Add a mapping from file path to a loaded profile's ID.
773  /// It is up to the caller to acquire the appropriate profile mutex lock.
774  void addFilePathToLoadedProfileMapping_(
775  const char *file_path,
776  int profile_id);
777 
778  /// Remove a mapping from file path to a loaded profile's ID if it exists,
779  /// otherwise do nothing.
780  /// It is up to the caller to acquire the appropriate profile mutex lock.
781  void removeFilePathToLoadedProfileMapping_(int profile_id);
782 
783  /// Remove all filePath-to-profile mappings.
784  /// It is up to the caller to acquire the appropriate profile mutex lock.
785  void clearFilePathToLoadedProfileMappings_();
786 
787  /// Return canonicalized file path by expanding variables, making absolute,
788  /// and normalizing.
789  UT_String convertFilePathToCanonicalForm_(
790  UT_String file_path) const;
791 
792  /// Remove the event. Delete it if it is a top-level event.
793  void removeEvent_(
794  int event_id,
795  UT_PerfMonEvent *event,
796  bool is_cancelled=false);
797 
798  // Find the running parent event (if any) of the given event
799  // and create a link between them.
800  void findAndLinkToRunningParentEvent_(
801  UT_PerfMonEvent *event);
802 
803  UT_PerfMonEvent *findRunningParentEvent_(
804  const UT_TaskScope *task,
805  bool for_memory_event,
806  bool require_auto_nest);
807 
808  void addChildToRunningParentEvent_(
809  UT_PerfMonEvent *event,
810  const UT_TaskScope *task,
811  bool for_memory_event,
812  bool require_auto_nest);
813 
814  /// Return the list of running events for the given task.
815  /// The most recently started event will appear at the end of the list.
816  /// This method will create a new list if no such list already exists.
817  UT_PerfMonEventList *getOrCreateRunningEventList_(
818  const UT_TaskScope *task,
819  bool for_memory_event);
820 
821  /// Return the list of running events for the given task.
822  /// Return NULL if no such list exists.
823  /// It is up to the caller to acquire the appropriate thread events lock.
824  UT_PerfMonEventList *getRunningEventList_(
825  const UT_TaskScope *task,
826  bool for_memory_event) const;
827 
828  /// Remove the specified event from the running events list
829  /// associated with the given task.
830  /// It is up to the caller to acquire the appropriate thread events lock.
831  void removeFromRunningEventList_(
832  const UT_TaskScope *task,
833  UT_PerfMonEvent *event);
834 
835  /// Add the specified event to the running events list
836  /// associated with the given task.
837  void addToRunningEventList_(
838  const UT_TaskScope *task,
839  UT_PerfMonEvent *event);
840 
841  /// Reset the thread tasks to running event lists data structure.
842  void resetRunningEventLists_();
843 
844  /// Contribute the event's data to any interested profiles.
845  void contributeEventToProfiles_(UT_PerfMonEvent *event);
846 
847  /// Return the index of the profile interest that matches the given
848  /// callee and callback. Return -1 if no such interest exists.
849  int findProfileInterest_(void *callee,
850  UT_PerfMonProfileEventMethod callback) const;
851 
852  /// Notify interests that the given profile event has taken place.
853  void notifyProfileInterests_(
854  UT_PerfMonProfileEventType event_type,
855  int profile_id) const;
856 
857  /// Return the index of the event interest that matches the given
858  /// callee and callback. Return -1 if no such interest exists.
859  int findEventInterest_(void *callee,
860  UT_PerfMonEventCB callback) const;
861 
862  /// Notify interests that the given event has been stopped.
863  void notifyEventInterests_(
864  const UT_PerfMonEvent *event) const;
865 
866  using RWLock = tbb::spin_rw_mutex;
867 
868  /// Return the lock to use for the given task's running events list.
869  RWLock &getRunningEventsLock_(
870  const UT_TaskScope *task,
871  bool for_memory_event);
872 
873  /// Return true if the given options are interested in recording
874  /// the passed-in event.
875  bool areOptionsInterestedInEvent_(
876  const UT_PerfMonRecordOptions &options,
877  const UT_PerfMonEvent *event) const;
878 
879  /// Implementation of stopEvent() without locking
880  fpreal stopEvent_(int event_id, bool return_value);
881 
882  /// Helper method for stopEvent().
883  /// Update cumulative frame statistics with the given frame value.
884  void addToCumulativeFrameStats_(
885  fpreal frame_value, bool is_memory_value);
886 
887  /// Initialize the default color ramp scheme.
888  void initDefaultColorRampScheme_();
889 
890  /// Keep track of the active profile.
891  int myActiveProfileId;
892 
893  /// Option that determines whether performance information is displayed
894  /// with Node info.
895  bool myDisplayNodeInfo;
896 
897  UT_Ramp myColorRamp;
898  UT_Ramp myDefaultColorRamp;
899 
900  // Members dealing with events.
901  SYS_AtomicInt32 myEventIdCounter;
903 
904  // Members dealing with profiles.
905  SYS_AtomicInt32 myProfileIdCounter;
907  UT_PerfMonProfileList myRecordingProfiles;
908  UT_PerfMonProfileList myCompletedProfiles;
909  UT_StringMap<int> myFilePathsToLoadedProfiles;
910 
911  // These locks protect the performance monitor's events and profiles.
912  // If you plan to use both locks in a method, be sure to
913  // lock the profiles lock first, then the events lock.
914  mutable RWLock myEventsLock;
915  mutable RWLock myProfilesLock;
916  mutable RWLock myProfileInterestsLock;
917  mutable RWLock myEventInterestsLock;
918 
919  /// A map of task scopes to running timed event lists for each thread.
920  typedef UT_Map<const UT_TaskScope *, UT_PerfMonEventList *> TaskToEventListMap;
921  UT_ThreadSpecificValue<TaskToEventListMap *> myTasksToRunningTimedEvents;
922  UT_ThreadSpecificValue<RWLock> myTasksToRunningTimedEventsLock;
923 
924  /// A map of task scopes to running memory event lists for each thread.
925  UT_ThreadSpecificValue<TaskToEventListMap *> myTasksToRunningMemoryEvents;
926  UT_ThreadSpecificValue<RWLock> myTasksToRunningMemoryEventsLock;
927 
928  /// A list of interests on profile events.
929  UT_ValArray<ut_PerfMonProfileInterest *> myProfileInterests;
930 
931  /// A list of interests on events.
933 
934  // Recording counters.
935  SYS_AtomicInt32 myIsRecordingCount;
936  SYS_AtomicInt32 myRecordCookStatsCount;
937  SYS_AtomicInt32 myRecordPDGCookStatsCount;
938  SYS_AtomicInt32 myRecordSolveStatsCount;
939  SYS_AtomicInt32 myRecordObjectDrawStatsCount;
940  SYS_AtomicInt32 myRecordObjectGPUDrawStatsCount;
941  SYS_AtomicInt32 myRecordViewportStatsCount;
942  SYS_AtomicInt32 myRecordPaneStatsCount;
943  SYS_AtomicInt32 myRecordScriptStatsCount;
944  SYS_AtomicInt32 myRecordRenderStatsCount;
945  SYS_AtomicInt32 myRecordThreadStatsCount;
946  SYS_AtomicInt32 myRecordFrameStatsCount;
947  SYS_AtomicInt32 myRecordMemoryStatsCount;
948  SYS_AtomicInt32 myRecordErrorsCount;
949 
950  // Frame stat counters.
951  fpreal myTotalFrameTime;
952  fpreal myTotalFrameMemory;
953  int myTimedFrameEventCounter;
954  int myMemoryFrameEventCounter;
955 };
956 
957 UT_API UT_Performance *UTgetPerformance(bool create=true);
958 UT_API void UTsetPerformance(UT_Performance *perfmon);
959 
960 #endif
961 
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: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.
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:278
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.