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.

262 lines
5.9 KiB

  1. /*++
  2. Copyright (c) 2000-2002 Microsoft Corporation
  3. Module Name:
  4. timetrace.c
  5. Abstract:
  6. This module implements a request timing tracing facility.
  7. Author:
  8. Michael Courage (mcourage) 8-Mar-2000
  9. Revision History:
  10. --*/
  11. #include "precomp.h"
  12. #if !ENABLE_TIME_TRACE
  13. static int g_TimeTraceDummyDeclarationToKeepW4WarningsQuiet;
  14. #else
  15. #pragma warning( disable : 4035 ) // Warning : No return value
  16. #pragma warning( disable : 4142 ) // Warning : benign redefinition of type
  17. __inline ULONGLONG RDTSC( VOID )
  18. {
  19. #if defined(_X86_)
  20. __asm __emit 0x0F __asm __emit 0xA2 // CPUID (memory barrier)
  21. __asm __emit 0x0F __asm __emit 0x31 // RDTSC
  22. #else
  23. return 0;
  24. #endif
  25. }
  26. #pragma warning( default : 4035 )
  27. #pragma warning( default : 4142 )
  28. /***************************************************************************++
  29. Routine Description:
  30. Creates a new (empty) time trace log buffer.
  31. Arguments:
  32. LogSize - Supplies the number of entries in the log.
  33. ExtraBytesInHeader - Supplies the number of extra bytes to include
  34. in the log header. This is useful for adding application-
  35. specific data to the log.
  36. Return Value:
  37. PTRACE_LOG - Pointer to the newly created log if successful,
  38. NULL otherwise.
  39. --***************************************************************************/
  40. PTRACE_LOG
  41. CreateTimeTraceLog(
  42. IN LONG LogSize,
  43. IN LONG ExtraBytesInHeader
  44. )
  45. {
  46. return CreateTraceLog(
  47. TIME_TRACE_LOG_SIGNATURE,
  48. LogSize,
  49. ExtraBytesInHeader,
  50. sizeof(TIME_TRACE_LOG_ENTRY),
  51. TRACELOG_HIGH_PRIORITY,
  52. UL_REF_TRACE_LOG_POOL_TAG
  53. );
  54. } // CreateTimeTraceLog
  55. /***************************************************************************++
  56. Routine Description:
  57. Destroys a time trace log buffer created with CreateTimeTraceLog().
  58. Arguments:
  59. pLog - Supplies the time trace log buffer to destroy.
  60. --***************************************************************************/
  61. VOID
  62. DestroyTimeTraceLog(
  63. IN PTRACE_LOG pLog
  64. )
  65. {
  66. DestroyTraceLog( pLog, UL_REF_TRACE_LOG_POOL_TAG );
  67. } // DestroyTimeTraceLog
  68. /***************************************************************************++
  69. Routine Description:
  70. Writes a new entry to the specified time trace log.
  71. Arguments:
  72. pLog - Supplies the log to write to.
  73. ConnectionId - the id of the connection we're tracing
  74. RequestId - the id of the request we're tracing
  75. Action - Supplies an action code for the new log entry.
  76. --***************************************************************************/
  77. VOID
  78. WriteTimeTraceLog(
  79. IN PTRACE_LOG pLog,
  80. IN HTTP_CONNECTION_ID ConnectionId,
  81. IN HTTP_REQUEST_ID RequestId,
  82. IN USHORT Action
  83. )
  84. {
  85. TIME_TRACE_LOG_ENTRY entry;
  86. //
  87. // Initialize the entry.
  88. //
  89. // entry.TimeStamp = KeQueryInterruptTime();
  90. entry.TimeStamp = RDTSC();
  91. entry.ConnectionId = ConnectionId;
  92. entry.RequestId = RequestId;
  93. entry.Action = Action;
  94. entry.Processor = (USHORT)KeGetCurrentProcessorNumber();
  95. //
  96. // Write it to the logs.
  97. //
  98. WriteTraceLog( pLog, &entry );
  99. } // WriteTimeTraceLog
  100. #endif // ENABLE_TIME_TRACE
  101. #if ENABLE_APP_POOL_TIME_TRACE
  102. /***************************************************************************++
  103. Routine Description:
  104. Creates a new (empty) time trace log buffer.
  105. Arguments:
  106. LogSize - Supplies the number of entries in the log.
  107. ExtraBytesInHeader - Supplies the number of extra bytes to include
  108. in the log header. This is useful for adding application-
  109. specific data to the log.
  110. Return Value:
  111. PTRACE_LOG - Pointer to the newly created log if successful,
  112. NULL otherwise.
  113. --***************************************************************************/
  114. PTRACE_LOG
  115. CreateAppPoolTimeTraceLog(
  116. IN LONG LogSize,
  117. IN LONG ExtraBytesInHeader
  118. )
  119. {
  120. return
  121. CreateTraceLog(
  122. APP_POOL_TIME_TRACE_LOG_SIGNATURE,
  123. LogSize,
  124. ExtraBytesInHeader,
  125. sizeof(APP_POOL_TIME_TRACE_LOG_ENTRY),
  126. TRACELOG_HIGH_PRIORITY,
  127. UL_REF_TRACE_LOG_POOL_TAG
  128. );
  129. } // CreateTimeTraceLog
  130. /***************************************************************************++
  131. Routine Description:
  132. Destroys a time trace log buffer created with CreateTimeTraceLog().
  133. Arguments:
  134. pLog - Supplies the time trace log buffer to destroy.
  135. --***************************************************************************/
  136. VOID
  137. DestroyAppPoolTimeTraceLog(
  138. IN PTRACE_LOG pLog
  139. )
  140. {
  141. DestroyTraceLog( pLog, UL_REF_TRACE_LOG_POOL_TAG );
  142. } // DestroyTimeTraceLog
  143. /***************************************************************************++
  144. Routine Description:
  145. Writes a new entry to the specified time trace log.
  146. Arguments:
  147. pLog - Supplies the log to write to.
  148. - App Pool
  149. - App Pool Process
  150. Action - Supplies an action code for the new log entry.
  151. --***************************************************************************/
  152. VOID
  153. WriteAppPoolTimeTraceLog(
  154. IN PTRACE_LOG pLog,
  155. IN PVOID Context1, // Appool
  156. IN PVOID Context2, // Appool Process
  157. IN USHORT Action
  158. )
  159. {
  160. APP_POOL_TIME_TRACE_LOG_ENTRY entry;
  161. //
  162. // Initialize the entry.
  163. //
  164. entry.TimeStamp = KeQueryInterruptTime();
  165. entry.Context1 = Context1;
  166. entry.Context2 = Context2;
  167. entry.Action = Action;
  168. entry.Processor = (USHORT)KeGetCurrentProcessorNumber();
  169. //
  170. // Write it to the logs.
  171. //
  172. WriteTraceLog( pLog, &entry );
  173. } // WriteTimeTraceLog
  174. #endif // ENABLE_APP_POOL_TIME_TRACE