Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
2.7 KiB

  1. // TODO: Move this to utility library.
  2. #pragma once
  3. #include <windows.h>
  4. #include <winperf.h>
  5. #include <malloc.h>
  6. // For now, use the symbol offset from the perfsym.h file to identify a particular counter.
  7. typedef __int32 PERFC;
  8. class CAccumulator
  9. {
  10. public:
  11. CAccumulator() { m_pb = NULL; m_cbAlloc = m_cbCur = 0; }
  12. ~CAccumulator() { free(m_pb); }
  13. bool Accumulate(void * pb, DWORD cb);
  14. BYTE * Buffer() { return m_pb; }
  15. DWORD Size() { return m_cbCur; }
  16. BYTE * Detach() { BYTE * pbT = m_pb; m_pb = NULL; m_cbAlloc = m_cbCur = 0; return pbT; }
  17. private:
  18. DWORD m_cbAlloc;
  19. DWORD m_cbCur;
  20. BYTE * m_pb;
  21. };
  22. struct PerfObject
  23. {
  24. DWORD ObjectNameTitleIndex;
  25. DWORD DetailLevel; // Do we care?
  26. DWORD DefaultCounter;
  27. LARGE_INTEGER PerfTime;
  28. LARGE_INTEGER PerfFreq;
  29. };
  30. struct PerfCounter
  31. {
  32. DWORD CounterNameTitleIndex; // Relative to start of this app's block; Offset into global database will be added later
  33. DWORD DefaultScale;
  34. DWORD DetailLevel; // Do we care?
  35. DWORD CounterType;
  36. };
  37. struct PerfInstanceHeader
  38. {
  39. bool fInUse; // TRUE if active instance
  40. DWORD dwPID; // Process ID of owning process
  41. };
  42. class CPerfCounterManager
  43. {
  44. friend class CPerfCounterObject;
  45. public:
  46. CPerfCounterManager() { m_hSharedMem = NULL; m_pbSharedMem = NULL; m_ppot = NULL; }
  47. ~CPerfCounterManager();
  48. DWORD Init(char * mapname, __int32 cCountersPerObject, __int32 cObjectsMax);
  49. // These functions used only by the performance DLL.
  50. DWORD Open(LPWSTR lpDeviceNames, char * appname, PerfObject * ppo, PerfCounter * apc);
  51. DWORD Collect(LPWSTR lpwszValue, LPVOID *lppData, LPDWORD lpcbBytes, LPDWORD lpcObjectTypes);
  52. DWORD Close();
  53. // These functions used only by the application, indirectly via CPerfCounterObject.
  54. __int32 AllocInstance();
  55. void FreeInstance(__int32 iInstance);
  56. private:
  57. HANDLE m_hSharedMem;
  58. unsigned __int8 * m_pbSharedMem;
  59. unsigned __int32 m_cCountersPerObject;
  60. unsigned __int32 m_cObjectsMax;
  61. unsigned __int32 m_cbPerCounterBlock;
  62. unsigned __int32 m_cbPerInstance;
  63. CAccumulator m_accumHeader;
  64. PERF_OBJECT_TYPE * m_ppot;
  65. };
  66. // An instance of a particular performance object.
  67. class CPerfCounterObject
  68. {
  69. public:
  70. CPerfCounterObject() { m_ppcm = NULL; }
  71. ~CPerfCounterObject();
  72. bool Init(CPerfCounterManager *);
  73. void IncrementCounter(PERFC perfc);
  74. void SetCounter(PERFC perfc, __int32 value);
  75. private:
  76. CPerfCounterManager * m_ppcm;
  77. int m_iInstance;
  78. };