HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UT_PerfMonTimedEvent.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_PerfMonTimedEvent.h (UT Library, C++)
7  *
8  * COMMENTS:
9  *
10  * Performance monitor timed event.
11  */
12 
13 #ifndef __UT_PerfMonTimedEvent__
14 #define __UT_PerfMonTimedEvent__
15 
16 #include "UT_API.h"
17 
18 #include <SYS/SYS_Time.h>
19 #include "UT_PerfMonEvent.h"
20 #include "UT_PerfMonTypes.h"
21 #include "UT_ValArray.h"
22 #include "UT_Map.h"
23 #include "UT_IntArray.h"
24 #include "UT_String.h"
25 #include "UT_Thread.h"
26 #include "UT_ThreadSpecificValue.h"
27 #include "UT_PerfMonUtils.h"
28 
30 {
31 public:
33  int id,
34  const char *name,
35  const char *object,
36  bool auto_nest_events,
37  UT_PerfMonCategory category,
38  UT_PerfMonObjectType object_type,
39  const char *object_icon=NULL,
40  const char *extra_info=NULL,
41  int frame_num = UT_PERFORMANCE_INVALID_FRAME);
42  virtual ~UT_PerfMonTimedEvent();
43 
44  /// Return true if the event is a timed event.
45  virtual bool isTimedEvent() const
46  { return true; }
47 
48  /// Start timing a threaded task.
49  void startTaskTimer(const UT_TaskScope *task);
50 
51  /// Stop timing a threaded task. Calculate the elapsed time and store it.
52  void stopTaskTimer(const UT_TaskScope *task);
53 
54  /// Override the event's elapsed time.
55  /// Handy when you know the event's elapsed time but not its
56  /// start time nor stop time.
57  void overrideTime(fpreal time)
59 
60  /// Return the start time.
61  /// Return NULL if the event has not started or if its time
62  /// has been overridden.
63  const SYS_TimeVal *startTime() const;
64 
65  /// Return the stop time.
66  /// Return NULL if the event has not stopped or if its time
67  /// has been overridden.
68  const SYS_TimeVal *stopTime() const;
69 
70  /// Return the time it took to complete the event.
71  /// Return 0 if the event has not started and stopped.
72  fpreal time() const
73  { return UT_PerfMonEvent::value(); }
74 
75  /// Return the time it took to complete the event excluding
76  /// the time it took to complete any child events.
77  /// Return 0 if the self time has not been calculated yet.
78  fpreal selfTime() const
79  { return UT_PerfMonEvent::selfValue(); }
80 
81  /// Return the thread id in which the event occured.
82  int threadId() const;
83 
84  // Pass back a list of ids for the threads that worked on the event.
85  void getThreadIds(UT_IntArray &thread_ids) const;
86 
87  /// Return the total time spent in the given thread.
88  fpreal totalTimeForThread(int thread_id) const;
89 
90  /// Format the event into a pretty string that can be outputted in a log.
91  virtual void getFormattedString(
92  UT_PerfMonLogTimeFormat time_format,
93  UT_String &str_event) const;
94 
95 protected:
96 
97  /// Perform work when the event is started.
98  virtual void subclassStart_();
99 
100  /// Perform work when the event is stopped.
101  virtual void subclassStop_();
102 
103  /// Perform work when the event's value has been overridden.
104  virtual void subclassOverrideValue_();
105 
106  /// Calculate the event's self value (time).
107  /// Return the self value.
109 
110  /// Collect the data from the given child event and merge it into this
111  /// event's children data.
112  virtual void subclassCollectDataFromChild_(
113  const UT_PerfMonEvent *child);
114 
115 private:
116 
117  /// Pass back a formatted string of this (frame) event.
118  void getFormattedFrameEventString_(
119  UT_PerfMonLogTimeFormat time_format,
120  UT_String &str_event) const;
121 
122  /// Pass back a formatted string of this (non-frame) event.
123  void getFormattedEventString_(
124  UT_PerfMonLogTimeFormat time_format,
125  UT_String &str_event) const;
126 
127  /// Pass back a formatted string of the given time.
128  void getFormattedTime_(
129  fpreal time,
130  UT_PerfMonLogTimeFormat time_format,
131  UT_String &str_time) const;
132 
133  /// Pass back a formatted string of the frequency calculated
134  /// by the given time.
135  void getFormattedFrequency_(
136  fpreal time, UT_String &str_frequency)
137  const;
138 
139  SYS_TimeVal *myStartTime;
140  SYS_TimeVal *myStopTime;
141  int myThreadId;
142 
143  /// List of running times for each thread. The times are represented
144  /// as a list of time blocks where each block is the timespan that the
145  /// thread was working on the event.
146  /// Assumption:
147  /// Task scopes for individual threads do not overlap.
148  /// Therefore we can store them in an array rather than a merged queue
150  const UT_ThreadSpecificValue<UT_TimeBlockList> &threadTimes() const;
151  mutable UT_ThreadSpecificValue<UT_TimeBlockList> *myThreadTimes;
152 
153  typedef UT_Map<const UT_TaskScope *, SYS_TimeVal *> ThreadTaskTable;
154  UT_ThreadSpecificValue<ThreadTaskTable> &activeThreadTasks();
155  const UT_ThreadSpecificValue<ThreadTaskTable> &activeThreadTasks() const;
156  mutable UT_ThreadSpecificValue<ThreadTaskTable> *myActiveThreadTasks;
157 
158  // Time blocks for completed child events.
159  UT_TimeBlockQueue myChildTimeBlocks;
160 };
161 
162 #endif
163 
struct timeval SYS_TimeVal
Definition: SYS_Time.h:27
UT_PerfMonLogTimeFormat
Unsorted map container.
Definition: UT_Map.h:83
virtual void subclassStart_()
Perform work when the event is started.
#define UT_API
Definition: UT_API.h:12
void overrideValue(fpreal value)
virtual bool isTimedEvent() const
Return true if the event is a timed event.
virtual void subclassStop_()
Perform work when the event is stopped.
virtual void subclassCollectDataFromChild_(const UT_PerfMonEvent *child)
void overrideTime(fpreal time)
UT_PerfMonObjectType
Object types.
UT_PerfMonCategory
Categories.
GLuint const GLchar * name
Definition: glcorearb.h:785
virtual void getFormattedString(UT_PerfMonLogTimeFormat time_format, UT_String &str_event) const
Format the event into a pretty string that can be outputted in a log.
double fpreal
Definition: SYS_Types.h:263
virtual void subclassOverrideValue_()
Perform work when the event's value has been overridden.
virtual fpreal subclassCalculateSelfValue_()
fpreal value() const
fpreal selfValue() const