sp.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. /*++
  2. Copyright (c) 2013 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. sp.h
  5. Abstract:
  6. This header contains definitions for the System Profiler.
  7. Author:
  8. Chris Stevens 1-Jul-2013
  9. --*/
  10. //
  11. // ------------------------------------------------------------------- Includes
  12. //
  13. #include <minoca/debug/spproto.h>
  14. //
  15. // --------------------------------------------------------------------- Macros
  16. //
  17. //
  18. // This macro collects thread statistics. It simply calls the function pointer
  19. // if it is enabled.
  20. //
  21. #define SpCollectThreadStatistic(_Thread, _Processor, _ScheduleOutReason) \
  22. if (SpCollectThreadStatisticRoutine != NULL) { \
  23. SpCollectThreadStatisticRoutine((_Thread), \
  24. (_Processor), \
  25. (_ScheduleOutReason)); \
  26. }
  27. #define SpProcessNewProcess(_ProcessId) \
  28. if (SpProcessNewProcessRoutine != NULL) { \
  29. SpProcessNewProcessRoutine(_ProcessId); \
  30. }
  31. #define SpProcessNewThread(_ProcessId, _ThreadId) \
  32. if (SpProcessNewThreadRoutine != NULL) { \
  33. SpProcessNewThreadRoutine(_ProcessId, _ThreadId); \
  34. }
  35. //
  36. // ---------------------------------------------------------------- Definitions
  37. //
  38. //
  39. // ------------------------------------------------------ Data Type Definitions
  40. //
  41. typedef enum _SP_INFORMATION_TYPE {
  42. SpInformationInvalid,
  43. SpInformationGetSetState,
  44. } SP_INFORMATION_TYPE, *PSP_INFORMATION_TYPE;
  45. /*++
  46. Enumeration Descriptoin:
  47. This enumeration describes the various operations for getting or setting
  48. profiler state information.
  49. Values:
  50. SpGetSetStateOperationNone - Indicates to take no action.
  51. SpGetSetStateOperationOverwrite - Indicates that the supplied profiler
  52. state should overwrite the current state. An profilers that are
  53. currently running, but not set in the supplied state will be disabled.
  54. SpGetSetStateOperationEnable - Indicates that the supplied profiler types
  55. should be enabled. Other currently enabled profiler types' state will
  56. not be changed.
  57. SpGetSetStateOperationDisable - Indicates that the supplied profiler types
  58. should be disabled. Other currently enabled profiler types' state will
  59. not be changed.
  60. --*/
  61. typedef enum _SP_GET_SET_STATE_OPERATION {
  62. SpGetSetStateOperationNone,
  63. SpGetSetStateOperationOverwrite,
  64. SpGetSetStateOperationEnable,
  65. SpGetSetStateOperationDisable,
  66. } SP_GET_SET_STATE_OPERATION, *PSP_GET_SET_STATE_OPERATION;
  67. /*++
  68. Structure Description:
  69. This structure defines the system profiler state to get or set.
  70. Members:
  71. Operation - Stores the get/set state operation to perform. This is ignored
  72. on a request to get system information.
  73. ProfilerTypeFlags - Stores a bitmask of flags indicating which system
  74. profilers are enabled on a get call or which system profilers to
  75. enable, disable, or overwite on a set call. See PROFILER_TYPE_FLAG_*
  76. for definitions.
  77. --*/
  78. typedef struct _SP_GET_SET_STATE_INFORMATION {
  79. SP_GET_SET_STATE_OPERATION Operation;
  80. ULONG ProfilerTypeFlags;
  81. } SP_GET_SET_STATE_INFORMATION, *PSP_GET_SET_STATE_INFORMATION;
  82. typedef
  83. VOID
  84. (*PSP_COLLECT_THREAD_STATISTIC) (
  85. PKTHREAD Thread,
  86. PPROCESSOR_BLOCK Processor,
  87. SCHEDULER_REASON ScheduleOutReason
  88. );
  89. /*++
  90. Routine Description:
  91. This routine collects statistics on a thread that is being scheduled out.
  92. This routine must be called at dispatch level inside the scheduler.
  93. Arguments:
  94. Thread - Supplies a pointer to the thread being scheduled out.
  95. Process - Supplies a pointer to the executing processor block.
  96. ScheduleOutReason - Supplies the reason the thread is being scheduled out.
  97. Return Value:
  98. None.
  99. --*/
  100. typedef
  101. VOID
  102. (*PSP_PROCESS_NEW_PROCESS) (
  103. PROCESS_ID ProcessId
  104. );
  105. /*++
  106. Routine Description:
  107. This routine collects statistics on a created process.
  108. Arguments:
  109. ProcessId - Supplies the ID of the process being created.
  110. Return Value:
  111. None.
  112. --*/
  113. typedef
  114. VOID
  115. (*PSP_PROCESS_NEW_THREAD) (
  116. PROCESS_ID ProcessId,
  117. THREAD_ID ThreadId
  118. );
  119. /*++
  120. Routine Description:
  121. This routine collects statistics on a created thread.
  122. Arguments:
  123. ProcessId - Supplies the ID of the process creating the new thread.
  124. ThreadId - Supplies the ID of the new thread being created.
  125. Return Value:
  126. None.
  127. --*/
  128. //
  129. // -------------------------------------------------------------------- Globals
  130. //
  131. //
  132. // Store a pointer to a function to call to collect thread statistics. This
  133. // function pointer is only set when profiling is active. Callers should not
  134. // access it directly, but use the macro to test and call it.
  135. //
  136. extern PSP_COLLECT_THREAD_STATISTIC SpCollectThreadStatisticRoutine;
  137. extern PSP_PROCESS_NEW_PROCESS SpProcessNewProcessRoutine;
  138. extern PSP_PROCESS_NEW_THREAD SpProcessNewThreadRoutine;
  139. //
  140. // -------------------------------------------------------- Function Prototypes
  141. //
  142. KSTATUS
  143. SpGetSetSystemInformation (
  144. BOOL FromKernelMode,
  145. SP_INFORMATION_TYPE InformationType,
  146. PVOID Data,
  147. PUINTN DataSize,
  148. BOOL Set
  149. );
  150. /*++
  151. Routine Description:
  152. This routine gets or sets system information.
  153. Arguments:
  154. FromKernelMode - Supplies a boolean indicating whether or not this request
  155. (and the buffer associated with it) originates from user mode (FALSE)
  156. or kernel mode (TRUE).
  157. InformationType - Supplies the information type.
  158. Data - Supplies a pointer to the data buffer where the data is either
  159. returned for a get operation or given for a set operation.
  160. DataSize - Supplies a pointer that on input contains the size of the
  161. data buffer. On output, contains the required size of the data buffer.
  162. Set - Supplies a boolean indicating if this is a get operation (FALSE) or
  163. a set operation (TRUE).
  164. Return Value:
  165. Status code.
  166. --*/
  167. VOID
  168. SpProfilerInterrupt (
  169. PTRAP_FRAME TrapFrame
  170. );
  171. /*++
  172. Routine Description:
  173. This routine handles periodic profiler interrupts, collecting information
  174. about the system for analysis.
  175. Arguments:
  176. TrapFrame - Supplies a pointer to the current trap frame.
  177. Return Value:
  178. None.
  179. --*/
  180. VOID
  181. SpSendProfilingData (
  182. VOID
  183. );
  184. /*++
  185. Routine Description:
  186. This routine sends profiling data to any listening consumer. It is called
  187. periodically on each processor during the clock interrupt.
  188. Arguments:
  189. None.
  190. Return Value:
  191. None.
  192. --*/
  193. KSTATUS
  194. SpGetProfilerData (
  195. PPROFILER_NOTIFICATION ProfilerNotification,
  196. PULONG Flags
  197. );
  198. /*++
  199. Routine Description:
  200. This routine fills the provided profiler notification with profiling data.
  201. A profiler consumer should call this routine to obtain data to send over
  202. the wire. It is assumed here that consumers will serialize consumption.
  203. Arguments:
  204. ProfilerNotification - Supplies a pointer to the profiler notification that
  205. is to be filled in with profiling data.
  206. Flags - Supplies a pointer to the types of profiling data the caller wants
  207. to collect. Upon return, the flags for the returned data will be
  208. returned.
  209. Return Value:
  210. Status code.
  211. --*/
  212. ULONG
  213. SpGetProfilerDataStatus (
  214. VOID
  215. );
  216. /*++
  217. Routine Description:
  218. This routine determines if there is profiling data for the current
  219. processor that needs to be sent to a consumer.
  220. Arguments:
  221. None.
  222. Return Value:
  223. Returns a set of flags representing which types of profiling data are
  224. available. Returns zero if nothing is available.
  225. --*/
  226. KSTATUS
  227. SpInitializeProfiler (
  228. VOID
  229. );
  230. /*++
  231. Routine Description:
  232. This routine initializes system profiling at processor start-up. It
  233. extends the profiling infrastructure as each processor comes online. If
  234. early profiling is not enabled, this routine just exits.
  235. Arguments:
  236. None.
  237. Return Value:
  238. Status code.
  239. --*/