From c4a99a2eb963ead9738b4c798bee2be21a93705b Mon Sep 17 00:00:00 2001 From: Elliot Lee Date: Wed, 19 Aug 1998 03:59:20 +0000 Subject: [PATCH] gmem.c: add ability to exclude memory chunks from memory profiling gmem.c: add ability to exclude memory chunks from memory profiling information. --- ChangeLog | 5 +++ ChangeLog.pre-2-0 | 5 +++ ChangeLog.pre-2-10 | 5 +++ ChangeLog.pre-2-12 | 5 +++ ChangeLog.pre-2-2 | 5 +++ ChangeLog.pre-2-4 | 5 +++ ChangeLog.pre-2-6 | 5 +++ ChangeLog.pre-2-8 | 5 +++ glib/gmem.c | 89 ++++++++++++++++++++++++++++++++++------------ gmem.c | 89 ++++++++++++++++++++++++++++++++++------------ 10 files changed, 174 insertions(+), 44 deletions(-) diff --git a/ChangeLog b/ChangeLog index c111e7bbf..256ebca3b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +1998-08-18: Elliot Lee + + . In gmem.c, add the ability to exclude memory chunks from the + memory profiling information. + Tue Aug 18 18:23:09 PDT 1998 Manish Singh * glib.h diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index c111e7bbf..256ebca3b 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,8 @@ +1998-08-18: Elliot Lee + + . In gmem.c, add the ability to exclude memory chunks from the + memory profiling information. + Tue Aug 18 18:23:09 PDT 1998 Manish Singh * glib.h diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index c111e7bbf..256ebca3b 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,8 @@ +1998-08-18: Elliot Lee + + . In gmem.c, add the ability to exclude memory chunks from the + memory profiling information. + Tue Aug 18 18:23:09 PDT 1998 Manish Singh * glib.h diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index c111e7bbf..256ebca3b 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,8 @@ +1998-08-18: Elliot Lee + + . In gmem.c, add the ability to exclude memory chunks from the + memory profiling information. + Tue Aug 18 18:23:09 PDT 1998 Manish Singh * glib.h diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index c111e7bbf..256ebca3b 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,8 @@ +1998-08-18: Elliot Lee + + . In gmem.c, add the ability to exclude memory chunks from the + memory profiling information. + Tue Aug 18 18:23:09 PDT 1998 Manish Singh * glib.h diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index c111e7bbf..256ebca3b 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,8 @@ +1998-08-18: Elliot Lee + + . In gmem.c, add the ability to exclude memory chunks from the + memory profiling information. + Tue Aug 18 18:23:09 PDT 1998 Manish Singh * glib.h diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index c111e7bbf..256ebca3b 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,8 @@ +1998-08-18: Elliot Lee + + . In gmem.c, add the ability to exclude memory chunks from the + memory profiling information. + Tue Aug 18 18:23:09 PDT 1998 Manish Singh * glib.h diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index c111e7bbf..256ebca3b 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,8 @@ +1998-08-18: Elliot Lee + + . In gmem.c, add the ability to exclude memory chunks from the + memory profiling information. + Tue Aug 18 18:23:09 PDT 1998 Manish Singh * glib.h diff --git a/glib/gmem.c b/glib/gmem.c index ace74bc62..c662ae710 100644 --- a/glib/gmem.c +++ b/glib/gmem.c @@ -21,8 +21,17 @@ #include "glib.h" /* #define ENABLE_MEM_PROFILE */ +/* #define ENABLE_MEM_PROFILE_EXCLUDES_MEM_CHUNKS */ /* #define ENABLE_MEM_CHECK */ +#if defined(ENABLE_MEM_PROFILE) && defined(ENABLE_MEM_PROFILE_EXCLUDES_MEM_CHUNKS) +#define ENTER_MEM_CHUNK_ROUTINE() allocating_for_mem_chunk++ +#define LEAVE_MEM_CHUNK_ROUTINE() allocating_for_mem_chunk-- +#else +#define ENTER_MEM_CHUNK_ROUTINE() +#define LEAVE_MEM_CHUNK_ROUTINE() +#endif + #define MAX_MEM_AREA 65536L #define MEM_AREA_SIZE 4L @@ -91,6 +100,7 @@ static GRealMemChunk *mem_chunks = NULL; static gulong allocations[4096] = { 0 }; static gulong allocated_mem = 0; static gulong freed_mem = 0; +static gint allocating_for_mem_chunk = 0; #endif /* ENABLE_MEM_PROFILE */ @@ -141,11 +151,17 @@ g_malloc (gulong size) *t = size; #ifdef ENABLE_MEM_PROFILE - if (size <= 4095) - allocations[size-1] += 1; - else - allocations[4095] += 1; - allocated_mem += size; +#ifdef ENABLE_MEM_PROFILE_EXCLUDES_MEM_CHUNKS + if(!allocating_for_mem_chunk) { +#endif + if (size <= 4095) + allocations[size-1] += 1; + else + allocations[4095] += 1; + allocated_mem += size; +#ifdef ENABLE_MEM_PROFILE_EXCLUDES_MEM_CHUNKS + } +#endif #endif /* ENABLE_MEM_PROFILE */ #endif /* ENABLE_MEM_PROFILE || ENABLE_MEM_CHECK */ @@ -198,11 +214,17 @@ g_malloc0 (gulong size) *t = size; #ifdef ENABLE_MEM_PROFILE - if (size <= 4095) - allocations[size-1] += 1; - else - allocations[4095] += 1; - allocated_mem += size; +#ifdef ENABLE_MEM_PROFILE_EXCLUDES_MEM_CHUNKS + if(!allocating_for_mem_chunk) { +#endif + if (size <= 4095) + allocations[size-1] += 1; + else + allocations[4095] += 1; + allocated_mem += size; +#ifdef ENABLE_MEM_PROFILE_EXCLUDES_MEM_CHUNKS + } +#endif #endif /* ENABLE_MEM_PROFILE */ #endif /* ENABLE_MEM_PROFILE */ @@ -276,11 +298,17 @@ g_realloc (gpointer mem, *t = size; #ifdef ENABLE_MEM_PROFILE - if (size <= 4095) - allocations[size-1] += 1; - else - allocations[4095] += 1; - allocated_mem += size; +#ifdef ENABLE_MEM_PROFILE_EXCLUDES_MEM_CHUNKS + if(!allocating_for_mem_chunk) { +#endif + if (size <= 4095) + allocations[size-1] += 1; + else + allocations[4095] += 1; + allocated_mem += size; +#ifdef ENABLE_MEM_PROFILE_EXCLUDES_MEM_CHUNKS + } +#endif #endif /* ENABLE_MEM_PROFILE */ #endif /* ENABLE_MEM_PROFILE || ENABLE_MEM_CHECK */ @@ -365,7 +393,9 @@ g_mem_chunk_new (gchar *name, { GRealMemChunk *mem_chunk; gulong rarea_size; - + + ENTER_MEM_CHUNK_ROUTINE(); + mem_chunk = g_new (struct _GRealMemChunk, 1); mem_chunk->name = name; mem_chunk->type = type; @@ -411,7 +441,9 @@ g_mem_chunk_new (gchar *name, if (mem_chunks) mem_chunks->prev = mem_chunk; mem_chunks = mem_chunk; - + + LEAVE_MEM_CHUNK_ROUTINE(); + return ((GMemChunk*) mem_chunk); } @@ -423,7 +455,9 @@ g_mem_chunk_destroy (GMemChunk *mem_chunk) GMemArea *temp_area; g_assert (mem_chunk != NULL); - + + ENTER_MEM_CHUNK_ROUTINE(); + rmem_chunk = (GRealMemChunk*) mem_chunk; mem_areas = rmem_chunk->mem_areas; @@ -446,6 +480,8 @@ g_mem_chunk_destroy (GMemChunk *mem_chunk) g_tree_destroy (rmem_chunk->mem_tree); g_free (rmem_chunk); + + LEAVE_MEM_CHUNK_ROUTINE(); } gpointer @@ -454,7 +490,9 @@ g_mem_chunk_alloc (GMemChunk *mem_chunk) GRealMemChunk *rmem_chunk; GMemArea *temp_area; gpointer mem; - + + ENTER_MEM_CHUNK_ROUTINE(); + g_assert (mem_chunk != NULL); rmem_chunk = (GRealMemChunk*) mem_chunk; @@ -571,8 +609,11 @@ g_mem_chunk_alloc (GMemChunk *mem_chunk) rmem_chunk->mem_area->index += rmem_chunk->atom_size; rmem_chunk->mem_area->free -= rmem_chunk->atom_size; rmem_chunk->mem_area->allocated += 1; - - outa_here: + +outa_here: + + LEAVE_MEM_CHUNK_ROUTINE(); + return mem; } @@ -586,7 +627,9 @@ g_mem_chunk_free (GMemChunk *mem_chunk, g_assert (mem_chunk != NULL); g_assert (mem != NULL); - + + ENTER_MEM_CHUNK_ROUTINE(); + rmem_chunk = (GRealMemChunk*) mem_chunk; /* Don't do anything if this is an ALLOC_ONLY chunk @@ -611,6 +654,8 @@ g_mem_chunk_free (GMemChunk *mem_chunk, rmem_chunk->num_marked_areas += 1; } } + + LEAVE_MEM_CHUNK_ROUTINE(); } /* This doesn't free the free_area if there is one */ diff --git a/gmem.c b/gmem.c index ace74bc62..c662ae710 100644 --- a/gmem.c +++ b/gmem.c @@ -21,8 +21,17 @@ #include "glib.h" /* #define ENABLE_MEM_PROFILE */ +/* #define ENABLE_MEM_PROFILE_EXCLUDES_MEM_CHUNKS */ /* #define ENABLE_MEM_CHECK */ +#if defined(ENABLE_MEM_PROFILE) && defined(ENABLE_MEM_PROFILE_EXCLUDES_MEM_CHUNKS) +#define ENTER_MEM_CHUNK_ROUTINE() allocating_for_mem_chunk++ +#define LEAVE_MEM_CHUNK_ROUTINE() allocating_for_mem_chunk-- +#else +#define ENTER_MEM_CHUNK_ROUTINE() +#define LEAVE_MEM_CHUNK_ROUTINE() +#endif + #define MAX_MEM_AREA 65536L #define MEM_AREA_SIZE 4L @@ -91,6 +100,7 @@ static GRealMemChunk *mem_chunks = NULL; static gulong allocations[4096] = { 0 }; static gulong allocated_mem = 0; static gulong freed_mem = 0; +static gint allocating_for_mem_chunk = 0; #endif /* ENABLE_MEM_PROFILE */ @@ -141,11 +151,17 @@ g_malloc (gulong size) *t = size; #ifdef ENABLE_MEM_PROFILE - if (size <= 4095) - allocations[size-1] += 1; - else - allocations[4095] += 1; - allocated_mem += size; +#ifdef ENABLE_MEM_PROFILE_EXCLUDES_MEM_CHUNKS + if(!allocating_for_mem_chunk) { +#endif + if (size <= 4095) + allocations[size-1] += 1; + else + allocations[4095] += 1; + allocated_mem += size; +#ifdef ENABLE_MEM_PROFILE_EXCLUDES_MEM_CHUNKS + } +#endif #endif /* ENABLE_MEM_PROFILE */ #endif /* ENABLE_MEM_PROFILE || ENABLE_MEM_CHECK */ @@ -198,11 +214,17 @@ g_malloc0 (gulong size) *t = size; #ifdef ENABLE_MEM_PROFILE - if (size <= 4095) - allocations[size-1] += 1; - else - allocations[4095] += 1; - allocated_mem += size; +#ifdef ENABLE_MEM_PROFILE_EXCLUDES_MEM_CHUNKS + if(!allocating_for_mem_chunk) { +#endif + if (size <= 4095) + allocations[size-1] += 1; + else + allocations[4095] += 1; + allocated_mem += size; +#ifdef ENABLE_MEM_PROFILE_EXCLUDES_MEM_CHUNKS + } +#endif #endif /* ENABLE_MEM_PROFILE */ #endif /* ENABLE_MEM_PROFILE */ @@ -276,11 +298,17 @@ g_realloc (gpointer mem, *t = size; #ifdef ENABLE_MEM_PROFILE - if (size <= 4095) - allocations[size-1] += 1; - else - allocations[4095] += 1; - allocated_mem += size; +#ifdef ENABLE_MEM_PROFILE_EXCLUDES_MEM_CHUNKS + if(!allocating_for_mem_chunk) { +#endif + if (size <= 4095) + allocations[size-1] += 1; + else + allocations[4095] += 1; + allocated_mem += size; +#ifdef ENABLE_MEM_PROFILE_EXCLUDES_MEM_CHUNKS + } +#endif #endif /* ENABLE_MEM_PROFILE */ #endif /* ENABLE_MEM_PROFILE || ENABLE_MEM_CHECK */ @@ -365,7 +393,9 @@ g_mem_chunk_new (gchar *name, { GRealMemChunk *mem_chunk; gulong rarea_size; - + + ENTER_MEM_CHUNK_ROUTINE(); + mem_chunk = g_new (struct _GRealMemChunk, 1); mem_chunk->name = name; mem_chunk->type = type; @@ -411,7 +441,9 @@ g_mem_chunk_new (gchar *name, if (mem_chunks) mem_chunks->prev = mem_chunk; mem_chunks = mem_chunk; - + + LEAVE_MEM_CHUNK_ROUTINE(); + return ((GMemChunk*) mem_chunk); } @@ -423,7 +455,9 @@ g_mem_chunk_destroy (GMemChunk *mem_chunk) GMemArea *temp_area; g_assert (mem_chunk != NULL); - + + ENTER_MEM_CHUNK_ROUTINE(); + rmem_chunk = (GRealMemChunk*) mem_chunk; mem_areas = rmem_chunk->mem_areas; @@ -446,6 +480,8 @@ g_mem_chunk_destroy (GMemChunk *mem_chunk) g_tree_destroy (rmem_chunk->mem_tree); g_free (rmem_chunk); + + LEAVE_MEM_CHUNK_ROUTINE(); } gpointer @@ -454,7 +490,9 @@ g_mem_chunk_alloc (GMemChunk *mem_chunk) GRealMemChunk *rmem_chunk; GMemArea *temp_area; gpointer mem; - + + ENTER_MEM_CHUNK_ROUTINE(); + g_assert (mem_chunk != NULL); rmem_chunk = (GRealMemChunk*) mem_chunk; @@ -571,8 +609,11 @@ g_mem_chunk_alloc (GMemChunk *mem_chunk) rmem_chunk->mem_area->index += rmem_chunk->atom_size; rmem_chunk->mem_area->free -= rmem_chunk->atom_size; rmem_chunk->mem_area->allocated += 1; - - outa_here: + +outa_here: + + LEAVE_MEM_CHUNK_ROUTINE(); + return mem; } @@ -586,7 +627,9 @@ g_mem_chunk_free (GMemChunk *mem_chunk, g_assert (mem_chunk != NULL); g_assert (mem != NULL); - + + ENTER_MEM_CHUNK_ROUTINE(); + rmem_chunk = (GRealMemChunk*) mem_chunk; /* Don't do anything if this is an ALLOC_ONLY chunk @@ -611,6 +654,8 @@ g_mem_chunk_free (GMemChunk *mem_chunk, rmem_chunk->num_marked_areas += 1; } } + + LEAVE_MEM_CHUNK_ROUTINE(); } /* This doesn't free the free_area if there is one */