[Python-modules-commits] [python-line-profiler] 01/03: New upstream version 2.0+ds1
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Tue Mar 7 13:04:45 UTC 2017
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to branch master
in repository python-line-profiler.
commit a769f88730c108ed7c560388eb93da80236c121b
Author: Ghislain Antony Vaillant <ghisvail at gmail.com>
Date: Tue Mar 7 12:33:18 2017 +0000
New upstream version 2.0+ds1
---
LICENSE.txt | 28 ++
LICENSE_Python.txt | 276 ++++++++++++
MANIFEST.in | 8 +
PKG-INFO | 33 ++
README.rst | 397 ++++++++++++++++++
_line_profiler.pyx | 228 ++++++++++
kernprof.py | 234 +++++++++++
line_profiler.egg-info/PKG-INFO | 33 ++
line_profiler.egg-info/SOURCES.txt | 22 +
line_profiler.egg-info/dependency_links.txt | 1 +
line_profiler.egg-info/entry_points.txt | 3 +
line_profiler.egg-info/requires.txt | 1 +
line_profiler.egg-info/top_level.txt | 3 +
line_profiler.py | 387 +++++++++++++++++
python25.pxd | 629 ++++++++++++++++++++++++++++
setup.cfg | 5 +
setup.py | 79 ++++
tests/test_kernprof.py | 74 ++++
tests/test_line_profiler.py | 99 +++++
timers.c | 68 +++
timers.h | 4 +
unset_trace.c | 7 +
unset_trace.h | 1 +
23 files changed, 2620 insertions(+)
diff --git a/LICENSE.txt b/LICENSE.txt
new file mode 100644
index 0000000..a2a399b
--- /dev/null
+++ b/LICENSE.txt
@@ -0,0 +1,28 @@
+This software is OSI Certified Open Source Software.
+OSI Certified is a certification mark of the Open Source Initiative.
+
+Copyright (c) 2008, Enthought, Inc.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ * Neither the name of Enthought, Inc. nor the names of its contributors may
+ be used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/LICENSE_Python.txt b/LICENSE_Python.txt
new file mode 100644
index 0000000..3bc28eb
--- /dev/null
+++ b/LICENSE_Python.txt
@@ -0,0 +1,276 @@
+The file timers.c was derived from the timer code in Python 2.5.2's _lsprof.c
+file and falls under the PSF license given below.
+
+
+A. HISTORY OF THE SOFTWARE
+==========================
+
+Python was created in the early 1990s by Guido van Rossum at Stichting
+Mathematisch Centrum (CWI, see http://www.cwi.nl) in the Netherlands
+as a successor of a language called ABC. Guido remains Python's
+principal author, although it includes many contributions from others.
+
+In 1995, Guido continued his work on Python at the Corporation for
+National Research Initiatives (CNRI, see http://www.cnri.reston.va.us)
+in Reston, Virginia where he released several versions of the
+software.
+
+In May 2000, Guido and the Python core development team moved to
+BeOpen.com to form the BeOpen PythonLabs team. In October of the same
+year, the PythonLabs team moved to Digital Creations (now Zope
+Corporation, see http://www.zope.com). In 2001, the Python Software
+Foundation (PSF, see http://www.python.org/psf/) was formed, a
+non-profit organization created specifically to own Python-related
+Intellectual Property. Zope Corporation is a sponsoring member of
+the PSF.
+
+All Python releases are Open Source (see http://www.opensource.org for
+the Open Source Definition). Historically, most, but not all, Python
+releases have also been GPL-compatible; the table below summarizes
+the various releases.
+
+ Release Derived Year Owner GPL-
+ from compatible? (1)
+
+ 0.9.0 thru 1.2 1991-1995 CWI yes
+ 1.3 thru 1.5.2 1.2 1995-1999 CNRI yes
+ 1.6 1.5.2 2000 CNRI no
+ 2.0 1.6 2000 BeOpen.com no
+ 1.6.1 1.6 2001 CNRI yes (2)
+ 2.1 2.0+1.6.1 2001 PSF no
+ 2.0.1 2.0+1.6.1 2001 PSF yes
+ 2.1.1 2.1+2.0.1 2001 PSF yes
+ 2.2 2.1.1 2001 PSF yes
+ 2.1.2 2.1.1 2002 PSF yes
+ 2.1.3 2.1.2 2002 PSF yes
+ 2.2.1 2.2 2002 PSF yes
+ 2.2.2 2.2.1 2002 PSF yes
+ 2.2.3 2.2.2 2003 PSF yes
+ 2.3 2.2.2 2002-2003 PSF yes
+ 2.3.1 2.3 2002-2003 PSF yes
+ 2.3.2 2.3.1 2002-2003 PSF yes
+ 2.3.3 2.3.2 2002-2003 PSF yes
+ 2.3.4 2.3.3 2004 PSF yes
+ 2.3.5 2.3.4 2005 PSF yes
+ 2.4 2.3 2004 PSF yes
+ 2.4.1 2.4 2005 PSF yes
+ 2.4.2 2.4.1 2005 PSF yes
+ 2.4.3 2.4.2 2006 PSF yes
+ 2.4.4 2.4.3 2006 PSF yes
+ 2.5 2.4 2006 PSF yes
+ 2.5.1 2.5 2007 PSF yes
+ 2.5.2 2.5.2 2008 PSF yes
+
+Footnotes:
+
+(1) GPL-compatible doesn't mean that we're distributing Python under
+ the GPL. All Python licenses, unlike the GPL, let you distribute
+ a modified version without making your changes open source. The
+ GPL-compatible licenses make it possible to combine Python with
+ other software that is released under the GPL; the others don't.
+
+(2) According to Richard Stallman, 1.6.1 is not GPL-compatible,
+ because its license has a choice of law clause. According to
+ CNRI, however, Stallman's lawyer has told CNRI's lawyer that 1.6.1
+ is "not incompatible" with the GPL.
+
+Thanks to the many outside volunteers who have worked under Guido's
+direction to make these releases possible.
+
+
+B. TERMS AND CONDITIONS FOR ACCESSING OR OTHERWISE USING PYTHON
+===============================================================
+
+PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
+--------------------------------------------
+
+1. This LICENSE AGREEMENT is between the Python Software Foundation
+("PSF"), and the Individual or Organization ("Licensee") accessing and
+otherwise using this software ("Python") in source or binary form and
+its associated documentation.
+
+2. Subject to the terms and conditions of this License Agreement, PSF
+hereby grants Licensee a nonexclusive, royalty-free, world-wide
+license to reproduce, analyze, test, perform and/or display publicly,
+prepare derivative works, distribute, and otherwise use Python
+alone or in any derivative version, provided, however, that PSF's
+License Agreement and PSF's notice of copyright, i.e., "Copyright (c)
+2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Python Software Foundation;
+All Rights Reserved" are retained in Python alone or in any derivative
+version prepared by Licensee.
+
+3. In the event Licensee prepares a derivative work that is based on
+or incorporates Python or any part thereof, and wants to make
+the derivative work available to others as provided herein, then
+Licensee hereby agrees to include in any such work a brief summary of
+the changes made to Python.
+
+4. PSF is making Python available to Licensee on an "AS IS"
+basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
+IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND
+DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
+FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON WILL NOT
+INFRINGE ANY THIRD PARTY RIGHTS.
+
+5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON
+FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS
+A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON,
+OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
+
+6. This License Agreement will automatically terminate upon a material
+breach of its terms and conditions.
+
+7. Nothing in this License Agreement shall be deemed to create any
+relationship of agency, partnership, or joint venture between PSF and
+Licensee. This License Agreement does not grant permission to use PSF
+trademarks or trade name in a trademark sense to endorse or promote
+products or services of Licensee, or any third party.
+
+8. By copying, installing or otherwise using Python, Licensee
+agrees to be bound by the terms and conditions of this License
+Agreement.
+
+
+BEOPEN.COM LICENSE AGREEMENT FOR PYTHON 2.0
+-------------------------------------------
+
+BEOPEN PYTHON OPEN SOURCE LICENSE AGREEMENT VERSION 1
+
+1. This LICENSE AGREEMENT is between BeOpen.com ("BeOpen"), having an
+office at 160 Saratoga Avenue, Santa Clara, CA 95051, and the
+Individual or Organization ("Licensee") accessing and otherwise using
+this software in source or binary form and its associated
+documentation ("the Software").
+
+2. Subject to the terms and conditions of this BeOpen Python License
+Agreement, BeOpen hereby grants Licensee a non-exclusive,
+royalty-free, world-wide license to reproduce, analyze, test, perform
+and/or display publicly, prepare derivative works, distribute, and
+otherwise use the Software alone or in any derivative version,
+provided, however, that the BeOpen Python License is retained in the
+Software, alone or in any derivative version prepared by Licensee.
+
+3. BeOpen is making the Software available to Licensee on an "AS IS"
+basis. BEOPEN MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
+IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, BEOPEN MAKES NO AND
+DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
+FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THE SOFTWARE WILL NOT
+INFRINGE ANY THIRD PARTY RIGHTS.
+
+4. BEOPEN SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF THE
+SOFTWARE FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS
+AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THE SOFTWARE, OR ANY
+DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
+
+5. This License Agreement will automatically terminate upon a material
+breach of its terms and conditions.
+
+6. This License Agreement shall be governed by and interpreted in all
+respects by the law of the State of California, excluding conflict of
+law provisions. Nothing in this License Agreement shall be deemed to
+create any relationship of agency, partnership, or joint venture
+between BeOpen and Licensee. This License Agreement does not grant
+permission to use BeOpen trademarks or trade names in a trademark
+sense to endorse or promote products or services of Licensee, or any
+third party. As an exception, the "BeOpen Python" logos available at
+http://www.pythonlabs.com/logos.html may be used according to the
+permissions granted on that web page.
+
+7. By copying, installing or otherwise using the software, Licensee
+agrees to be bound by the terms and conditions of this License
+Agreement.
+
+
+CNRI LICENSE AGREEMENT FOR PYTHON 1.6.1
+---------------------------------------
+
+1. This LICENSE AGREEMENT is between the Corporation for National
+Research Initiatives, having an office at 1895 Preston White Drive,
+Reston, VA 20191 ("CNRI"), and the Individual or Organization
+("Licensee") accessing and otherwise using Python 1.6.1 software in
+source or binary form and its associated documentation.
+
+2. Subject to the terms and conditions of this License Agreement, CNRI
+hereby grants Licensee a nonexclusive, royalty-free, world-wide
+license to reproduce, analyze, test, perform and/or display publicly,
+prepare derivative works, distribute, and otherwise use Python 1.6.1
+alone or in any derivative version, provided, however, that CNRI's
+License Agreement and CNRI's notice of copyright, i.e., "Copyright (c)
+1995-2001 Corporation for National Research Initiatives; All Rights
+Reserved" are retained in Python 1.6.1 alone or in any derivative
+version prepared by Licensee. Alternately, in lieu of CNRI's License
+Agreement, Licensee may substitute the following text (omitting the
+quotes): "Python 1.6.1 is made available subject to the terms and
+conditions in CNRI's License Agreement. This Agreement together with
+Python 1.6.1 may be located on the Internet using the following
+unique, persistent identifier (known as a handle): 1895.22/1013. This
+Agreement may also be obtained from a proxy server on the Internet
+using the following URL: http://hdl.handle.net/1895.22/1013".
+
+3. In the event Licensee prepares a derivative work that is based on
+or incorporates Python 1.6.1 or any part thereof, and wants to make
+the derivative work available to others as provided herein, then
+Licensee hereby agrees to include in any such work a brief summary of
+the changes made to Python 1.6.1.
+
+4. CNRI is making Python 1.6.1 available to Licensee on an "AS IS"
+basis. CNRI MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
+IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, CNRI MAKES NO AND
+DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
+FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON 1.6.1 WILL NOT
+INFRINGE ANY THIRD PARTY RIGHTS.
+
+5. CNRI SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON
+1.6.1 FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS
+A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON 1.6.1,
+OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
+
+6. This License Agreement will automatically terminate upon a material
+breach of its terms and conditions.
+
+7. This License Agreement shall be governed by the federal
+intellectual property law of the United States, including without
+limitation the federal copyright law, and, to the extent such
+U.S. federal law does not apply, by the law of the Commonwealth of
+Virginia, excluding Virginia's conflict of law provisions.
+Notwithstanding the foregoing, with regard to derivative works based
+on Python 1.6.1 that incorporate non-separable material that was
+previously distributed under the GNU General Public License (GPL), the
+law of the Commonwealth of Virginia shall govern this License
+Agreement only as to issues arising under or with respect to
+Paragraphs 4, 5, and 7 of this License Agreement. Nothing in this
+License Agreement shall be deemed to create any relationship of
+agency, partnership, or joint venture between CNRI and Licensee. This
+License Agreement does not grant permission to use CNRI trademarks or
+trade name in a trademark sense to endorse or promote products or
+services of Licensee, or any third party.
+
+8. By clicking on the "ACCEPT" button where indicated, or by copying,
+installing or otherwise using Python 1.6.1, Licensee agrees to be
+bound by the terms and conditions of this License Agreement.
+
+ ACCEPT
+
+
+CWI LICENSE AGREEMENT FOR PYTHON 0.9.0 THROUGH 1.2
+--------------------------------------------------
+
+Copyright (c) 1991 - 1995, Stichting Mathematisch Centrum Amsterdam,
+The Netherlands. All rights reserved.
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the name of Stichting Mathematisch
+Centrum or CWI not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior
+permission.
+
+STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
+THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
+FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644
index 0000000..a24056f
--- /dev/null
+++ b/MANIFEST.in
@@ -0,0 +1,8 @@
+include LICENSE.txt
+include LICENSE_Python.txt
+include README.rst
+include python25.pxd
+include timers.h
+include _line_profiler.c
+include unset_trace.h
+recursive-include tests *.py
diff --git a/PKG-INFO b/PKG-INFO
new file mode 100644
index 0000000..0ded524
--- /dev/null
+++ b/PKG-INFO
@@ -0,0 +1,33 @@
+Metadata-Version: 1.1
+Name: line_profiler
+Version: 2.0
+Summary: Line-by-line profiler.
+Home-page: https://github.com/rkern/line_profiler
+Author: Robert Kern
+Author-email: robert.kern at enthought.com
+License: BSD
+Download-URL: https://github.com/rkern/line_profiler/tarball/2.0
+Description: line_profiler will profile the time individual lines of code take to execute.
+ The profiler is implemented in C via Cython in order to reduce the overhead of
+ profiling.
+
+ Also included is the script kernprof.py which can be used to conveniently
+ profile Python applications and scripts either with line_profiler or with the
+ function-level profiling tools in the Python standard library.
+
+Keywords: timing,timer,profiling,profiler,line_profiler
+Platform: UNKNOWN
+Classifier: Development Status :: 5 - Production/Stable
+Classifier: Intended Audience :: Developers
+Classifier: License :: OSI Approved :: BSD License
+Classifier: Operating System :: OS Independent
+Classifier: Programming Language :: C
+Classifier: Programming Language :: Python
+Classifier: Programming Language :: Python :: 2
+Classifier: Programming Language :: Python :: 2.7
+Classifier: Programming Language :: Python :: 3
+Classifier: Programming Language :: Python :: 3.2
+Classifier: Programming Language :: Python :: 3.3
+Classifier: Programming Language :: Python :: 3.4
+Classifier: Programming Language :: Python :: Implementation :: CPython
+Classifier: Topic :: Software Development
diff --git a/README.rst b/README.rst
new file mode 100644
index 0000000..25aed25
--- /dev/null
+++ b/README.rst
@@ -0,0 +1,397 @@
+line_profiler and kernprof
+--------------------------
+
+`line_profiler` is a module for doing line-by-line profiling of functions.
+kernprof is a convenient script for running either `line_profiler` or the Python
+standard library's cProfile or profile modules, depending on what is available.
+
+They are available under a `BSD license`_.
+
+.. _BSD license: https://raw.githubusercontent.com/rkern/line_profiler/master/LICENSE.txt
+
+.. contents::
+
+
+Installation
+============
+
+Releases of `line_profiler` can be installed using pip::
+
+ $ pip install line_profiler
+
+Source releases and any binaries can be downloaded from the PyPI link.
+
+ http://pypi.python.org/pypi/line_profiler
+
+To check out the development sources, you can use Git_::
+
+ $ git clone https://github.com/rkern/line_profiler.git
+
+You may also download source tarballs of any snapshot from that URL.
+
+Source releases will require a C compiler in order to build `line_profiler`.
+In addition, git checkouts will also require Cython_ >= 0.10. Source releases
+on PyPI should contain the pregenerated C sources, so Cython should not be
+required in that case.
+
+`kernprof` is a single-file pure Python script and does not require
+a compiler. If you wish to use it to run cProfile and not line-by-line
+profiling, you may copy it to a directory on your `PATH` manually and avoid
+trying to build any C extensions.
+
+.. _git: http://git-scm.com/
+.. _Cython: http://www.cython.org
+.. _build and install: http://docs.python.org/install/index.html
+
+
+line_profiler
+=============
+
+The current profiling tools supported in Python 2.7 and later only time
+function calls. This is a good first step for locating hotspots in one's program
+and is frequently all one needs to do to optimize the program. However,
+sometimes the cause of the hotspot is actually a single line in the function,
+and that line may not be obvious from just reading the source code. These cases
+are particularly frequent in scientific computing. Functions tend to be larger
+(sometimes because of legitimate algorithmic complexity, sometimes because the
+programmer is still trying to write FORTRAN code), and a single statement
+without function calls can trigger lots of computation when using libraries like
+numpy. cProfile only times explicit function calls, not special methods called
+because of syntax. Consequently, a relatively slow numpy operation on large
+arrays like this, ::
+
+ a[large_index_array] = some_other_large_array
+
+is a hotspot that never gets broken out by cProfile because there is no explicit
+function call in that statement.
+
+LineProfiler can be given functions to profile, and it will time the execution
+of each individual line inside those functions. In a typical workflow, one only
+cares about line timings of a few functions because wading through the results
+of timing every single line of code would be overwhelming. However, LineProfiler
+does need to be explicitly told what functions to profile. The easiest way to
+get started is to use the `kernprof` script. ::
+
+ $ kernprof -l script_to_profile.py
+
+`kernprof` will create an instance of LineProfiler and insert it into the
+`__builtins__` namespace with the name `profile`. It has been written to be
+used as a decorator, so in your script, you decorate the functions you want
+to profile with @profile. ::
+
+ @profile
+ def slow_function(a, b, c):
+ ...
+
+The default behavior of `kernprof` is to put the results into a binary file
+script_to_profile.py.lprof . You can tell `kernprof` to immediately view the
+formatted results at the terminal with the [-v/--view] option. Otherwise, you
+can view the results later like so::
+
+ $ python -m line_profiler script_to_profile.py.lprof
+
+For example, here are the results of profiling a single function from
+a decorated version of the pystone.py benchmark (the first two lines are output
+from `pystone.py`, not `kernprof`)::
+
+ Pystone(1.1) time for 50000 passes = 2.48
+ This machine benchmarks at 20161.3 pystones/second
+ Wrote profile results to pystone.py.lprof
+ Timer unit: 1e-06 s
+
+ File: pystone.py
+ Function: Proc2 at line 149
+ Total time: 0.606656 s
+
+ Line # Hits Time Per Hit % Time Line Contents
+ ==============================================================
+ 149 @profile
+ 150 def Proc2(IntParIO):
+ 151 50000 82003 1.6 13.5 IntLoc = IntParIO + 10
+ 152 50000 63162 1.3 10.4 while 1:
+ 153 50000 69065 1.4 11.4 if Char1Glob == 'A':
+ 154 50000 66354 1.3 10.9 IntLoc = IntLoc - 1
+ 155 50000 67263 1.3 11.1 IntParIO = IntLoc - IntGlob
+ 156 50000 65494 1.3 10.8 EnumLoc = Ident1
+ 157 50000 68001 1.4 11.2 if EnumLoc == Ident1:
+ 158 50000 63739 1.3 10.5 break
+ 159 50000 61575 1.2 10.1 return IntParIO
+
+
+The source code of the function is printed with the timing information for each
+line. There are six columns of information.
+
+ * Line #: The line number in the file.
+
+ * Hits: The number of times that line was executed.
+
+ * Time: The total amount of time spent executing the line in the timer's
+ units. In the header information before the tables, you will see a line
+ "Timer unit:" giving the conversion factor to seconds. It may be different
+ on different systems.
+
+ * Per Hit: The average amount of time spent executing the line once in the
+ timer's units.
+
+ * % Time: The percentage of time spent on that line relative to the total
+ amount of recorded time spent in the function.
+
+ * Line Contents: The actual source code. Note that this is always read from
+ disk when the formatted results are viewed, *not* when the code was
+ executed. If you have edited the file in the meantime, the lines will not
+ match up, and the formatter may not even be able to locate the function
+ for display.
+
+If you are using IPython, there is an implementation of an %lprun magic command
+which will let you specify functions to profile and a statement to execute. It
+will also add its LineProfiler instance into the __builtins__, but typically,
+you would not use it like that.
+
+For IPython 0.11+, you can install it by editing the IPython configuration file
+`~/.ipython/profile_default/ipython_config.py` to add the `'line_profiler'`
+item to the extensions list::
+
+ c.TerminalIPythonApp.extensions = [
+ 'line_profiler',
+ ]
+
+
+To get usage help for %lprun, use the standard IPython help mechanism::
+
+ In [1]: %lprun?
+
+These two methods are expected to be the most frequent user-level ways of using
+LineProfiler and will usually be the easiest. However, if you are building other
+tools with LineProfiler, you will need to use the API. There are two ways to
+inform LineProfiler of functions to profile: you can pass them as arguments to
+the constructor or use the `add_function(f)` method after instantiation. ::
+
+ profile = LineProfiler(f, g)
+ profile.add_function(h)
+
+LineProfiler has the same `run()`, `runctx()`, and `runcall()` methods as
+cProfile.Profile as well as `enable()` and `disable()`. It should be noted,
+though, that `enable()` and `disable()` are not entirely safe when nested.
+Nesting is common when using LineProfiler as a decorator. In order to support
+nesting, use `enable_by_count()` and `disable_by_count()`. These functions will
+increment and decrement a counter and only actually enable or disable the
+profiler when the count transitions from or to 0.
+
+After profiling, the `dump_stats(filename)` method will pickle the results out
+to the given file. `print_stats([stream])` will print the formatted results to
+sys.stdout or whatever stream you specify. `get_stats()` will return LineStats
+object, which just holds two attributes: a dictionary containing the results and
+the timer unit.
+
+
+kernprof
+========
+
+`kernprof` also works with cProfile, its third-party incarnation lsprof, or the
+pure-Python profile module depending on what is available. It has a few main
+features:
+
+ * Encapsulation of profiling concerns. You do not have to modify your script
+ in order to initiate profiling and save the results. Unless if you want to
+ use the advanced __builtins__ features, of course.
+
+ * Robust script execution. Many scripts require things like __name__,
+ __file__, and sys.path to be set relative to it. A naive approach at
+ encapsulation would just use execfile(), but many scripts which rely on
+ that information will fail. kernprof will set those variables correctly
+ before executing the script.
+
+ * Easy executable location. If you are profiling an application installed on
+ your PATH, you can just give the name of the executable. If kernprof does
+ not find the given script in the current directory, it will search your
+ PATH for it.
+
+ * Inserting the profiler into __builtins__. Sometimes, you just want to
+ profile a small part of your code. With the [-b/--builtin] argument, the
+ Profiler will be instantiated and inserted into your __builtins__ with the
+ name "profile". Like LineProfiler, it may be used as a decorator, or
+ enabled/disabled with `enable_by_count()` and `disable_by_count()`, or
+ even as a context manager with the "with profile:" statement.
+
+ * Pre-profiling setup. With the [-s/--setup] option, you can provide
+ a script which will be executed without profiling before executing the
+ main script. This is typically useful for cases where imports of large
+ libraries like wxPython or VTK are interfering with your results. If you
+ can modify your source code, the __builtins__ approach may be
+ easier.
+
+The results of profile script_to_profile.py will be written to
+script_to_profile.py.prof by default. It will be a typical marshalled file that
+can be read with pstats.Stats(). They may be interactively viewed with the
+command::
+
+ $ python -m pstats script_to_profile.py.prof
+
+Such files may also be viewed with graphical tools like kcachegrind_ through the
+converter program pyprof2calltree_ or RunSnakeRun_.
+
+.. _kcachegrind: http://kcachegrind.sourceforge.net/html/Home.html
+.. _pyprof2calltree: http://pypi.python.org/pypi/pyprof2calltree/
+.. _RunSnakeRun: http://www.vrplumber.com/programming/runsnakerun/
+
+
+Frequently Asked Questions
+==========================
+
+* Why the name "kernprof"?
+
+ I didn't manage to come up with a meaningful name, so I named it after
+ myself.
+
+* Why not use hotshot instead of line_profile?
+
+ hotshot can do line-by-line timings, too. However, it is deprecated and may
+ disappear from the standard library. Also, it can take a long time to
+ process the results while I want quick turnaround in my workflows. hotshot
+ pays this processing time in order to make itself minimally intrusive to the
+ code it is profiling. Code that does network operations, for example, may
+ even go down different code paths if profiling slows down execution too
+ much. For my use cases, and I think those of many other people, their
+ line-by-line profiling is not affected much by this concern.
+
+* Why not allow using hotshot from kernprof.py?
+
+ I don't use hotshot, myself. I will accept contributions in this vein,
+ though.
+
+* The line-by-line timings don't add up when one profiled function calls
+ another. What's up with that?
+
+ Let's say you have function F() calling function G(), and you are using
+ LineProfiler on both. The total time reported for G() is less than the time
+ reported on the line in F() that calls G(). The reason is that I'm being
+ reasonably clever (and possibly too clever) in recording the times.
+ Basically, I try to prevent recording the time spent inside LineProfiler
+ doing all of the bookkeeping for each line. Each time Python's tracing
+ facility issues a line event (which happens just before a line actually gets
+ executed), LineProfiler will find two timestamps, one at the beginning
+ before it does anything (t_begin) and one as close to the end as possible
+ (t_end). Almost all of the overhead of LineProfiler's data structures
+ happens in between these two times.
+
+ When a line event comes in, LineProfiler finds the function it belongs to.
+ If it's the first line in the function, we record the line number and
+ *t_end* associated with the function. The next time we see a line event
+ belonging to that function, we take t_begin of the new event and subtract
+ the old t_end from it to find the amount of time spent in the old line. Then
+ we record the new t_end as the active line for this function. This way, we
+ are removing most of LineProfiler's overhead from the results. Well almost.
+ When one profiled function F calls another profiled function G, the line in
+ F that calls G basically records the total time spent executing the line,
+ which includes the time spent inside the profiler while inside G.
+
+ The first time this question was asked, the questioner had the G() function
+ call as part of a larger expression, and he wanted to try to estimate how
+ much time was being spent in the function as opposed to the rest of the
+ expression. My response was that, even if I could remove the effect, it
+ might still be misleading. G() might be called elsewhere, not just from the
+ relevant line in F(). The workaround would be to modify the code to split it
+ up into two lines, one which just assigns the result of G() to a temporary
+ variable and the other with the rest of the expression.
+
+ I am open to suggestions on how to make this more robust. Or simple
+ admonitions against trying to be clever.
+
+* Why do my list comprehensions have so many hits when I use the LineProfiler?
+
+ LineProfiler records the line with the list comprehension once for each
+ iteration of the list comprehension.
+
+* Why is kernprof distributed with line_profiler? It works with just cProfile,
+ right?
+
+ Partly because kernprof.py is essential to using line_profiler effectively,
+ but mostly because I'm lazy and don't want to maintain the overhead of two
+ projects for modules as small as these. However, kernprof.py is
+ a standalone, pure Python script that can be used to do function profiling
+ with just the Python standard library. You may grab it and install it by
+ itself without `line_profiler`.
+
+* Do I need a C compiler to build `line_profiler`? kernprof.py?
+
+ You do need a C compiler for line_profiler. kernprof.py is a pure Python
+ script and can be installed separately, though.
+
+* Do I need Cython to build `line_profiler`?
+
+ You should not have to if you are building from a released source tarball.
+ It should contain the generated C sources already. If you are running into
+ problems, that may be a bug; let me know. If you are building from
+ a git checkout or snapshot, you will need Cython to generate the
+ C sources. You will probably need version 0.10 or higher. There is a bug in
+ some earlier versions in how it handles NULL PyObject* pointers.
+
+* What version of Python do I need?
+
+ Both `line_profiler` and `kernprof` have been tested with Python 2.7, and
+ 3.2-3.4.
+
+
+To Do
+=====
+
+cProfile uses a neat "rotating trees" data structure to minimize the overhead of
+looking up and recording entries. LineProfiler uses Python dictionaries and
+extension objects thanks to Cython. This mostly started out as a prototype that
+I wanted to play with as quickly as possible, so I passed on stealing the
+rotating trees for now. As usual, I got it working, and it seems to have
+acceptable performance, so I am much less motivated to use a different strategy
+now. Maybe later. Contributions accepted!
+
+
+Bugs and Such
+=============
+
+Bugs and pull requested can be submitted on GitHub_.
+
+.. _GitHub: https://github.com/rkern/line_profiler
+
+
+Changes
+=======
+
+2.0
+~~~
+* BUG: Added support for IPython 5.0+, removed support for IPython <=0.12
+
+1.1
+~~~
+* BUG: Read source files as bytes.
+
+1.0
+~~~
+* ENH: `kernprof.py` is now installed as `kernprof`.
+* ENH: Python 3 support. Thanks to the long-suffering Mikhail Korobov for being
+ patient.
+* Dropped 2.6 as it was too annoying.
+* ENH: The `stripzeros` and `add_module` options. Thanks to Erik Tollerud for
+ contributing it.
+* ENH: Support for IPython cell blocks. Thanks to Michael Forbes for adding
+ this feature.
+* ENH: Better warnings when building without Cython. Thanks to David Cournapeau
+ for spotting this.
+
+1.0b3
+~~~~~
+
+* ENH: Profile generators.
+* BUG: Update for compatibility with newer versions of Cython. Thanks to Ondrej
+ Certik for spotting the bug.
+* BUG: Update IPython compatibility for 0.11+. Thanks to Yaroslav Halchenko and
+ others for providing the updated imports.
+
+1.0b2
+~~~~~
+
+* BUG: fixed line timing overflow on Windows.
+* DOC: improved the README.
+
+1.0b1
+~~~~~
+
+* Initial release.
diff --git a/_line_profiler.pyx b/_line_profiler.pyx
new file mode 100644
index 0000000..4798d32
--- /dev/null
+++ b/_line_profiler.pyx
@@ -0,0 +1,228 @@
+from python25 cimport PyFrameObject, PyObject, PyStringObject
+
+
+cdef extern from "frameobject.h":
+ ctypedef int (*Py_tracefunc)(object self, PyFrameObject *py_frame, int what, PyObject *arg)
+
+cdef extern from "Python.h":
+ ctypedef long long PY_LONG_LONG
+ cdef bint PyCFunction_Check(object obj)
+
+ cdef void PyEval_SetProfile(Py_tracefunc func, object arg)
+ cdef void PyEval_SetTrace(Py_tracefunc func, object arg)
+
+ ctypedef object (*PyCFunction)(object self, object args)
+
+ ctypedef struct PyMethodDef:
+ char *ml_name
+ PyCFunction ml_meth
+ int ml_flags
+ char *ml_doc
+
+ ctypedef struct PyCFunctionObject:
+ PyMethodDef *m_ml
+ PyObject *m_self
+ PyObject *m_module
+
+ # They're actually #defines, but whatever.
+ cdef int PyTrace_CALL
+ cdef int PyTrace_EXCEPTION
+ cdef int PyTrace_LINE
+ cdef int PyTrace_RETURN
+ cdef int PyTrace_C_CALL
+ cdef int PyTrace_C_EXCEPTION
+ cdef int PyTrace_C_RETURN
+
+cdef extern from "timers.h":
+ PY_LONG_LONG hpTimer()
+ double hpTimerUnit()
+
+cdef extern from "unset_trace.h":
+ void unset_trace()
+
+
+def label(code):
+ """ Return a (filename, first_lineno, func_name) tuple for a given code
+ object.
+
+ This is the same labelling as used by the cProfile module in Python 2.5.
+ """
+ if isinstance(code, str):
+ return ('~', 0, code) # built-in functions ('~' sorts at the end)
+ else:
+ return (code.co_filename, code.co_firstlineno, code.co_name)
+
+
+cdef class LineTiming:
+ """ The timing for a single line.
+ """
+ cdef public object code
+ cdef public int lineno
+ cdef public PY_LONG_LONG total_time
+ cdef public long nhits
+
+ def __init__(self, object code, int lineno):
+ self.code = code
+ self.lineno = lineno
+ self.total_time = 0
+ self.nhits = 0
+
+ cdef hit(self, PY_LONG_LONG dt):
+ """ Record a line timing.
+ """
+ self.nhits += 1
+ self.total_time += dt
+
+ def astuple(self):
+ """ Convert to a tuple of (lineno, nhits, total_time).
+ """
+ return (self.lineno, self.nhits, self.total_time)
+
+ def __repr__(self):
+ return '<LineTiming for %r\n lineno: %r\n nhits: %r\n total_time: %r>' % (self.code, self.lineno, self.nhits, <long>self.total_time)
+
+
+# Note: this is a regular Python class to allow easy pickling.
+class LineStats(object):
+ """ Object to encapsulate line-profile statistics.
+
+ Attributes
+ ----------
+ timings : dict
+ Mapping from (filename, first_lineno, function_name) of the profiled
+ function to a list of (lineno, nhits, total_time) tuples for each
+ profiled line. total_time is an integer in the native units of the
+ timer.
+ unit : float
+ The number of seconds per timer unit.
+ """
+ def __init__(self, timings, unit):
+ self.timings = timings
+ self.unit = unit
+
+
+cdef class LineProfiler:
+ """ Time the execution of lines of Python code.
+ """
+ cdef public list functions
+ cdef public dict code_map
+ cdef public dict last_time
+ cdef public double timer_unit
+ cdef public long enable_count
+
+ def __init__(self, *functions):
+ self.functions = []
+ self.code_map = {}
+ self.last_time = {}
+ self.timer_unit = hpTimerUnit()
+ self.enable_count = 0
+ for func in functions:
+ self.add_function(func)
+
+ def add_function(self, func):
+ """ Record line profiling information for the given Python function.
+ """
+ try:
+ code = func.__code__
+ except AttributeError:
+ import warnings
+ warnings.warn("Could not extract a code object for the object %r" % (func,))
+ return
+ if code not in self.code_map:
+ self.code_map[code] = {}
+ self.functions.append(func)
+
+ def enable_by_count(self):
+ """ Enable the profiler if it hasn't been enabled before.
+ """
+ if self.enable_count == 0:
+ self.enable()
+ self.enable_count += 1
+
+ def disable_by_count(self):
+ """ Disable the profiler if the number of disable requests matches the
+ number of enable requests.
+ """
+ if self.enable_count > 0:
+ self.enable_count -= 1
+ if self.enable_count == 0:
+ self.disable()
+
+ def __enter__(self):
+ self.enable_by_count()
+
+ def __exit__(self, exc_type, exc_val, exc_tb):
+ self.disable_by_count()
+
+ def enable(self):
+ PyEval_SetTrace(python_trace_callback, self)
+
+ def disable(self):
+ self.last_time = {}
+ unset_trace()
+
+ def get_stats(self):
+ """ Return a LineStats object containing the timings.
+ """
+ stats = {}
+ for code in self.code_map:
+ entries = self.code_map[code].values()
+ key = label(code)
+ stats[key] = [e.astuple() for e in entries]
+ stats[key].sort()
+ return LineStats(stats, self.timer_unit)
+
+
+cdef class LastTime:
+ """ Record the last callback call for a given line.
+ """
+ cdef int f_lineno
+ cdef PY_LONG_LONG time
+
+ def __cinit__(self, int f_lineno, PY_LONG_LONG time):
+ self.f_lineno = f_lineno
+ self.time = time
+
+
+cdef int python_trace_callback(object self_, PyFrameObject *py_frame, int what,
+ PyObject *arg):
+ """ The PyEval_SetTrace() callback.
+ """
+ cdef LineProfiler self
... 1790 lines suppressed ...
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-line-profiler.git
More information about the Python-modules-commits
mailing list