Small patch to show only memory usage.
- From: "R. Bernstein" <rocky panix com>
- To: gtk-devel-list gnome org
- Subject: Small patch to show only memory usage.
- Date: Mon, 22 Jan 2001 19:16:30 -0500 (EST)
Summary:
Here's a little patch that allows a little finer user control over
what information gets dumped when asking about memory statistics.
Motivation:
In tracking down memory leaks in my program, or gnome, or gtk, etc.,
often all I care about is the total amount used. Since I may have to
make extensive calls to get the summary information having the one
line instead of the 30 or so speeds things up and facilitates my
ability to scan the output looking for problems.
Implimentation details:
In the patch, I added a single new function:
void g_mem_summarize (const gchar *msg, gboolean show_alloc_size,
gboolean show_large_alloc, gboolean show_alloc,
gboolean show_freed, gboolean show_used);
which has booleans for each of the pieces of the output for the
existing routine, g_mem_profile(void). g_mem_profile then is just a
call to this new routine which setts all of the parameters to
TRUE.
Another possible interface would be to have just one parameter which
is interpreted as bit vector. One would also have to define a bunch of
bitmasks to allow each of the pieces analogous to be used. This is
similar say to the way the C lib 2 open() routine works with O_APPEND,
O_CREAT and so on.
R. Bernstein
rocky panix com
This has been posted as gtk-rocky-012201-0.patch.tar.gz to ftp.gtk.org
and the above text sent to ftp-admin gimp org as a README.
--- glib-orig.h Thu Mar 23 21:34:01 2000
+++ glib.h Sat Jan 6 09:18:27 2001
@@ -1366,8 +1366,11 @@
#endif /* !USE_DMALLOC */
-void g_mem_profile (void);
-void g_mem_check (gpointer mem);
+void g_mem_profile (void);
+void g_mem_summarize (const gchar *msg, gboolean show_alloc_size,
+ gboolean show_large_alloc, gboolean show_alloc,
+ gboolean show_freed, gboolean show_used);
+void g_mem_check (gpointer mem);
/* Generic allocators
*/
--- gmem-orig.c Fri May 19 03:25:05 2000
+++ gmem.c Sat Jan 6 09:59:53 2001
@@ -415,16 +415,27 @@
#endif /* ! USE_DMALLOC */
-
void
g_mem_profile (void)
{
+ g_mem_summarize(NULL, TRUE, TRUE, TRUE, TRUE, TRUE);
+}
+
+void
+g_mem_summarize (const gchar *msg, gboolean show_alloc_size,
+ gboolean show_large_alloc, gboolean show_alloc,
+ gboolean show_freed, gboolean show_used)
+{
#ifdef ENABLE_MEM_PROFILE
gint i;
gulong local_allocations[MEM_PROFILE_TABLE_SIZE];
gulong local_allocated_mem;
gulong local_freed_mem;
+ if (msg != NULL) {
+ g_log (g_log_domain_glib, G_LOG_LEVEL_INFO,"%s", msg);
+ }
+
g_mutex_lock (mem_profile_lock);
for (i = 0; i < MEM_PROFILE_TABLE_SIZE; i++)
local_allocations[i] = allocations[i];
@@ -433,17 +444,20 @@
g_mutex_unlock (mem_profile_lock);
for (i = 0; i < (MEM_PROFILE_TABLE_SIZE - 1); i++)
- if (local_allocations[i] > 0)
+ if (local_allocations[i] > 0 && show_alloc_size)
g_log (g_log_domain_glib, G_LOG_LEVEL_INFO,
"%lu allocations of %d bytes", local_allocations[i], i + 1);
- if (local_allocations[MEM_PROFILE_TABLE_SIZE - 1] > 0)
+ if (local_allocations[MEM_PROFILE_TABLE_SIZE - 1] > 0 && show_large_alloc)
g_log (g_log_domain_glib, G_LOG_LEVEL_INFO,
"%lu allocations of greater than %d bytes",
local_allocations[MEM_PROFILE_TABLE_SIZE - 1], MEM_PROFILE_TABLE_SIZE - 1);
- g_log (g_log_domain_glib, G_LOG_LEVEL_INFO, "%lu bytes allocated", local_allocated_mem);
- g_log (g_log_domain_glib, G_LOG_LEVEL_INFO, "%lu bytes freed", local_freed_mem);
- g_log (g_log_domain_glib, G_LOG_LEVEL_INFO, "%lu bytes in use", local_allocated_mem - local_freed_mem);
+ if (show_alloc)
+ g_log (g_log_domain_glib, G_LOG_LEVEL_INFO, "%lu bytes allocated", local_allocated_mem);
+ if (show_freed)
+ g_log (g_log_domain_glib, G_LOG_LEVEL_INFO, "%lu bytes freed", local_freed_mem);
+ if (show_used)
+ g_log (g_log_domain_glib, G_LOG_LEVEL_INFO, "%lu bytes in use", local_allocated_mem - local_freed_mem);
#endif /* ENABLE_MEM_PROFILE */
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]