Setting up TraceMalloc with Songbird is straightforward, and you can mostly follow the documentation here http://www.mozilla.org/projects/foot...ive-bloat.html
Read that document before going any further.
There are a few tricky bits though, so I'll document the steps I used. These instructions are Mac specific, but other platforms may be similar.
Start by building your own XULRunner. See http://wiki.songbirdnest.com/Developer/Articles/Getting_Started/Core_Player_Development/Building_Songbird/Building_XULRunner_for_Songbird
We need a hybrid half-release-half-debug-plus-tracemalloc build, so modify your debug mozconfig as follows:
-ac_add_options --disable-optimize --enable-debug
+ac_add_options --enable-cpp-rtti
+ac_add_options --enable-trace-malloc
+ac_add_options --disable-debug
+ac_add_options --enable-optimize="-O -g"
Now check out the mozilla/tools/trace-malloc directory from mozilla central and copy it into your XULRunner tree make -f client.mk build ld: library not found for -ltracemalloc
collect2: ld returned 1 exit status cd compiled/xulrunner-debug
cp staticlib/libtracemalloc.a dist/lib/
make /builds/songbird/trunk/tools/scripts/make-mozilla-sdk.sh /builds/xulrunner/mozilla /builds/xulrunner/mozilla/compiled/xulrunner-debug /builds/songbird/trunk/dependencies/macosx-i686/mozilla/release
/builds/songbird/trunk/tools/scripts/make-xulrunner-tarball.sh /builds/xulrunner/mozilla/compiled/xulrunner-debug/dist/bin /builds/songbird/trunk/dependencies/macosx-i686/xulrunner/release xulrunner.tar.gz Index: configure.ac
===================================================================
--- configure.ac (revision 12576)
+++ configure.ac (working copy)
@@ -685,18 +685,18 @@
MACOSX_FRAMEWORKS="$MACOSX_CONTENTS/Frameworks"
XULRUNNERDIR="/XUL.framework"
- GCC_COMPILER_FLAGS="-c -fexceptions -fnon-call-exceptions -funwind-tables -fasynchronous-unwind-tables -fno-common -fpascal-strings -fno-rtti -no-cpp-precomp -Wall -Wconversion -Wpointer-arith -Wcast-align -Woverloaded-virtual -Wsynth -Wno-ctor-dtor-privacy -Wno-non-virtual-dtor -Wno-long-long -fshort-wchar -pipe"
+ GCC_COMPILER_FLAGS="-c -fexceptions -fnon-call-exceptions -funwind-tables -fasynchronous-unwind-tables -fno-common -fpascal-strings -frtti -no-cpp-precomp -Wall -Wconversion -Wpointer-arith -Wcast-align -Woverloaded-virtual -Wsynth -Wno-ctor-dtor-privacy -Wno-non-virtual-dtor -Wno-long-long -fshort-wchar -pipe"
if test "$enable_debug" = "yes"; then
GCC_COMPILER_FLAGS="-ggdb3 $GCC_COMPILER_FLAGS -fno-inline -O1"
else
# Use -O2 on OS X, better than -Os according to moz perf tests
- GCC_COMPILER_FLAGS="-gstabs+ $GCC_COMPILER_FLAGS -O2"
+ GCC_COMPILER_FLAGS="$GCC_COMPILER_FLAGS -O -g"
fi
# We always want to include "mozilla-config.h"
GCC_COMPILER_FLAGS="$GCC_COMPILER_FLAGS -include \"mozilla-config.h\""
- GCC_LINKER_FLAGS="-lpthread -lobjc -shared-libgcc -lstdc++ -Wl,-executable_path,\$(topsrcdir)/$OBJDIRNAME/$DISTDIRNAME$MACOSX_FRAMEWORKS$XULRUNNERDIR"
+ GCC_LINKER_FLAGS="-lpthread -ltracemalloc -lobjc -shared-libgcc -lstdc++ -Wl,-executable_path,\$(topsrcdir)/$OBJDIRNAME/$DISTDIRNAME$MACOSX_FRAMEWORKS$XULRUNNERDIR"
CFLAGS="$CFLAGS $GCC_COMPILER_FLAGS"
CXXFLAGS="$CXXFLAGS $GCC_COMPILER_FLAGS"
Then copy over the tracemalloc library, since the make-sdk script ignores itcp /builds/xulrunner/mozilla/compiled/xulrunner-debug/staticlib/libtracemalloc.a /builds/songbird/trunk/dependencies/macosx-i686/mozilla/release/lib/make -f songbird.mk clobber ; make -f songbird.mk Index: build/rules.mk
===================================================================
--- build/rules.mk (revision 12576)
+++ build/rules.mk (working copy)
@@ -50,10 +50,6 @@
endif
endif
-ifeq (macosx,$(SB_PLATFORM))
- SB_DYLD_LIBRARY_PATH = $(DEPS_DIR)/libIDL/$(SB_CONFIGURATION)/lib:$(DEPS_DIR)/glib/$(SB_CONFIGURATION)/lib:$(DEPS_DIR)/gettext/$(SB_CONFIGURATION)/lib
- export DYLD_LIBRARY_PATH = $(SB_DYLD_LIBRARY_PATH)
-endif
cd compiled/dist/Songbird.app/Contents/MacOS/
./songbird --trace-malloc /dev/null TraceMallocDumpAllocations("before.snapshot");TraceMallocDumpAllocations("after.snapshot");/builds/songbird/trunk/tools/tracemalloc/fix-macosx-stack.pl before.snapshot > before.fixedsnapshot
/builds/songbird/trunk/tools/tracemalloc/fix-macosx-stack.pl after.snapshot > after.fixedsnapshot ruby /builds/songbird/trunk/tools/tracemalloc/whatsnew.rb before.fixedsnapshot after.fixedsnapshot > whatsnew.fixedsnapshot/builds/xulrunner/mozilla/tools/trace-malloc/diffbloatdump.pl --depth=50 before.fixedsnapshot after.fixedsnapshot > snapshot.diff 3951360 AllocateAudioBufferList
3951360 open_decoder
3951360 qtwrapper_audio_decoder_sink_setcaps
3951360 gst_pad_set_caps
3951360 gst_pad_configure_sink
3951360 gst_pad_chain_unchecked
3951360 gst_pad_push
3951360 gst_base_src_loop
3951360 gst_task_func
3951360 g_thread_pool_thread_proxy
3951360 g_thread_create_proxy
3951360 _pthread_start
This indicates that our quicktime wrapper allocated 4MB that was never freed. /builds/xulrunner/mozilla/tools/trace-malloc/histogram.pl whatsnew.fixedsnapshot void* 7103 2551872
gfxTextRun 19 6341
sbPropertyArray 91 3276
sbPropertyData 66 2640
sbSimpleProperty 13 416
gfxImageSurface 9 360
sbLocalDatabaseResourcePropertyBag 3 312
gfxQuartzImageSurface 9 144
gfxQuartzSurface 2 80
gfxAtsuiFontGroup 1 80
sbLocalDatabaseMediaItem 1 64
There is a type database that can be used to infer void* allocations, but it is outdated and Windows specific. We could update it, but the effort required doesn't seem worthwhile.ruby /builds/songbird/trunk/tools/tracemalloc/blame-map.rb < whatsnew.fixedsnapshot > json-treemap-data.js
open treemap.html
| File | Size | Date | Attached by | |||
|---|---|---|---|---|---|---|
| treemap.png No description | 29.78 kB | 14:51, 2 Mar 2009 | matt | Actions | ||
