LeakReport.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #pragma once
  6. namespace Memory
  7. {
  8. #ifdef LEAK_REPORT
  9. class LeakReport
  10. {
  11. public:
  12. class UrlRecord
  13. {
  14. public:
  15. void * scriptEngine;
  16. private:
  17. wchar_t const * url;
  18. time_t time;
  19. DWORD tid;
  20. UrlRecord * next;
  21. void * globalObject;
  22. friend class LeakReport;
  23. };
  24. static void StartRedirectOutput();
  25. static void EndRedirectOutput();
  26. static void StartSection(wchar_t const * msg, ...);
  27. static void StartSection(wchar_t const * msg, va_list argptr);
  28. static void EndSection();
  29. static void Print(wchar_t const * msg, ...);
  30. static UrlRecord * LogUrl(wchar_t const * url, void * globalObject);
  31. static void DumpUrl(DWORD tid);
  32. private:
  33. static CriticalSection s_cs;
  34. static AutoFILE file;
  35. static bool openReportFileFailed;
  36. static DWORD nestedSectionCount;
  37. static DWORD nestedRedirectOutputCount;
  38. static UrlRecord * urlRecordHead;
  39. static UrlRecord * urlRecordTail;
  40. static bool EnsureLeakReportFile();
  41. };
  42. class AutoLeakReportSection
  43. {
  44. public:
  45. AutoLeakReportSection(Js::ConfigFlagsTable& flags, wchar_t const * msg, ...);
  46. ~AutoLeakReportSection();
  47. private:
  48. Js::ConfigFlagsTable& m_flags;
  49. };
  50. #define STRINGIFY2(x,y) x ## y
  51. #define STRINGIFY(x,y) STRINGIFY2(x,y)
  52. #define LEAK_REPORT_PRINT(msg, ...) if (Js::Configuration::Global.flags.IsEnabled(Js::LeakReportFlag)) LeakReport::Print(msg, __VA_ARGS__)
  53. #define AUTO_LEAK_REPORT_SECTION(flags, msg, ...) AutoLeakReportSection STRINGIFY(__autoLeakReportSection, __COUNTER__)(flags, msg, __VA_ARGS__)
  54. #define AUTO_LEAK_REPORT_SECTION_0(flags, msg) AutoLeakReportSection STRINGIFY(__autoLeakReportSection, __COUNTER__)(flags, msg, "")
  55. #else
  56. #define LEAK_REPORT_PRINT(msg, ...)
  57. #define AUTO_LEAK_REPORT_SECTION(flags, msg, ...)
  58. #define AUTO_LEAK_REPORT_SECTION_0(flags, msg)
  59. #endif
  60. }