mirror of
https://salsa.debian.org/dskoll/remind.git
synced 2026-04-16 06:18:47 +02:00
Keep track of dynamic buffer allocations.
This commit is contained in:
12
src/dynbuf.c
12
src/dynbuf.c
@@ -17,6 +17,15 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static size_t NumMallocs = 0;
|
||||
static size_t BytesMalloced = 0;
|
||||
|
||||
void DBufGetMallocStats(size_t *num_mallocs, size_t *bytes_malloced)
|
||||
{
|
||||
*num_mallocs = NumMallocs;
|
||||
*bytes_malloced = BytesMalloced;
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
%FUNCTION: DBufMakeRoom
|
||||
%ARGUMENTS:
|
||||
@@ -45,6 +54,9 @@ static int DBufMakeRoom(DynamicBuffer *dbuf, size_t n)
|
||||
buf = malloc(size);
|
||||
if (!buf) return E_NO_MEM;
|
||||
|
||||
NumMallocs++;
|
||||
BytesMalloced += size;
|
||||
|
||||
/* Copy contents */
|
||||
strcpy(buf, dbuf->buffer);
|
||||
|
||||
|
||||
@@ -29,6 +29,8 @@ int DBufPuts(DynamicBuffer *dbuf, char const *str);
|
||||
void DBufFree(DynamicBuffer *dbuf);
|
||||
int DBufGets(DynamicBuffer *dbuf, FILE *fp);
|
||||
|
||||
void DBufGetMallocStats(size_t *num_mallocs, size_t *bytes_malloced);
|
||||
|
||||
#define DBufValue(bufPtr) ((bufPtr)->buffer)
|
||||
#define DBufLen(bufPtr) ((bufPtr)->len)
|
||||
|
||||
|
||||
@@ -62,12 +62,17 @@ exitfunc(void)
|
||||
/* Kill any execution-time-limiter process */
|
||||
unlimit_execution_time();
|
||||
|
||||
size_t num_mallocs, bytes_malloced;
|
||||
|
||||
if (DebugFlag & DB_UNUSED_VARS) {
|
||||
DumpUnusedVars();
|
||||
}
|
||||
if (DebugFlag & DB_HASHSTATS) {
|
||||
fflush(stdout);
|
||||
fflush(ErrFp);
|
||||
DBufGetMallocStats(&num_mallocs, &bytes_malloced);
|
||||
fprintf(ErrFp, "DynBuf Mallocs: %lu mallocs; %lu bytes\n",
|
||||
(unsigned long) num_mallocs, (unsigned long) bytes_malloced);
|
||||
fprintf(ErrFp, "Variable hash table statistics:\n");
|
||||
dump_var_hash_stats();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user