Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cPerfMon.h
Go to the documentation of this file.
1 //
5 //
6 
7 #ifndef _INC_cPerfMon_H
8 #define _INC_cPerfMon_H
9 #ifndef NO_PRAGMA_ONCE
10 #pragma once
11 #endif
12 
13 #if defined(_WIN32) && defined(_MSC_VER) && ! defined(UNDER_CE)
14 #include "../GrayLibBase.h"
18 #include <Pdh.h> // HQUERY
19 //#include <winperf.h>
20 
21 #define USE_PERFMON
22 
23 namespace GrayLib
24 {
25  UNITTEST2_PREDEF(cPerfMon);
26 
27  class GRAYLIB_LINK cPerfMonCounter
28  {
31  public:
32  PDH_HCOUNTER m_hCounter;
33  public:
34  cPerfMonCounter() noexcept
35  : m_hCounter(HANDLE_NULL)
36  {
37  }
38  // Assume QueryPerfData has been called.
39  HRESULT GetCounterValue(OUT PDH_FMT_COUNTERVALUE& FmtValue, DWORD dwFormat) const;
40  HRESULT RemovePerfCounter();
41  };
42 
43  class GRAYLIB_LINK cPerfMonQuery
44  {
48 
49  public:
50  static const FILECHAR_t* k_szModule; // _FN("pdh.dll")
51  static const FILECHAR_t* k_szProcessorTime;
52  PDH_HQUERY m_hQuery;
53  public:
54  cPerfMonQuery() noexcept;
55  ~cPerfMonQuery();
56 
57  HRESULT OpenPerf(const FILECHAR_t* pszDataSource = nullptr, DWORD_PTR dwUserData = 0);
58  HRESULT ClosePerf();
59 
60  HRESULT AddPerfCounter( OUT cPerfMonCounter& Counter, const FILECHAR_t* pszDataSource, DWORD_PTR dwUserData = 0);
61  HRESULT QueryPerfData();
62 
63  UNITTEST_FRIEND(cPerfMon);
64  };
65 }
66 #endif // _WIN32
67 #endif // _INC_cPerfMon_H
#define GRAYLIB_LINK
Definition: GrayLibBase.h:35
INT32 HRESULT
_WIN32 style error codes. INT32
Definition: SysTypes.h:465
#define HANDLE_NULL
Invalid OS handle for _WIN32. Not invalid OS handle for linux.
Definition: cOSHandle.h:21
#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: cMesh.h:22
UNITTEST2_PREDEF(cQuadtree)
char FILECHAR_t
a UTF8 char in a file name. like TCHAR
Definition: FileName.h:22