Profiling Hedge

Once you have implemented a testcase which is running and doing what you want, the computation might still take longer than you expected. A program to visualize profile data of your code's run is KCachegrind, which can be installed on a Ubuntu system by

sudo apt-get install kcachegrind

Profiling a whole computation

To profile the whole computation, start your testcase with

python -m lsprofcalltree your_testcase.py

and get a log file called your_testcase.py.log. Open this file with KCachegrind by

kcachegrind your_testcase.py.log

and analyze the graphs to get an idea of where the most time is spent in your computation.

Profiling a single method

To profile a single method of your testcase, you have to add some lines to your code. The following lines shall serve you as an example for profiling a method called profiled_method with the arguments arguments.

   1 from cProfile import Profile
   2 prof = Profile()
   3 try:
   4     prof.runcall(lambda: profiled_method(arguments))
   5 finally:
   6     from lsprofcalltree import KCacheGrind
   7     kg = KCacheGrind(prof)
   8     import sys
   9     kg.output(open(
  10         "your_testcase_profiled_method.log",
  11         "w"))

You would get a log file called your_testcase_profiled_method.log which you can analyze with KCachegrind. In experiments/hedge/maxwell/maxwell-cuda.py you can find an example for that.

Plotting the computation time data

If you want to plot the computation time data, have look at the part of this Wiki that explains plotting graphs with matplotlib.