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.

140 lines
3.3 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. strlog.hxx
  5. Abstract:
  6. This module contains public declarations and definitions for printing
  7. strings to a tracelog. This module uses the generic TRACE_LOG facility
  8. in tracelog.h.
  9. String trace logs are useful for debugging race conditions. They're
  10. faster than DBG_PRINTF (which writes to the debugger and/or a log file)
  11. and they don't cause context swaps. However, they're also clunkier
  12. than DBG_PRINTF.
  13. String trace logs can be dumped via the !inetdbg.st command
  14. in either NTSD or CDB.
  15. Author:
  16. George V. Reilly (GeorgeRe) 22-Jun-1998
  17. Revision History:
  18. --*/
  19. #ifndef _STRLOG_HXX_
  20. #define _STRLOG_HXX_
  21. #include <tracelog.h>
  22. # if !defined( dllexp)
  23. # define dllexp __declspec( dllexport)
  24. # endif // !defined( dllexp)
  25. // To use CStringTraceLog, something like the following is suggested
  26. //
  27. // #ifdef FOOBAR_STRING_TRACE_LOG
  28. // # include <strlog.hxx>
  29. // # define FOOBAR_STL_PRINTF m_stl.Printf
  30. // # define FOOBAR_STL_PUTS(s) m_stl.Puts(s)
  31. // #else // !FOOBAR_STRING_TRACE_LOG
  32. // # define FOOBAR_STL_PRINTF ((void) 0) /* compiles to nothing */
  33. // # define FOOBAR_STL_PUTS(s) ((void) 0) /* compiles to nothing */
  34. // #endif // !FOOBAR_STRING_TRACE_LOG
  35. //
  36. // class CFooBar
  37. // {
  38. // // ... whatever
  39. // #ifdef FOOBAR_STRING_TRACE_LOG
  40. // CStringTraceLog m_stl;
  41. // #endif
  42. // };
  43. //
  44. // CFooBar::FooBar()
  45. // : m_foo( NULL ),
  46. // m_bar( 17.23 ),
  47. // #ifdef FOOBAR_STRING_TRACE_LOG
  48. // , m_stl(100, 1000)
  49. // #endif
  50. // { /* whatever */ }
  51. //
  52. // void CFooBar::Method(int n, const char* psz)
  53. // {
  54. // FOOBAR_STL_PRINTF("Method(%d, %s)", n, psz);
  55. // // etc
  56. // }
  57. class dllexp CStringTraceLog
  58. {
  59. public:
  60. enum {
  61. MIN_CCH = 16, MAX_CCH = 2048,
  62. };
  63. CStringTraceLog(
  64. UINT cchEntrySize = 80,
  65. UINT cLogSize = 100);
  66. ~CStringTraceLog();
  67. // Writes a %-formatted string to the log. Returns the index of the
  68. // entry within the tracelog.
  69. LONG __cdecl
  70. Printf(
  71. LPCSTR pszFormat,
  72. ...);
  73. // Preferred when no formatting is needed, as it's much faster than
  74. // Printf. Returns the index of the entry within the tracelog.
  75. LONG
  76. Puts(
  77. LPCSTR psz);
  78. // Empties the log.
  79. void
  80. ResetLog();
  81. private:
  82. enum {
  83. SIGNATURE = 'glTS',
  84. SIGNATURE_X = 'XlTS',
  85. };
  86. class CLogEntry
  87. {
  88. public:
  89. CLogEntry()
  90. {
  91. ::QueryPerformanceCounter(&m_liTimeStamp);
  92. m_nThread = ::GetCurrentThreadId();
  93. m_ach[0] = '\0';
  94. }
  95. LARGE_INTEGER m_liTimeStamp; // unique high-resolution timestamp
  96. DWORD m_nThread; // Writing thread
  97. CHAR m_ach[MAX_CCH]; // only use m_cch chars of this string
  98. };
  99. // Private, unimplemented copy ctor and op= to prevent
  100. // compiler synthesizing them.
  101. CStringTraceLog(const CStringTraceLog&);
  102. CStringTraceLog& operator=(const CStringTraceLog&);
  103. LONG m_Signature;
  104. UINT m_cch;
  105. PTRACE_LOG m_ptlog;
  106. };
  107. #endif // _STRLOG_HXX_