[dtrace-discuss] Getting total memory allocated so far

Lally Singh
Wed, 02 Jan 2008 18:02:17 -0000

I''d like to track to total amount of memory the application''s
actually
using right now.   More specifically, I guess these rules would do it:

1. start at M=0
2. for each call to malloc(): set M += size of block returned by malloc
3. for each call to free(): set M -= size of block freed.

I''m using the term ''size of block'' to account for
malloc rounding the
amount requested up to its nearest internal block size.

Pretending that malloc() rounds up to 16 byte increments: if the app
called a=malloc(28), b=malloc(60), free(a), then M=64 (from the
still-used malloc of b, which was rounded up to 64).

So really, just how much memory the app''s using via malloc/free right
now.

Thanks,


On Jan 2, 2008 10:44 AM, Jim Mauro <James.Mauro at sun.com>
wrote:
>
> Can you be more specific about "track memory usage"???
> There''s a broad range of things that could fall into tracking
memory usage.
> For example, if you''re just interested in tracking total physical
and/or
> virtual
> address space sizes, you can use prstat(1). If you''re interested
in the
> various
> segments, you could take some pmap(1) samples from the target process
> periodically.
>
> What, precisely, would you like to track?
>
> Thanks,
> /jim
>
>
>
> Lally Singh wrote:
> > Hey all, I''ve been trying to track memory usage in an
application.
> > I''ve got probes into malloc() and free(), but I''d
like to just get a
> > total allocated amount at any given time (as malloc & free only
give
> > me deltas, and buffer filling can make my running count worthless).
> >
> > Is there any probe for that?  This is on Solaris 10, and I can
> > recompile the app as needed (but there are too many calls to malloc()
> > to directly instrument them or what not).  Would libumem help with
> > this?
> >
> > Thanks in advance!
> >
> > Btw, dtrace is a godsend.  Like a year less working on my PhD godsend.
> >
> >
>



--
H. Lally Singh
Ph.D. Candidate, Computer Science
Virginia Tech