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.

428 lines
16 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. perf.h
  5. Abstract:
  6. This module contains the macro definition of all performance hooks.
  7. Author:
  8. Stephen Hsiao (shsiao) 01-Jan-2000
  9. Revision History:
  10. --*/
  11. #ifndef _PERF_H
  12. #define _PERF_H
  13. #include <wmistr.h>
  14. #include <ntwmi.h>
  15. #include <ntperf.h>
  16. extern PERFINFO_GROUPMASK *PPerfGlobalGroupMask;
  17. extern const PERFINFO_HOOK_HANDLE PerfNullHookHandle;
  18. #define PERF_NULL_HOOK_HANDLE (PerfNullHookHandle)
  19. typedef enum _PERFINFO_START_LOG_LOCATION {
  20. PERFINFO_START_LOG_AT_BOOT,
  21. PERFINFO_START_LOG_POST_BOOT,
  22. PERFINFO_START_LOG_FROM_GLOBAL_LOGGER
  23. } PERFINFO_START_LOG_LOCATION, *PPERFINFO_START_LOG_LOCATION;
  24. typedef struct _PERFINFO_ENTRY_TABLE {
  25. PVOID *Table;
  26. LONG NumberOfEntries;
  27. } PERFINFO_ENTRY_TABLE, *PPERFINFO_ENTRY_TABLE;
  28. NTSTATUS
  29. PerfInfoStartLog (
  30. PERFINFO_GROUPMASK *pGroupMask,
  31. PERFINFO_START_LOG_LOCATION StartLogLocation
  32. );
  33. NTSTATUS
  34. PerfInfoStopLog (
  35. VOID
  36. );
  37. NTSTATUS
  38. PerfInfoLogFileName(
  39. PVOID FileObject,
  40. PUNICODE_STRING SourceString
  41. );
  42. ULONG
  43. PerfInfoCalcHashValue(
  44. PVOID Key,
  45. ULONG Len
  46. );
  47. BOOLEAN
  48. PerfInfoAddToFileHash(
  49. PPERFINFO_ENTRY_TABLE HashTable,
  50. PVOID ObjectPointer
  51. );
  52. VOID
  53. ObPerfHandleTableWalk (
  54. PEPROCESS Process,
  55. PPERFINFO_ENTRY_TABLE HashTable
  56. );
  57. VOID
  58. FASTCALL
  59. PerfProfileInterrupt(
  60. IN KPROFILE_SOURCE Source,
  61. IN PVOID InstructionPointer
  62. );
  63. VOID
  64. PerfInfoFlushProfileCache(
  65. VOID
  66. );
  67. #define PERFINFO_IS_ANY_GROUP_ON() (PPerfGlobalGroupMask != NULL)
  68. #define PERFINFO_IS_GROUP_ON(_Group) PerfIsGroupOnInGroupMask(_Group, PPerfGlobalGroupMask)
  69. #define PERF_FINISH_HOOK(_HookHandle) WmiReleaseKernelBuffer((_HookHandle).WmiBufferHeader);
  70. NTSTATUS
  71. PerfInfoReserveBytes(
  72. PPERFINFO_HOOK_HANDLE Hook,
  73. USHORT HookId,
  74. ULONG BytesToReserve
  75. );
  76. NTSTATUS
  77. PerfInfoLogBytes(
  78. USHORT HookId,
  79. PVOID Data,
  80. ULONG NumBytes
  81. );
  82. NTSTATUS
  83. PerfInfoLogBytesAndUnicodeString(
  84. USHORT HookId,
  85. PVOID SourceData,
  86. ULONG SourceByteCount,
  87. PUNICODE_STRING String
  88. );
  89. //
  90. // Macros for TimeStamps
  91. //
  92. #ifdef NTPERF
  93. #if defined(_X86_)
  94. __inline
  95. LONGLONG
  96. PerfGetCycleCount(
  97. )
  98. {
  99. __asm{
  100. RDTSC
  101. }
  102. }
  103. #elif defined(_AMD64_)
  104. #define PerfGetCycleCount() ReadTimeStampCounter()
  105. #elif defined(_IA64_)
  106. #define PerfGetCycleCount() __getReg(CV_IA64_ApITC)
  107. #else
  108. #error "perf: a target architecture must be defined."
  109. #endif
  110. #define PerfTimeStamp(TS) TS.QuadPart = PerfGetCycleCount();
  111. #else
  112. #define PerfTimeStamp(TS) TS.QuadPart = (*WmiGetCpuClock)();
  113. #endif //NTPERF
  114. //
  115. // Macros used in \nt\base\ntos\io\iomgr\parse.c
  116. //
  117. #define PERFINFO_LOG_FILE_CREATE(FileObject, CompleteName) \
  118. if (PERFINFO_IS_GROUP_ON(PERF_FILENAME_ALL)){ \
  119. PerfInfoLogFileName(FileObject, CompleteName); \
  120. }
  121. // Macros used in \nt\base\ntos\mm\creasect.c
  122. //
  123. #define PERFINFO_SECTION_CREATE(ControlArea) \
  124. if (PERFINFO_IS_GROUP_ON(PERF_FILENAME_ALL)){ \
  125. PerfInfoLogFileName(ControlArea->FilePointer, \
  126. &(ControlArea)->FilePointer->FileName); \
  127. }
  128. //
  129. // Macros used in \nt\base\ntos\ps\psquery.c
  130. //
  131. #define PERFINFO_CONVERT_TO_GUI_THREAD(EThread) \
  132. if (PERFINFO_IS_GROUP_ON(PERF_MEMORY)) { \
  133. PERFINFO_THREAD_INFORMATION _ThreadInfo; \
  134. _ThreadInfo.ProcessId = HandleToUlong((EThread)->Cid.UniqueProcess); \
  135. _ThreadInfo.ThreadId = HandleToUlong((EThread)->Cid.UniqueThread); \
  136. _ThreadInfo.StackBase = (EThread)->Tcb.StackBase; \
  137. _ThreadInfo.StackLimit = (EThread)->Tcb.StackLimit; \
  138. _ThreadInfo.UserStackBase = 0; \
  139. _ThreadInfo.UserStackLimit = 0; \
  140. _ThreadInfo.StartAddr = 0; \
  141. _ThreadInfo.Win32StartAddr = 0; \
  142. _ThreadInfo.WaitMode = -1; \
  143. PerfInfoLogBytes( \
  144. PERFINFO_LOG_TYPE_CONVERTTOGUITHREAD, \
  145. &_ThreadInfo, \
  146. sizeof(_ThreadInfo) \
  147. ); \
  148. }
  149. //
  150. // Macros used in \NT\PRIVATE\NTOS\ps\psdelete.c
  151. //
  152. #define PERFINFO_PROCESS_DELETE(EProcess) \
  153. WmiTraceProcess(EProcess, FALSE);
  154. #define PERFINFO_THREAD_DELETE(EThread) \
  155. WmiTraceThread(EThread, NULL, FALSE);
  156. //
  157. // Macros used in \NT\PRIVATE\NTOS\ps\create.c
  158. //
  159. #define PERFINFO_PROCESS_CREATE(EProcess) \
  160. WmiTraceProcess(EProcess, TRUE);
  161. #define PERFINFO_THREAD_CREATE(EThread, ITeb) \
  162. WmiTraceThread(EThread, ITeb, TRUE); \
  163. //
  164. // ntos\ke\ia64\clock.c Sampled Profile stuff for IA64. The x86 version is in
  165. // assembly.
  166. //
  167. #if defined(_IA64_)
  168. #define PERFINFO_PROFILE(_frame, _source) \
  169. if (PERFINFO_IS_GROUP_ON(PERF_PROFILE)) { \
  170. PerfProfileInterrupt(_source, (PVOID)_frame->StIIP); \
  171. }
  172. #endif
  173. #ifdef NTPERF
  174. extern PERFINFO_GROUPMASK StartAtBootGroupMask;
  175. extern ULONG PerfInfo_InitialStackWalk_Threshold_ms;
  176. extern VOID * BBTBuffer;
  177. extern ULONG PerfInfoLoggingToPerfMem;
  178. #define PerfBufHdr() ((PPERFINFO_TRACEBUF_HEADER) BBTBuffer)
  179. #define PERFINFO_IS_PERFMEM_ALLOCATED() (PerfBufHdr() != NULL)
  180. #define PERFINFO_IS_LOGGING_TO_PERFMEM() (PerfInfoLoggingToPerfMem != 0)
  181. #define PERFINFO_SET_LOGGING_TO_PERFMEM(Flag) PerfInfoLoggingToPerfMem = (Flag);
  182. #define PerfQueryBufferSizeBytes() (PAGE_SIZE * (PerfBufHdr()->PagesReserved))
  183. NTSTATUS
  184. PerfInfoStartPerfMemLog(
  185. );
  186. NTSTATUS
  187. PerfInfoStopPerfMemLog(
  188. );
  189. PVOID
  190. FASTCALL
  191. PerfInfoReserveBytesFromPerfMem(
  192. ULONG BytesToReserve
  193. );
  194. NTSTATUS
  195. PerfInfoSetPerformanceTraceInformation (
  196. IN PVOID SystemInformation,
  197. IN ULONG SystemInformationLength
  198. );
  199. NTSTATUS
  200. PerfInfoQueryPerformanceTraceInformation (
  201. IN PVOID SystemInformation,
  202. IN ULONG SystemInformationLength,
  203. OUT PULONG ReturnLength
  204. );
  205. VOID
  206. PerfInfoSetProcessorSpeed(
  207. VOID
  208. );
  209. //
  210. // Macros used in \nt\base\ntos\mm\
  211. //
  212. #define PERFINFO_MMINIT_START() \
  213. PerfInfoSetProcessorSpeed(); \
  214. if (PerfIsAnyGroupOnInGroupMask(&StartAtBootGroupMask)) { \
  215. PerfInfoStartLog(&StartAtBootGroupMask, PERFINFO_START_LOG_AT_BOOT); \
  216. PerfBufHdr()->GetStack_CSwitchDelta = \
  217. 1000 * \
  218. PerfInfo_InitialStackWalk_Threshold_ms * \
  219. PerfBufHdr()->CalcPerfFrequency; \
  220. \
  221. PerfBufHdr()->GetStack_DrvDelayDelta = \
  222. PerfBufHdr()->GetStack_CSwitchDelta; \
  223. }
  224. #else
  225. #define PERFINFO_MMINIT_START()
  226. #endif // NTPERF
  227. #ifndef NTPERF_PRIVATE
  228. #define PERFINFO_ADD_OBJECT_TO_ALLOCATED_TYPE_LIST(CreatorInfo, ObjectType)
  229. #define PERFINFO_ADDPOOLPAGE(CheckType, PoolIndex, Addr, PoolDesc)
  230. #define PERFINFO_ADDTOWS(PageFrame, Address, Pid)
  231. #define PERFINFO_BIGFOOT_REPLACEMENT_CLAIMS(WorkingSetList, WsInfo)
  232. #define PERFINFO_BIGFOOT_REPLACEMENT_FAULTS(WorkingSetList, WsInfo)
  233. #define PERFINFO_BIGPOOLALLOC(Type, PTag, NumBytes, Addr)
  234. #define PERFINFO_CLEAR_OBJECT(CurrentState, Object)
  235. #define PERFINFO_DECLARE_OB_ENUMERATE_ALLOCATED_OBJECTS_BY_TYPE()
  236. #define PERFINFO_DECLARE_OBJECT(Object)
  237. #define PERFINFO_DECREFCNT(PageFrame, Flag, Type)
  238. #define PERFINFO_DEFINE_OB_ENUMERATE_ALLOCATED_OBJECTS_BY_TYPE()
  239. #define PERFINFO_DELETE_STACK(PointerPte, NumberOfPtes)
  240. #define PERFINFO_DETACH_PROCESS(KThread, KProcess)
  241. #define PERFINFO_DO_PAGEFAULT_CLUSTERING() 1
  242. #define PERFINFO_DRIVER_INTENTIONAL_DELAY()
  243. #define PERFINFO_DRIVER_STACKTRACE()
  244. #define PERFINFO_EXALLOCATEPOOLWITHTAG_DECL()
  245. #define PERFINFO_EXFREEPOOLWITHTAG_DECL()
  246. #define PERFINFO_FAULT_NOTIFICATION(Address, TrapInfo)
  247. #define PERFINFO_FREEPOOL(Addr)
  248. #define PERFINFO_FREEPOOLPAGE(CheckType, PoolIndex, Addr, PoolDesc)
  249. #define PERFINFO_GET_PAGE_INFO(PointerPte)
  250. #define PERFINFO_GET_PAGE_INFO_REPLACEMENT(PointerPte)
  251. #define PERFINFO_GET_PAGE_INFO_WITH_DECL(PointerPte)
  252. #define PERFINFO_GROW_STACK(EThread)
  253. #define PERFINFO_HIBER_ADJUST_PAGECOUNT_FOR_BBTBUFFER(pPageCount)
  254. #define PERFINFO_HIBER_DUMP_PERF_BUFFER()
  255. #define PERFINFO_HIBER_HANDLE_BBTBUFFER_RANGE(HiberContext)
  256. #define PERFINFO_HIBER_PAUSE_LOGGING()
  257. #define PERFINFO_HIBER_REINIT_TRACE()
  258. #define PERFINFO_HIBER_START_LOGGING()
  259. #define PERFINFO_HIVECELL_REFERENCE_FLAT(Hive, pcell, Cell)
  260. #define PERFINFO_HIVECELL_REFERENCE_PAGED(Hive, pcell, Cell, Type, Map)
  261. #define PERFINFO_IMAGE_LOAD(LdrDataTableEntry)
  262. #define PERFINFO_IMAGE_UNLOAD(Address)
  263. #define PERFINFO_INIT_KTHREAD(KThread)
  264. #define PERFINFO_INIT_TRACEFLAGS(OptnString, SpecificOptn)
  265. #define PERFINFO_INITIALIZE_OBJECT_ALLOCATED_TYPE_LIST_HEAD(NewObjectType)
  266. #define PERFINFO_INSERT_FRONT_STANDBY(Page)
  267. #define PERFINFO_INSERTINLIST(Page, ListHead)
  268. #define PERFINFO_INSWAP_PROCESS(OutProcess)
  269. #define PERFINFO_LOG_MARK(PMARK)
  270. #define PERFINFO_LOG_MARK_SPRINTF(PMARK, VARIABLE)
  271. #define PERFINFO_LOG_WS_REMOVAL(Type, WsInfo)
  272. #define PERFINFO_LOG_WS_REPLACEMENT(WsInfo)
  273. #define PERFINFO_MOD_PAGE_WRITER3()
  274. #define PERFINFO_MUNG_FILE_OBJECT_TYPE_INITIALIZER(init)
  275. #define PERFINFO_PAGE_INFO_DECL()
  276. #define PERFINFO_PAGE_INFO_REPLACEMENT_DECL()
  277. #define PERFINFO_POOL_ALLOC_COMMON(Type, PTag, NumBytes)
  278. #define PERFINFO_POOLALLOC(Type, PTag, NumBytes)
  279. #define PERFINFO_POOLALLOC_ADDR(Addr)
  280. #define PERFINFO_POOLALLOC_EARLYEXIT()
  281. #define PERFINFO_POWER_BATTERY_LIFE_INFO(_RemainingCapacity, _Rate)
  282. #define PERFINFO_POWER_IDLE_STATE_CHANGE(_PState, _Direction)
  283. #define PERFINFO_PRIVATE_COPY_ON_WRITE(CopyFrom, PAGE_SIZE)
  284. #define PERFINFO_PRIVATE_PAGE_DEMAND_ZERO(VirtualAddress)
  285. #define PERFINFO_REG_DELETE_KEY(KeyControlBlock)
  286. #define PERFINFO_REG_DELETE_VALUE(KeyControlBlock, ValueName)
  287. #define PERFINFO_REG_DUMP_CACHE()
  288. #define PERFINFO_REG_ENUM_KEY(KeyControlBlock, Index)
  289. #define PERFINFO_REG_ENUM_VALUE(KeyControlBlock, Index)
  290. #define PERFINFO_REG_KCB_CREATE(kcb)
  291. #define PERFINFO_REG_NOTIFY(NotifiedKCB, ModifiedKCB)
  292. #define PERFINFO_REG_PARSE(kcb, RemainingName)
  293. #define PERFINFO_REG_QUERY_KEY(KeyControlBlock)
  294. #define PERFINFO_REG_QUERY_MULTIVALUE(KeyControlBlock, CurrentName)
  295. #define PERFINFO_REG_QUERY_VALUE(KeyControlBlock, ValueName)
  296. #define PERFINFO_REG_SET_VALUE_DECL()
  297. #define PERFINFO_REG_SET_VALUE(KeyControlBlock)
  298. #define PERFINFO_REG_SET_VALUE_DONE(ValueName)
  299. #define PERFINFO_REG_SET_VALUE_EXIST()
  300. #define PERFINFO_REG_SET_VALUE_NEW()
  301. #define PERFINFO_REGPARSE(kcb, RemainingName)
  302. #define PERFINFO_REGPARSE_END(status)
  303. #define PERFINFO_REMOVE_OBJECT_FROM_ALLOCATED_TYPE_LIST(CreatorInfo, ObjectHeader)
  304. #define PERFINFO_SECTION_CREATE1(File)
  305. #define PERFINFO_SEGMENT_DELETE(FileName)
  306. #define PERFINFO_SHUTDOWN_LOG_LAST_MEMORY_SNAPSHOT()
  307. #define PERFINFO_SHUTDOWN_DUMP_PERF_BUFFER()
  308. #define PERFINFO_SIGNAL_OBJECT(CurrentState, Object)
  309. #define PERFINFO_SOFTFAULT(PageFrame, Address, Type)
  310. #define PERFINFO_STACKWALK_THRESHHOLD_CM_DECL
  311. #define PERFINFO_STACKWALK_THRESHHOLD_DECL
  312. #define PERFINFO_UNLINKFREEPAGE(Index, Location)
  313. #define PERFINFO_UNLINKPAGE(Index, Location)
  314. #define PERFINFO_UNMUNG_FILE_OBJECT_TYPE_INITIALIZER(init)
  315. #define PERFINFO_UNWAIT_OBJECT(Object, Status)
  316. #define PERFINFO_UNWAIT_OBJECTS(Object, CountIn, WaitType, WaitStatus)
  317. #define PERFINFO_WAIT_ON_OBJECT(Object)
  318. #define PERFINFO_WAIT_ON_OBJECTS(Object, CountIn, WaitType)
  319. #define PERFINFO_WAITLOGGED_DECL
  320. #define PERFINFO_WSMANAGE_ACTUALTRIM(Trim)
  321. #define PERFINFO_WSMANAGE_CHECK()
  322. #define PERFINFO_WSMANAGE_DECL()
  323. #define PERFINFO_WSMANAGE_DUMPENTRIES()
  324. #define PERFINFO_WSMANAGE_DUMPENTRIES_CLAIMS()
  325. #define PERFINFO_WSMANAGE_DUMPENTRIES_FAULTS()
  326. #define PERFINFO_WSMANAGE_DUMPWS(VmSupport, SampledAgeCounts)
  327. #define PERFINFO_WSMANAGE_FINALACTION(TrimAction)
  328. #define PERFINFO_WSMANAGE_LOGINFO_CLAIMS(TrimAction)
  329. #define PERFINFO_WSMANAGE_LOGINFO_FAULTS(TrimAction)
  330. #define PERFINFO_WSMANAGE_STARTLOG()
  331. #define PERFINFO_WSMANAGE_STARTLOG_CLAIMS()
  332. #define PERFINFO_WSMANAGE_STARTLOG_FAULTS()
  333. #define PERFINFO_WSMANAGE_TOTRIM(Trim)
  334. #define PERFINFO_WSMANAGE_TRIMACTION(TrimAction)
  335. #define PERFINFO_WSMANAGE_TRIMEND_CLAIMS(Criteria)
  336. #define PERFINFO_WSMANAGE_TRIMEND_FAULTS(Criteria)
  337. #define PERFINFO_WSMANAGE_TRIMWS(Process, SessionSpace, VmSupport)
  338. #define PERFINFO_WSMANAGE_TRIMWS_CLAIMINFO(VmSupport)
  339. #define PERFINFO_WSMANAGE_TRIMWS_CLAIMINFO(VmSupport)
  340. #define PERFINFO_WSMANAGE_WAITFORWRITER_CLAIMS()
  341. #define PERFINFO_WSMANAGE_WAITFORWRITER_FAULTS()
  342. #define PERFINFO_WSMANAGE_WILLTRIM(ReductionGoal, FreeGoal)
  343. #define PERFINFO_WSMANAGE_WILLTRIM_CLAIMS(Criteria)
  344. #define PERFINFO_WSMANAGE_WILLTRIM_FAULTS(Criteria)
  345. #define PERF_BRANCH_TRACING_OFF_KD()
  346. #define PERF_BRANCH_TRACING_ON_KD()
  347. #define PERF_PF_MODLOAD_DECL()
  348. #define PERF_PF_MODLOAD_SAVE()
  349. #define PERF_PF_MODLOAD_RESTORE()
  350. #define PERF_PF_SANITIZE_CONTEXT(Context)
  351. #define PERF_BRANCH_TRACING_BREAKPOINT(ExceptionRecord, TrapFrame)
  352. #define PERF_ASSERT_TRACING_OFF()
  353. #define PERF_IS_BRANCH_TRACING_ON()
  354. #define PERFINFO_LOG_PREFETCH_BEGIN_TRACE(ScenarioId, ScenarioType, Process)
  355. #define PERFINFO_LOG_PREFETCH_END_TRACE(ScenarioId, ScenarioType, Process, Status)
  356. #define PERFINFO_LOG_PREFETCH_SECTIONS(PrefetchHeader, PrefetchType, PagesToPrefetch)
  357. #define PERFINFO_LOG_PREFETCH_SECTIONS_END(PrefetchHeader, Status, PagesRequested)
  358. #define PERFINFO_LOG_PREFETCH_METADATA(PrefetchHeader)
  359. #define PERFINFO_LOG_PREFETCH_METADATA_END(PrefetchHeader, Status)
  360. #define PERFINFO_LOG_PREFETCH_SCENARIO(PrefetchHeader, ScenarioId, ScenarioType)
  361. #define PERFINFO_LOG_PREFETCH_SCENARIO_END(PrefetchHeader, Status)
  362. #define PERFINFO_LOG_PREFETCH_REQUEST(RequestId, NumLists, RequestLists)
  363. #define PERFINFO_LOG_PREFETCH_READLIST(RequestId, ReadList)
  364. #define PERFINFO_LOG_PREFETCH_READ(FileObject, Offset, ByteCount)
  365. #else
  366. #include "..\perf\perfinfokrn.h"
  367. #endif // !NTPERF_PRIVATE
  368. #endif // PERF_H