11line_profiler and kernprof
22--------------------------
33
4- line_profiler is a module for doing line-by-line profiling of functions.
5- kernprof is a convenient script for running either line_profiler or the Python
4+ ` line_profiler ` is a module for doing line-by-line profiling of functions.
5+ kernprof is a convenient script for running either ` line_profiler ` or the Python
66standard library's cProfile or profile modules, depending on what is available.
77
88They are available under a `BSD license `_.
99
10- .. _BSD license : http ://packages.python.org/ line_profiler/LICENSE.txt
10+ .. _BSD license : https ://raw.githubusercontent.com/rkern/ line_profiler/master /LICENSE.txt
1111
1212.. contents ::
1313
1414
1515Installation
1616============
1717
18- Source releases and any binaries can be downloaded from the PyPI link.
18+ Releases of ` line_profiler ` can be installed using pip _::
1919
20- http://pypi.python.org/pypi/ line_profiler
20+ $ pip install line_profiler
2121
22- The current release of the kernprof.py script may be downloaded separately here:
22+ Source releases and any binaries can be downloaded from the PyPI link.
2323
24- http://packages .python.org/line_profiler/kernprof.py
24+ http://pypi .python.org/pypi/line_profiler
2525
26- To check out the development sources, you can use Mercurial _ ::
26+ To check out the development sources, you can use Git _ ::
2727
28- $ hg clone https://bitbucket.org/robertkern /line_profiler
28+ $ git clone https://github.com/rkern /line_profiler.git
2929
3030You may also download source tarballs of any snapshot from that URL.
3131
32- Source releases will require a C compiler in order to build line_profiler. In
33- addition, Mercurial checkouts will also require Cython _ >= 0.10. Source releases
32+ Source releases will require a C compiler in order to build ` line_profiler `.
33+ In addition, git checkouts will also require Cython _ >= 0.10. Source releases
3434on PyPI should contain the pregenerated C sources, so Cython should not be
3535required in that case.
3636
37- kernprof.py is a single-file pure Python script and does not require a compiler.
38- If you wish to use it to run cProfile and not line-by-line profiling, you may
39- copy it to a directory on your PATH manually and avoid trying to build any
40- C extensions.
41-
42- In order to build and install line_profiler, you will simply use the standard
43- `build and install `_ for most Python packages::
44-
45- $ python setup.py install
37+ `kernprof.py ` is a single-file pure Python script and does not require
38+ a compiler. If you wish to use it to run cProfile and not line-by-line
39+ profiling, you may copy it to a directory on your `PATH ` manually and avoid
40+ trying to build any C extensions.
4641
47- .. _ Mercurial : http://www.selenic. com/mercurial/wiki /
42+ .. _ git : http://git-scm. com/
4843.. _Cython : http://www.cython.org
4944.. _build and install : http://docs.python.org/install/index.html
5045
@@ -75,27 +70,29 @@ of each individual line inside those functions. In a typical workflow, one only
7570cares about line timings of a few functions because wading through the results
7671of timing every single line of code would be overwhelming. However, LineProfiler
7772does need to be explicitly told what functions to profile. The easiest way to
78- get started is to use the kernprof.py script.
73+ get started is to use the ` kernprof ` script. ::
7974
80- If you use "kernprof.py [-l/--line-by-line] script_to_profile.py", an instance
81- of LineProfiler will be created and inserted into the __builtins__ namespace
82- with the name "profile". It has been written to be used as a decorator, so in
83- your script, you can decorate any function you want to profile with @profile. ::
75+ $ kernprof -l script_to_profile.py
76+
77+ `kernprof ` will create an instance of LineProfiler and insert it into the
78+ `__builtins__ ` namespace with the name `profile `. It has been written to be
79+ used as a decorator, so in your script, you can decorate any function you want
80+ to profile with @profile. ::
8481
8582 @profile
8683 def slow_function(a, b, c):
8784 ...
8885
89- The default behavior of kernprof is to put the results into a binary file
90- script_to_profile.py.lprof . You can tell kernprof to immediately view the
86+ The default behavior of ` kernprof ` is to put the results into a binary file
87+ script_to_profile.py.lprof . You can tell ` kernprof ` to immediately view the
9188formatted results at the terminal with the [-v/--view] option. Otherwise, you
9289can view the results later like so::
9390
9491 $ python -m line_profiler script_to_profile.py.lprof
9592
9693For example, here are the results of profiling a single function from
9794a decorated version of the pystone.py benchmark (the first two lines are output
98- from pystone.py, not kernprof)::
95+ from ` pystone.py ` , not ` kernprof ` )::
9996
10097 Pystone(1.1) time for 50000 passes = 2.48
10198 This machine benchmarks at 20161.3 pystones/second
@@ -148,21 +145,11 @@ line. There are six columns of information.
148145If you are using IPython, there is an implementation of an %lprun magic command
149146which will let you specify functions to profile and a statement to execute. It
150147will also add its LineProfiler instance into the __builtins__, but typically,
151- you would not use it like that. For IPython 0.10, you can install it by editing
152- the IPython configuration file ~/.ipython/ipy_user_conf.py to add the following
153- lines::
154-
155- # These two lines are standard and probably already there.
156- import IPython.ipapi
157- ip = IPython.ipapi.get()
158-
159- # These two are the important ones.
160- import line_profiler
161- ip.expose_magic('lprun', line_profiler.magic_lprun)
148+ you would not use it like that.
162149
163150For IPython 0.11+, you can install it by editing the IPython configuration file
164- ~/.ipython/profile_default/ipython_config.py to add the `'line_profiler' ` item
165- to the extensions list::
151+ ` ~/.ipython/profile_default/ipython_config.py ` to add the `'line_profiler' `
152+ item to the extensions list::
166153
167154 c.TerminalIPythonApp.extensions = [
168155 'line_profiler',
@@ -200,7 +187,7 @@ the timer unit.
200187kernprof
201188========
202189
203- kernprof also works with cProfile, its third-party incarnation lsprof, or the
190+ ` kernprof ` also works with cProfile, its third-party incarnation lsprof, or the
204191pure-Python profile module depending on what is available. It has a few main
205192features:
206193
@@ -324,19 +311,19 @@ Frequently Asked Questions
324311 projects for modules as small as these. However, kernprof.py is
325312 a standalone, pure Python script that can be used to do function profiling
326313 with just the Python standard library. You may grab it and install it by
327- itself without line_profiler.
314+ itself without ` line_profiler ` .
328315
329- * Do I need a C compiler to build line_profiler? kernprof.py?
316+ * Do I need a C compiler to build ` line_profiler ` ? kernprof.py?
330317
331318 You do need a C compiler for line_profiler. kernprof.py is a pure Python
332319 script and can be installed separately, though.
333320
334- * Do I need Cython to build line_profiler?
321+ * Do I need Cython to build ` line_profiler ` ?
335322
336323 You should not have to if you are building from a released source tarball.
337324 It should contain the generated C sources already. If you are running into
338325 problems, that may be a bug; let me know. If you are building from
339- a Mercurial checkout or snapshot, you will need Cython to generate the
326+ a git checkout or snapshot, you will need Cython to generate the
340327 C sources. You will probably need version 0.10 or higher. There is a bug in
341328 some earlier versions in how it handles NULL PyObject* pointers.
342329
@@ -367,16 +354,25 @@ now. Maybe later. Contributions accepted!
367354Bugs and Such
368355=============
369356
370- If you find a bug, or a missing feature you really want added, please post to
371- the enthought-dev _ mailing list or email the author at
372- 357+ Bugs and pull requested can be submitted on GitHub _.
373358
374- .. _ enthought-dev : https://mail.enthought. com/mailman/listinfo/enthought-dev
359+ .. _ GitHub : https://github. com/rkern/line_profiler
375360
376361
377362Changes
378363=======
379364
365+ 1.0
366+ ~~~
367+ * ENH: Python 3 support. Thanks to the long-suffering Mikhail Korobov for being
368+ patient.
369+ * ENH: The `stripzeros ` and `add_module ` options. Thanks to Erik Tollerud for
370+ contributing it.
371+ * ENH: Support for IPython cell blocks. Thanks to Michael Forbes for adding
372+ this feature.
373+ * ENH: Better warnings when building without Cython. Thanks to David Cournapeau
374+ for spotting this.
375+
3803761.0b3
381377~~~~~
382378
@@ -396,4 +392,3 @@ Changes
396392~~~~~
397393
398394* Initial release.
399-
0 commit comments