Re: gobject patch to track memory use

On Thu, 2005-02-24 at 22:15 -0600, Federico Mena Quintero wrote:
> On Thu, 2005-02-24 at 18:23 +0100, Alexander Larsson wrote:
> > I spent some day today hacking up a patch to gobject that lets you track
> > what types of GObjects are using memory.
> > 
> > It keeps a list of all live objects, and when you send the process a
> > SIGUSR2 it prints a memory profile. For the size it counts the basic
> > size of the object plus all private data registered with the object. 
> > 
> > Furthermore it adds some API that lets you register a function to
> > calculate the size an object uses. This is useful for objects that own
> > memory allocations that are not GObjects. I also made a gtk+ patch using
> > this to track the real size of GdkPixbuf object.
> This is very nice!  Memprof only shows you mallocs grouped by stack
> trace, but sometimes you need the aggregated size of an object as it
> grows from auxiliary functions.
> I wonder if this patch could be obviated somehow by enhancing the
> memprof GUI to let you group related functions together.  So, you would
> group
>    foo_object_new()
>    foo_object_grow_some_internal_buffer()
>    foo_object_add_string()
>    ... etc ...

One could detect all the allocation in one source file and group them
together. In a one-source-file-per-object model this will work pretty

> > Even without specific functions for all types this is quite useful, as
> > you can see the object counts. I've already detected some strange things
> > in nautilus with this. The top of the memory profile there looks like:
> > 
> > GtkImage: 231 allocated at 104 base size bytes, 23 kb total size
> > GstPadTemplate: 334 allocated at 76 base size bytes, 24 kb total size
> > GtkSeparatorMenuItem: 284 allocated at 96 base size bytes, 26 kb total size
> > NautilusIconCanvasItem: 502 allocated at 64 base size bytes, 31 kb total size
> > GtkAccelLabel: 306 allocated at 168 base size bytes, 50 kb total size
> > NautilusVFSFile: 1005 allocated at 128 base size bytes, 296 kb total size
> > GdkPixbuf: 340 allocated at 52 base size bytes, 6409 kb total size
> What's the strange thing you detected?  Just curious.

We're allocating about 140 GtkSeparatorMenuItem per window. Apparently
GtkUIManager allocates two per placeholder in the xml files.

> It may be nice to enable this patch if you compile glib with
> --enable-debug.

Or at least something like it. I think the way you register the memuse
handler is a bit ugly.

 Alexander Larsson                                            Red Hat, Inc 
                   alexl redhat com    alla lysator liu se 
He's a maverick day-dreaming waffle chef who dotes on his loving old ma. She's 
a strong-willed green-skinned barmaid who inherited a spooky stately manor 
from her late maiden aunt. They fight crime! 

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]