wavelength 1.0.0
Loading...
Searching...
No Matches
heaptracker.h
Go to the documentation of this file.
1#pragma once
2
3#include <stddef.h>
4
5#include "os/allocinfo.h"
6#include "os/blockstattable.h"
7#include "os/prnstream.h"
8
16public:
18 static constexpr int kHistorySize = 20;
19
21 struct FrameCounts {
22 int mAllocs;
23 int mFrees;
24 };
25
35 HeapTracker(int nHeap, int *pStart, int *pEnd);
36
43 static void *operator new(size_t nSize);
44
48 static void operator delete(void *) noexcept {
49 }
50
61 void SetRange(int *pStart, int *pEnd);
62
70
81 void Alloc(int nRequested, const char *pszTag, int nActual, void *pData);
82
93 void Realloc(void *pOld, int nRequested, int nActual, void *pNew);
94
104 void PoolAlloc(int nSize, const char *pszTag, void *pData);
105
114 void Free(void *pData, bool bPool);
115
122 void Poll();
123
132
142
151 void Report(PrnStream &stream, int nMinSize);
152
160 void ReportDiff(PrnStream &stream);
161
162private:
163 int mHeap;
164 int *mStart;
165 int *mEnd;
166 int mSizeWords;
167 AllocInfo **mInfos;
168 int mNumAllocs;
169 int mBytesActual;
170 int mPeakNumAllocs;
171 int mPeakBytes;
172 int mAllocsThisFrame;
173 int mFreesThisFrame;
174 int mHistoryIndex;
175 BlockStatTable *mStats[2];
176 BlockStatTable *mPoolStats[2];
177 int mCurrentStats;
178 FrameCounts mHistory[kHistorySize];
179};
Record of one tracked allocation: its sizes, its tags, and the call stack that made it.
Definition allocinfo.h:11
Table of allocation totals by tag, filled from a HeapTracker for a report.
Definition blockstattable.h:21
HeapTracker(int nHeap, int *pStart, int *pEnd)
Track a heap, with a cleared slot for each word.
void CreateTables()
Create the two pairs of statistics tables the reports fill.
void PoolAlloc(int nSize, const char *pszTag, void *pData)
Mark the record at an address as a pool block, creating the record when there is none.
void Poll()
Store the counts of the frame in the history and start new ones.
void Free(void *pData, bool bPool)
Remove the record of an allocation, or only its pool block marks.
void SetRange(int *pStart, int *pEnd)
Move the end of the heap after the heap was resized.
void Alloc(int nRequested, const char *pszTag, int nActual, void *pData)
Record an allocation.
void Report(PrnStream &stream, int nMinSize)
Write the totals of the heap and the totals of each tag.
void Realloc(void *pOld, int nRequested, int nActual, void *pNew)
Move the record of an allocation that changed size or address.
static constexpr int kHistorySize
The frames of allocation counts Poll() retains.
Definition heaptracker.h:18
void ReportByRecord(PrnStream &stream)
Write the number of allocations with each distinct record, using the heap "debug" for the report's ow...
void ReportDiff(PrnStream &stream)
Write the changes of each tag since the previous report, and switch tables.
int FreeBytes()
Report the bytes of the heap not handed out.
Text output stream.
Definition prnstream.h:16
Allocations and frees of one frame.
Definition heaptracker.h:21
int mAllocs
Definition heaptracker.h:22
int mFrees
Definition heaptracker.h:23