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.

193 lines
5.8 KiB

  1. /*++
  2. Copyright (C) 1998-1999 Microsoft Corporation
  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. // structure for passing to extensible counter open procedure wait thread
  39. typedef struct _OPEN_PROC_WAIT_INFO {
  40. struct _OPEN_PROC_WAIT_INFO *pNext;
  41. LPWSTR szLibraryName;
  42. LPWSTR szServiceName;
  43. DWORD dwWaitTime;
  44. } OPEN_PROC_WAIT_INFO, FAR * LPOPEN_PROC_WAIT_INFO;
  45. //#define PERFLIB_TIMING_THREAD_TIMEOUT 120000 // 2 min (in milliseconds)
  46. #define PERFLIB_TIMING_THREAD_TIMEOUT 30000 // 30 sec (for debugging)
  47. // timing thread handles
  48. #define PL_TIMER_START_EVENT 0
  49. #define PL_TIMER_EXIT_EVENT 1
  50. #define PL_TIMER_NUM_OBJECTS 2
  51. #define PERFLIB_TIMER_INTERVAL 500 // 500 ms Timer
  52. __inline
  53. LONGLONG
  54. GetTimeAsLongLong ()
  55. /*++
  56. Returns time performance timer converted to ms.
  57. -*/
  58. {
  59. LARGE_INTEGER liCount, liFreq;
  60. LONGLONG llReturn;
  61. if (QueryPerformanceCounter (&liCount) &&
  62. QueryPerformanceFrequency (&liFreq)) {
  63. llReturn = liCount.QuadPart * 1000 / liFreq.QuadPart;
  64. } else {
  65. llReturn = 0;
  66. }
  67. return llReturn;
  68. }
  69. //
  70. // Definition of handle table for extensible objects
  71. //
  72. typedef PM_OPEN_PROC *OPENPROC;
  73. typedef PM_COLLECT_PROC *COLLECTPROC;
  74. typedef PM_QUERY_PROC *QUERYPROC;
  75. typedef PM_CLOSE_PROC *CLOSEPROC;
  76. #define EXT_OBJ_INFO_NAME_LENGTH 32
  77. typedef struct _ExtObject {
  78. LPVOID pNext; // not used
  79. HANDLE hMutex; // sync mutex for this function
  80. OPENPROC OpenProc; // address of the open routine
  81. LPSTR szOpenProcName; // open procedure name
  82. LPWSTR szLinkageString; // param for open proc
  83. DWORD dwOpenTimeout; // wait time in MS for open proc
  84. COLLECTPROC CollectProc; // address of the collect routine
  85. QUERYPROC QueryProc; // address of query proc
  86. LPSTR szCollectProcName; // collect procedure name
  87. DWORD dwCollectTimeout; // wait time in MS for collect proc
  88. CLOSEPROC CloseProc; // address of the close routine
  89. LPSTR szCloseProcName; // close procedure name
  90. HMODULE hLibrary ; // handle returned by LoadLibraryW
  91. LPWSTR szLibraryName; // full path of library
  92. HKEY hPerfKey; // handle to performance sub key fo this service
  93. DWORD dwNumObjects; // number of supported objects
  94. DWORD dwObjList[MAX_PERF_OBJECTS_IN_QUERY_FUNCTION]; // address of array of supported objects
  95. DWORD dwFlags; // flags
  96. LPWSTR szServiceName; // service name
  97. LONGLONG llLastUsedTime; // FILETIME of last access
  98. // Performance statistics
  99. LONGLONG llElapsedTime; // time spent in call
  100. DWORD dwCollectCount; // number of times Collect successfully called
  101. DWORD dwOpenCount; // number of Loads & opens
  102. DWORD dwCloseCount; // number of Unloads & closes
  103. DWORD dwLockoutCount; // count of lock timeouts
  104. DWORD dwErrorCount; // count of errors (other than timeouts)
  105. } ExtObject, *pExtObject;
  106. const DWORD dwExtCtrOpenProcWaitMs = 10000;
  107. // ext object flags
  108. #define PERF_EO_QUERY_FUNC ((DWORD)0x00000001) // use query proc
  109. #define PERF_EO_BAD_DLL ((DWORD)0x00000002) // true when DLL ret. error
  110. #define PERF_EO_KEEP_RESIDENT ((DWORD)0x00000004) // true if lib should not be trimmed
  111. #define PERF_EO_OBJ_IN_QUERY ((DWORD)0x80000000) // true when in query list
  112. #ifdef __cplusplus
  113. class CPerfDataLibrary {
  114. public:
  115. pExtObject pLibInfo;
  116. WCHAR szQueryString[MAX_PERF_OBJECTS_IN_QUERY_FUNCTION * 10]; // string of objects to query
  117. DWORD dwRefCount; // number of classes referencing this object
  118. CPerfDataLibrary (void);
  119. ~CPerfDataLibrary (void);
  120. };
  121. class CPerfObjectAccess {
  122. private:
  123. HANDLE m_hObjectHeap;
  124. // list of libraries referenced
  125. CFlexArray m_aLibraries;
  126. LONG lEventLogLevel;
  127. HANDLE hEventLog;
  128. DWORD AddLibrary (IWbemClassObject *pClass,
  129. IWbemQualifierSet *pClassQualifiers,
  130. LPCWSTR szRegistryKey,
  131. DWORD dwPerfIndex);
  132. DWORD OpenExtObjectLibrary (pExtObject pObj);
  133. DWORD CloseLibrary (CPerfDataLibrary *pLib);
  134. //
  135. // Timer functions
  136. //
  137. HANDLE StartPerflibFunctionTimer (LPOPEN_PROC_WAIT_INFO pInfo);
  138. DWORD KillPerflibFunctionTimer (HANDLE hPerflibTimer);
  139. DWORD DestroyPerflibFunctionTimer (void);
  140. public:
  141. CPerfObjectAccess (void);
  142. ~CPerfObjectAccess (void);
  143. // used by timing thread
  144. HANDLE hTimerHandles[PL_TIMER_NUM_OBJECTS];
  145. HANDLE hTimerDataMutex;
  146. HANDLE hPerflibTimingThread;
  147. LPOPEN_PROC_WAIT_INFO pTimerItemListHead;
  148. DWORD AddClass (IWbemClassObject *pClass, BOOL bCatalogQuery);
  149. DWORD CollectData(LPBYTE pBuffer, LPDWORD pdwBufferSize, LPWSTR pszItemList=NULL);
  150. DWORD RemoveClass(IWbemClassObject *pClass);
  151. };
  152. #endif // _cplusplus
  153. #endif // _NT_PERF_OBJECT_ACCESS_H