Using Valgrind for memory check

valgrind is a utility for detecting memory leaks, useful for detecting when are you triying to acees a memorythat has not been previously allocated.

valgrind --tool=memcheck ./programname

Profiling with Zoom

Configure Zoom for Xmipp

You need to follow this instructions once.

  • Type Zoom
  • Select Sampling -> AllowZoomScriptControl
  • In toolbar check that Config combo Box is set to Time Profile
more info is available at http://www.rotateright.com/zoom-quick-start.html (see configuration)

Scripting (zoomscript)

Execute your program:

zoomscript exec `which xmipp_program_name` program_parameters

wait until the program finish.

  • select Topology butterfly (This is a Combo Box in the bottom left).
In the Zoom window appears a new "profile" with the execution results. See http://www.rotateright.com/zoom-quick-start.html for details (profile browser section)

Profiling with GProf

This is a -very basic- guide to profiling with GNU gprof:

1. Compile with "-pg" flag in both CXXFLAGS and LDFLAGS

1. Run the program normally. It will run slower. A file "gmon.out" will be generated.

1. Run gprof with the executable as argument. Redirect its output to a file for convenience

$ gprof myprog > profile.txt

1. Analyze output.


  • Optimize only the bottlenecks!!

  • The second table is more useful (search for granularity)

Profiling with Oprofiler

Oprofiler allows the user to analyze running code to look for bottlenecks on it. Next is a simple example of how to do it with xmipp.

First: Compilation must be done by enabling the debug flag. This will allow a more precise analysis of the results as the names of the invoked functions will appear human readeable.

./scons.configure debug=yes

( NOTE: If any complain arises about "-pg" flag during compilation, just remove "-pg" occurrences from SConstruct file on the xmipp root).

Second: Start the oprofiler daemon. The oprofiler daemon must be run as root as it has strong links with the kernel of the system. So, as root, let's start the daemon which will collect statistics (disabling kernel statistics to center on our program):

opcontrol --no-vmlinux

Since the next instruction, the daemon will keep track of everything which is being executed.

opcontrol  --start

Third: Call your program

./xmipp_reconstruct_art ...

Fourth: Stop the daemon from collecting data:

opcontrol  --shutdown

Fifth: Analyze data.

opreport --symbols

shows this:

CPU: P4 / Xeon with 2 hyper-threads, speed 2992.66 MHz (estimated)
Counted GLOBAL_POWER_EVENTS events (time during which processor is not stopped) with a unit mask of 0x01 (mandatory) count 1215752192
 samples  %        app name                 symbol name
 88       43.5644  xmipp_reconstruct_art    void project_SimpleGrid<double>(VolumeT<double>*, SimpleGrid const*, Basis const*, Projection*, Projection*, int, int, VolumeT<int> const*, Matrix2D<double>*, double, int, int)
25       12.3762  xmipp_reconstruct_art    std::vector<SimpleGrid, std::allocator<SimpleGrid> >::operator=(std::vector<SimpleGrid, std::allocator<SimpleGrid> > const&)
22       10.8911  xmipp_reconstruct_art    VolumeT<double>** std::__copy_backward<true, std::random_access_iterator_tag>::copy_b<VolumeT<double>*>(VolumeT<double>* const*, VolumeT<double>* const*, VolumeT<double>**)
12        5.9406  xmipp_reconstruct_art    Matrix3D<double>::print_stats(std::ostream&) const
 7         3.4653  xmipp_reconstruct_art    Grid::operator=(Grid const&)

Which tells us that the most time-consumin function in our reconstruction code is projectSimpleGrid.

Profiling in Python

cProfile and profile provide deterministic profiling of Python programs. A profile is a set of statistics that describes how often and for how long various parts of the program executed. These statistics can be formatted into reports via the pstats module. See more in http://docs.python.org/2/library/profile.html

For example, for profiling the main protocol windows (xmipp_protocols) we can use:

python -m cProfile `which xmipp_protocols`

The previous example will print out the usage statistics. If you want to graphically analyze it, there is a nice tool, RunSnake that do the job for us. In order to use RunSnake, we need to profile in the following way:

python -m  cProfile -o protocols.profile `which xmipp_protocols`
runsnake protocols.profile