HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UT_PerfMonProfile.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_PerfMonProfile.h (UT Library, C++)
7  *
8  * COMMENTS:
9  *
10  * Performance monitor profile.
11  */
12 
13 #ifndef __UT_PerfMonProfile__
14 #define __UT_PerfMonProfile__
15 
16 #include "UT_API.h"
17 
18 #include "UT_PerfMonEvent.h"
20 #include "UT_PerfMonTypes.h"
21 #include "UT_RWLock.h"
22 #include "UT_String.h"
23 #include "UT_StringArray.h"
24 #include "UT_StringMap.h"
25 #include "UT_PerfMonStats.h"
26 
27 class UT_PerfMonStats;
28 class UT_PerfMonEvent;
30 
32 {
33 public:
34  /// `id` is the unique id generated by the performance monitor for
35  /// this profile. `title` is a user-readable profile title.
36  UT_PerfMonProfile(int id, const char *title,
37  const UT_PerfMonRecordOptions *options=NULL);
38 
40 
41  /// ********************************************************
42  /// GENERAL.
43  /// ********************************************************
44 
45  /// Return the profile id that was assigned by the performance monitor.
46  int id() const;
47 
48  /// Return the user-readable profile title.
49  const char *title() const;
50 
51  void uiFriendlyTitle(UT_String &title) const;
52 
53  /// Set the profile title.
54  void setTitle(const char *title);
55 
56  /// ********************************************************
57  /// EVENT RECORDING.
58  /// ********************************************************
59 
60  /// Start recording events.
61  void startRecording();
62 
63  /// Stop event recording.
64  void stopRecording();
65 
66  /// Add the given event to the log.
67  /// The performance monitor is responsible for the deletion of the event.
68  void addEvent(UT_PerfMonEvent *event);
69 
70  /// Collect data from the event. The data contributes to the profile's
71  /// statistics.
72  void collectDataFromEvent(UT_PerfMonEvent *event);
73 
74  /// Return true if the profile is active.
75  /// An active profile is one that is still interested in events
76  /// but may not be recording at the moment (i.e. if it is paused).
77  bool isActive() const;
78 
79  /// Turn on/off event recording.
80  void enableRecording(bool enable);
81 
82  /// Return true if the profile is recording.
83  bool isRecording() const;
84 
85  /// Return the recording options.
86  const UT_PerfMonRecordOptions &recordOptions() const;
87 
88  /// Set the recording options.
89  void setRecordOptions(
90  const UT_PerfMonRecordOptions &options);
91 
92  /// Return the minimum frame recorded
93  int getMinFrame() const;
94 
95  /// Return the maximum frame recorded
96  int getMaxFrame() const;
97 
98  /// Return whether the current profile is a diff profile, for the purposes
99  /// of rendering differently in OPUI
100  bool getIsDiff() const;
101 
102  /// Return a list of stat definitions registered with the profile.
103  /// Return NULL if the profile has no stat definitions.
104  const UT_PerfMonStatDefinitions &statDefinitions() const;
105 
106  /// Return a list of stat names that belong to the given stat category.
107  /// Return NULL if `category` is not a valid enum value.
108  const UT_StringArray *statsByCategory(
109  UT_PerfMonCategory category) const;
110 
111  /// Return the stat definition with the given name.
112  /// Return NULL if no such definition has been registered with the profile.
113  const UT_PerfMonStatDefinition *getStatDefinition(
114  const char *stat_name) const;
115 
116  /// Return the set of stats collected by the profile.
117  /// Return NULL if the profile has not started or if the profile
118  /// is still recording.
119  const UT_PerfMonStats *stats() const;
120 
121  /// Calculate percent changes on a per stat basis.
122  fpreal statsPercentValue(const UT_PerfMonStats* stats,
123  const char *stat_name) const;
124 
125  fpreal statsPercentValue(const UT_PerfMonStats* stats,
126  const char *stat_name,
127  int first_frame,
128  int last_frame,
129  int thread_id = UT_PERFMON_STAT_WALL_TIME) const;
130 
131  fpreal diffStatsPercentValue(const UT_PerfMonStats* stats,
132  const char *stat_name) const;
133 
134  fpreal diffStatsPercentValue(const UT_PerfMonStats* stats,
135  const char *stat_name,
136  int first_frame,
137  int last_frame,
138  int thread_id = UT_PERFMON_STAT_WALL_TIME) const;
139 
140  fpreal getMaxStatValue(const char * stat_name) const;
141 
142  /// Override the generated stats (if any) in the profile
143  /// with the specified stats. The profile takes ownership of
144  /// the stat objects and the stat definitions.
145  /// `min_frame` and `max_frame` describe the frame range that the stats
146  /// reside in.
147  void setStats(
148  UT_PerfMonStats *stats,
149  const UT_PerfMonStatDefinitions &stat_defs,
150  int min_frame, int max_frame);
151 
152  void createDiffStats(const UT_PerfMonProfile *profile1,
153  const UT_PerfMonProfile *profile2);
154 
155  const UT_PerfMonStats *getStatsByPath(const char *path) const;
156 
157  const char *getDiffProfileTitle(int index) const;
158 
159  /// Save the collected stats to disk.
160  /// Return true if the save succeeded. Return false otherwise.
161  bool save(const char *file_path) const;
162 
163  /// Export the collected stats in CSV format.
164  /// Return true if the export succeeded. Return false otherwise.
165  bool exportStatsAsCSV(const char *file_path) const;
166 
167  /// Clear recorded stats in the profile.
168  void clearStats();
169 
170 private:
171  /// Clear out contents of the profile and delete any objects
172  /// that it owns.
173  void clear_();
174 
175  /// Create a new, empty root stats object.
176  /// The caller of this method takes ownership of the new object.
177  UT_PerfMonStats *newRootStats_() const;
178 
179  /// Helper method for updateStatsFromEvents().
180  /// Update stats from the given frame event.
181  void updateStatsFromTimedFrameEvent_(
182  UT_PerfMonTimedEvent *event);
183 
184  /// Helper method for updateStatsFromEvents().
185  /// Update stats from the given event and its child events.
186  void updateStatsFromTimedEvent_(
187  UT_PerfMonTimedEvent *event);
188 
189  /// Helper method for updateStatsFromEvents().
190  /// Update stats from the given memory event.
191  void updateStatsFromMemoryEvent_(
192  UT_PerfMonEvent *event);
193 
194  /// Return the specified stat object.
195  /// Return NULL if no such object exists.
196  UT_PerfMonStats *getStats_(const char *name,
197  UT_PerfMonObjectType object_type) const;
198 
199  /// Return the specified stat object.
200  /// Create a new object if it does not exist.
201  UT_PerfMonStats *getOrCreateStats_(const char *name,
202  UT_PerfMonObjectType object_type,
203  const char *object_icon);
204 
205  /// Return the specified category stat for the given object type.
206  /// Create a new stat object if it does not exist.
207  UT_PerfMonStats *getOrCreateCategoryStats_(
209 
210  /// Helper method for createDiffStats().
211  /// Create diff stats for the category stats that appear
212  /// in the given 2 source profiles.
213  void createDiffStatsForCategories_(
214  const UT_PerfMonProfile *profile1,
215  const UT_PerfMonProfile *profile2,
216  const char *profile_title1,
217  const char *profile_title2);
218 
219  /// Helper method for createDiffStats().
220  /// Create the diff stats for the given 2 source category stats.
221  /// Register the diff stats with the profile.
222  void createCategoryDiffStats_(
223  const UT_PerfMonStats *src_category_stats1,
224  const UT_PerfMonStats *src_category_stats2,
225  const char *profile_title1,
226  const char *profile_title2);
227 
228  /// Helper method for createDiffStats().
229  /// Return a list of stat objects that need diff stats generated for them.
230  /// Only the stat object's path and type are used from the list.
231  /// Parent stat objects always appear before their children in the list.
232  void getStatsThatNeedDiffing_(
233  const UT_PerfMonProfile *profile1,
234  const UT_PerfMonProfile *profile2,
235  UT_ConstPerfMonStatsList &stats_need_diffing)
236  const;
237 
238  /// Helper method for createDiffStats().
239  /// Create a diff stats for the 2 given sources and register
240  /// the diff stats with the profile.
241  void createDiffStats_(
242  const UT_PerfMonStats *src_stats1,
243  const UT_PerfMonStats *src_stats2,
244  const char *profile_title1,
245  const char *profile_title2);
246 
247  /// Register the stat definitions from the 2 given source profiles.
248  /// The definitions are registered as diff stat definitions.
249  void registerDiffStatDefs_(
250  const UT_PerfMonProfile *src_profile1,
251  const UT_PerfMonProfile *src_profile2);
252 
253  /// Helper method for updateStatsFromEvents().
254  /// Update the collection of statistics with the given event.
255  void updateStatsFromTimedEvent_(
256  UT_PerfMonStats *stats,
257  const char *event_name,
258  UT_PerfMonCategory category,
259  fpreal event_time,
260  int thread_id,
261  int frame);
262 
263  /// Keep a record of largest seconds values for each stat-type across
264  /// all frames. Used for diff stats and diff stat bar rendering.
265  void updateMaxStats_(fpreal val, const char * stat_name);
266 
267  /// Helper function for diffStatsPercentValue
268  void getDiffIndices_(int &index1, int &index2,
269  const UT_PerfMonStats *stats,
270  const char *stat_name) const;
271 
272  /// Register the given stat definition.
273  /// If the name of the stat definition is already registered,
274  /// then don't do anything.
275  /// Returns the registered stat definition.
277  registerStat_(const char *name, UT_PerfMonCategory category,
278  UT_PerfMonStatType type, bool is_diff = false);
279 
280  /// Update the minimum and maximum frames registered in this profile
281  /// after examining the given frame number.
282  void updateMinAndMaxFrames_(int frame);
283 
284  /// Set the minimum frame to the given number.
285  void setMinFrame_(int frame);
286 
287  /// Set the maximum frame to the given number.
288  void setMaxFrame_(int frame);
289 
290  int myId;
291  int myMinFrame;
292  int myMaxFrame;
293  UT_String myTitle;
294  bool myIsActive;
295  bool myIsRecording;
296  bool myIsDiff;
297  UT_PerfMonRecordOptions myRecordOptions;
298  mutable UT_PerfMonStats *myStats;
301  // maps UT_Strings to fpreals
302  UT_StringMap<fpreal> *myMaxStatValues;
303  UT_String myDiffProfile0;
304  UT_String myDiffProfile1;
305 
306  // Table of statistics contained within the profile.
307  // Maps stat names to the stat definitions (i.e. name, type, etc.).
309  UT_PerfMonStatDefinitions *myStatDefs;
310 
311  // Table of statistics contained within the profile.
312  // Groups the statistics by category.
313  UT_Array<UT_StringArray> myStatsByCategory;
314 };
315 
317 
318 #endif
GLsizei const GLchar *const * path
Definition: glcorearb.h:3340
Definition of a collected statistic.
#define UT_API
Definition: UT_API.h:12
struct _cl_event * event
Definition: glcorearb.h:2960
GLuint id
Definition: glcorearb.h:654
UT_PerfMonObjectType
Object types.
UT_PerfMonStatType
UT_PerfMonCategory
Categories.
GLuint const GLchar * name
Definition: glcorearb.h:785
A collection of statistics for a particular object (i.e. node, viewport).
UT_ValArray< UT_PerfMonProfile * > UT_PerfMonProfileList
double fpreal
Definition: SYS_Types.h:269
GLuint index
Definition: glcorearb.h:785
GLuint GLfloat * val
Definition: glcorearb.h:1607
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107