Profiling Overview

Profiling can mean a few different things, so here are the current ways!

Profiling with Valgrind

This option is Linux only. See Profiling with Valgrind for details.

Profiling with cProfile

Mantid supports profiling of its underlying code using the cProfile module from python.

Launch Mantid Workbench from the command line using the script in the installation folder, adding the --profile modifier with a path to the output file.

E.g: path/to/install/bin/workbench --profile path/to/outputFile.prof

This profile can then either be sent to the developers upon request or be analysed using the python module snakeviz.

Profiling with Yappi

cProfile can only profile the current thread, this makes it useful for diagnosing PyQt performance issues (such as random hangs when a user does something), but poor for diagnosing workflow algorithm issues.

Yappi (Yet Another Python Profiler) is multithreading aware. cProfile which will show everything up to the exec, or run call. Yappi will profile the thread and show any slow points within the separate thread.

Note: This will not with QThreads and may crash or be unable to profile inside. It is recommended you migrate workers by inheriting from IQtAsync, see async_qt_adaptor.py for details. Using native threading enables tooling, makes testing simple and produces readable stack traces.

To use Yappi instead of cProfile simple append –yappi to the list of arguments after profile, e.g.:

# If you do not have yappi installed
python3 -m pip install yappi --user
# Run with Yappi profiler
./MantidWorkbench --profile name_of_profile.out --yappi

KCachegrind can be used to view profiling data, see Profiling with Valgrind for more details on usage.

Profiling an algorithm

On Linux, the build can be configured to generate algorithm profiling information. See AlgorithmProfiler for details.

Other Profiling Tools

Linux

Callgrind/KCachegrind

gperftools

  • Takes snapshot of run and prints percentage of calls in functions

See here for a list of other tools: http://www.pixelbeat.org/programming/profiling/

Windows

Very Sleepy:

  • Start/stop recording of program using a button

  • Not as detailed or flexible as callgrind