Debian Codegraph @

docs/devguide/profiling.rst

raw
1 ===================
2 Profiling PyGObject
3 ===================
4
5 Setup
6 =====
7
8 General vpath build setup with jhbuild shell (x86_64):
9
10 .. code-block:: bash
11
12 mkdir _build
13 cd _build
14 export PYTHON=`which python3.3`
15 jhbuild shell
16 ../configure --prefix=$JHBUILD_PREFIX --libdir=$JHBUILD_LIBDIR --with-python=$PYTHON
17 make
18
19 Devise a simple script to profile (myproftest.py):
20
21 .. code-block:: python
22
23 from gi.repository import Gtk
24
25 model = Gtk.ListStore(str, str, str, int, int, int)
26 columns = [0, 1, 2, 3, 4, 5]
27 row = ['a'*16, 'b'*16, 'c'*16, 1, 2, 3]
28
29 for i in range(100000):
30 model.insert_with_valuesv(-1, columns, row)
31
32 Python Profile
33 ==============
34
35 Use cProfile and kcachegrind (via pyprof2calltree):
36
37 .. code-block:: bash
38
39 PROFTEST=myproftest
40 $PYTHON -m cProfile -o $PROFTEST.pyprof $PROFTEST.py
41 pyprof2calltree -i $PROFTEST.pyprof -k
42
43 C Extension (callgrind)
44 =======================
45
46 .. code-block:: bash
47
48 PROFTEST=myproftest
49 valgrind --tool=callgrind --callgrind-out-file=$PROFTEST.callgrind $PYTHON $PROFTEST.py
50 kcachegrind $PROFTEST.callgrind
51
52 C Extension (gperftools)
53 ========================
54
55 Google PerfTools https://code.google.com/p/gperftools
56
57 .. code-block:: bash
58
59 PROFTEST=myproftest
60 $PYTHON -m yep -o $PROFTEST.py.prof $PROFTEST.py
61 google-pprof --callgrind $PYTHON $PROFTEST.py.prof > $PROFTEST.callgrind
62 kcachegrind $PROFTEST.callgrind