From d09b5657f2c37d53497579d7253ad47c8e796dbb Mon Sep 17 00:00:00 2001 From: Tyrann Date: Mon, 2 Oct 2006 17:56:34 +0930 Subject: [PATCH] [PATCH] qbsp: Fix reporting of peak winding memory use The number reported for peak memory usage by winding_t structs was not accurate, due to just using the sizeof(winding_t) for accounting. Track the _bytes_ used by each type in a separate array. This is pretty much redundant for everything except windings, but it's the simplest way to implement it for now. Also tidied up the verbose memory output a bit - the total column is pretty useless, so just don't print it. Re-align the other columns and special case the "Total" line, as only the "Peak Bytes" value is really interesting. Signed-off-by: Tyrann --- qbsp/globals.c | 2 +- qbsp/util.c | 37 ++++++++++++++++++++++--------------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/qbsp/globals.c b/qbsp/globals.c index da01b01f..aaadc00a 100644 --- a/qbsp/globals.c +++ b/qbsp/globals.c @@ -30,7 +30,7 @@ const int rgcMemSize[GLOBAL + 1] = { sizeof(byte), sizeof(dclipnode_t), sizeof(dleaf_t), sizeof(unsigned short), sizeof(dedge_t), sizeof(int), sizeof(dmodel_t), sizeof(mapface_t), - sizeof(mapbrush_t), sizeof(mapentity_t), sizeof(winding_t), + sizeof(mapbrush_t), sizeof(mapentity_t), 1 /* winding_t */, sizeof(face_t), sizeof(plane_t), sizeof(portal_t), sizeof(surface_t), sizeof(node_t), sizeof(brush_t), sizeof(miptex_t), sizeof(wvert_t), sizeof(wedge_t), diff --git a/qbsp/util.c b/qbsp/util.c index 8eac1155..a1babc06 100644 --- a/qbsp/util.c +++ b/qbsp/util.c @@ -37,6 +37,8 @@ static int rgMemTotal[GLOBAL + 1]; static int rgMemActive[GLOBAL + 1]; static int rgMemPeak[GLOBAL + 1]; +static int rgMemActiveBytes[GLOBAL + 1]; +static int rgMemPeakBytes[GLOBAL + 1]; /* ========== @@ -96,8 +98,11 @@ AllocMem(int Type, int cElements, bool fZero) rgMemTotal[Type] += cElements; rgMemActive[Type] += cElements; + rgMemActiveBytes[Type] += cSize; if (rgMemActive[Type] > rgMemPeak[Type]) rgMemPeak[Type] = rgMemActive[Type]; + if (rgMemActiveBytes[Type] > rgMemPeakBytes[Type]) + rgMemPeakBytes[Type] = rgMemActiveBytes[Type]; // Also keep global statistics rgMemTotal[GLOBAL] += cSize; @@ -120,9 +125,12 @@ FreeMem(void *pMem, int Type, int cElements) rgMemActive[Type] -= cElements; if (Type == WINDING) { pMem = (char *)pMem - sizeof(int); + rgMemActiveBytes[Type] -= *(int *)pMem; rgMemActive[GLOBAL] -= *(int *)pMem; - } else + } else { + rgMemActiveBytes[Type] -= cElements * rgcMemSize[Type]; rgMemActive[GLOBAL] -= cElements * rgcMemSize[Type]; + } free(pMem); } @@ -136,26 +144,25 @@ PrintMem void PrintMem(void) { - char *rgszMemTypes[] = - { "BSPEntity", "BSPPlane", "BSPTex", "BSPVertex", "BSPVis", - "BSPNode", "BSPTexinfo", "BSPFace", "BSPLight", "BSPClipnode", - "BSPLeaf", + char *rgszMemTypes[] = { + "BSPEntity", "BSPPlane", "BSPTex", "BSPVertex", "BSPVis", "BSPNode", + "BSPTexinfo", "BSPFace", "BSPLight", "BSPClipnode", "BSPLeaf", "BSPMarksurface", "BSPEdge", "BSPSurfedge", "BSPModel", "Mapface", - "Mapbrush", - "Mapentity", "Winding", "Face", "Plane", "Portal", "Surface", "Node", - "Brush", - "Miptex", "World verts", "World edges", "Hash verts", "Other (bytes)", - "Total (bytes)" + "Mapbrush", "Mapentity", "Winding", "Face", "Plane", "Portal", + "Surface", "Node", "Brush", "Miptex", "World verts", "World edges", + "Hash verts", "Other", "Total" }; int i; if (options.fVerbose) { Message(msgLiteral, - "\nData type Current Peak Total Peak Bytes\n"); - for (i = 0; i <= GLOBAL; i++) - Message(msgLiteral, "%-16s %8d %8d %10d %9d\n", rgszMemTypes[i], - rgMemActive[i], rgMemPeak[i], rgMemTotal[i], - rgMemPeak[i] * rgcMemSize[i]); + "\nData type CurrentNum PeakNum PeakMem\n"); + for (i = 0; i <= OTHER; i++) + Message(msgLiteral, "%-16s %9d %9d %12d\n", + rgszMemTypes[i], rgMemActive[i], rgMemPeak[i], + rgMemPeakBytes[i]); + Message(msgLiteral, "%-16s %12d\n", + rgszMemTypes[GLOBAL], rgMemPeak[GLOBAL]); } else Message(msgLiteral, "Bytes used: %d\n", rgMemPeak[GLOBAL]); }