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.

179 lines
7.2 KiB

  1. //---------------------------------------------------------------------------
  2. // log.h - theme logging routines
  3. //---------------------------------------------------------------------------
  4. #pragma once
  5. //---------------------------------------------------------------------------
  6. #ifndef LOG_H
  7. #define LOG_H
  8. //---------------------------------------------------------------------------
  9. #include "logopts.h" // log options as enums
  10. //---------------------------------------------------------------------------
  11. #ifdef DEBUG
  12. #define LOGGING 1
  13. #endif
  14. //-----------------------------------------------------------------
  15. //---- set this to "GetMemUsage", "GetUserCount", or "GetGdiCount" ----
  16. //---- it controls which resource is tracked across entry/exit calls ----
  17. #define ENTRY_EXIT_FUNC GetGdiCount()
  18. #define ENTRY_EXIT_NAME L"GdiCount()"
  19. //-----------------------------------------------------------------
  20. // Note:
  21. // For builds without DEBUG defined (FRE builds), calling
  22. // code will reference an underscore version of all public
  23. // logging routines (_xxx()). These functions are defined
  24. // as inline with little or no code (no code means no caller
  25. // code is generated).
  26. //
  27. // For DEBUG defined (CHK) builds, the calling code connects
  28. // with the normally named logging routines.
  29. //
  30. // This is done to keep calling code to a minimum for FRE
  31. // builds, to avoid LOG2(), LOG3() type defines that vary
  32. // with param count, and to keep build system happy when
  33. // mixing FRE and CHK callers and libraries.
  34. //-----------------------------------------------------------------
  35. //---- these are used for CHK builds only but must be defined for both ----
  36. void Log(UCHAR uLogOption, LPCSTR pszSrcFile, int iLineNum, int iEntryCode, LPCWSTR pszFormat, ...);
  37. BOOL LogStartUp();
  38. BOOL LogShutDown();
  39. void LogControl(LPCSTR pszOptions, BOOL fEcho);
  40. void TimeToStr(UINT uRaw, WCHAR *pszBuff, ULONG cchBuff);
  41. DWORD StartTimer();
  42. DWORD StopTimer(DWORD dwStartTime);
  43. HRESULT OpenLogFile(LPCWSTR pszLogFileName);
  44. void CloseLogFile();
  45. int GetMemUsage();
  46. int GetUserCount();
  47. int GetGdiCount();
  48. BOOL LogOptionOn(int iLogOption);
  49. //-----------------------------------------------------------------
  50. #ifdef LOGGING
  51. #define LogEntry(pszFunc) \
  52. LOGENTRYCODE; Log(LO_TMAPI, LOGPARAMS, 1, L"%s ENTRY (%s=%d)", pszFunc, \
  53. ENTRY_EXIT_NAME, _iEntryValue);
  54. #define LogEntryC(pszFunc, pszClass) \
  55. LOGENTRYCODE; Log(LO_TMAPI, LOGPARAMS, 1, L"%s ENTRY, class=%s (%s=%d)", \
  56. pszFunc, pszClass, ENTRY_EXIT_NAME, _iEntryValue);
  57. #define LogEntryW(pszFunc) \
  58. LOGENTRYCODEW; Log(LO_TMAPI, LOGPARAMS, 1, L"%s ENTRY (%s=%d)", pszFunc, \
  59. ENTRY_EXIT_NAME, _iEntryValue);
  60. #define LogEntryCW(pszFunc, pszClass) \
  61. LOGENTRYCODEW; Log(LO_TMAPI, LOGPARAMS, 1, L"%s ENTRY, class=%s (%s=%d)", \
  62. pszFunc, pszClass, ENTRY_EXIT_NAME, _iEntryValue);
  63. #define LogEntryNC(pszFunc) \
  64. LOGENTRYCODE; Log(LO_NCTRACE, LOGPARAMS, 1, L"%s ENTRY (%s=%d)", \
  65. pszFunc, ENTRY_EXIT_NAME, _iEntryValue);
  66. #define LogEntryMsg(pszFunc, hwnd, umsg) \
  67. LOGENTRYCODE; Log(LO_NCMSGS, LOGPARAMS, 1, L"%s ENTRY (hwnd=0x%x, umsg=0x%x, %s=%d)", \
  68. pszFunc, hwnd, umsg, ENTRY_EXIT_NAME, _iEntryValue);
  69. #define LogExit(pszFunc) LOGEXIT(pszFunc, LO_TMAPI)
  70. #define LogExitC(pszFunc, cls) LOGEXITCLS(pszFunc, LO_TMAPI, cls)
  71. #define LogExitNC(pszFunc) LOGEXIT(pszFunc, LO_NCTRACE)
  72. #define LogExitMsg(pszFunc) LOGEXIT(pszFunc, LO_NCMSGS)
  73. #define LOGEXIT(pszFunc, filter) \
  74. { \
  75. LOGEXITCODE; \
  76. if (_iEntryValue != _ExitValue) \
  77. Log(filter, LOGPARAMS, -1, L"%s EXIT [%s delta: %d]", pszFunc, ENTRY_EXIT_NAME, _ExitValue-_iEntryValue); \
  78. else \
  79. Log(filter, LOGPARAMS, -1, L"%s EXIT", pszFunc); \
  80. }
  81. #define LOGEXITCLS(pszFunc, filter, cls) \
  82. { \
  83. LOGEXITCODE; \
  84. if (_iEntryValue != _ExitValue) \
  85. Log(filter, LOGPARAMS, -1, L"%s EXIT, class=%s [%s delta: %d]", pszFunc, cls, ENTRY_EXIT_NAME, _ExitValue-_iEntryValue); \
  86. else \
  87. Log(filter, LOGPARAMS, -1, L"%s EXIT, class=%s", pszFunc, cls); \
  88. }
  89. #ifndef _X86_
  90. #define DEBUG_BREAK if (LogOptionOn(LO_BREAK)) DebugBreak(); else
  91. #else
  92. #define DEBUG_BREAK if (LogOptionOn(LO_BREAK)) __asm {int 3} else
  93. #endif
  94. //---- change this when you want to track something different for entry/exit ----
  95. #define LOGENTRYCODE int _iEntryValue = ENTRY_EXIT_FUNC
  96. #define LOGENTRYCODEW _iEntryValue = ENTRY_EXIT_FUNC
  97. #define LOGEXITCODE int _ExitValue = ENTRY_EXIT_FUNC
  98. #else
  99. //---- for FRE builds, connect to the inline routines ----
  100. #define Log _Log
  101. #define LogStartUp _LogStartUp
  102. #define LogShutDown _LogShutDown
  103. #define LogControl _LogControl
  104. #define TimeToStr _TimeToStr
  105. #define StartTimer _StartTimer
  106. #define StopTimer _StopTimer
  107. #define OpenLogFile _OpenLogFile
  108. #define CloseLogFile _CloseLogFile
  109. #define LogOptionOn _LogOptionOn
  110. #define GetMemUsage _GetMemUsage
  111. #define GetUserCount _GetUserCount
  112. #define GetGdiCount _GetGdiCount
  113. #define LogEntry(pszFunc)
  114. #define LogEntryC(pszFunc, pszClass)
  115. #define LogEntryW(pszFunc)
  116. #define LogEntryCW(pszFunc, pszClass)
  117. #define LogExit(pszFunc)
  118. #define LogExitC(pszFunc, pszClass)
  119. #define LogExitW(pszFunc, pszClass)
  120. #define LogEntryNC(pszFunc)
  121. #define LogExitNC(pszFunc)
  122. #define LogEntryMsg(pszFunc, hwnd, umsg)
  123. #define LogExitMsg(x)
  124. #define DEBUG_BREAK (0)
  125. //---- for FRE builds, make these guys gen no or minimum code ----
  126. inline void _Log(UCHAR uLogOption, LPCSTR pszSrcFile, int iLineNum, int iEntryExitCode, LPCWSTR pszFormat, ...) {}
  127. inline BOOL _LogStartUp() {return TRUE;}
  128. inline BOOL _LogShutDown() {return TRUE;}
  129. inline void _LogControl(LPCSTR pszOptions, BOOL fEcho) {}
  130. inline void _TimeToStr(UINT uRaw, WCHAR *pszBuff, ULONG cchBuf) {}
  131. inline DWORD _StartTimer() {return 0;}
  132. inline DWORD _StopTimer(DWORD dwStartTime) {return 0;}
  133. inline HRESULT _OpenLogFile(LPCWSTR pszLogFileName) {return E_NOTIMPL;}
  134. inline void _CloseLogFile() {}
  135. inline BOOL _LogOptionOn(int iIndex) {return FALSE;}
  136. inline BOOL _pszClassName(int iIndex) {return FALSE;}
  137. inline int GetMemUsage() {return 0;}
  138. inline int GetUserCount() {return 0;}
  139. inline int GetGdiCount() {return 0;}
  140. #endif
  141. //---------------------------------------------------------------------------
  142. #undef ASSERT
  143. #define ATLASSERT(exp) _ASSERTE(exp)
  144. #define ASSERT(exp) _ASSERTE(exp)
  145. #define _ATL_NO_DEBUG_CRT
  146. //---------------------------------------------------------------------------
  147. #ifdef LOGGING
  148. # ifndef _ASSERTE
  149. # define _ASSERTE(exp) if (! (exp)) { Log(LOG_ASSERT, L#exp); DEBUG_BREAK; } else
  150. # endif _ASSERTE
  151. # define CLASSPTR(x) ((x) ? ((CRenderObj *)x)->_pszClassName : L"")
  152. # define SHARECLASS(x) (LPCWSTR)x->_pszClassName
  153. #else
  154. # ifndef _ASSERTE
  155. # define _ASSERTE(exp) (0)
  156. # endif _ASSERTE
  157. # define CLASSPTR(x) NULL
  158. # define SHARECLASS(x) NULL
  159. #endif
  160. //---------------------------------------------------------------------------
  161. #endif