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.

175 lines
3.7 KiB

  1. /*++
  2. Copyright (c) 1998-2001 Microsoft Corporation
  3. Module Name:
  4. reftrace.cxx
  5. Abstract:
  6. This module implements a reference count tracing facility.
  7. Author:
  8. Keith Moore (keithmo) 10-Jun-1998
  9. Revision History:
  10. --*/
  11. #include "precomp.h"
  12. #if REFERENCE_DEBUG
  13. /***************************************************************************++
  14. Routine Description:
  15. Creates a new (empty) ref count trace log buffer.
  16. Arguments:
  17. LogSize - Supplies the number of entries in the log.
  18. ExtraBytesInHeader - Supplies the number of extra bytes to include
  19. in the log header. This is useful for adding application-
  20. specific data to the log.
  21. Return Value:
  22. PTRACE_LOG - Pointer to the newly created log if successful,
  23. NULL otherwise.
  24. --***************************************************************************/
  25. PTRACE_LOG
  26. CreateRefTraceLog(
  27. IN ULONG LogSize,
  28. IN ULONG ExtraBytesInHeader
  29. )
  30. {
  31. return CreateTraceLog(
  32. REF_TRACELOG_SIGNATURE,
  33. LogSize,
  34. ExtraBytesInHeader,
  35. sizeof(REF_TRACE_LOG_ENTRY)
  36. );
  37. } // CreateRefTraceLog
  38. /***************************************************************************++
  39. Routine Description:
  40. Destroys a ref count trace log buffer created with CreateRefTraceLog().
  41. Arguments:
  42. pLog - Supplies the ref count trace log buffer to destroy.
  43. --***************************************************************************/
  44. VOID
  45. DestroyRefTraceLog(
  46. IN PTRACE_LOG pLog
  47. )
  48. {
  49. DestroyTraceLog( pLog );
  50. } // DestroyRefTraceLog
  51. /***************************************************************************++
  52. Routine Description:
  53. W/O destroying the ref trace this function simply does reset and cleanup.
  54. Arguments:
  55. pLog - Supplies the ref count trace log buffer to destroy.
  56. --***************************************************************************/
  57. VOID
  58. ResetRefTraceLog(
  59. IN PTRACE_LOG pLog
  60. )
  61. {
  62. ResetTraceLog( pLog );
  63. } // ResetTraceLog
  64. /***************************************************************************++
  65. Routine Description:
  66. Writes a new entry to the specified ref count trace log.
  67. Arguments:
  68. pLog - Supplies the log to write to.
  69. pLog2 - Supplies a secondary log to write to.
  70. Action - Supplies an action code for the new log entry.
  71. NewRefCount - Supplies the updated reference count.
  72. pContext - Supplies an uninterpreted context to associate with
  73. the log entry.
  74. pFileName - Supplies the filename of the routine writing the log entry.
  75. LineNumber - Supplies he line number of the routine writing the log
  76. entry.
  77. --***************************************************************************/
  78. LONGLONG
  79. WriteRefTraceLog(
  80. IN PTRACE_LOG pLog,
  81. IN PTRACE_LOG pLog2,
  82. IN USHORT Action,
  83. IN LONG NewRefCount,
  84. IN PVOID pContext,
  85. IN PVOID pFileName,
  86. IN USHORT LineNumber
  87. )
  88. {
  89. REF_TRACE_LOG_ENTRY entry;
  90. LONGLONG index;
  91. ASSERT(Action < (1 << REF_TRACE_ACTION_BITS));
  92. //
  93. // Initialize the entry.
  94. //
  95. RtlGetCallersAddress( &entry.pCaller, &entry.pCallersCaller );
  96. entry.NewRefCount = NewRefCount;
  97. entry.pContext = pContext;
  98. entry.pFileName = pFileName;
  99. entry.LineNumber = LineNumber;
  100. entry.Action = Action;
  101. entry.Processor = (UCHAR)KeGetCurrentProcessorNumber();
  102. entry.pProcess = PsGetCurrentProcess();
  103. entry.pThread = PsGetCurrentThread();
  104. //
  105. // Write it to the logs.
  106. //
  107. WriteTraceLog( g_pMondoGlobalTraceLog, &entry );
  108. index = WriteTraceLog( pLog, &entry );
  109. if (pLog2 != NULL)
  110. index = WriteTraceLog( pLog2, &entry );
  111. return index;
  112. } // WriteRefTraceLog
  113. #endif // REFERENCE_DEBUG