LeakReport.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. char16 const * url;
  18. #if _MSC_VER
  19. __time64_t time;
  20. #else
  21. time_t time;
  22. #endif
  23. DWORD tid;
  24. UrlRecord * next;
  25. void * globalObject;
  26. friend class LeakReport;
  27. };
  28. static void StartRedirectOutput();
  29. static void EndRedirectOutput();
  30. static void StartSection(char16 const * msg, ...);
  31. static void StartSection(char16 const * msg, va_list argptr);
  32. static void EndSection();
  33. static void Print(char16 const * msg, ...);
  34. static UrlRecord * LogUrl(char16 const * url, void * globalObject);
  35. static void DumpUrl(DWORD tid);
  36. private:
  37. static CriticalSection s_cs;
  38. static AutoFILE file;
  39. static bool openReportFileFailed;
  40. static DWORD nestedSectionCount;
  41. static DWORD nestedRedirectOutputCount;
  42. static UrlRecord * urlRecordHead;
  43. static UrlRecord * urlRecordTail;
  44. static bool EnsureLeakReportFile();
  45. };
  46. class AutoLeakReportSection
  47. {
  48. public:
  49. AutoLeakReportSection(Js::ConfigFlagsTable& flags, char16 const * msg, ...);
  50. ~AutoLeakReportSection();
  51. private:
  52. Js::ConfigFlagsTable& m_flags;
  53. };
  54. #define STRINGIFY2(x,y) x ## y
  55. #define STRINGIFY(x,y) STRINGIFY2(x,y)
  56. #define LEAK_REPORT_PRINT(msg, ...) if (Js::Configuration::Global.flags.IsEnabled(Js::LeakReportFlag)) LeakReport::Print(msg, __VA_ARGS__)
  57. #define AUTO_LEAK_REPORT_SECTION(flags, msg, ...) AutoLeakReportSection STRINGIFY(__autoLeakReportSection, __COUNTER__)(flags, msg, __VA_ARGS__)
  58. #define AUTO_LEAK_REPORT_SECTION_0(flags, msg) AutoLeakReportSection STRINGIFY(__autoLeakReportSection, __COUNTER__)(flags, msg, "")
  59. #else
  60. #define LEAK_REPORT_PRINT(msg, ...)
  61. #define AUTO_LEAK_REPORT_SECTION(flags, msg, ...)
  62. #define AUTO_LEAK_REPORT_SECTION_0(flags, msg)
  63. #endif
  64. }