tags:

views:

191

answers:

2

I want to be able to get an estimate of how much code & static data is used by my C++ program?

Is there a way to find this out by looking at the executable or object files? Or perhaps something I can do at runtime?

Will otool help?

+1  A: 

I think otool can help. Specifically, "otool -s {segment} {section}" should print out the details. I'm not sure if you can get information about __DATA or __TEXT without specifying a section. Maybe those sizes are reported in the mach header: "otool -h"?

otool -s MyApp.bundle/Contents/MacOS/MyApp __DATA __data  
otool -s MyApp.bundle/Contents/MacOS/MyApp __TEXT __text

Anyway, Apple documents what gets copied into each section per-segment here: Apple's mach-o format documentation

Mike Haboustak
+3  A: 
  • "size" is the traditional tool and works on all unix flavors.
  • "otool" has a bit finer grain control and has a lot of options.

.

$ size python
__TEXT  __DATA  __OBJC  others  dec     hex
860160  159744  0       2453504 3473408 350000
Mark Harrison