Code Poetry
and Text Adventures

by catid posted (>30 days ago) 6:01pm Sun. Apr 21st 2013 PDT
Just sharing my experience getting gperftools working on mac.  The goal was to do CPU profiling of the decompressor to see where I need to optimize the C code.

So I checked out gprof first, which doesn't work with clang.  So I looked at Google's gperftools.

gperftools haven't been updated in a year and look abandoned at this point.  They require code changes to do ProfilerStart() and ProfilerStop() in addition to linking to some profiler library, and the documentation is atrocious.

Furthermore it doesn't work with clang on mac either.  Running pprof results in function addresses but no symbols so I can't tell where in the code it's talking about.  Looking at the Google groups it seems like no one knows how to fix it.

I figured out what was wrong but couldn't fix it because clang lacks a lot of useful command-line options.  The problem is that gperftools is not able to resolve the ASLR addresses.  This is a security feature that loads modules to random addresses on startup.  So I needed to disable ASLR.

Reading around online I found that on Mac, ASLR is disabled when PIE is disabled (position-independent execution).  So I tried --disable-aslr, --disable_aslr, --disable-pie, etc, etc on clang's linker line with no luck.

Then I gave up on clang and tried lvm-g++.  The --no-pie option worked and I could get gperftools output to work.

However, gperftools only displays function-level counters and not with good resolution even after I fiddled with its options and editing my code.

So, today I dusted off my Windows 7 laptop at home and got GCIF building and running there with MSVC2010.  Since I've done a lot of development in this environment it's optimized.  Seems a little slower than my desktop at work, maybe due to compiler differences.

Plus MSVC2010 has a delightfully fully-featured profiler in the Ultimate edition with a graphical click-through interface and code annotation with coloring.  It's sooo much better than trying to profile from the command-line.