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.

177 lines
4.8 KiB

  1. /*++ BUILD Version: 0001 // Increment this if a change has global effects
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. perfutil.h
  5. Abstract:
  6. This file supports routines used to parse and
  7. create Performance Monitor Data Structures.
  8. It actually supports Performance Object types with
  9. multiple instances
  10. Author:
  11. Bob Watson 28-Jul-1995
  12. Revision History:
  13. --*/
  14. #ifndef _PERFUTIL_H_
  15. #define _PERFUTIL_H_
  16. #include <windows.h>
  17. #include <winperf.h>
  18. #define MAX_INSTANCE_NAME 32
  19. #ifdef _WIN64
  20. #define SMALL_BUFFER_SIZE ((DWORD)8192)
  21. #else
  22. #define SMALL_BUFFER_SIZE ((DWORD)4096)
  23. #endif
  24. #define MEDIUM_BUFFER_SIZE ((DWORD)(4096*8))
  25. #define LARGE_BUFFER_SIZE ((DWORD)(4096*16))
  26. #define INCREMENT_BUFFER_SIZE ((DWORD)(4096*2))
  27. #define MAX_VALUE_NAME_LENGTH 256*sizeof(WCHAR)
  28. #define MAX_VALUE_DATA_LENGTH 256*sizeof(WCHAR)
  29. //
  30. // Until USER supports Unicode, we have to work in ASCII:
  31. //
  32. #define DEFAULT_NT_CODE_PAGE 437
  33. #define UNICODE_CODE_PAGE 0
  34. // enable this define to log process heap data to the event log
  35. #ifdef PROBE_HEAP_USAGE
  36. #undef PROBE_HEAP_USAGE
  37. #endif
  38. //
  39. // Utility macro. This is used to reserve a DWORD multiple of
  40. // bytes for Unicode strings embedded in the definitional data,
  41. // viz., object instance names.
  42. //
  43. // Assumes x is DWORD, and returns a DWORD
  44. //
  45. #define DWORD_MULTIPLE(x) (((ULONG)(x) + ((sizeof(DWORD))-1)) & ~((ULONG)(sizeof(DWORD))-1))
  46. #define QWORD_MULTIPLE(x) (((ULONG)(x) + ((sizeof(ULONG64))-1)) & ~((ULONG)(sizeof(ULONG64))-1))
  47. #define PAGESIZE_MULTIPLE(x) \
  48. (((ULONG)(x) + ((SMALL_BUFFER_SIZE)-1)) & ~((ULONG)(SMALL_BUFFER_SIZE)-1))
  49. //
  50. // Returns a PVOID
  51. //
  52. #define ALIGN_ON_DWORD(x) \
  53. ((VOID *)(((ULONG_PTR)(x) + ((sizeof(DWORD))-1)) & ~((ULONG_PTR)(sizeof(DWORD))-1)))
  54. #define ALIGN_ON_QWORD(x) \
  55. ((VOID *)(((ULONG_PTR)(x) + ((sizeof(ULONG64))-1)) & ~((ULONG_PTR)(sizeof(ULONG64))-1)))
  56. extern const WCHAR GLOBAL_STRING[]; // Global command (get all local ctrs)
  57. extern const WCHAR FOREIGN_STRING[]; // get data from foreign computers
  58. extern const WCHAR COSTLY_STRING[];
  59. extern const WCHAR NULL_STRING[];
  60. extern const WCHAR szTotalValue[];
  61. extern const WCHAR szDefaultTotalString[];
  62. #define DEFAULT_TOTAL_STRING_LEN 14
  63. extern DWORD MESSAGE_LEVEL;
  64. #define QUERY_GLOBAL 1
  65. #define QUERY_ITEMS 2
  66. #define QUERY_FOREIGN 3
  67. #define QUERY_COSTLY 4
  68. // function prototypes for data collection routines
  69. typedef DWORD (APIENTRY PM_LOCAL_COLLECT_PROC) (LPVOID *, LPDWORD, LPDWORD);
  70. typedef struct _POS_FUNCTION_INFO {
  71. DWORD dwObjectId;
  72. DWORD dwCollectFunctionBit;
  73. DWORD dwDataFunctionBit;
  74. PM_LOCAL_COLLECT_PROC *pCollectFunction;
  75. } POS_FUNCTION_INFO, * PPOS_FUNCTION_INFO;
  76. //
  77. // The definition of the only routine of perfutil.c, It builds part of a
  78. // performance data instance (PERF_INSTANCE_DEFINITION) as described in
  79. // winperf.h
  80. //
  81. HANDLE MonOpenEventLog (IN LPWSTR);
  82. VOID MonCloseEventLog ();
  83. DWORD GetQueryType (IN LPWSTR);
  84. BOOL IsNumberInUnicodeList (DWORD, LPWSTR);
  85. BOOL
  86. MonBuildInstanceDefinition(
  87. PERF_INSTANCE_DEFINITION *pBuffer,
  88. PVOID *pBufferNext,
  89. DWORD ParentObjectTitleIndex,
  90. DWORD ParentObjectInstance,
  91. DWORD UniqueID,
  92. LPWSTR Name
  93. );
  94. LONG
  95. GetPerflibKeyValue (
  96. LPCWSTR szItem,
  97. DWORD dwRegType,
  98. DWORD dwMaxSize, // ... of pReturnBuffer in bytes
  99. LPVOID pReturnBuffer,
  100. DWORD dwDefaultSize, // ... of pDefault in bytes
  101. LPVOID pDefault
  102. );
  103. //
  104. // Memory Probe macro
  105. //
  106. #ifdef PROBE_HEAP_USAGE
  107. typedef struct _LOCAL_HEAP_INFO_BLOCK {
  108. DWORD AllocatedEntries;
  109. DWORD AllocatedBytes;
  110. DWORD FreeEntries;
  111. DWORD FreeBytes;
  112. } LOCAL_HEAP_INFO, *PLOCAL_HEAP_INFO;
  113. #define HEAP_PROBE() { \
  114. DWORD dwHeapStatus[5]; \
  115. NTSTATUS CallStatus; \
  116. dwHeapStatus[4] = __LINE__; \
  117. if (!(CallStatus = memprobe (dwHeapStatus, 16L, NULL))) { \
  118. REPORT_INFORMATION_DATA (TCP_HEAP_STATUS, LOG_DEBUG, \
  119. &dwHeapStatus, sizeof(dwHeapStatus)); \
  120. } else { \
  121. REPORT_ERROR_DATA (TCP_HEAP_STATUS_ERROR, LOG_DEBUG, \
  122. &CallStatus, sizeof (DWORD)); \
  123. } \
  124. }
  125. #else
  126. #define HEAP_PROBE() ;
  127. #endif
  128. #ifdef DBG
  129. #define PERF_HEAP_FLAGS HEAP_ZERO_MEMORY | HEAP_GENERATE_EXCEPTIONS
  130. #else
  131. #define PERF_HEAP_FLAGS HEAP_ZERO_MEMORY
  132. #endif
  133. #ifndef PERF_HEAP
  134. #define PERF_HEAP RtlProcessHeap()
  135. #endif
  136. #define ALLOCMEM(size) HeapAlloc (PERF_HEAP, PERF_HEAP_FLAGS, size)
  137. #define REALLOCMEM(pointer, newsize) \
  138. HeapReAlloc (PERF_HEAP, 0, pointer, newsize)
  139. #define FREEMEM(pointer) HeapFree (PERF_HEAP, 0, pointer)
  140. #endif //_PERFUTIL_H_