gmem.c: add ability to exclude memory chunks from memory profiling

gmem.c: add ability to exclude memory chunks from memory profiling
	information.
This commit is contained in:
Elliot Lee 1998-08-19 03:59:20 +00:00
parent 47074edbbd
commit c4a99a2eb9
10 changed files with 174 additions and 44 deletions

View File

@ -1,3 +1,8 @@
1998-08-18: Elliot Lee <sopwith@redhat.com>
. 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 <yosh@gimp.org> Tue Aug 18 18:23:09 PDT 1998 Manish Singh <yosh@gimp.org>
* glib.h * glib.h

View File

@ -1,3 +1,8 @@
1998-08-18: Elliot Lee <sopwith@redhat.com>
. 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 <yosh@gimp.org> Tue Aug 18 18:23:09 PDT 1998 Manish Singh <yosh@gimp.org>
* glib.h * glib.h

View File

@ -1,3 +1,8 @@
1998-08-18: Elliot Lee <sopwith@redhat.com>
. 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 <yosh@gimp.org> Tue Aug 18 18:23:09 PDT 1998 Manish Singh <yosh@gimp.org>
* glib.h * glib.h

View File

@ -1,3 +1,8 @@
1998-08-18: Elliot Lee <sopwith@redhat.com>
. 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 <yosh@gimp.org> Tue Aug 18 18:23:09 PDT 1998 Manish Singh <yosh@gimp.org>
* glib.h * glib.h

View File

@ -1,3 +1,8 @@
1998-08-18: Elliot Lee <sopwith@redhat.com>
. 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 <yosh@gimp.org> Tue Aug 18 18:23:09 PDT 1998 Manish Singh <yosh@gimp.org>
* glib.h * glib.h

View File

@ -1,3 +1,8 @@
1998-08-18: Elliot Lee <sopwith@redhat.com>
. 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 <yosh@gimp.org> Tue Aug 18 18:23:09 PDT 1998 Manish Singh <yosh@gimp.org>
* glib.h * glib.h

View File

@ -1,3 +1,8 @@
1998-08-18: Elliot Lee <sopwith@redhat.com>
. 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 <yosh@gimp.org> Tue Aug 18 18:23:09 PDT 1998 Manish Singh <yosh@gimp.org>
* glib.h * glib.h

View File

@ -1,3 +1,8 @@
1998-08-18: Elliot Lee <sopwith@redhat.com>
. 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 <yosh@gimp.org> Tue Aug 18 18:23:09 PDT 1998 Manish Singh <yosh@gimp.org>
* glib.h * glib.h

View File

@ -21,8 +21,17 @@
#include "glib.h" #include "glib.h"
/* #define ENABLE_MEM_PROFILE */ /* #define ENABLE_MEM_PROFILE */
/* #define ENABLE_MEM_PROFILE_EXCLUDES_MEM_CHUNKS */
/* #define ENABLE_MEM_CHECK */ /* #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 MAX_MEM_AREA 65536L
#define MEM_AREA_SIZE 4L #define MEM_AREA_SIZE 4L
@ -91,6 +100,7 @@ static GRealMemChunk *mem_chunks = NULL;
static gulong allocations[4096] = { 0 }; static gulong allocations[4096] = { 0 };
static gulong allocated_mem = 0; static gulong allocated_mem = 0;
static gulong freed_mem = 0; static gulong freed_mem = 0;
static gint allocating_for_mem_chunk = 0;
#endif /* ENABLE_MEM_PROFILE */ #endif /* ENABLE_MEM_PROFILE */
@ -141,11 +151,17 @@ g_malloc (gulong size)
*t = size; *t = size;
#ifdef ENABLE_MEM_PROFILE #ifdef ENABLE_MEM_PROFILE
#ifdef ENABLE_MEM_PROFILE_EXCLUDES_MEM_CHUNKS
if(!allocating_for_mem_chunk) {
#endif
if (size <= 4095) if (size <= 4095)
allocations[size-1] += 1; allocations[size-1] += 1;
else else
allocations[4095] += 1; allocations[4095] += 1;
allocated_mem += size; allocated_mem += size;
#ifdef ENABLE_MEM_PROFILE_EXCLUDES_MEM_CHUNKS
}
#endif
#endif /* ENABLE_MEM_PROFILE */ #endif /* ENABLE_MEM_PROFILE */
#endif /* ENABLE_MEM_PROFILE || ENABLE_MEM_CHECK */ #endif /* ENABLE_MEM_PROFILE || ENABLE_MEM_CHECK */
@ -198,11 +214,17 @@ g_malloc0 (gulong size)
*t = size; *t = size;
#ifdef ENABLE_MEM_PROFILE #ifdef ENABLE_MEM_PROFILE
#ifdef ENABLE_MEM_PROFILE_EXCLUDES_MEM_CHUNKS
if(!allocating_for_mem_chunk) {
#endif
if (size <= 4095) if (size <= 4095)
allocations[size-1] += 1; allocations[size-1] += 1;
else else
allocations[4095] += 1; allocations[4095] += 1;
allocated_mem += size; allocated_mem += size;
#ifdef ENABLE_MEM_PROFILE_EXCLUDES_MEM_CHUNKS
}
#endif
#endif /* ENABLE_MEM_PROFILE */ #endif /* ENABLE_MEM_PROFILE */
#endif /* ENABLE_MEM_PROFILE */ #endif /* ENABLE_MEM_PROFILE */
@ -276,11 +298,17 @@ g_realloc (gpointer mem,
*t = size; *t = size;
#ifdef ENABLE_MEM_PROFILE #ifdef ENABLE_MEM_PROFILE
#ifdef ENABLE_MEM_PROFILE_EXCLUDES_MEM_CHUNKS
if(!allocating_for_mem_chunk) {
#endif
if (size <= 4095) if (size <= 4095)
allocations[size-1] += 1; allocations[size-1] += 1;
else else
allocations[4095] += 1; allocations[4095] += 1;
allocated_mem += size; allocated_mem += size;
#ifdef ENABLE_MEM_PROFILE_EXCLUDES_MEM_CHUNKS
}
#endif
#endif /* ENABLE_MEM_PROFILE */ #endif /* ENABLE_MEM_PROFILE */
#endif /* ENABLE_MEM_PROFILE || ENABLE_MEM_CHECK */ #endif /* ENABLE_MEM_PROFILE || ENABLE_MEM_CHECK */
@ -366,6 +394,8 @@ g_mem_chunk_new (gchar *name,
GRealMemChunk *mem_chunk; GRealMemChunk *mem_chunk;
gulong rarea_size; gulong rarea_size;
ENTER_MEM_CHUNK_ROUTINE();
mem_chunk = g_new (struct _GRealMemChunk, 1); mem_chunk = g_new (struct _GRealMemChunk, 1);
mem_chunk->name = name; mem_chunk->name = name;
mem_chunk->type = type; mem_chunk->type = type;
@ -412,6 +442,8 @@ g_mem_chunk_new (gchar *name,
mem_chunks->prev = mem_chunk; mem_chunks->prev = mem_chunk;
mem_chunks = mem_chunk; mem_chunks = mem_chunk;
LEAVE_MEM_CHUNK_ROUTINE();
return ((GMemChunk*) mem_chunk); return ((GMemChunk*) mem_chunk);
} }
@ -424,6 +456,8 @@ g_mem_chunk_destroy (GMemChunk *mem_chunk)
g_assert (mem_chunk != NULL); g_assert (mem_chunk != NULL);
ENTER_MEM_CHUNK_ROUTINE();
rmem_chunk = (GRealMemChunk*) mem_chunk; rmem_chunk = (GRealMemChunk*) mem_chunk;
mem_areas = rmem_chunk->mem_areas; 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_tree_destroy (rmem_chunk->mem_tree);
g_free (rmem_chunk); g_free (rmem_chunk);
LEAVE_MEM_CHUNK_ROUTINE();
} }
gpointer gpointer
@ -455,6 +491,8 @@ g_mem_chunk_alloc (GMemChunk *mem_chunk)
GMemArea *temp_area; GMemArea *temp_area;
gpointer mem; gpointer mem;
ENTER_MEM_CHUNK_ROUTINE();
g_assert (mem_chunk != NULL); g_assert (mem_chunk != NULL);
rmem_chunk = (GRealMemChunk*) mem_chunk; rmem_chunk = (GRealMemChunk*) mem_chunk;
@ -573,6 +611,9 @@ g_mem_chunk_alloc (GMemChunk *mem_chunk)
rmem_chunk->mem_area->allocated += 1; rmem_chunk->mem_area->allocated += 1;
outa_here: outa_here:
LEAVE_MEM_CHUNK_ROUTINE();
return mem; return mem;
} }
@ -587,6 +628,8 @@ g_mem_chunk_free (GMemChunk *mem_chunk,
g_assert (mem_chunk != NULL); g_assert (mem_chunk != NULL);
g_assert (mem != NULL); g_assert (mem != NULL);
ENTER_MEM_CHUNK_ROUTINE();
rmem_chunk = (GRealMemChunk*) mem_chunk; rmem_chunk = (GRealMemChunk*) mem_chunk;
/* Don't do anything if this is an ALLOC_ONLY 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; rmem_chunk->num_marked_areas += 1;
} }
} }
LEAVE_MEM_CHUNK_ROUTINE();
} }
/* This doesn't free the free_area if there is one */ /* This doesn't free the free_area if there is one */

45
gmem.c
View File

@ -21,8 +21,17 @@
#include "glib.h" #include "glib.h"
/* #define ENABLE_MEM_PROFILE */ /* #define ENABLE_MEM_PROFILE */
/* #define ENABLE_MEM_PROFILE_EXCLUDES_MEM_CHUNKS */
/* #define ENABLE_MEM_CHECK */ /* #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 MAX_MEM_AREA 65536L
#define MEM_AREA_SIZE 4L #define MEM_AREA_SIZE 4L
@ -91,6 +100,7 @@ static GRealMemChunk *mem_chunks = NULL;
static gulong allocations[4096] = { 0 }; static gulong allocations[4096] = { 0 };
static gulong allocated_mem = 0; static gulong allocated_mem = 0;
static gulong freed_mem = 0; static gulong freed_mem = 0;
static gint allocating_for_mem_chunk = 0;
#endif /* ENABLE_MEM_PROFILE */ #endif /* ENABLE_MEM_PROFILE */
@ -141,11 +151,17 @@ g_malloc (gulong size)
*t = size; *t = size;
#ifdef ENABLE_MEM_PROFILE #ifdef ENABLE_MEM_PROFILE
#ifdef ENABLE_MEM_PROFILE_EXCLUDES_MEM_CHUNKS
if(!allocating_for_mem_chunk) {
#endif
if (size <= 4095) if (size <= 4095)
allocations[size-1] += 1; allocations[size-1] += 1;
else else
allocations[4095] += 1; allocations[4095] += 1;
allocated_mem += size; allocated_mem += size;
#ifdef ENABLE_MEM_PROFILE_EXCLUDES_MEM_CHUNKS
}
#endif
#endif /* ENABLE_MEM_PROFILE */ #endif /* ENABLE_MEM_PROFILE */
#endif /* ENABLE_MEM_PROFILE || ENABLE_MEM_CHECK */ #endif /* ENABLE_MEM_PROFILE || ENABLE_MEM_CHECK */
@ -198,11 +214,17 @@ g_malloc0 (gulong size)
*t = size; *t = size;
#ifdef ENABLE_MEM_PROFILE #ifdef ENABLE_MEM_PROFILE
#ifdef ENABLE_MEM_PROFILE_EXCLUDES_MEM_CHUNKS
if(!allocating_for_mem_chunk) {
#endif
if (size <= 4095) if (size <= 4095)
allocations[size-1] += 1; allocations[size-1] += 1;
else else
allocations[4095] += 1; allocations[4095] += 1;
allocated_mem += size; allocated_mem += size;
#ifdef ENABLE_MEM_PROFILE_EXCLUDES_MEM_CHUNKS
}
#endif
#endif /* ENABLE_MEM_PROFILE */ #endif /* ENABLE_MEM_PROFILE */
#endif /* ENABLE_MEM_PROFILE */ #endif /* ENABLE_MEM_PROFILE */
@ -276,11 +298,17 @@ g_realloc (gpointer mem,
*t = size; *t = size;
#ifdef ENABLE_MEM_PROFILE #ifdef ENABLE_MEM_PROFILE
#ifdef ENABLE_MEM_PROFILE_EXCLUDES_MEM_CHUNKS
if(!allocating_for_mem_chunk) {
#endif
if (size <= 4095) if (size <= 4095)
allocations[size-1] += 1; allocations[size-1] += 1;
else else
allocations[4095] += 1; allocations[4095] += 1;
allocated_mem += size; allocated_mem += size;
#ifdef ENABLE_MEM_PROFILE_EXCLUDES_MEM_CHUNKS
}
#endif
#endif /* ENABLE_MEM_PROFILE */ #endif /* ENABLE_MEM_PROFILE */
#endif /* ENABLE_MEM_PROFILE || ENABLE_MEM_CHECK */ #endif /* ENABLE_MEM_PROFILE || ENABLE_MEM_CHECK */
@ -366,6 +394,8 @@ g_mem_chunk_new (gchar *name,
GRealMemChunk *mem_chunk; GRealMemChunk *mem_chunk;
gulong rarea_size; gulong rarea_size;
ENTER_MEM_CHUNK_ROUTINE();
mem_chunk = g_new (struct _GRealMemChunk, 1); mem_chunk = g_new (struct _GRealMemChunk, 1);
mem_chunk->name = name; mem_chunk->name = name;
mem_chunk->type = type; mem_chunk->type = type;
@ -412,6 +442,8 @@ g_mem_chunk_new (gchar *name,
mem_chunks->prev = mem_chunk; mem_chunks->prev = mem_chunk;
mem_chunks = mem_chunk; mem_chunks = mem_chunk;
LEAVE_MEM_CHUNK_ROUTINE();
return ((GMemChunk*) mem_chunk); return ((GMemChunk*) mem_chunk);
} }
@ -424,6 +456,8 @@ g_mem_chunk_destroy (GMemChunk *mem_chunk)
g_assert (mem_chunk != NULL); g_assert (mem_chunk != NULL);
ENTER_MEM_CHUNK_ROUTINE();
rmem_chunk = (GRealMemChunk*) mem_chunk; rmem_chunk = (GRealMemChunk*) mem_chunk;
mem_areas = rmem_chunk->mem_areas; 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_tree_destroy (rmem_chunk->mem_tree);
g_free (rmem_chunk); g_free (rmem_chunk);
LEAVE_MEM_CHUNK_ROUTINE();
} }
gpointer gpointer
@ -455,6 +491,8 @@ g_mem_chunk_alloc (GMemChunk *mem_chunk)
GMemArea *temp_area; GMemArea *temp_area;
gpointer mem; gpointer mem;
ENTER_MEM_CHUNK_ROUTINE();
g_assert (mem_chunk != NULL); g_assert (mem_chunk != NULL);
rmem_chunk = (GRealMemChunk*) mem_chunk; rmem_chunk = (GRealMemChunk*) mem_chunk;
@ -573,6 +611,9 @@ g_mem_chunk_alloc (GMemChunk *mem_chunk)
rmem_chunk->mem_area->allocated += 1; rmem_chunk->mem_area->allocated += 1;
outa_here: outa_here:
LEAVE_MEM_CHUNK_ROUTINE();
return mem; return mem;
} }
@ -587,6 +628,8 @@ g_mem_chunk_free (GMemChunk *mem_chunk,
g_assert (mem_chunk != NULL); g_assert (mem_chunk != NULL);
g_assert (mem != NULL); g_assert (mem != NULL);
ENTER_MEM_CHUNK_ROUTINE();
rmem_chunk = (GRealMemChunk*) mem_chunk; rmem_chunk = (GRealMemChunk*) mem_chunk;
/* Don't do anything if this is an ALLOC_ONLY 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; rmem_chunk->num_marked_areas += 1;
} }
} }
LEAVE_MEM_CHUNK_ROUTINE();
} }
/* This doesn't free the free_area if there is one */ /* This doesn't free the free_area if there is one */