Development:Profiling

Profile Application Execution
Go to the directory where your code is, and run the following command:

python -m cProfile -o openlp.prof openlp.py

Your application should run normally, without any unusual errors.

Command Line
Once you have run your application, you'll want to see the profiling statistics. Create a file called  with the following code:

import pstats p = pstats.Stats('openlp.prof') p.sort_stats('cumulative').print_stats(20)
 * 1) !/usr/bin/env python

Running this should give you output similar to this:

ncalls tottime  percall  cumtime  percall filename:lineno(function) 1   0.000    0.000    1.092    1.092 openlp/plugins/bibles/lib/mediaitem.py:341(onBibleAddClick) 1   0.001    0.001    0.971    0.971 openlp/core/ui/servicemanager.py:188(addServiceItem) 1   0.000    0.000    0.969    0.969 openlp/core/lib/serviceitem.py:59(render) 203   0.036    0.000    0.946    0.005 openlp/core/lib/renderer.py:293(_render_and_wrap_single_line) 3753   0.165    0.000    0.893    0.000 openlp/core/lib/renderer.py:396(_get_extent_and_render) 25   0.794    0.032    0.794    0.032 {built-in method scaled} 5   0.000    0.000    0.614    0.123 openlp/core/lib/rendermanager.py:157(generate_slide) 5   0.000    0.000    0.606    0.121 openlp/core/lib/renderer.py:126(generate_frame_from_lines) 20   0.000    0.000    0.605    0.030 openlp/core/lib/renderer.py:266(_render_lines_unaligned) 1   0.000    0.000    0.523    0.523 openlp/core/ui/servicemanager.py:214(makeLive) 1   0.000    0.000    0.523    0.523 openlp/core/ui/slidecontroller.py:307(addServiceManagerItem) 5   0.000    0.000    0.520    0.104 openlp/core/ui/slidecontroller.py:67(addRow) 5   0.001    0.000    0.520    0.104 openlp/core/ui/slidecontroller.py:52(insertRow) 8   0.428    0.053    0.428    0.053 {built-in method setStandardButtons}

KCachegrind
You also can use KCachegrind if you like to have a GUI. This also for example enables you to see where a function call came from and other useful things. Install it with: sudo apt-get install kcachegrind

You will need to install pyprof2calltree, which allows you to convert openlp.prof to something kcachegrind can manage: sudo easy_install pyprof2calltree

To start kcachegrind simply execute: pyprof2calltree -i openlp.prof -k

More Profiling Information
To see more or other profiling information, or to sort by other columns, see the Profilers page in the Python documentation, and in particular.

Related Links

 * Python speed
 * Python Patterns - An Optimization Anecdote