From 037b641aa1ada4cd13d917995e20a90716166a11 Mon Sep 17 00:00:00 2001 From: Olivier Grisel <olivier.grisel@ensta.org> Date: Sat, 28 Jan 2012 18:47:12 +0100 Subject: [PATCH] cosmit in memory debugging doc --- doc/developers/debugging.rst | 43 +++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/doc/developers/debugging.rst b/doc/developers/debugging.rst index 832eb3d4b7..f3e28110f1 100644 --- a/doc/developers/debugging.rst +++ b/doc/developers/debugging.rst @@ -6,39 +6,46 @@ Developers' Tips for Debugging Memory errors: debugging Cython with valgrind ============================================= + While python/numpy's built-in memory management is relatively robust, it can -lead to performance penalties for some routines. For this reason, much of -the high-performance code in scikit-learn in written in cython. This +lead to performance penalties for some routines. For this reason, much of +the high-performance code in scikit-learn in written in cython. This performance gain comes with a tradeoff, however: it is very easy for memory bugs to crop up in cython code, especially in situations where that code relies heavily on pointer arithmetic. -Memory errors can manifest themselves a number of ways. The easiest ones to -debug are often segmentation faults and related glibc errors. Uninitialized +Memory errors can manifest themselves a number of ways. The easiest ones to +debug are often segmentation faults and related glibc errors. Uninitialized variables can lead to unexpected behavior that is difficult to track down. A very useful tool when debugging these sorts of errors is -`valgrind <http://valgrind.org>`_. +valgrind_. + Valgrind is a command-line tool that can trace memory errors in a variety of -code. Follow these steps: +code. Follow these steps: + + 1. Install `valgrind`_ on your system. + + 2. Download the python valgrind suppression file: `valgrind-python.supp`_. + + 3. Follow the directions in the `README.valgrind`_ file to customize your + python suppressions. If you don't, you will have spurious output coming + related to the python interpreter instead of your own code. + + 4. Run valgrind as follows:: - 1. Install valgrind from `valgrind.org <http://valgrind.org>`_. - 2 Download the python valgrind suppression file: `valgrind-python.supp <http://svn.python.org/projects/python/trunk/Misc/valgrind-python.supp>`_. + $> valgrind -v --suppressions=valgrind-python.supp python my_test_script.py - 3. Download the valgrind/python readme file: - `README.valgrind <http://svn.python.org/projects/python/trunk/Misc/README.valgrind>`_. +.. _valgrind: http://valgrind.org +.. _`README.valgrind`: http://svn.python.org/projects/python/trunk/Misc/README.valgrind +.. _`valgrind-python.supp`: http://svn.python.org/projects/python/trunk/Misc/valgrind-python.supp - 4. Follow the directions in the README file to set up your python - suppressions. - 5. Run valgrind as follows:: - - $> valgrind -v --suppressions=valgrind-python.supp python my_test_script.py The result will be a list of all the memory-related errors, which reference -lines in the C-code generated by cython from your .pyx file. If you examine +lines in the C-code generated by cython from your .pyx file. If you examine the referenced lines in the .c file, you will see comments which indicate the -corresponding location in your .pyx source file. Hopefully the output will +corresponding location in your .pyx source file. Hopefully the output will give you clues as to the source of your memory error. For more information on valgrind and the array of options it has, see the -tutorials and documentation on the `valgrind web site <http://valgrind.org>`_. \ No newline at end of file +tutorials and documentation on the `valgrind web site <http://valgrind.org>`_. -- GitLab