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.

387 lines
9.3 KiB

  1. /*++
  2. Copyright (C) 1996 Microsoft Corporation
  3. Module Name:
  4. pdhidef.h
  5. Abstract:
  6. function definitions used internally by the performance data helper
  7. functions
  8. --*/
  9. #ifndef _PDHI_DEFS_H_
  10. #define _PDHI_DEFS_H_
  11. #include "pdhitype.h" // required for data type definitions
  12. #include "pdhmsg.h" // error message definitions
  13. #include "strings.h" // for string constants
  14. #if DBG
  15. #define STATIC_PDH_FUNCTION PDH_STATUS __stdcall
  16. #define STATIC_BOOL BOOL __stdcall
  17. #define STATIC_DWORD DWORD __stdcall
  18. #else
  19. #define STATIC_PDH_FUNCTION static PDH_STATUS __stdcall
  20. #define STATIC_BOOL static BOOL __stdcall
  21. #define STATIC_DWORD static DWORD __stdcall
  22. #endif
  23. // global variable declarations
  24. extern HANDLE ThisDLLHandle;
  25. extern WCHAR szStaticLocalMachineName[];
  26. extern HANDLE hPdhDataMutex;
  27. extern HANDLE hPdhHeap;
  28. extern HANDLE hEventLog;
  29. #ifndef _SHOW_PDH_MEM_ALLOCS
  30. #define G_ALLOC(s) HeapAlloc (hPdhHeap, HEAP_GENERATE_EXCEPTIONS | HEAP_ZERO_MEMORY, s)
  31. #define G_REALLOC(h,s) HeapReAlloc (hPdhHeap, HEAP_GENERATE_EXCEPTIONS, h, s)
  32. #define G_FREE(h) HeapFree (hPdhHeap, 0, h)
  33. #define G_SIZE(h) HeapSize (hPdhHeap, 0, h)
  34. #else
  35. __inline
  36. LPVOID
  37. PdhiHeapAlloc(LPSTR szSourceFileName, DWORD dwLineNo, DWORD s)
  38. {
  39. LPVOID lpRetVal;
  40. CHAR szOutputString[MAX_PATH];
  41. lpRetVal = HeapAlloc (hPdhHeap, HEAP_ZERO_MEMORY, s);
  42. sprintf (szOutputString, "\n%s (%d): +%d Bytes Allocated to 0x%8.8x",
  43. szSourceFileName, dwLineNo,
  44. (lpRetVal != NULL ? s : 0), (DWORD)lpRetVal);
  45. OutputDebugStringA (szOutputString);
  46. return lpRetVal;
  47. }
  48. __inline
  49. LPVOID
  50. PdhiHeapReAlloc(LPSTR szSourceFileName, DWORD dwLineNo,
  51. LPVOID h, DWORD s)
  52. {
  53. LPVOID lpRetVal;
  54. CHAR szOutputString[MAX_PATH];
  55. DWORD dwBeforeSize;
  56. dwBeforeSize = HeapSize (hPdhHeap, 0, h);
  57. lpRetVal = HeapReAlloc (hPdhHeap, 0, h, s);
  58. sprintf (szOutputString, "\n%s (%d): -%d Bytes Freed from 0x%8.8x\n%s (%d): +%d Bytes Reallocd to 0x%8.8x",
  59. szSourceFileName, dwLineNo,
  60. dwBeforeSize, (DWORD) h,
  61. szSourceFileName, dwLineNo,
  62. (lpRetVal != NULL ? s : 0), (DWORD)lpRetVal);
  63. OutputDebugStringA (szOutputString);
  64. return lpRetVal;
  65. }
  66. __inline
  67. BOOL
  68. PdhiHeapFree(LPSTR szSourceFileName, DWORD dwLineNo,
  69. LPVOID h)
  70. {
  71. BOOL bRetVal;
  72. CHAR szOutputString[MAX_PATH];
  73. DWORD dwBlockSize;
  74. dwBlockSize = HeapSize (hPdhHeap, 0, h);
  75. bRetVal = HeapFree (hPdhHeap, 0, h);
  76. sprintf (szOutputString, "\n%s (%d): -%d Bytes Freed from 0x%8.8x",
  77. szSourceFileName, dwLineNo,
  78. (bRetVal ? dwBlockSize : 0), (DWORD)h);
  79. OutputDebugStringA (szOutputString);
  80. return bRetVal;
  81. }
  82. #define G_ALLOC(s) PdhiHeapAlloc (__FILE__, __LINE__, s)
  83. #define G_REALLOC(h,s) PdhiHeapReAlloc (__FILE__, __LINE__, h, s)
  84. #define G_FREE(h) PdhiHeapFree (__FILE__, __LINE__, h)
  85. #define G_SIZE(h) HeapSize (hPdhHeap, 0, h)
  86. #endif
  87. // (assumes dword is 4 bytes long and pointer is a dword in size)
  88. #define ALIGN_ON_DWORD(x) ((VOID *)( ((DWORD)(x) & 0x00000003) ? ( ((DWORD)(x) & 0xFFFFFFFC) + 4 ) : ( (DWORD)(x) ) ))
  89. #define DWORD_MULTIPLE(x) ((((x)+sizeof(DWORD)-1)/sizeof(DWORD))*sizeof(DWORD))
  90. #define CLEAR_FIRST_FOUR_BYTES(x) *(DWORD *)(x) = 0L
  91. // (assumes QuadWORD is 8 bytes long and pointer is dword in size)
  92. #define ALIGN_ON_QWORD(x) ((VOID *)( ((DWORD)(x) & 0x00000007) ? ( ((DWORD)(x) & 0xFFFFFFF8) + 8 ) : ( (DWORD)(x) ) ))
  93. #define QWORD_MULTIPLE(x) ((((x)+sizeof(LONGLONG)-1)/sizeof(LONGLONG))*sizeof(LONGLONG))
  94. #define CLEAR_FIRST_EIGHT_BYTES(x) *(LONGLONG *)(x) = 0L
  95. #define WAIT_FOR_AND_LOCK_MUTEX(h) (h != NULL ? WaitForSingleObject(h, 60000) : WAIT_TIMEOUT)
  96. #define RELEASE_MUTEX(h) (h != NULL ? ReleaseMutex(h) : TRUE)
  97. // special perf counter type used by text log files
  98. // value is stored as a double precision floating point value
  99. #define PERF_DOUBLE_RAW (0x00000400 | PERF_TYPE_NUMBER | \
  100. PERF_NUMBER_DECIMAL)
  101. #define LODWORD(ll) ((DWORD)((LONGLONG)ll & 0x00000000FFFFFFFF))
  102. #define HIDWORD(ll) ((DWORD)(((LONGLONG)ll >> 32) & 0x00000000FFFFFFFF))
  103. #define SMALL_BUFFER_SIZE 4096
  104. #define MEDIUM_BUFFER_SIZE 16834
  105. #define LARGE_BUFFER_SIZE 65536
  106. // set this to 1 to report code errors (i.e. debugging information)
  107. // to the event log.
  108. #define PDHI_REPORT_CODE_ERRORS 0
  109. // set this to 1 to report user errors (i.e. things the normal user
  110. // would care about) to the event log.
  111. #define PDHI_REPORT_USER_ERRORS 1
  112. // USER category errors are typically configuration, schema or access
  113. // access errors, errors the user can usually do something about
  114. #define PDH_EVENT_CATEGORY_USER 100
  115. // COUNTER category errors are errors returned do to valid data returning
  116. // invalid results. These are a special subset of USER Category errors.
  117. #define PDH_EVENT_CATEGORY_COUNTER 110
  118. // DEBUG category errors are of interest only to PDH developers as they
  119. // indicate problems that can normally only be fixed by modifying the
  120. // program code.
  121. #define PDH_EVENT_CATEGORY_DEBUG 200
  122. #define REPORT_EVENT(t,c,id) ReportEvent (hEventLog, t, c, id, NULL, 0, 0, NULL, NULL)
  123. //
  124. // Log file entries
  125. //
  126. extern LPCSTR szTsvLogFileHeader;
  127. extern LPCSTR szCsvLogFileHeader;
  128. extern LPCSTR szBinLogFileHeader;
  129. extern LPCSTR szTsvType;
  130. extern LPCSTR szCsvType;
  131. extern LPCSTR szBinaryType;
  132. extern const DWORD dwFileHeaderLength;
  133. extern const DWORD dwTypeLoc;
  134. extern const DWORD dwVersionLoc;
  135. extern const DWORD dwFieldLength;
  136. PDH_FUNCTION
  137. PdhiGetLogCounterInfo (
  138. IN HLOG hLog,
  139. IN PPDHI_COUNTER pCounter
  140. );
  141. PDH_FUNCTION
  142. PdhiEnumLoggedMachines (
  143. IN LPCWSTR szDataSource,
  144. IN LPVOID mszMachineList,
  145. IN LPDWORD pcchBufferSize,
  146. IN BOOL bUnicode
  147. );
  148. PDH_FUNCTION
  149. PdhiEnumLoggedObjects (
  150. IN LPCWSTR szDataSource,
  151. IN LPCWSTR szMachineName,
  152. IN LPVOID mszObjectList,
  153. IN LPDWORD pcchBufferSize,
  154. IN DWORD dwDetailLevel,
  155. IN BOOL bRefresh,
  156. IN BOOL bUnicode
  157. );
  158. PDH_FUNCTION
  159. PdhiEnumLoggedObjectItems (
  160. IN LPCWSTR szDataSource,
  161. IN LPCWSTR szMachineName,
  162. IN LPCWSTR szObjectName,
  163. IN LPVOID mszCounterList,
  164. IN LPDWORD pdwCounterListLength,
  165. IN LPVOID mszInstanceList,
  166. IN LPDWORD pdwInstanceListLength,
  167. IN DWORD dwDetailLevel,
  168. IN DWORD dwFlags,
  169. IN BOOL bUnicode
  170. );
  171. BOOL
  172. PdhiDataSourceHasDetailLevels (
  173. IN LPWSTR szDataSource
  174. );
  175. PDH_FUNCTION
  176. PdhiGetMatchingLogRecord (
  177. IN HLOG hLog,
  178. IN LONGLONG *pStartTime,
  179. IN LPDWORD pdwIndex
  180. );
  181. PDH_FUNCTION
  182. PdhiGetCounterValueFromLogFile (
  183. IN HLOG hLog,
  184. IN DWORD dwIndex,
  185. IN PERFLIB_COUNTER *pPath,
  186. IN PPDH_RAW_COUNTER pValue
  187. );
  188. // query.c
  189. BOOL
  190. PdhiQueryCleanup (
  191. );
  192. // cutils.c
  193. BOOL
  194. AssignCalcFunction (
  195. IN DWORD dwCounterType,
  196. IN LPCOUNTERCALC *pCalcFunc,
  197. IN LPCOUNTERSTAT *pStatFunc
  198. );
  199. PDH_STATUS
  200. PdhiComputeFormattedValue (
  201. IN LPCOUNTERCALC pCalcFunc,
  202. IN DWORD dwCounterType,
  203. IN LONG lScale,
  204. IN DWORD dwFormat,
  205. IN PPDH_RAW_COUNTER pRawValue1,
  206. IN PPDH_RAW_COUNTER pRawValue2,
  207. IN PLONGLONG pTimeBase,
  208. IN DWORD dwReserved,
  209. IN OUT PPDH_FMT_COUNTERVALUE fmtValue
  210. );
  211. // qutils.c
  212. DWORD
  213. PdhiAsyncTimerThreadProc (
  214. LPVOID pArg
  215. );
  216. BOOL
  217. IsValidQuery (
  218. IN HQUERY hQuery
  219. );
  220. BOOL
  221. IsValidCounter (
  222. IN HCOUNTER hCounter
  223. );
  224. BOOL
  225. InitCounter (
  226. IN OUT PPDHI_COUNTER pCounter
  227. );
  228. BOOL
  229. ParseFullPathNameW (
  230. IN LPCWSTR szFullCounterPath,
  231. IN OUT PDWORD pdwBufferLength,
  232. IN OUT PPDHI_COUNTER_PATH pCounter
  233. );
  234. BOOL
  235. ParseInstanceName (
  236. IN LPCWSTR szInstanceString,
  237. IN OUT LPWSTR szInstanceName,
  238. IN OUT LPWSTR szParentName,
  239. IN OUT LPDWORD lpIndex
  240. );
  241. BOOL
  242. FreeCounter (
  243. IN PPDHI_COUNTER pThisCounter
  244. );
  245. BOOL
  246. InitPerflibCounterInfo (
  247. IN OUT PPDHI_COUNTER pCounter
  248. );
  249. BOOL
  250. AddMachineToQueryLists (
  251. IN PPERF_MACHINE pMachine,
  252. IN PPDHI_COUNTER pNewCounter
  253. );
  254. BOOL
  255. UpdateCounterValue (
  256. IN PPDHI_COUNTER pCounter
  257. );
  258. BOOL
  259. UpdateMultiInstanceCounterValue (
  260. IN PPDHI_COUNTER pCounter
  261. );
  262. #define GPCDP_GET_BASE_DATA 0x00000001
  263. PVOID
  264. GetPerfCounterDataPtr (
  265. IN PPERF_DATA_BLOCK pPerfData,
  266. IN PPDHI_COUNTER_PATH pPath,
  267. IN PPERFLIB_COUNTER pplCtr ,
  268. IN DWORD dwFlags,
  269. IN PDWORD pStatus
  270. );
  271. LONG
  272. GetQueryPerfData (
  273. IN PPDHI_QUERY pQuery
  274. );
  275. BOOL
  276. GetInstanceByNameMatch (
  277. IN PPERF_MACHINE pMachine,
  278. IN OUT PPDHI_COUNTER pCounter
  279. );
  280. PDH_FUNCTION
  281. PdhiResetLogBuffers (
  282. IN HLOG hLog
  283. );
  284. DWORD
  285. AddUniqueStringToMultiSz (
  286. IN LPVOID mszDest,
  287. IN LPSTR szSource,
  288. IN BOOL bUnicodeDest
  289. );
  290. DWORD
  291. AddUniqueWideStringToMultiSz (
  292. IN LPVOID mszDest,
  293. IN LPWSTR szSource,
  294. IN BOOL bUnicodeDest
  295. );
  296. BOOL
  297. PdhiBrowseDataSource (
  298. IN HWND hWndParent,
  299. IN LPVOID szFileName,
  300. IN LPDWORD pcchFileNameSize,
  301. IN BOOL bUnicodeString
  302. );
  303. LPWSTR
  304. PdhiGetExplainText (
  305. IN LPCWSTR szMachineName,
  306. IN LPCWSTR szObjectName,
  307. IN LPCWSTR szCounterName
  308. );
  309. LONG
  310. GetCurrentServiceState (
  311. SC_HANDLE hService,
  312. BOOL * bStopped,
  313. BOOL * bPaused
  314. );
  315. #endif // _PDHI_DEFS_H_
  316.