On Wed, Sep 03, 2003 at 06:53:09PM -0400, Jesse Guardiani wrote:
> Howdy list,
> I'm a Sys Admin running FreeBSD 4.8-RELEASE
> servers.
> During a recent programming/installation
> project, I found myself wanting to know
> the peak memory usage of a given command/process.
> Is there any way to gather this information
> without recompiling an application with a
> sleep or wait statement at the (assumed)
> point of peak memory usage and then looking
> at the process with 'ps'?

That depends on exactly how much time you've got to record the peak
memory usage.  If it's going to be changing faster than you could
catch just by running ps(1) -- like:

    % ps -p NNN -o rsz

where NNN is the pid of your process, then you're probably going to
have to interrupt the process somehow.  You can do that by attaching
to the process using gdb(1), eg:

    % gdb PROGNAME NNN

this will stop the process and leave you in the debugger at the
current program counter.  You'ld have to create a break point when the
program calls malloc(3) or friends, continue running until it hits the
break point, step over the malloc call, check the size using ps(1),
and then continue running again until the next malloc(3) call. Repeat
until the program ends. See the gdb info pages for the gory details.
Nb. this whole thing with gdb(1) is going to be a great deal easier if
you have the source code to your program available and you can run an
unstripped binary.  Doing such a trick on a stripped binary is getting
into real guru territory.  Programs run a lot slower when attached in
a debugger, plus if the program makes heavy use of malloc, it's going
to get really tedious very quickly.



Dr Matthew J Seaman MA, D.Phil.                       26 The Paddocks
                                                      Savill Way
PGP: http://www.infracaninophile.co.uk/pgpkey         Marlow
Tel: +44 1628 476614                                  Bucks., SL7 1TH UK

Attachment: pgp00000.pgp
Description: PGP signature

Reply via email to