diff --git a/TODO b/TODO index eb5eafd7..aefef472 100644 --- a/TODO +++ b/TODO @@ -5,11 +5,6 @@ - do conv and morph quickly as simple wrappers over the vips7 operations -- with VIPS_ARRAY() etc., we could note the mem use on the object we alloc - local to, might make for interesting stats - - does vips_malloc() used the tracked mem system? - - do much fancier profiling with timing on all locks saved in memory and dumped on exit diff --git a/libvips/include/vips/object.h b/libvips/include/vips/object.h index 79356dea..5d27210a 100644 --- a/libvips/include/vips/object.h +++ b/libvips/include/vips/object.h @@ -456,6 +456,11 @@ struct _VipsObject { gboolean preclose; gboolean close; gboolean postclose; + + /* Total memory allocated relative to this object, handy for + * profiling. + */ + size_t local_memory; }; struct _VipsObjectClass { diff --git a/libvips/iofuncs/memory.c b/libvips/iofuncs/memory.c index 8f423be1..fe95d338 100644 --- a/libvips/iofuncs/memory.c +++ b/libvips/iofuncs/memory.c @@ -150,9 +150,11 @@ vips_malloc( VipsObject *object, size_t size ) buf = g_malloc( size ); - if( object ) + if( object ) { g_signal_connect( object, "postclose", G_CALLBACK( vips_malloc_cb ), buf ); + object->local_memory += size; + } return( buf ); } @@ -179,9 +181,11 @@ vips_strdup( VipsObject *object, const char *str ) str_dup = g_strdup( str ); - if( object ) + if( object ) { g_signal_connect( object, "postclose", G_CALLBACK( vips_malloc_cb ), str_dup ); + object->local_memory += strlen( str ); + } return( str_dup ); } diff --git a/libvips/iofuncs/object.c b/libvips/iofuncs/object.c index 88fdecbb..1047b0b0 100644 --- a/libvips/iofuncs/object.c +++ b/libvips/iofuncs/object.c @@ -1232,6 +1232,9 @@ vips_object_real_dump( VipsObject *object, VipsBuf *buf ) { vips_buf_appendf( buf, " %s (%p)", G_OBJECT_TYPE_NAME( object ), object ); + + if( object->local_memory ) + vips_buf_appendf( buf, " %zd bytes", object->local_memory ); } static void @@ -2448,8 +2451,11 @@ vips_object_print_all_cb( VipsObject *object, int *n ) char str[32768]; VipsBuf buf = VIPS_BUF_STATIC( str ); - fprintf( stderr, "%d) %s (%p)\n", + fprintf( stderr, "%d) %s (%p)", *n, G_OBJECT_TYPE_NAME( object ), object ); + if( object->local_memory ) + fprintf( stderr, " %zd bytes", object->local_memory ); + fprintf( stderr, "\n" ); vips_object_summary_class( class, &buf ); vips_buf_appends( &buf, " " );