Fixed creation and displaying of JSON memory dump for dedicated allocations in custom pools.

This commit is contained in:
Adam Sawicki 2021-12-21 16:23:13 +01:00
parent 9bb70bef1b
commit 556834c0b4
2 changed files with 27 additions and 26 deletions

View File

@ -17077,9 +17077,7 @@ void VmaAllocator_T::PrintDetailedMap(VmaJsonWriter& json)
if (!pool->m_DedicatedAllocations.IsEmpty()) if (!pool->m_DedicatedAllocations.IsEmpty())
{ {
json.WriteString("DedicatedAllocations"); json.WriteString("DedicatedAllocations");
json.BeginObject();
pool->m_DedicatedAllocations.BuildStatsString(json); pool->m_DedicatedAllocations.BuildStatsString(json);
json.EndObject();
} }
json.EndObject(); json.EndObject();
} }

View File

@ -74,7 +74,7 @@ def IsDataEmpty():
if 'DefaultPoolBlocks' in dictMemType and len(dictMemType['DefaultPoolBlocks']) > 0: if 'DefaultPoolBlocks' in dictMemType and len(dictMemType['DefaultPoolBlocks']) > 0:
return False return False
if 'CustomPools' in dictMemType: if 'CustomPools' in dictMemType:
for lBlockList in dictMemType['CustomPools'].values(): for lBlockList in dictMemType['CustomPools'].values()['Blocks']:
if len(lBlockList) > 0: if len(lBlockList) > 0:
return False return False
return True return True
@ -99,10 +99,13 @@ def CalcParams():
for objBlock in lDefaultPoolBlocks: for objBlock in lDefaultPoolBlocks:
iMaxBlockSize = max(iMaxBlockSize, objBlock['Size']) iMaxBlockSize = max(iMaxBlockSize, objBlock['Size'])
dCustomPools = dictMemType['CustomPools'] dCustomPools = dictMemType['CustomPools']
for lBlocks in dCustomPools.values(): for poolData in dCustomPools.values():
iImgSizeY += len(lBlocks) * (IMG_MARGIN * 2 + FONT_SIZE + MAP_SIZE) iImgSizeY += len(poolData['Blocks']) * (IMG_MARGIN * 2 + FONT_SIZE + MAP_SIZE)
for objBlock in lBlocks: for objBlock in poolData['Blocks']:
iMaxBlockSize = max(iMaxBlockSize, objBlock['Size']) iMaxBlockSize = max(iMaxBlockSize, objBlock['Size'])
iImgSizeY += len(poolData['DedicatedAllocations']) * (IMG_MARGIN * 2 + FONT_SIZE + MAP_SIZE)
for tDedicatedAlloc in poolData['DedicatedAllocations']:
iMaxBlockSize = max(iMaxBlockSize, tDedicatedAlloc[1])
fPixelsPerByte = (IMG_SIZE_X - IMG_MARGIN * 2) / float(iMaxBlockSize) fPixelsPerByte = (IMG_SIZE_X - IMG_MARGIN * 2) / float(iMaxBlockSize)
return iImgSizeY, fPixelsPerByte return iImgSizeY, fPixelsPerByte
@ -213,18 +216,12 @@ if 'Pools' in jsonSrc:
sFullName = sPoolId + ' "' + sName + '"' sFullName = sPoolId + ' "' + sName + '"'
else: else:
sFullName = sPoolId sFullName = sPoolId
dstBlockArray = [] typeData['CustomPools'][sFullName] = { 'Blocks':[], 'DedicatedAllocations':[] }
typeData['CustomPools'][sFullName] = dstBlockArray
for sBlockId, objBlock in objBlocks.items(): for sBlockId, objBlock in objBlocks.items():
ProcessBlock(dstBlockArray, int(sBlockId), objBlock, sAlgorithm) ProcessBlock(typeData['CustomPools'][sFullName]['Blocks'], int(sBlockId), objBlock, sAlgorithm)
if 'DedicatedAllocations' in objPool: if 'DedicatedAllocations' in objPool:
for tType in objPool['DedicatedAllocations'].items(): for objAlloc in objPool['DedicatedAllocations']:
sType = tType[0] typeData['CustomPools'][sFullName]['DedicatedAllocations'].append((objAlloc['Type'], int(objAlloc['Size']), int(objAlloc['Usage']) if ('Usage' in objAlloc) else 0))
assert sType[:5] == 'Type '
iType = int(sType[5:])
typeData = GetDataForMemoryType(iType)
for objAlloc in tType[1]:
typeData['CustomPools'][sFullName].append((objAlloc['Type'], int(objAlloc['Size']), int(objAlloc['Usage']) if ('Usage' in objAlloc) else 0))
if IsDataEmpty(): if IsDataEmpty():
@ -281,8 +278,8 @@ for iMemTypeIndex in sorted(data.keys()):
DrawBlock(draw, y, objBlock) DrawBlock(draw, y, objBlock)
y += MAP_SIZE + IMG_MARGIN y += MAP_SIZE + IMG_MARGIN
index = 0 index = 0
for sPoolName, listPool in dictMemType['CustomPools'].items(): for sPoolName, pool in dictMemType['CustomPools'].items():
for objBlock in listPool: for objBlock in pool['Blocks']:
if 'Algorithm' in objBlock and objBlock['Algorithm']: if 'Algorithm' in objBlock and objBlock['Algorithm']:
sAlgorithm = ' (Algorithm: %s)' % (objBlock['Algorithm']) sAlgorithm = ' (Algorithm: %s)' % (objBlock['Algorithm'])
else: else:
@ -290,10 +287,15 @@ for iMemTypeIndex in sorted(data.keys()):
draw.text((IMG_MARGIN, y), "Custom pool %s%s block %d" % (sPoolName, sAlgorithm, objBlock['ID']), fill=COLOR_TEXT_H2, font=font) draw.text((IMG_MARGIN, y), "Custom pool %s%s block %d" % (sPoolName, sAlgorithm, objBlock['ID']), fill=COLOR_TEXT_H2, font=font)
y += FONT_SIZE + IMG_MARGIN y += FONT_SIZE + IMG_MARGIN
DrawBlock(draw, y, objBlock) DrawBlock(draw, y, objBlock)
y += FONT_SIZE + IMG_MARGIN y += 2 * (FONT_SIZE + IMG_MARGIN)
DrawDedicatedAllocationBlock(draw, y, objBlock['DedicatedAllocations'])
y += MAP_SIZE + IMG_MARGIN
index += 1 index += 1
alloc_index = 0
for objAlloc in pool['DedicatedAllocations']:
draw.text((IMG_MARGIN, y), "Custom pool %s%s dedicated allocation %d" % (sPoolName, sAlgorithm, alloc_index), fill=COLOR_TEXT_H2, font=font)
y += FONT_SIZE + IMG_MARGIN
DrawDedicatedAllocationBlock(draw, y, objAlloc)
y += MAP_SIZE + IMG_MARGIN
alloc_index += 1
del draw del draw
img.save(args.output) img.save(args.output)
@ -308,7 +310,8 @@ Main data structure - variable `data` - is a dictionary. Key is integer - memory
- Fixed key 'Size'. Value is int. - Fixed key 'Size'. Value is int.
- Fixed key 'Suballocations'. Value is list of tuples as above. - Fixed key 'Suballocations'. Value is list of tuples as above.
- Fixed key 'CustomPools'. Value is dictionary. - Fixed key 'CustomPools'. Value is dictionary.
- Key is string with pool ID/name. Value is list of objects representing memory blocks, each containing dictionary with: - Key is string with pool ID/name. Value is a dictionary with:
- Fixed key 'Blocks'. Value is a list of objects representing memory blocks, each containing dictionary with:
- Fixed key 'ID'. Value is int. - Fixed key 'ID'. Value is int.
- Fixed key 'Size'. Value is int. - Fixed key 'Size'. Value is int.
- Fixed key 'Algorithm'. Optional. Value is string. - Fixed key 'Algorithm'. Optional. Value is string.