wavelength 1.0.0
Loading...
Searching...
No Matches
MemTrack.h
Go to the documentation of this file.
1#pragma once
2
3#include "utl/AllocInfo.h"
4#include "utl/Data.h"
5#include "utl/MemStats.h"
6#include "utl/PrnStream.h"
7
15class MemTrack {
16public:
25 MemTrack(int heap, int *begin, int *end);
26
34 void SetHeapRange(int *heapBegin, int *heapEnd);
35
42
52 void Alloc(int size, const char *type, int actual, void *ptr);
53
62 void PoolAlloc(int size, const char *type, void *ptr);
63
71 void Free(void *ptr, bool pooled);
72
79 int BytesFree() const;
80
88
96 void Report(PrnStream &stream, int minSize);
97
104 void DiffReport(PrnStream &stream);
105
111 bool InitOK() const {
112 return mMemMirror != NULL;
113 }
114
115private:
122 AllocInfo **MirrorSlot(void *ptr) const {
123 return mMemMirror + (static_cast<int *>(ptr) - mHeapBegin);
124 }
125
126 int mHeap;
127 int *mHeapBegin;
128 int *mHeapEnd;
129 int mMemMirrorSize;
130 AllocInfo **mMemMirror;
131 int mCurNumAllocs;
132 int mCurByteAllocs;
133 int mMaxNumAllocs;
134 int mMaxByteAllocs;
135 int mTotalAllocs;
136 int mTotalFrees;
137 int mReserved2c; // +0x2c, cleared by the constructor and not read.
138 BlockStatTable *mStats[2];
139 BlockStatTable *mPoolStats[2];
140 int mCurStat;
141 unsigned char mReserved44[0xa0]; // +0x44, allocated with the object and not used.
142};
143
151
160void MemTrackInit(int heap, int *begin, int *end);
161
168
178void MemTrackAlloc(int size, const char *type, int actual, void *ptr);
179
187void MemTrackFree(int heap, void *ptr);
188
197void MemTrackPoolAlloc(int size, const char *type, void *ptr);
198
205void MemTrackPoolFree(void *ptr);
206
215void MemTrackReport(int heap, int minSize, PrnStream &stream);
216
224void MemTrackReportAllocsByName(int heap, PrnStream &stream);
225
236void DataHeapReport(DataArray *args, void *data);
void MemTrackReportAllocsByName(int heap, PrnStream &stream)
Print how many allocations of a heap share each name and size.
bool MemTrackEnabled()
Report whether allocation tracking is built in.
void MemTrackPoolAlloc(int size, const char *type, void *ptr)
Record a pool node in the main heap's tracker.
void MemTrackPoolFree(void *ptr)
Forget a pool node.
void DataHeapReport(DataArray *args, void *data)
Run the heap_report script command.
void MemTrackReport(int heap, int minSize, PrnStream &stream)
Print a heap's report and its change since the previous one, after the date and time.
void MemTrackFree(int heap, void *ptr)
Forget a heap allocation.
void MemTrackAlloc(int size, const char *type, int actual, void *ptr)
Record a heap allocation in the current heap's tracker.
void MemTrackDataInit()
Add the debug heap the tracker's own containers use and register the heap_report command.
Record of one tracked allocation: its sizes, its tags, and the call stack that made it.
Definition allocinfo.h:11
Reference-counted array of script data nodes.
Definition dataarray.h:20
void SetHeapRange(int *heapBegin, int *heapEnd)
Follow a heap that grew or shrank.
void PoolAlloc(int size, const char *type, void *ptr)
Record a pool node.
int BytesFree() const
Report the bytes of the heap not allocated.
void ReportAllocsByName(PrnStream &stream)
Print how many allocations share each name and size.
void Free(void *ptr, bool pooled)
Forget an allocation or a pool node.
void CreateStatTables()
Create the statistics tables.
void Report(PrnStream &stream, int minSize)
Print the heap's totals and its allocations by name.
MemTrack(int heap, int *begin, int *end)
Start tracking a heap.
bool InitOK() const
Report whether the mirror array was allocated.
Definition MemTrack.h:111
void Alloc(int size, const char *type, int actual, void *ptr)
Record a heap allocation.
void DiffReport(PrnStream &stream)
Print the change of every total since the previous report, then swap the tables.
Text output stream.
Definition prnstream.h:16
bool MemTrackInit()
Prepare the pool of AllocInfo records, when the development memory is present.