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