spproto.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. /*++
  2. Copyright (c) 2013 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. spproto.h
  5. Abstract:
  6. This header contains definitions for the system profiler protocol. It is
  7. used by both the profiling application and the target system.
  8. Author:
  9. Chris Stevens 11-Jul-2013
  10. --*/
  11. //
  12. // ------------------------------------------------------------------- Includes
  13. //
  14. //
  15. // ---------------------------------------------------------------- Definitions
  16. //
  17. //
  18. // Define a sentinel value for data within the profiler sampling array.
  19. //
  20. #define PROFILER_DATA_SENTINEL 0x57A67000
  21. #define PROFILER_DATA_SENTINEL_MASK 0xFFFFF000
  22. //
  23. // Define a macro to test whether or not a value is the sentinel.
  24. //
  25. #define IS_PROFILER_DATA_SENTINEL(_Value) \
  26. ((_Value & PROFILER_DATA_SENTINEL_MASK) == PROFILER_DATA_SENTINEL)
  27. //
  28. // Define a macro to get the data size, in bytes, from a profiler data
  29. // sentinel.
  30. //
  31. #define GET_PROFILER_DATA_SIZE(_Value) \
  32. (_Value & ~PROFILER_DATA_SENTINEL_MASK)
  33. //
  34. // Define the various types of profiling data available for collection.
  35. //
  36. #define PROFILER_TYPE_FLAG_STACK_SAMPLING 0x00000001
  37. #define PROFILER_TYPE_FLAG_MEMORY_STATISTICS 0x00000002
  38. #define PROFILER_TYPE_FLAG_THREAD_STATISTICS 0x00000004
  39. //
  40. // Define the minimum length of the profiler notification data buffer.
  41. //
  42. #define PROFILER_NOTIFICATION_SIZE 1
  43. //
  44. // Defines a value that marks the head of a proflier pool memory structure.
  45. //
  46. #define PROFILER_POOL_MAGIC 0x6C6F6F50 // 'looP'
  47. //
  48. // ------------------------------------------------------ Data Type Definitions
  49. //
  50. //
  51. // The positive values here line up with the SCHEDULER_REASON enum.
  52. //
  53. typedef enum _PROFILER_THREAD_EVENT {
  54. ProfilerThreadEventInvalid = 0,
  55. ProfilerThreadEventPreemption = 1,
  56. ProfilerThreadEventBlocking = 2,
  57. ProfilerThreadEventYielding = 3,
  58. ProfilerThreadEventSuspending = 4,
  59. ProfilerThreadEventExiting = 5,
  60. ProfilerThreadEventSchedulerMax,
  61. ProfilerThreadEventAlternateMin = 0x80,
  62. ProfilerThreadEventNewThread = 0x80,
  63. ProfilerThreadEventNewProcess = 0x81,
  64. ProfilerThreadEventTimeCounter = 0x82,
  65. ProfilerThreadEventMax
  66. } PROFILER_THREAD_EVENT, *PPROFILER_THREAD_EVENT;
  67. /*++
  68. Enumeration Descriptoin:
  69. This enumeration describes the various profiler data types.
  70. Values:
  71. ProfilerDataTypeStack - Indicates that the profiler data is from stack
  72. sampling.
  73. ProfilerDataTypeMemory - Indicates that the profiler data is from memory
  74. statistics.
  75. ProfilerDataTypeThread - Indicates that the profiler data is from the
  76. thread profiler.
  77. ProfilerDataTypeMax - Indicates an invalid profiler data type and the total
  78. number of profiler types.
  79. --*/
  80. typedef enum _PROFILER_DATA_TYPE {
  81. ProfilerDataTypeInvalid,
  82. ProfilerDataTypeStack,
  83. ProfilerDataTypeMemory,
  84. ProfilerDataTypeThread,
  85. ProfilerDataTypeMax
  86. } PROFILER_DATA_TYPE, *PPROFILER_DATA_TYPE;
  87. /*++
  88. Structure Description:
  89. This structure defines the header of a profiler notification payload. It is
  90. sent by the profiling producer to the consumer on periodic clock intervals.
  91. Members:
  92. Processor - Stores the number of the processor that is sending this
  93. notification to the consumer.
  94. DataSize - Stores the size of the rest of the profiler notification, which
  95. follows immediately after this field.
  96. --*/
  97. typedef struct _PROFILER_NOTIFICATION_HEADER {
  98. PROFILER_DATA_TYPE Type;
  99. ULONG Processor;
  100. ULONG DataSize;
  101. // Data follows here.
  102. } PACKED PROFILER_NOTIFICATION_HEADER, *PPROFILER_NOTIFICATION_HEADER;
  103. /*++
  104. Structure Description:
  105. This structure defines the contents of a profiler notification.
  106. Members:
  107. Header - Stores a profiler notification header.
  108. Data - Stores an array of bytes that store the profiler data being sent to
  109. the consumer.
  110. --*/
  111. typedef struct _PROFILER_NOTIFICATION {
  112. PROFILER_NOTIFICATION_HEADER Header;
  113. BYTE Data[PROFILER_NOTIFICATION_SIZE];
  114. } PACKED PROFILER_NOTIFICATION, *PPROFILER_NOTIFICATION;
  115. /*++
  116. Enumeration Descriptoin:
  117. This enumeration describes the various memory types used by the profiler.
  118. Values:
  119. ProfilerMemoryTypeNonPagedPool - Indicates that the profiler memory is of
  120. non-paged pool type.
  121. ProfilerMemoryTypePagedPool - Indicates that the profiler memory is of
  122. paged pool type.
  123. ProfilerMEmoryTypeMax - Indicates the maximum number of profiler memory
  124. types.
  125. --*/
  126. typedef enum _PROFILER_MEMORY_TYPE {
  127. ProfilerMemoryTypeNonPagedPool,
  128. ProfilerMemoryTypePagedPool,
  129. ProfilerMemoryTypeMax
  130. } PROFILER_MEMORY_TYPE, *PPROFILER_MEMORY_TYPE;
  131. /*++
  132. Structure Description:
  133. This structure defines a pool of memory for the profiler.
  134. Members:
  135. Magic - Stores a magic number, POOL_MAGIC. This is used by the initialize
  136. routine to determine if the emergency resources are utilized or just
  137. uninitialized.
  138. TagCount - Stores the number of unique tags that have been used for
  139. allocations.
  140. ProfilerMemoryType - Stores the profiler memory type that the pool should
  141. use when requesting additional memory.
  142. TotalPoolSize - Stores the total size of the memory pool, in bytes.
  143. FreeListSize - Stores the amount of free memory in the pool, in bytes.
  144. TotalAllocationCalls - Stores the number of calls to allocate memory since
  145. the pool's initialization.
  146. FailedAllocations - Stores the number of calls to allocate memory that
  147. have been failed.
  148. TotalFreeCalls - Stores the number of calls to free memory since the pool's
  149. initialization.
  150. --*/
  151. typedef struct _PROFILER_MEMORY_POOL {
  152. ULONG Magic;
  153. ULONG TagCount;
  154. PROFILER_MEMORY_TYPE ProfilerMemoryType;
  155. ULONGLONG TotalPoolSize;
  156. ULONGLONG FreeListSize;
  157. ULONGLONG TotalAllocationCalls;
  158. ULONGLONG FailedAllocations;
  159. ULONGLONG TotalFreeCalls;
  160. } PACKED PROFILER_MEMORY_POOL, *PPROFILER_MEMORY_POOL;
  161. /*++
  162. Structure Description:
  163. This structure defines profiler statistics for one allocation tag.
  164. Members:
  165. Tag - Stores the allocation tag associated with this statistic.
  166. LargestAllocation - Stores the largest single allocation ever made under
  167. this tag, in bytes.
  168. ActiveSize - Stores the total number of bytes currently allocated under
  169. this tag.
  170. LargestActiveSize - Stores the largest number of bytes the active size has
  171. ever been.
  172. LifetimeAllocationSize - Stores the total number of bytes that have been
  173. allocated under this tag (not necessarily all at once).
  174. ActiveAllocationCount - Stores the current number of allocations under this
  175. allocation tag.
  176. LargestActiveAllocationCount - Stores the largest number the active
  177. allocation count has ever been for this tag.
  178. --*/
  179. typedef struct _PROFILER_MEMORY_POOL_TAG_STATISTIC {
  180. ULONG Tag;
  181. ULONG LargestAllocation;
  182. ULONGLONG ActiveSize;
  183. ULONGLONG LargestActiveSize;
  184. ULONGLONG LifetimeAllocationSize;
  185. ULONG ActiveAllocationCount;
  186. ULONG LargestActiveAllocationCount;
  187. } PACKED PROFILER_MEMORY_POOL_TAG_STATISTIC,
  188. *PPROFILER_MEMORY_POOL_TAG_STATISTIC;
  189. /*++
  190. Structure Description:
  191. This structure defines a context swap event in the profiler.
  192. Members:
  193. EventType - Stores the type of event that occurred. This identifies it as a
  194. context swap event (by using positive numbers), and also provides the
  195. scheduling out reason.
  196. ScheduleOutReason - Stores the reason for the scheduling event.
  197. TimeCount - Stores the current time counter value.
  198. BlockingQueue - Stores a pointer to the queue that the old thread is
  199. blocking on in the case of a blocking event.
  200. ThreadId - Stores the ID of the thread being scheduled out.
  201. ProcessId - Stores the ID of the process that owns the thread.
  202. --*/
  203. typedef struct _PROFILER_CONTEXT_SWAP {
  204. CHAR EventType;
  205. ULONGLONG TimeCount;
  206. ULONGLONG BlockingQueue;
  207. ULONG ThreadId;
  208. ULONG ProcessId;
  209. } PACKED PROFILER_CONTEXT_SWAP, *PPROFILER_CONTEXT_SWAP;
  210. /*++
  211. Structure Description:
  212. This structure defines a time counter calibration event in the thread
  213. profiler.
  214. Members:
  215. EventType - Stores the event type, which will always be
  216. ProfilerThreadEventTimeCounter.
  217. TimeCounter - Stores a value of the time counter.
  218. SystemTimeSeconds - Stores the seconds of the system time that matches the
  219. time counter value.
  220. SystemTimeNanoseconds - Stores the seconds of the system time that matches
  221. the time counter value.
  222. TimeCounterFrequency - Stores the frequency of the time counter.
  223. --*/
  224. typedef struct _PROFILER_THREAD_TIME_COUNTER {
  225. CHAR EventType;
  226. ULONGLONG TimeCounter;
  227. ULONGLONG TimeCounterFrequency;
  228. ULONGLONG SystemTimeSeconds;
  229. ULONG SystemTimeNanoseconds;
  230. } PACKED PROFILER_THREAD_TIME_COUNTER, *PPROFILER_THREAD_TIME_COUNTER;
  231. /*++
  232. Structure Description:
  233. This structure defines a process creation event.
  234. Members:
  235. EventType - Stores the event type, which will always be
  236. ProfilerThreadEventNewProcess.
  237. StructureSize - Stores the size of the structure including the null
  238. terminated name.
  239. ProcessId - Stores the identifier of the process.
  240. TimeCounter - Stores the time counter value when this process was created,
  241. or 0 if the process was created before profiling was enabled.
  242. Name - Stores the null terminated name of the process.
  243. --*/
  244. typedef struct _PROFILER_THREAD_NEW_PROCESS {
  245. CHAR EventType;
  246. ULONG StructureSize;
  247. ULONG ProcessId;
  248. ULONGLONG TimeCounter;
  249. CHAR Name[ANYSIZE_ARRAY];
  250. } PACKED PROFILER_THREAD_NEW_PROCESS, *PPROFILER_THREAD_NEW_PROCESS;
  251. /*++
  252. Structure Description:
  253. This structure defines a thread creation event.
  254. Members:
  255. EventType - Stores the event type, which will always be
  256. ProfilerThreadEventNewThread.
  257. StructureSize - Stores the size of the structure including the null
  258. terminated name.
  259. ThreadId - Stores the identifier of the thread.
  260. TimeCounter - Stores the time counter value when this thread was created,
  261. or 0 if the thread was created before profiling was enabled.
  262. Name - Stores the null terminated name of the process.
  263. --*/
  264. typedef struct _PROFILER_THREAD_NEW_THREAD {
  265. CHAR EventType;
  266. ULONG StructureSize;
  267. ULONG ProcessId;
  268. ULONG ThreadId;
  269. ULONGLONG TimeCounter;
  270. CHAR Name[ANYSIZE_ARRAY];
  271. } PACKED PROFILER_THREAD_NEW_THREAD, *PPROFILER_THREAD_NEW_THREAD;
  272. //
  273. // -------------------------------------------------------------------- Globals
  274. //
  275. //
  276. // -------------------------------------------------------- Function Prototypes
  277. //