Static And Dynamic Memory Usage Of An Executable
Nick Clifton
nickc@redhat.com
Thu Nov 17 01:02:00 GMT 2005
Hi Steven,
> in static, i want to know what is the size of each segment, i.e. heap, data,
> text,
The "size" program can give you the information about the data and text
segments. Alternatively you might prefer to use the "objdump" program.
If the heap is actually a segment, then it should show up in the listing
provided by objdump, but for a lot of systems the heap is not actually a
segment, but rather the memory space between two symbols. In this case
you will need to use the "objdump" or "nm" programs to obtain the values
of these symbols and then perform the necessary arithmetic to compute
the heap size.
> in dynamic, i want to know, what size of heap and stack is enough to run
> the program ( a runtime memory usage graph ).
There is no GNU utility to collect this information for you. You will
have to write your own. You can take advantage of the hook inserted by
gcc when it is compiling code for profiling. This hook is a call to a
special external function which is made at the start of every function
compiled by gcc. Usually this function would record the address of the
function and maybe the time as well, but you could have it record the
current stack and heap pointers. See the gcc documentation for more
information.
Cheers
Nick
More information about the Binutils
mailing list