Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cTaskProfiler.h
Go to the documentation of this file.
1 //
4 //
5 
6 #ifndef _INC_cTaskProfiler_H
7 #define _INC_cTaskProfiler_H
8 #ifndef NO_PRAGMA_ONCE
9 #pragma once
10 #endif
11 
12 #include "../GrayLibBase.h"
18 
19 #define USE_PROFILER_TEST // just use a test pattern for data.
20 
21 namespace GrayLib
22 {
25  {
28  public:
29  static const TIMEPERF_t k_NOTIME_BYTERATE = ((TIMEPERF_t)-1);
30  static const TIMEPERF_t k_NOTIME_COUNT = ((TIMEPERF_t)-2);
32  UINT m_nSamples;
33  };
34 
35  typedef int TASK_PROFILER_t;
36 
38  {
41 
42  public:
43  THREADID_t m_nThreadId;
44 
45  // Store the last task start time.
48  };
49 
51  {
56 
57  public:
59 
60  protected:
65 
66  // Sample Windows. (For All Tasks we are tracking)
70 
71  // The current action (per thread)
73 
74  protected:
75  void InitTestCurrentWindow();
76  void ClearCurrentWindow();
78  {
79  return m_CurWindow.ElementAt(idTask);
80  }
81 
82  public:
83  cTaskProfiler(TASK_PROFILER_t iQtyTasks);
84  virtual ~cTaskProfiler();
85 
86  bool isProfilingActive() const
87  {
88  return(m_iSampleWindowSec ? true : false);
89  }
91  {
92  return m_iSampleWindowSec;
93  }
94  void put_SampleWindowLen(TIMESECD_t iSampleWindowSec);
95 
97  {
98  return m_iTaskQty;
99  }
101  {
103  return m_Cur.m_idTaskCur;
104  }
105 
106  TASK_PROFILER_t SwitchTask(TASK_PROFILER_t idTask);
107 
109  {
111  cThreadGuard guard(m_LockProf);
112  cTaskProfilerRec& rec = m_CurWindow.ElementAt(idTask);
113  rec.m_Time = Type; // ignore time for this task.
114  rec.m_nSamples += nSamples;
115  }
117  {
119  cThreadGuard guard(m_LockProf);
120  cTaskProfilerRec& rec = m_CurWindow.ElementAt(idTask);
121  rec.m_Time = Type; // ignore time for this task.
122  rec.m_nSamples = nSamples;
123  }
124 
125  cStringA GetTaskStatusDesc(TASK_PROFILER_t idTask) const;
126 
127  float GetTaskPercent(TASK_PROFILER_t idTask) const
128  {
130  ASSERT(IS_INDEX_GOOD(idTask, get_TaskQty()));
131  return((float)((double)(m_PrvWindow[idTask].m_Time.m_nTime) / (double)(m_TimeWindowSize.m_nTime)));
132  }
134  {
136  ASSERT(IS_INDEX_GOOD(idTask, get_TaskQty()));
137  return((TIMESECF_t)m_PrvWindow[idTask].m_Time.get_Seconds());
138  }
139 
141  {
143  return m_Cur.m_TimeTaskSwitch.get_AgePerf();
144  }
145  double get_TaskDiffSec() const
146  {
148  return m_Cur.m_TimeTaskSwitch.get_AgeSeconds();
149  }
150 
151 #if 0
152  UINT GetTaskSamples(TASK_PROFILER_t idTask) const
153  {
154  return m_PrvWindow[idTask].m_nSamples;
155  }
156 #endif
157 
158  virtual void OnSampleWindowComplete();
159 
161  };
162 };
163 #endif // _INC_cTaskProfiler_H
#define GRAYLIB_LINK
Definition: GrayLibBase.h:35
#define IS_INDEX_GOOD(i, q)
cast the (likely) int to unsigned to check for negatives.
Definition: Index.h:35
#define ASSERT(exp)
Definition: cDebugAssert.h:87
Definition: cTaskProfiler.h:25
UINT m_nSamples
how many samples/passes made into this.
Definition: cTaskProfiler.h:32
cTimePerf m_Time
accumulated time in QueryPerformanceFrequency units.
Definition: cTaskProfiler.h:31
static const TIMEPERF_t k_NOTIME_COUNT
time is not relevant. just a UINT count of something.
Definition: cTaskProfiler.h:30
static const TIMEPERF_t k_NOTIME_BYTERATE
time is not relevant. a UINT count of bytes.
Definition: cTaskProfiler.h:29
Definition: cTaskProfiler.h:38
THREADID_t m_nThreadId
only for a single thread. other threads don't count!
Definition: cTaskProfiler.h:43
cTimePerf m_TimeTaskSwitch
QueryPerformanceCount() of last task switch. (on this thread)
Definition: cTaskProfiler.h:47
TASK_PROFILER_t m_idTaskCur
What task are we currently processing? (on this thread)
Definition: cTaskProfiler.h:46
Definition: cTaskProfiler.h:51
TIMEPERF_t get_TaskDiff() const
Definition: cTaskProfiler.h:140
UINT m_nSampleFrame
total number of sample frames.
Definition: cTaskProfiler.h:58
TIMESECD_t m_iSampleWindowSec
The sample window size (in seconds). 0=off.
Definition: cTaskProfiler.h:62
void IncTaskCount(TASK_PROFILER_t idTask, UINT nSamples, TIMEPERF_t Type=cTaskProfilerRec::k_NOTIME_BYTERATE)
Definition: cTaskProfiler.h:108
double get_TaskDiffSec() const
Definition: cTaskProfiler.h:145
TIMESECF_t GetTaskTimeSec(TASK_PROFILER_t idTask) const
Definition: cTaskProfiler.h:133
void SetTaskCount(TASK_PROFILER_t idTask, UINT nSamples, TIMEPERF_t Type=cTaskProfilerRec::k_NOTIME_COUNT)
Definition: cTaskProfiler.h:116
UNITTEST_FRIEND(cTaskProfiler)
float GetTaskPercent(TASK_PROFILER_t idTask) const
Definition: cTaskProfiler.h:127
bool isProfilingActive() const
Definition: cTaskProfiler.h:86
TIMESECD_t get_SampleWindowLen() const
Definition: cTaskProfiler.h:90
cTimePerf m_TimeWindowSize
same as m_iSampleWindowSec but in cTimePerf units.
Definition: cTaskProfiler.h:63
cArrayTyped< cTaskProfilerRec, cTaskProfilerRec & > m_PrvWindow
Definition: cTaskProfiler.h:67
cArrayTyped< cTaskProfilerRec, cTaskProfilerRec & > m_CurWindow
Definition: cTaskProfiler.h:68
cThreadLockCount m_LockProf
make sure we can't conflict this.
Definition: cTaskProfiler.h:64
TASK_PROFILER_t get_TaskQty() const
Definition: cTaskProfiler.h:96
cTimePerf m_TimeTotal
Total time collected for this sample window. (so far)
Definition: cTaskProfiler.h:69
cTaskProfilerThread m_Cur
Definition: cTaskProfiler.h:72
const TASK_PROFILER_t m_iTaskQty
Definition: cTaskProfiler.h:61
TASK_PROFILER_t get_TaskCurrent() const
Definition: cTaskProfiler.h:100
cTaskProfilerRec & GetTaskCur(TASK_PROFILER_t idTask)
Definition: cTaskProfiler.h:77
TYPE & ElementAt(ITERATE_t nIndex)
Definition: cArray.h:167
Definition: cArray.h:437
Definition: cLocker.h:72
Definition: cThreadLock.h:498
Definition: cTimeSys.h:225
TIMEPERF_t get_AgePerf() const noexcept
Definition: cTimeSys.h:276
TIMEPERF_t m_nTime
Arbitrary start time in k_nFreq units. 64 byte unsigned type.
Definition: cTimeSys.h:231
double get_AgeSeconds() const noexcept
Definition: cTimeSys.h:293
Definition: cMesh.h:22
int TASK_PROFILER_t
an application specific enum of specific tasks we are tracking.
Definition: cTaskProfiler.h:35
UNITTEST2_PREDEF(cQuadtree)
int TIMESECD_t
signed delta seconds. like TIMESEC_t. redefined in TimeUnits.h.
Definition: cTimeSys.h:19
UINT64 TIMEPERF_t
The system very high precision performance timer. cTimeSpec.
Definition: cTimeSys.h:221
float TIMESECF_t
delta float seconds.
Definition: cTimeSys.h:20