All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
MemoryMonitor.h
1 #pragma once
2 
3 #include <fstream>
4 #include <string>
5 
6 #include "SpinLock.h"
7 
8 namespace Eegeo
9 {
10  namespace Helpers
11  {
12  class IFileIO;
13  };
14 
15  class ThreadMemoryMonitor;
16  struct AllocationRecord;
17 
19  {
20  public:
21 
22  MemoryMonitor();
23 
24  void RegisterThreadMonitor(ThreadMemoryMonitor* monitor);
25  void UnregisterThreadMonitor(ThreadMemoryMonitor* monitor);
26 
27  bool RemoveAllocationRecordFromDifferentThread(ThreadMemoryMonitor* excludedMonitor, AllocationRecord* record);
28  bool FindAllocationRecordFromDifferentThread(ThreadMemoryMonitor* excludedMonitor, AllocationRecord* record);
29 
30  uint64_t GenerateNextAllocationIndex();
31 
32  static ThreadMemoryMonitor& GetMemoryMonitorForThread();
33  static MemoryMonitor& GetGlobalMemoryMonitor();
34 
35  void Report(Eegeo::Helpers::IFileIO& fileIO, const char* outputPath);
36 
37  private:
38 
39 #if defined(EEGEO_WIN)
40  volatile LONGLONG m_allocationIndexGenerator;
41 #else
42  volatile int64_t m_allocationIndexGenerator;
43 #endif
44  ThreadMemoryMonitor* m_firstThreadMonitor;
45  Eegeo::SpinLock m_globalLock;
46  };
47 };