HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UT_PerfMonEvent.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_PerfMonEvent.h (UT Library, C++)
7  *
8  * COMMENTS:
9  *
10  * Performance monitor generic event.
11  */
12 
13 #ifndef __UT_PerfMonEvent__
14 #define __UT_PerfMonEvent__
15 
16 #include "UT_API.h"
17 
18 #include <SYS/SYS_Time.h>
19 #include "UT_Assert.h"
20 #include "UT_PerfMonTypes.h"
21 #include "UT_ValArray.h"
22 #include "UT_String.h"
23 #include "UT_StringHolder.h"
24 #include "UT_PerfMonUtils.h"
25 
28 
30 {
31 public:
33  int id,
34  const char *name,
35  const char *object,
36  bool auto_nest_events,
37  UT_PerfMonCategory category,
39  UT_PerfMonObjectType object_type,
40  const char *object_icon=NULL,
41  const char *extra_info=NULL,
42  int frame_num = UT_PERFORMANCE_INVALID_FRAME);
43  virtual ~UT_PerfMonEvent();
44 
45  /// Return the unique id assigned by the performance monitor.
46  int id() const;
47 
48  /// Return the frame number in which the event occured.
49  int frameNum() const;
50 
51  /// Return the event name.
52  const char *name() const;
53 
54  /// Return the object that the event applies to.
55  const char *object() const;
56 
57  /// Set the object that the event applies to.
58  void setObject(const char *object);
59 
60  /// Return the icon used for the object.
61  /// Return NULL if the object has no associated icon.
62  const char *objectIcon() const;
63 
64  /// Return extra information about the event.
65  /// Return NULL if there is no extra information.
66  const char *extraInfo() const;
67 
68  /// Set extra information that will be displayed with the event
69  /// in profile statistics and in the event log.
70  void setExtraInfo(const char *extra_info);
71 
72  /// Return the event type.
73  UT_PerfMonEventType type() const;
74 
75  /// Return the event object type.
76  UT_PerfMonObjectType objectType() const;
77 
78  /// Return true if this event has automatic child event nesting enabled.
79  bool isAutoNestEnabled() const;
80 
81  /// Return the category.
82  UT_PerfMonCategory category() const;
83 
84  /// Return true if the event is a timed event.
85  virtual bool isTimedEvent() const
86  {
87  UT_ASSERT(
88  myType != UT_PERFMON_TIMED_EVENT
89  );
90  return false;
91  }
92 
93  /// Start the event. This puts the event in a running state.
94  /// Real work is performed in subclassStart_().
95  void start();
96 
97  /// Stop the event. This removes the event from a running state.
98  /// Real work is performed in subclassStop_().
99  void stop();
100 
101  /// Return true if the event is in the running state.
102  /// Return false otherwise.
103  bool isRunning() const;
104 
105  /// Return the event value.
106  /// If no value has been set, then return 0.
107  fpreal value() const;
108 
109  /// Return the event value minus the value of any of the descendent events.
110  /// If no self value has been calculated, then return 0.
111  fpreal selfValue() const;
112 
113  /// Set the event value.
114  void setValue(fpreal val);
115 
116  /// Override the event's value.
117  /// Handy when you know the event's value and not its starting
118  /// or stopping values.
119  void overrideValue(fpreal value);
120 
121  /// Calculate the event's self value.
122  /// Do nothing if the event's main value has not been set.
123  /// This can be an expensive call since the values of the event's
124  /// descendents must be examined.
125  void calculateSelfValue();
126 
127  /// Add a child event.
128  void appendChild(UT_PerfMonEvent *event);
129 
130  /// Remove the given child event. Do nothing if the given event
131  /// is not actually a child of this event.
132  void removeChild(UT_PerfMonEvent *event);
133 
134  /// Remove all child events.
135  void removeChildren();
136 
137  /// Return the number of child events.
138  int numChildren() const;
139 
140  /// Return the child at the given index.
141  const UT_PerfMonEvent *getChild(int index) const;
142  UT_PerfMonEvent *getChild(int index);
143 
144  /// Add a parent event.
145  void appendParent(UT_PerfMonEvent *event);
146 
147  /// Remove the given parent event. Do nothing if the given event
148  /// is not actually a parent of this event.
149  void removeParent(UT_PerfMonEvent *event);
150 
151  /// Remove all parent events.
152  void removeParents();
153 
154  /// Return the number of parent events.
155  int numParents() const;
156 
157  /// Return the parent at the given index.
158  const UT_PerfMonEvent *getParent(int index) const;
159  UT_PerfMonEvent *getParent(int index);
160 
161  /// Format the event into a pretty string that can be outputted in a log.
162  virtual void getFormattedString(
163  UT_PerfMonLogTimeFormat time_format,
164  UT_String &str_event) const;
165 
166 protected:
167 
168  /// Return true if the value has been overridden.
169  bool isValueOverridden_() const;
170 
171  /// Perform work when the event is started.
172  virtual void subclassStart_();
173 
174  /// Perform work when the event is stopped.
175  virtual void subclassStop_();
176 
177  /// Perform work when the event's value has been overridden.
178  virtual void subclassOverrideValue_();
179 
180  /// Perform work to calculate the event's self value.
181  /// Return the calculated self value.
182  virtual fpreal subclassCalculateSelfValue_();
183 
184  /// Collect the data from the given child event and merge it into this
185  /// event's children data.
186  virtual void subclassCollectDataFromChild_(
187  const UT_PerfMonEvent *child);
188 
189  /// Pass back a formatted string of this event's object path and extra info.
190  void getFormattedObjectPathAndExtraInfo_(
191  bool enclose_obj_path_in_parens,
192  UT_String &object_path,
193  UT_String &extra_info) const;
194 
195 private:
196 
197  /// Collect the data from the given child event and merge it into this
198  /// event's children data.
199  void collectDataFromChild_(
200  const UT_PerfMonEvent *child);
201 
202  int myId;
203  UT_StringHolder myName;
204  UT_StringHolder myObject;
205  UT_StringHolder myObjectIcon;
206  UT_StringHolder myExtraInfo;
207  bool myIsAutoNestEnabled;
208  int myFrameNum;
209  fpreal myValue;
210  fpreal mySelfValue;
211  bool myIsValueSet;
212  bool myIsSelfValueSet;
213  bool myIsValueOverridden;
214  UT_PerfMonCategory myCategory;
215  UT_PerfMonEventList myChildren;
216  UT_PerfMonEventList myParents;
217  UT_PerfMonEventType myType;
218  UT_PerfMonObjectType myObjectType;
219 
220  bool myIsRunning;
221 };
222 
223 #endif
224 
UT_PerfMonLogTimeFormat
UT_PerfMonEventType
Event types.
GLuint start
Definition: glcorearb.h:474
virtual bool isTimedEvent() const
Return true if the event is a timed event.
#define UT_API
Definition: UT_API.h:12
UT_ValArray< UT_PerfMonEvent * > UT_PerfMonEventList
struct _cl_event * event
Definition: glcorearb.h:2960
GLuint id
Definition: glcorearb.h:654
UT_PerfMonObjectType
Object types.
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:102
UT_PerfMonCategory
Categories.
GLuint const GLchar * name
Definition: glcorearb.h:785
GLsizei const GLfloat * value
Definition: glcorearb.h:823
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