Differences between revisions 13 and 14
Revision 13 as of 2012-10-19 16:21:26
Size: 0
Editor: 46
Comment:
Revision 14 as of 2013-01-16 23:14:50
Size: 1994
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
## page was renamed from SciComp/Hedge/HowTo/ProfilingHedge
## page was renamed from SciComp/HedgeHowTo/ProfilingHedge
= Profiling Hedge =

<<TableOfContents>>

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 [[http://kcachegrind.sourceforge.net/html/Home.html|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 [[http://kcachegrind.sourceforge.net/html/Home.html|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`.
{{{#!python
from cProfile import Profile
prof = Profile()
try:
    prof.runcall(lambda: profiled_method(arguments))
finally:
    from lsprofcalltree import KCacheGrind
    kg = KCacheGrind(prof)
    import sys
    kg.output(open(
        "your_testcase_profiled_method.log",
        "w"))
}}}
You would get a log file called `your_testcase_profiled_method.log` which you can analyze with [[http://kcachegrind.sourceforge.net/html/Home.html|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 [[http://webapp.dam.brown.edu/wiki/SciComp/PythonHowTo/Plot|plotting graphs with matplotlib]].

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.

Hedge/HowTo/ProfilingHedge (last edited 2013-01-16 23:14:50 by AndreasKloeckner)