Profiling Python with valgrind === --- ### 1. Under Linux, install valgrind as follows (Fedora): ```bash= sudo yum install valgrind kcachegrind ``` and pyprof2calltree: ```bash= pip install pyprof2calltree ``` --- ### 2. Create a Python script (let us call it run.py) --- ### 3. Create the file containing the profile information using valgrind/callgrind ```bash= python -m cProfile -o profile_data.pyprof run.py # this converts the stats into a callgrind format pyprof2calltree -i profile_data.pyprof ``` --- ### 4. Visualisation ```bash= kcachegrind profile_data.pyprof.log ``` Alternatively, for visualisation, you can also use gprof2dot and graphviz (dot): ```bash= gprof2dot.py --format=callgrind --output=out.dot profile_data.pyprof.log dot -Tsvg out.dot -o graph.svg ```