Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
alloctracker.h
Go to the documentation of this file.
1 
18 #ifndef ION_BASE_ALLOCTRACKER_H_
19 #define ION_BASE_ALLOCTRACKER_H_
20 
25 
27 #define ION_ALLOC_TRACKER_DEFINED 1
28 
31 #if defined(__cplusplus)
32 
33 #include <memory>
34 #include <new>
35 
36 #include "base/integral_types.h"
37 
38 namespace ion {
39 namespace base {
40 
45 class ION_API AllocTracker {
46  public:
48  enum AllocType {
49  kNonArrayAlloc, // Allocations using new.
50  kArrayAlloc, // Allocations using new[].
51  kInternalAlloc, // Allocations for internal AllocTracker use.
52  };
53  static const int kNumAllocTypes = kInternalAlloc + 1;
54 
56  struct TypeCounts {
57  TypeCounts() : allocs(0), bytes(0) {}
58  uint64 allocs;
59  uint64 bytes;
60  };
61 
63  struct Counts {
64  TypeCounts counts[kNumAllocTypes];
65  };
66 
68  static AllocTracker* GetMutableInstance();
69  static const AllocTracker& GetInstance();
70 
71  AllocTracker();
72 
75  void SetBaseline();
76 
79  const Counts& GetBaselineCounts() const { return baseline_counts_; }
80 
82  const Counts& GetAllCounts() const { return all_counts_; }
83 
86  const Counts& GetOpenCounts() const { return open_counts_; }
87 
89  void* New(std::size_t size, AllocType type);
90  void Delete(void* ptr, AllocType type);
91 
92  private:
94  class Helper;
95 
97  virtual ~AllocTracker();
98 
99  Counts baseline_counts_; // Allocations when baseline is set.
100  Counts all_counts_; // All allocations.
101  Counts open_counts_; // Allocations for which delete was not called.
102 
103  std::unique_ptr<Helper> helper_;
104 };
105 
106 } // namespace base
107 } // namespace ion
108 
112 void* operator new(std::size_t size);
113 void* operator new[](std::size_t size);
114 void operator delete(void* ptr);
115 void operator delete[](void* ptr);
116 
117 #endif // __cplusplus
118 
119 #endif // ION_BASE_ALLOCTRACKER_H_
std::string type
Definition: printer.cc:353