2009年2月4日星期三

Profiling Memory Usage for NS2 Simulation

I am using ns2 to simulate peer-to-peer networking. However, it turns out that the simulator consumes much more memory than I expected. I am sure that my algorithm could not use so much memory. What's happening during the simulation.

I tried dmalloc, but it seems that the dmalloc supporting in ns2 is out-of-data and causes some error. Finally I gave up dmalloc and turned to valgrind.

I used valgrind to detect memory leaks and errors. Today I learned that it can also do memory usage profiling.

First, you have to pass '-g' option to compiler and re-make ns2. It is recommended to remove any optimization flags when debugging.

Then run your program by typing "valgrind --tool=massif ns test_script.tcl". BTW, I recommend u to specify a threshold for massif by using "valgrind --tool=massif --threshold=0.01 ns test_script.tcl" to get more detailed information.

massif will generate a report in current directory. The default name is massif.out.pid, where pid is the process number.

massif.out is a plain text file. Though u can read it directly, there is another helpful tool, ms_print to gather information in the report and print it more readable. Use ms_print --threshold=0.01 massif.out to format the report.

The output of ms_print is very easy to understand and the online document of valgrind has a detailed description about that. Please refer to http://valgrind.org/docs/manual/ms-manual.html

没有评论: