views:

84

answers:

4

Hello, I wrote an application that needs to be compared with another one that does the same job.. mine is in OCaml while other one is in Java.

I would like to make two runs on the programs and monitor the RAM usage during the time elapsed by these executions. Both programs are really memory and cpu intensive so I'll have enough data to compare them but I don't know how.

I know that it is not so much meaningful to benchmark applications written in different languages but is there a tool that simply monitors RAM usage of a program during time maybe providing a data set or a graph as the result?

EDIT: ideal operating system is Mac OS X or just unix

+2  A: 

You can monitor Java usage with /usr/bin/jvisualvm

The Activity Monitor program can give you a rough estimate of the resource usage of any usual Unix program.

Thorbjørn Ravn Andersen
I'm actually using Activity Monitor but since there are many GC sweeps in both programs it's hard to estimate the usage without having the whole dataset along time
Jack
For finer details for Java have a look at jvisualvm (start from TErminal.app)
Thorbjørn Ravn Andersen
+3  A: 

while : ; do ps --no-header -o %cpu,vsz,rss -p PID; sleep 1 ; done

ygrek
+3  A: 

I use a solution comparable to ygrek's. It is quite universal in terms of the implementation language, as long as you are using Unix. A small issue is that the commands top and ps that can both be used for this purpose are both working differently on BSD Unix (that Mac OS X derives from) and Linux. I guess that his commandline is for Linux.

For Mac OS X, I used:

top -s 10 -l 10000 | grep <PID or process name>

and for Linux:

top -d 10 -n 10000 | grep <PID or process name>

The 10 is the sampling period in seconds.

If you want to get your information from OCaml's GC, you can use OCaml's GC module, but that is not directly comparable to the behavior of a Java program.

Edited to add: where a GC is involved, there is a trade-off between memory overhead and CPU time overhead. The GC can work harder to make dead blocks available sooner and thus keep memory consumption lower. If you find that this makes it hard to compare your two programs, you can adjust OCaml's GC to make it use the same kind of trade-off as the Java GC. This is documented in the GC module. I expect Java allows this setting to be tuned too.

Pascal Cuoq
+1  A: 

Valgrind's Massif tool can do this for native code.

Gaius