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.

147 lines
3.0 KiB

  1. /*++
  2. Copyright (c) 2000-2001 Microsoft Corporation
  3. Module Name:
  4. timetrace.cxx
  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. #pragma warning( disable : 4035 ) // Warning : No return value
  14. #pragma warning( disable : 4142 ) // Warning : benign redefinition of type
  15. __inline ULONGLONG RDTSC( VOID )
  16. {
  17. #if defined(_X86_)
  18. __asm __emit 0x0F __asm __emit 0xA2 // CPUID (memory barrier)
  19. __asm __emit 0x0F __asm __emit 0x31 // RDTSC
  20. #else
  21. return 0;
  22. #endif
  23. }
  24. #pragma warning( default : 4035 )
  25. #pragma warning( default : 4142 )
  26. /***************************************************************************++
  27. Routine Description:
  28. Creates a new (empty) time trace log buffer.
  29. Arguments:
  30. LogSize - Supplies the number of entries in the log.
  31. ExtraBytesInHeader - Supplies the number of extra bytes to include
  32. in the log header. This is useful for adding application-
  33. specific data to the log.
  34. Return Value:
  35. PTRACE_LOG - Pointer to the newly created log if successful,
  36. NULL otherwise.
  37. --***************************************************************************/
  38. PTRACE_LOG
  39. CreateTimeTraceLog(
  40. IN LONG LogSize,
  41. IN LONG ExtraBytesInHeader
  42. )
  43. {
  44. return CreateTraceLog(
  45. TIME_TRACE_LOG_SIGNATURE,
  46. LogSize,
  47. ExtraBytesInHeader,
  48. sizeof(TIME_TRACE_LOG_ENTRY)
  49. );
  50. } // CreateTimeTraceLog
  51. /***************************************************************************++
  52. Routine Description:
  53. Destroys a time trace log buffer created with CreateTimeTraceLog().
  54. Arguments:
  55. pLog - Supplies the time trace log buffer to destroy.
  56. --***************************************************************************/
  57. VOID
  58. DestroyTimeTraceLog(
  59. IN PTRACE_LOG pLog
  60. )
  61. {
  62. DestroyTraceLog( pLog );
  63. } // DestroyTimeTraceLog
  64. /***************************************************************************++
  65. Routine Description:
  66. Writes a new entry to the specified time trace log.
  67. Arguments:
  68. pLog - Supplies the log to write to.
  69. ConnectionId - the id of the connection we're tracing
  70. RequestId - the id of the request we're tracing
  71. Action - Supplies an action code for the new log entry.
  72. --***************************************************************************/
  73. VOID
  74. WriteTimeTraceLog(
  75. IN PTRACE_LOG pLog,
  76. IN HTTP_CONNECTION_ID ConnectionId,
  77. IN HTTP_REQUEST_ID RequestId,
  78. IN USHORT Action
  79. )
  80. {
  81. TIME_TRACE_LOG_ENTRY entry;
  82. //
  83. // Initialize the entry.
  84. //
  85. // entry.TimeStamp = KeQueryInterruptTime();
  86. entry.TimeStamp = RDTSC();
  87. entry.ConnectionId = ConnectionId;
  88. entry.RequestId = RequestId;
  89. entry.Action = Action;
  90. entry.Processor = (USHORT)KeGetCurrentProcessorNumber();
  91. //
  92. // Write it to the logs.
  93. //
  94. WriteTraceLog( pLog, &entry );
  95. } // WriteTimeTraceLog
  96. #endif // ENABLE_TIME_TRACE