diff options
author | Brian Salomon <bsalomon@google.com> | 2017-03-28 16:51:02 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-03-28 22:51:34 +0000 |
commit | a5002c384d97de24c61c5486fa0f84ab01179147 (patch) | |
tree | 8e5505f870e3444fcea93ad0b809a511d18f55b8 /src/gpu/GrMemoryPool.cpp | |
parent | 90b49b5f847c5cb92c902cc31d7fb87d18baa9fa (diff) |
Add debug helper for finding leaks in GrMemoryPool.h
Change-Id: I1d11769f9e99606af5e7752b3a6d055a5bf6a48d
Reviewed-on: https://skia-review.googlesource.com/10289
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'src/gpu/GrMemoryPool.cpp')
-rw-r--r-- | src/gpu/GrMemoryPool.cpp | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/gpu/GrMemoryPool.cpp b/src/gpu/GrMemoryPool.cpp index 91cecbd4c2..32a3612972 100644 --- a/src/gpu/GrMemoryPool.cpp +++ b/src/gpu/GrMemoryPool.cpp @@ -6,8 +6,10 @@ */ #include "GrMemoryPool.h" - #include "SkMalloc.h" +#ifdef SK_DEBUG +#include "SkAtomics.h" +#endif #ifdef SK_DEBUG #define VALIDATE this->validate() @@ -36,6 +38,19 @@ GrMemoryPool::GrMemoryPool(size_t preallocSize, size_t minAllocSize) { GrMemoryPool::~GrMemoryPool() { VALIDATE; +#ifdef SK_DEBUG + int i = 0; + int n = fAllocatedIDs.count(); + fAllocatedIDs.foreach([&i, n] (int32_t id) { + if (++i == 1) { + SkDebugf("Leaked IDs (in no particular order): %d", id); + } else if (i < 11) { + SkDebugf(", %d%s", id, (n == i ? "\n" : "")); + } else if (i == 11) { + SkDebugf(", ...\n"); + } + }); +#endif SkASSERT(0 == fAllocationCnt); SkASSERT(fHead == fTail); SkASSERT(0 == fHead->fLiveCount); @@ -66,13 +81,15 @@ void* GrMemoryPool::allocate(size_t size) { // so that we can decrement the live count on delete in constant time. AllocHeader* allocData = reinterpret_cast<AllocHeader*>(ptr); SkDEBUGCODE(allocData->fSentinal = kAssignedMarker); + SkDEBUGCODE(allocData->fID = []{static int32_t gID; return sk_atomic_inc(&gID) + 1;}()); + // You can set a breakpoint here when a leaked ID is allocated to see the stack frame. + SkDEBUGCODE(fAllocatedIDs.add(allocData->fID)); allocData->fHeader = fTail; ptr += kPerAllocPad; fTail->fPrevPtr = fTail->fCurrPtr; fTail->fCurrPtr += size; fTail->fFreeSize -= size; fTail->fLiveCount += 1; - SkDEBUGCODE(++fAllocationCnt); VALIDATE; return reinterpret_cast<void*>(ptr); @@ -84,6 +101,7 @@ void GrMemoryPool::release(void* p) { AllocHeader* allocData = reinterpret_cast<AllocHeader*>(ptr); SkASSERT(kAssignedMarker == allocData->fSentinal); SkDEBUGCODE(allocData->fSentinal = kFreedMarker); + SkDEBUGCODE(fAllocatedIDs.remove(allocData->fID)); BlockHeader* block = allocData->fHeader; SkASSERT(kAssignedMarker == block->fBlockSentinal); if (1 == block->fLiveCount) { @@ -181,6 +199,7 @@ void GrMemoryPool::validate() { prev = block; } while ((block = block->fNext)); SkASSERT(allocCount == fAllocationCnt); + SkASSERT(fAllocationCnt == fAllocatedIDs.count()); SkASSERT(prev == fTail); SkASSERT(fAllocBlockCnt != 0 || fSize == 0); #endif |