Static And Dynamic Memory Usage Of An Executable

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Static And Dynamic Memory Usage Of An Executable

narke

i am developing embedded program, the memory resource is strictly limited. so,
during development i want to keep an eye on how big my program will be.
in static, i want to know what is the size of each segment, i.e. heap, data,
text, in dynamic, i want to know, what size of heap and stack is enough to run
the program ( a runtime memory usage graph ).

what Gnu utility can give me information as above?  thanks in advance.


--
steven woody (id: narke)

John McFarland: Hey, what are you guys doing?
Alex: Get the fuck out and don't come back! Some heavy shit's going down!

        - Elephant (2003)

Reply | Threaded
Open this post in threaded view
|

Re: Static And Dynamic Memory Usage Of An Executable

Nick Clifton
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


Reply | Threaded
Open this post in threaded view
|

Re: Static And Dynamic Memory Usage Of An Executable

SandeepKsinha
On 11/16/05, Nick Clifton <[hidden email]> wrote:

> 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.
We do have valgrind under the GNU utilities. It is a runtime memory
profiler which can give us asll the information about the runtime
allocation of memory.

>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.

Try valgrinf , it has a tool memprof. It will give you all the details
about runtime allocation of memory tht u reuqire.
--
Regards,
Sandeep