Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cCodeProfiler.h
Go to the documentation of this file.
1 //
6 //
7 
8 #ifndef _INC_cCodeProfiler_H
9 #define _INC_cCodeProfiler_H
10 #ifndef NO_PRAGMA_ONCE
11 #pragma once
12 #endif
13 
14 #include "cTimeSys.h"
15 #include "cUnitTestDecl.h"
16 #include "cDebugAssert.h"
17 
18 namespace Gray
19 {
20  UNITTEST2_PREDEF(cCodeProfiler);
21 
23  {
27 
28  friend class cCodeProfilerControl;
29 
30  private:
31  cDebugSourceLine m_src;
32  cTimePerf m_nTimeStart;
33 
34  static bool sm_bActive;
35 
36  private:
37  void StopTime();
38 
39  public:
41  : m_src(src) // Current source file + Current line in that file
42  , m_nTimeStart(sm_bActive) // Cheat a little and burn off 4 instructions inside counted function time.
43  {
45  }
46 
48  {
49  if (sm_bActive) // inline check for maximum speed.
50  StopTime();
51  }
52 
53  UNITTEST_FRIEND(cCodeProfiler);
54  };
55 
56  // cCodeProfileFunc usage requires only single declaration at beginning of function
57 #if 0 // defined(_DEBUG)
58 #define CODEPROFILEFUNC() cCodeProfileFunc _tagPROFILE_CLASS(DEBUGSOURCELINE)
59 #else
60 #define CODEPROFILEFUNC() __noop // compile out profiling. Do nothing.
61 #endif
62 };
63 #endif
#define GRAYCORE_LINK
Definition: GrayCore.h:47
#define UNITTEST2_PREDEF(x)
Definition: cUnitTestDecl.h:19
#define UNITTEST_FRIEND(n)
Define this in the class body to be unit tested. Allow the unit test to access private/protected stuf...
Definition: cUnitTestDecl.h:17
Definition: cCodeProfiler.h:23
cCodeProfileFunc(cDebugSourceLine src)
Definition: cCodeProfiler.h:40
~cCodeProfileFunc()
Definition: cCodeProfiler.h:47
Definition: cTimeSys.h:225
< The main namespace for all Core functions.
Definition: GrayCore.cpp:14
Definition: cDebugAssert.h:29