For Programmers: Free Programming Magazines  


Home > Archive > Unix Programming > March 2007 > peak memory usage









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author peak memory usage
Rares Vernica

2007-03-21, 5:41 am

Hi,

What is the right tool to find the peak memory usage of a C++ program?

I tried Valgrind but is does not seem to be able to answer my question.
I know "top" shows the memory usage, but it shows it in real time and it
is difficult to get the peak.

Thanks a lot,
Ray
Giorgos Keramidas

2007-03-21, 5:41 am

Rares Vernica <rvernica@gmail.com> writes:
> What is the right tool to find the peak memory usage of a C++ program?


It depends on what operating system you are targetting.

> I tried Valgrind but is does not seem to be able to answer my
> question. I know "top" shows the memory usage, but it shows it in real
> time and it is difficult to get the peak.


Some UNIX systems have other tools too, i.e. on Solaris, you can use
libumem.so.1 and mdb to track down memory usage with a lot of detail.

- Giorgos

Rares Vernica

2007-03-21, 5:41 am

Giorgos Keramidas wrote:
> Rares Vernica <rvernica@gmail.com> writes:
>
> It depends on what operating system you are targetting.
>
>
> Some UNIX systems have other tools too, i.e. on Solaris, you can use
> libumem.so.1 and mdb to track down memory usage with a lot of detail.
>
> - Giorgos
>


I am using Linux (Ubuntu).

Thanks a lot,
Ray
Paul Pluzhnikov

2007-03-21, 5:41 am

Rares Vernica <rvernica@gmail.com> writes:

> What is the right tool to find the peak memory usage of a C++ program?
>
> I tried Valgrind but is does not seem to be able to answer my
> question. I know "top" shows the memory usage, but it shows it in real
> time and it is difficult to get the peak.


Here is what Insure++ produces:

$ cat junk.c
#include <string.h>
int main(int argc, char *argv[])
{
size_t size = 100;
size_t i;
void *vp;

if (1 < argc) size = atoi(argv[1]);
vp = malloc(size);
vp = realloc(vp, 2*size);
free(vp);

return 0;
}

$ insure gcc -g junk.c && ./a.out
************************** INSURE SUMMARY ************************* v7.1 **
* Program : a.out *
* Arguments : *
* Directory : /home/paul *
* Compiled on : Mar 20, 2007 21:37:26 *
* Run on : Mar 20, 2007 21:39:13 *
* Elapsed time : 00:00:00 *
* Malloc HWM : 243 bytes *
****************************************
***********************************
.... some other stuff ...

$ ./a.out 500 2>&1 | grep HWM
* Malloc HWM : 1043 bytes (1K) *

$ ./a.out 2000 2>&1 | grep HWM
* Malloc HWM : 4043 bytes (3K) *

Keeping track of malloc high-water-mark is a tiny fraction of what
Insure can do ...

Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
Rares Vernica

2007-03-21, 7:05 pm

Paul Pluzhnikov wrote:
> Rares Vernica <rvernica@gmail.com> writes:
>
>
> Here is what Insure++ produces:
>
> $ cat junk.c
> #include <string.h>
> int main(int argc, char *argv[])
> {
> size_t size = 100;
> size_t i;
> void *vp;
>
> if (1 < argc) size = atoi(argv[1]);
> vp = malloc(size);
> vp = realloc(vp, 2*size);
> free(vp);
>
> return 0;
> }
>
> $ insure gcc -g junk.c && ./a.out
> ************************** INSURE SUMMARY ************************* v7.1 **
> * Program : a.out *
> * Arguments : *
> * Directory : /home/paul *
> * Compiled on : Mar 20, 2007 21:37:26 *
> * Run on : Mar 20, 2007 21:39:13 *
> * Elapsed time : 00:00:00 *
> * Malloc HWM : 243 bytes *
> ****************************************
***********************************
> ... some other stuff ...
>
> $ ./a.out 500 2>&1 | grep HWM
> * Malloc HWM : 1043 bytes (1K) *
>
> $ ./a.out 2000 2>&1 | grep HWM
> * Malloc HWM : 4043 bytes (3K) *
>
> Keeping track of malloc high-water-mark is a tiny fraction of what
> Insure can do ...
>
> Cheers,


Seems nice, but is not free. :(

Thanks,
Ray
Paul Pluzhnikov

2007-03-21, 10:03 pm

Rares Vernica <rvernica@gmail.com> writes:

>
> Seems nice, but is not free. :(


You never asked for "free" in your original post.
You get what you ask for.

Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
George Peter Staplin

2007-03-24, 4:04 am

Rares Vernica wrote:
> Hi,
>
> What is the right tool to find the peak memory usage of a C++ program?
>
> I tried Valgrind but is does not seem to be able to answer my question.
> I know "top" shows the memory usage, but it shows it in real time and it
> is difficult to get the peak.
>
> Thanks a lot,
> Ray


I wrote a tool for monitoring peaks in NetBSD. It should be fairly easy
to port to other systems. It's much easier and more reliable to use a
graph, than to watch numbers that change quickly.

http://mini.net/tcl/14888

I hope that helps.

-George
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2010 codecomments.com