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.

84 lines
3.1 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996.
  5. //
  6. // File: tracer.hxx
  7. //
  8. // Contents: A class which logs messages to a temporary trace file. The user
  9. // may view the previous n entries in the trace file and send them
  10. // to a permanent file if he/she wishes.
  11. //
  12. // Classes: CTracer
  13. //
  14. // Functions:
  15. //
  16. // Coupling:
  17. //
  18. // Notes: The maximum size for a trace file is 5MB. Any writes to the
  19. // file after it reaces the limit are ignored. This class maps a
  20. // view of the entire trace file into the process' address space.
  21. // This places an upper limit on the number of trace objects
  22. // existing simultaneously in a single process to 4GB / 5MB, or
  23. // about 800.
  24. //
  25. // History: 10-28-1996 ericne Created
  26. //
  27. //----------------------------------------------------------------------------
  28. #ifndef _CTRACER
  29. #define _CTRACER
  30. #include <windows.h>
  31. #include <tchar.h>
  32. #include "autohndl.hxx"
  33. const DWORD dwMaxFileSize = 0x0500000; // Trace file cannot exceed 5 megs
  34. const DWORD dwMaxCharsInFile = dwMaxFileSize / sizeof( TCHAR );
  35. const TCHAR tcsEndOfEntry = _T('\0');
  36. //+---------------------------------------------------------------------------
  37. //
  38. // Class: CTracer ()
  39. //
  40. // Purpose:
  41. //
  42. // Interface: CTracer -- Default member initialization
  43. // ~CTracer -- Closes handles
  44. // Init -- Creates temp file and memory-maps it
  45. // Trace -- Adds an entry into the trace file
  46. // Dump -- Sends the previous n entries to a file stream
  47. // Interact -- Interactive dialog with the user
  48. // Clear -- Flush the contents of the trace file
  49. // m_hTempFile -- handle to the temp file (DELETE_ON_CLOSE)
  50. // m_hMappedFile -- handle to the file mapping
  51. // m_tcsFileStart -- pointer to the start mapped view
  52. // m_dwPut -- put index
  53. // m_dwGet -- get index
  54. //
  55. // History: 10-29-1996 ericne Created
  56. //
  57. // Notes:
  58. //
  59. //----------------------------------------------------------------------------
  60. class CTracer
  61. {
  62. public:
  63. CTracer();
  64. virtual ~CTracer( );
  65. BOOL Init( ); // creates temp file and maps it
  66. void Trace( LPCTSTR, ... ); // format string, variable args
  67. void Dump( FILE*, int ); // sink, nbr entries to display
  68. void Interact( ); // Interactive dialog with the user
  69. void Clear( ); // Empties the trace file
  70. private:
  71. CFileHandle m_hTempFile; // CreateFile
  72. CAutoHandle m_hMappedFile; // CreateFileMapping
  73. LPTSTR m_tcsFileStart; // MapViewOfFile
  74. DWORD m_dwPut;
  75. DWORD m_dwGet;
  76. };
  77. #endif