HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 UT_StringHolder &name,
35  const UT_StringHolder &object,
36  bool auto_nest_events,
37  UT_PerfMonCategory category,
39  UT_PerfMonObjectType object_type,
40  const UT_StringHolder &object_icon=NULL,
41  const UT_StringHolder &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 UT_StringHolder &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(
71  const UT_StringHolder &extra_info);
72 
73  /// Return the event type.
74  UT_PerfMonEventType type() const;
75 
76  /// Return the event object type.
77  UT_PerfMonObjectType objectType() const;
78 
79  /// Return true if this event has automatic child event nesting enabled.
80  bool isAutoNestEnabled() const;
81 
82  /// Return the category.
83  UT_PerfMonCategory category() const;
84 
85  /// Return true if the event is a timed event.
86  virtual bool isTimedEvent() const
87  {
88  UT_ASSERT(
89  myType != UT_PERFMON_TIMED_EVENT
90  );
91  return false;
92  }
93 
94  /// Start the event. This puts the event in a running state.
95  /// Real work is performed in subclassStart_().
96  void start();
97 
98  /// Stop the event. This removes the event from a running state.
99  /// Real work is performed in subclassStop_().
100  void stop();
101 
102  /// Return true if the event is in the running state.
103  /// Return false otherwise.
104  bool isRunning() const;
105 
106  /// Return the event value.
107  /// If no value has been set, then return 0.
108  fpreal value() const;
109 
110  /// Return the event value minus the value of any of the descendent events.
111  /// If no self value has been calculated, then return 0.
112  fpreal selfValue() const;
113 
114  /// Set the event value.
115  void setValue(fpreal val);
116 
117  /// Override the event's value.
118  /// Handy when you know the event's value and not its starting
119  /// or stopping values.
120  void overrideValue(fpreal value);
121 
122  /// Calculate the event's self value.
123  /// Do nothing if the event's main value has not been set.
124  /// This can be an expensive call since the values of the event's
125  /// descendents must be examined.
126  void calculateSelfValue();
127 
128  /// Add a child event.
129  void appendChild(UT_PerfMonEvent *event);
130 
131  /// Remove the given child event. Do nothing if the given event
132  /// is not actually a child of this event.
133  void removeChild(UT_PerfMonEvent *event);
134 
135  /// Remove all child events.
136  void removeChildren();
137 
138  /// Return the number of child events.
139  int numChildren() const;
140 
141  /// Return the child at the given index.
142  const UT_PerfMonEvent *getChild(int index) const;
143  UT_PerfMonEvent *getChild(int index);
144 
145  /// Add a parent event.
146  void appendParent(UT_PerfMonEvent *event);
147 
148  /// Remove the given parent event. Do nothing if the given event
149  /// is not actually a parent of this event.
150  void removeParent(UT_PerfMonEvent *event);
151 
152  /// Remove all parent events.
153  void removeParents();
154 
155  /// Return the number of parent events.
156  int numParents() const;
157 
158  /// Return the parent at the given index.
159  const UT_PerfMonEvent *getParent(int index) const;
160  UT_PerfMonEvent *getParent(int index);
161 
162  /// Format the event into a pretty string that can be outputted in a log.
163  virtual void getFormattedString(
164  UT_PerfMonLogTimeFormat time_format,
165  UT_String &str_event) const;
166 
167 protected:
168 
169  /// Return true if the value has been overridden.
170  bool isValueOverridden_() const;
171 
172  /// Perform work when the event is started.
173  virtual void subclassStart_();
174 
175  /// Perform work when the event is stopped.
176  virtual void subclassStop_();
177 
178  /// Perform work when the event's value has been overridden.
179  virtual void subclassOverrideValue_();
180 
181  /// Perform work to calculate the event's self value.
182  /// Return the calculated self value.
183  virtual fpreal subclassCalculateSelfValue_();
184 
185  /// Collect the data from the given child event and merge it into this
186  /// event's children data.
187  virtual void subclassCollectDataFromChild_(
188  const UT_PerfMonEvent *child);
189 
190  /// Pass back a formatted string of this event's object path and extra info.
191  void getFormattedObjectPathAndExtraInfo_(
192  bool enclose_obj_path_in_parens,
193  UT_String &object_path,
194  UT_String &extra_info) const;
195 
196 private:
197 
198  /// Collect the data from the given child event and merge it into this
199  /// event's children data.
200  void collectDataFromChild_(
201  const UT_PerfMonEvent *child);
202 
203  int myId;
204  UT_StringHolder myName;
205  UT_StringHolder myObject;
206  UT_StringHolder myObjectIcon;
207  UT_StringHolder myExtraInfo;
208  bool myIsAutoNestEnabled;
209  int myFrameNum;
210  fpreal myValue;
211  fpreal mySelfValue;
212  bool myIsValueSet;
213  bool myIsSelfValueSet;
214  bool myIsValueOverridden;
215  UT_PerfMonCategory myCategory;
216  UT_PerfMonEventList myChildren;
217  UT_PerfMonEventList myParents;
218  UT_PerfMonEventType myType;
219  UT_PerfMonObjectType myObjectType;
220 
221  bool myIsRunning;
222 };
223 
224 #endif
225 
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:13
UT_ValArray< UT_PerfMonEvent * > UT_PerfMonEventList
struct _cl_event * event
Definition: glcorearb.h:2960
GLuint id
Definition: glcorearb.h:654
UT_PerfMonObjectType
Object types.
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:270
GLuint index
Definition: glcorearb.h:785
GLuint GLfloat * val
Definition: glcorearb.h:1607
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:126