Leaked source code of windows server 2003
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.

163 lines
5.2 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. PerfAcc.h
  5. Abstract:
  6. Windows NT Perf Object Access Class Definition
  7. --*/
  8. #ifndef _NT_PERF_OBJECT_ACCESS_H
  9. #define _NT_PERF_OBJECT_ACCESS_H
  10. #include <windows.h>
  11. #include <winperf.h>
  12. #include <ntprfctr.h>
  13. #include <wbemidl.h>
  14. #include <assert.h>
  15. #include "flexarry.h"
  16. #include "utils.h"
  17. #if (DBG && _OUTPUT_DEBUG_STRINGS)
  18. #define DebugPrint(x) OutputDebugString (x)
  19. #else
  20. #define DebugPrint(x)
  21. #endif
  22. //
  23. // constants used by guard page testing
  24. //
  25. #define GUARD_PAGE_SIZE 1024
  26. #define GUARD_PAGE_CHAR 0xA5
  27. #define GUARD_PAGE_DWORD 0xA5A5A5A5
  28. #define LOG_UNDEFINED ((LONG)-1)
  29. #define LOG_NONE 0
  30. #define LOG_USER 1
  31. #define LOG_DEBUG 2
  32. #define LOG_VERBOSE 3
  33. #define EXT_TEST_UNDEFINED 0
  34. #define EXT_TEST_ALL 1
  35. #define EXT_TEST_BASIC 2
  36. #define EXT_TEST_NONE 3
  37. #define EXT_TEST_NOMEMALLOC 4
  38. __inline
  39. LONGLONG
  40. GetTimeAsLongLong ()
  41. /*++
  42. Returns time performance timer converted to ms.
  43. -*/
  44. {
  45. LARGE_INTEGER liCount, liFreq;
  46. LONGLONG llReturn;
  47. if (QueryPerformanceCounter (&liCount) &&
  48. QueryPerformanceFrequency (&liFreq)) {
  49. llReturn = liCount.QuadPart * 1000 / liFreq.QuadPart;
  50. } else {
  51. llReturn = 0;
  52. }
  53. return llReturn;
  54. }
  55. //
  56. // Definition of handle table for extensible objects
  57. //
  58. typedef PM_OPEN_PROC *OPENPROC;
  59. typedef PM_COLLECT_PROC *COLLECTPROC;
  60. typedef PM_QUERY_PROC *QUERYPROC;
  61. typedef PM_CLOSE_PROC *CLOSEPROC;
  62. #define EXT_OBJ_INFO_NAME_LENGTH 32
  63. typedef struct _ExtObject {
  64. LPVOID pNext; // not used
  65. HANDLE hMutex; // sync mutex for this function
  66. OPENPROC OpenProc; // address of the open routine
  67. LPSTR szOpenProcName; // open procedure name
  68. LPWSTR szLinkageString; // param for open proc
  69. DWORD dwOpenTimeout; // wait time in MS for open proc
  70. COLLECTPROC CollectProc; // address of the collect routine
  71. QUERYPROC QueryProc; // address of query proc
  72. LPSTR szCollectProcName; // collect procedure name
  73. DWORD dwCollectTimeout; // wait time in MS for collect proc
  74. CLOSEPROC CloseProc; // address of the close routine
  75. LPSTR szCloseProcName; // close procedure name
  76. HMODULE hLibrary ; // handle returned by LoadLibraryW
  77. LPWSTR szLibraryName; // full path of library
  78. HKEY hPerfKey; // handle to performance sub key fo this service
  79. DWORD dwNumObjects; // number of supported objects
  80. DWORD dwObjList[MAX_PERF_OBJECTS_IN_QUERY_FUNCTION]; // address of array of supported objects
  81. DWORD dwFlags; // flags
  82. LPWSTR szServiceName; // service name
  83. LONGLONG llLastUsedTime; // FILETIME of last access
  84. // Performance statistics
  85. LONGLONG llElapsedTime; // time spent in call
  86. DWORD dwCollectCount; // number of times Collect successfully called
  87. DWORD dwOpenCount; // number of Loads & opens
  88. DWORD dwCloseCount; // number of Unloads & closes
  89. DWORD dwLockoutCount; // count of lock timeouts
  90. DWORD dwErrorCount; // count of errors (other than timeouts)
  91. DWORD dwOpenFail;
  92. DWORD ADThreadId; // thread recieving Access Denied
  93. DWORD dwFirstCounter;
  94. DWORD dwLastCounter;
  95. } ExtObject, *pExtObject;
  96. const DWORD dwExtCtrOpenProcWaitMs = 10000;
  97. // ext object flags
  98. #define PERF_EO_QUERY_FUNC ((DWORD)0x00000001) // use query proc
  99. #define PERF_EO_BAD_DLL ((DWORD)0x00000002) // true when DLL ret. error
  100. #define PERF_EO_KEEP_RESIDENT ((DWORD)0x00000004) // true if lib should not be trimmed
  101. #define PERF_EO_OBJ_IN_QUERY ((DWORD)0x80000000) // true when in query list
  102. #ifdef __cplusplus
  103. class CPerfDataLibrary {
  104. public:
  105. pExtObject pLibInfo;
  106. WCHAR szQueryString[MAX_PERF_OBJECTS_IN_QUERY_FUNCTION * 10]; // string of objects to query
  107. DWORD dwRefCount; // number of classes referencing this object
  108. CPerfDataLibrary (void);
  109. ~CPerfDataLibrary (void);
  110. };
  111. class CPerfObjectAccess {
  112. private:
  113. HANDLE m_hObjectHeap;
  114. // list of libraries referenced
  115. CFlexArray m_aLibraries;
  116. LONG lEventLogLevel;
  117. HANDLE hEventLog;
  118. DWORD AddLibrary (IWbemClassObject *pClass,
  119. IWbemQualifierSet *pClassQualifiers,
  120. LPCWSTR szRegistryKey,
  121. DWORD dwPerfIndex);
  122. DWORD OpenExtObjectLibrary (pExtObject pObj);
  123. DWORD CloseLibrary (CPerfDataLibrary *pLib);
  124. public:
  125. CPerfObjectAccess (void);
  126. ~CPerfObjectAccess (void);
  127. DWORD AddClass (IWbemClassObject *pClass, BOOL bCatalogQuery);
  128. DWORD CollectData(LPBYTE pBuffer, LPDWORD pdwBufferSize, LPWSTR pszItemList=NULL);
  129. DWORD RemoveClass(IWbemClassObject *pClass);
  130. BOOL CheckClassExist(LPWSTR wszClassName, IWbemClassObject * pClass);
  131. };
  132. #endif // _cplusplus
  133. #endif // _NT_PERF_OBJECT_ACCESS_H