All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ThreadMemoryMonitor.h
1 #pragma once
2 
3 #include "AllocationHashTable.h"
4 #include "SpinLock.h"
5 #include "TagStack.h"
6 
7 #include <fstream>
8 
9 namespace Eegeo
10 {
11  class MemoryMonitor;
12 
14  {
15  public:
16 
17  ThreadMemoryMonitor(MemoryMonitor& memoryMonitor);
19 
20  void PushTag(const char* tag);
21  void PopTag();
22  void AddAllocationRecord(AllocationRecord* record);
23  bool RemoveAllocationRecord(AllocationRecord* record, bool canFallBackToGlobal = true);
24  bool FindAllocationRecord(AllocationRecord* record, bool canFallBackToGlobal = true);
25  void AnnotateAllocation(void* allocation, const char* type, const char* file, int line, int elementCount);
26  void DumpAllocationsToCSV(std::fstream& writer);
27  void SetNext(ThreadMemoryMonitor* next) { m_next = next; }
28  ThreadMemoryMonitor* GetNext() { return m_next; }
29 
30  void PauseTracking() { m_trackingPaused = true; }
31  void ResumeTracking() { m_trackingPaused = false; }
32  bool IsTrackingPaused() const { return m_trackingPaused; }
33 
34  private:
35 
36  ThreadMemoryMonitor* m_next;
37  void* m_threadId;
38  Eegeo::SpinLock m_lock;
39  bool m_trackingPaused;
40 
41  MemoryMonitor& m_memoryMonitor;
42  typedef TagStack<32> MemTagStack;
43  MemTagStack m_tags;
44  size_t m_totalBytesAllocatedOnThread;
45  AllocationHashTable m_allocations;
46  };
47 };