WSGI middleware for line-by-line profiling
Project description
wsgi_lineprof is a WSGI middleware for line-by-line profiling.
wsgi_lineprof has the following features:
WSGI middleware: It can be integrated with any WSGI-compatible applications and frameworks including Django, Pyramid, Flask, Bottle, and more.
Easily pluggable: All configurations for profiling in one place. Users don’t need to make any changes to their application.
wsgi_lineprof is not recommended to be used in production environment because of the overhead of profiling.
At a Glance
You can use wsgi_lineprof as a WSGI middleware of existing applications.
$ pip install wsgi_lineprof
Example usage with Bottle:
import time
import bottle
from wsgi_lineprof.middleware import LineProfilerMiddleware
app = bottle.default_app()
@app.route('/')
def index():
time.sleep(1)
return "Hello world!!"
if __name__ == "__main__":
# Add wsgi_lineprof as a WSGI middleware!
app = LineProfilerMiddleware(app)
bottle.run(app=app)
Run the above script to start web server, then access http://127.0.0.1:8080.
wsgi_lineprof writes results to stdout every time an HTTP request is processed by default. You can see the output like this in your console:
... (snip) ... File: ./app.py Name: index Total time: 1.00518 [sec] Line Hits Time Code =================================== 9 @app.route('/') 10 def index(): 11 1 1005175 time.sleep(1) 12 1 4 return "Hello world!!" ... (snip) ...
Results contain many other functions, you can remove unnecessary results by using filters.
Requirements
Python 2.7
Python 3.4
Python 3.5
Python 3.6
Python 3.7
Filters
You can get results from specific files or sort results by using filters. For example, use FilenameFilter to filter results with filename and use TotalTimeSorter to sort results by total_time.
import time
import bottle
from wsgi_lineprof.filters import FilenameFilter, TotalTimeSorter
from wsgi_lineprof.middleware import LineProfilerMiddleware
app = bottle.default_app()
def get_name():
# Get some data...
time.sleep(1)
return "Monty Python"
@app.route('/')
def index():
name = get_name()
return "Hello, {}!!".format(name)
if __name__ == "__main__":
filters = [
# Results which filename contains "app2.py"
FilenameFilter("app2.py"),
# Sort by total time of results
TotalTimeSorter(),
]
# Add wsgi_lineprof as a WSGI middleware
app = LineProfilerMiddleware(app, filters=filters)
bottle.run(app=app)
Run the above script to start web server, then access http://127.0.0.1:8080. You can see results in stdout.
$ ./app2.py Bottle v0.12.10 server starting up (using WSGIRefServer())... Listening on http://127.0.0.1:8080/ Hit Ctrl-C to quit. Time unit: 1e-06 [sec] File: ./app2.py Name: index Total time: 1.00526 [sec] Line Hits Time Code =================================== 15 @app.route('/') 16 def index(): 17 1 1005250 name = get_name() 18 1 11 return "Hello, {}!!".format(name) File: ./app2.py Name: get_name Total time: 1.00523 [sec] Line Hits Time Code =================================== 10 def get_name(): 11 # Get some data... 12 1 1005226 time.sleep(1) 13 1 4 return "Monty Python" 127.0.0.1 - - [30/Nov/2016 17:21:12] "GET / HTTP/1.1" 200 21
There are more useful filters in wsgi_lineprof.filters. Examples:
FilenameFilter("(file1|file2).py", regex=True)
NameFilter("(fun1|fun2).py", regex=True)
Stream
By using stream option, you can output results to a file. For example, you can output logs to lineprof.log.
f = open("lineprof.log", "w")
app = LineProfilerMiddleware(app, stream=f)
bottle.run(app=app)
Async Stream
By using async_stream option, wsgi_lineprof starts a new thread for writing results. This option is useful when you do not want the main thread blocked for writing results.
# Start a new thread for writing results
app = LineProfilerMiddleware(app, async_stream=True)
bottle.run(app=app)
Accumulate Mode
By default, wsgi_lineprof writes results every time a request is processed. By enabling accumulate option, wsgi_lineprof accumulate results of all requests and writes the result on interpreter termination.
app = LineProfilerMiddleware(app, accumulate=True)
bottle.run(app=app)
Links
Special Thanks
This project uses code from the following project:
This project is inspired by the following project:
wsgi_lineprof is integrated with the following projects:
wsgi_lineprof is mentioned in the following entries:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file wsgi_lineprof-0.6.0.tar.gz
.
File metadata
- Download URL: wsgi_lineprof-0.6.0.tar.gz
- Upload date:
- Size: 57.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93c2878320d80564bc27f82cc34411be4fa375bc67728afd487c95bdfad57cd6 |
|
MD5 | 47de0868be9f43baf3a7ed5d836a6896 |
|
BLAKE2b-256 | efc7506477e1c3fc8f5d254bcfe90019d5590d586af2fe98dfc1900d9ffbdf01 |
Provenance
File details
Details for the file wsgi_lineprof-0.6.0-cp37-cp37m-manylinux1_x86_64.whl
.
File metadata
- Download URL: wsgi_lineprof-0.6.0-cp37-cp37m-manylinux1_x86_64.whl
- Upload date:
- Size: 125.0 kB
- Tags: CPython 3.7m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85817f8b2495186e76c0aacd9afbde4e181e6907de1ee4eec0677e06941c87ca |
|
MD5 | cdbc3cc7cb1f990f1f19752ae45056f7 |
|
BLAKE2b-256 | 0d40109c3a1a7d466d224172a16ed07c619ebcfdbdb7760f30567fae9a52afb4 |
Provenance
File details
Details for the file wsgi_lineprof-0.6.0-cp37-cp37m-manylinux1_i686.whl
.
File metadata
- Download URL: wsgi_lineprof-0.6.0-cp37-cp37m-manylinux1_i686.whl
- Upload date:
- Size: 117.1 kB
- Tags: CPython 3.7m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9d9588b9519f318bfe5ec4241628120d2512451215dd3032fdcf519f634dcf9e |
|
MD5 | 91ee23b667b71f0dba0a6500632be09d |
|
BLAKE2b-256 | a4b24ca54c1e1b69d5ce26e5fbe38bd784207c39f4a785bd82943a31733e0cbd |
Provenance
File details
Details for the file wsgi_lineprof-0.6.0-cp37-cp37m-macosx_10_14_x86_64.macosx_10_12_x86_64.macosx_10_11_x86_64.macosx_10_10_x86_64.whl
.
File metadata
- Download URL: wsgi_lineprof-0.6.0-cp37-cp37m-macosx_10_14_x86_64.macosx_10_12_x86_64.macosx_10_11_x86_64.macosx_10_10_x86_64.whl
- Upload date:
- Size: 40.0 kB
- Tags: CPython 3.7m, macOS 10.10+ x86-64, macOS 10.11+ x86-64, macOS 10.12+ x86-64, macOS 10.14+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e2b36de8c16c89886bdf734aca66a9e0cfc199b687000d2ca2196cd1133add3e |
|
MD5 | b90a184c6c64a5f474d0da1bcb80c2c3 |
|
BLAKE2b-256 | c9173e0c3786880f2be219f83a1a0bef95157f67206d2d2f14862b7c12571711 |
Provenance
File details
Details for the file wsgi_lineprof-0.6.0-cp36-cp36m-manylinux1_x86_64.whl
.
File metadata
- Download URL: wsgi_lineprof-0.6.0-cp36-cp36m-manylinux1_x86_64.whl
- Upload date:
- Size: 125.1 kB
- Tags: CPython 3.6m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74d605d9d14aed98f370b1e0d04f9c98d863e531b6b3968931c62a6f8fd9d433 |
|
MD5 | 1d0b8b19dc6c792ed571637b69bda32a |
|
BLAKE2b-256 | 2b6deb0aaee01e8611248576c1e528ca3295385737185e5391e414fccbeb999c |
Provenance
File details
Details for the file wsgi_lineprof-0.6.0-cp36-cp36m-manylinux1_i686.whl
.
File metadata
- Download URL: wsgi_lineprof-0.6.0-cp36-cp36m-manylinux1_i686.whl
- Upload date:
- Size: 117.1 kB
- Tags: CPython 3.6m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 367a926fcd6062cad539b4b76cfb221f1e73818b0af0dbaba7af35e5ec8b8ca0 |
|
MD5 | aa7d6ec267c0e4e90a729820258bbcfb |
|
BLAKE2b-256 | 6a6fe47e4f5951cab067fd893a654bac3dffca0f9e6c946c2ff3189ef90841d8 |
Provenance
File details
Details for the file wsgi_lineprof-0.6.0-cp36-cp36m-macosx_10_13_x86_64.macosx_10_12_x86_64.macosx_10_11_x86_64.macosx_10_10_x86_64.whl
.
File metadata
- Download URL: wsgi_lineprof-0.6.0-cp36-cp36m-macosx_10_13_x86_64.macosx_10_12_x86_64.macosx_10_11_x86_64.macosx_10_10_x86_64.whl
- Upload date:
- Size: 40.1 kB
- Tags: CPython 3.6m, macOS 10.10+ x86-64, macOS 10.11+ x86-64, macOS 10.12+ x86-64, macOS 10.13+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 176856ed3508be065be76f71ac734b49a505d790fd4345d799ba420c8d7291b8 |
|
MD5 | 49cc66a6999e69d81ebe85773774ee05 |
|
BLAKE2b-256 | 84e7007707c1f71bfeb628287e4b05161f0a766c7fde87f4e3ef85f01328415d |
Provenance
File details
Details for the file wsgi_lineprof-0.6.0-cp35-cp35m-manylinux1_x86_64.whl
.
File metadata
- Download URL: wsgi_lineprof-0.6.0-cp35-cp35m-manylinux1_x86_64.whl
- Upload date:
- Size: 122.7 kB
- Tags: CPython 3.5m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5586b3cc85083e3a4c41c95ac0560bd80122122db24e550fbc07284394f80c10 |
|
MD5 | 4f1d5647c428472387bfd305b70ddea1 |
|
BLAKE2b-256 | 188b2754eff97b9bdad91900c5d8122ee6f94a470aade7600063b4a718413ee0 |
Provenance
File details
Details for the file wsgi_lineprof-0.6.0-cp35-cp35m-manylinux1_i686.whl
.
File metadata
- Download URL: wsgi_lineprof-0.6.0-cp35-cp35m-manylinux1_i686.whl
- Upload date:
- Size: 114.4 kB
- Tags: CPython 3.5m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b2eb7e5fa9a2dd3761aa97d61bade019e7e9e2ea4419f0f7f947cb19311a7c47 |
|
MD5 | 36d4a76b227ce573fc8a4428a1e2cff6 |
|
BLAKE2b-256 | 7440b8f5fc983cf58501b3c650ab3b2be836b27696ad2519d4216ae782a2daa0 |
Provenance
File details
Details for the file wsgi_lineprof-0.6.0-cp35-cp35m-macosx_10_13_x86_64.macosx_10_12_x86_64.macosx_10_11_x86_64.macosx_10_10_x86_64.whl
.
File metadata
- Download URL: wsgi_lineprof-0.6.0-cp35-cp35m-macosx_10_13_x86_64.macosx_10_12_x86_64.macosx_10_11_x86_64.macosx_10_10_x86_64.whl
- Upload date:
- Size: 39.5 kB
- Tags: CPython 3.5m, macOS 10.10+ x86-64, macOS 10.11+ x86-64, macOS 10.12+ x86-64, macOS 10.13+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83afc9c78dc046a4d0512d7db7d6f521095e50926765cbcf92a6b402a0cad809 |
|
MD5 | 67276c21c3091002d229b09265b39150 |
|
BLAKE2b-256 | 903d10ac58c653660821b6af035985ff9ae935f839c965b35781bd90f0d095c1 |
Provenance
File details
Details for the file wsgi_lineprof-0.6.0-cp34-cp34m-manylinux1_x86_64.whl
.
File metadata
- Download URL: wsgi_lineprof-0.6.0-cp34-cp34m-manylinux1_x86_64.whl
- Upload date:
- Size: 121.5 kB
- Tags: CPython 3.4m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 925c231ff1c5a3015795726d9ad76273479d835844c5ec266229f4ffb666ec67 |
|
MD5 | 7847002bbee9d6f51833b6ebf2eb32ce |
|
BLAKE2b-256 | c7d088d3ceb0d18778ed374059b2d4a077d89f08448d044dedb0aa9fc4b8709e |
Provenance
File details
Details for the file wsgi_lineprof-0.6.0-cp34-cp34m-manylinux1_i686.whl
.
File metadata
- Download URL: wsgi_lineprof-0.6.0-cp34-cp34m-manylinux1_i686.whl
- Upload date:
- Size: 114.1 kB
- Tags: CPython 3.4m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 73044a41f6aff2712fddbe10eedab3e9c28ef5e2dea22c131349fe18ebc4e6f6 |
|
MD5 | 36de7056a14e21b6517e02ef6205a30a |
|
BLAKE2b-256 | c3a69982fda03a5d9243f140b527fbacc361f398ecc911d249b89deea7f6480f |
Provenance
File details
Details for the file wsgi_lineprof-0.6.0-cp34-cp34m-macosx_10_13_x86_64.macosx_10_12_x86_64.macosx_10_11_x86_64.macosx_10_10_x86_64.whl
.
File metadata
- Download URL: wsgi_lineprof-0.6.0-cp34-cp34m-macosx_10_13_x86_64.macosx_10_12_x86_64.macosx_10_11_x86_64.macosx_10_10_x86_64.whl
- Upload date:
- Size: 39.1 kB
- Tags: CPython 3.4m, macOS 10.10+ x86-64, macOS 10.11+ x86-64, macOS 10.12+ x86-64, macOS 10.13+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 427cfd26ab9b76acfd5a2249388fa33d880383a0a43b170cc7c967c874ed0efa |
|
MD5 | 1512bc708d66d65db3847e6d4473c52c |
|
BLAKE2b-256 | 5c450a37a3d21f9e97944a2785f211d98684856a6963ab6bfdb9a32194a3a85e |
Provenance
File details
Details for the file wsgi_lineprof-0.6.0-cp27-cp27mu-manylinux1_x86_64.whl
.
File metadata
- Download URL: wsgi_lineprof-0.6.0-cp27-cp27mu-manylinux1_x86_64.whl
- Upload date:
- Size: 111.6 kB
- Tags: CPython 2.7mu
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dcc34f7e6058d1820f40926d420c3bd8e0d7476479e4fa99acdac467e0fa29c2 |
|
MD5 | bae0dc2e29182f76453b8903ab4f1906 |
|
BLAKE2b-256 | 7679ec62f6de646c29dccd7d8d9d8a0b116dadbc771bb33d902e7f8e376c3f8e |
Provenance
File details
Details for the file wsgi_lineprof-0.6.0-cp27-cp27mu-manylinux1_i686.whl
.
File metadata
- Download URL: wsgi_lineprof-0.6.0-cp27-cp27mu-manylinux1_i686.whl
- Upload date:
- Size: 104.6 kB
- Tags: CPython 2.7mu
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 18d91159c34ae9511f1fd34d908d704b8e0e1a3c9bbbda11e346f8a32929dee1 |
|
MD5 | 0f1716cfbe689933348f9397ceb9f0ec |
|
BLAKE2b-256 | 0a5b49975379fdf72df60ac5fb60752e0962d497039afb5b57cf4c5513111b66 |
Provenance
File details
Details for the file wsgi_lineprof-0.6.0-cp27-cp27m-manylinux1_x86_64.whl
.
File metadata
- Download URL: wsgi_lineprof-0.6.0-cp27-cp27m-manylinux1_x86_64.whl
- Upload date:
- Size: 111.6 kB
- Tags: CPython 2.7m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f36c47cb03df6d165f19838537a93045cbd7cf6d4a6e0df51a61e2c1209caa7f |
|
MD5 | 0f2588892ea0a3854cfe751aa7ea6156 |
|
BLAKE2b-256 | 08128a4d60b705879ac18226894e125814f271223a18df5bd160732b2f0dd7bc |
Provenance
File details
Details for the file wsgi_lineprof-0.6.0-cp27-cp27m-manylinux1_i686.whl
.
File metadata
- Download URL: wsgi_lineprof-0.6.0-cp27-cp27m-manylinux1_i686.whl
- Upload date:
- Size: 104.6 kB
- Tags: CPython 2.7m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 381ec88bdfd2d121c2b9204e2bf156c7774df37ff241b91380ebc1c717a50eb6 |
|
MD5 | 050593cf1bd1a2535e877c19680c829b |
|
BLAKE2b-256 | 343962066b3913af04ad69ecfb5410ddd97dba46bd0065ca68253cdc0aa4a8ca |
Provenance
File details
Details for the file wsgi_lineprof-0.6.0-cp27-cp27m-macosx_10_13_x86_64.macosx_10_12_x86_64.macosx_10_11_x86_64.macosx_10_10_x86_64.whl
.
File metadata
- Download URL: wsgi_lineprof-0.6.0-cp27-cp27m-macosx_10_13_x86_64.macosx_10_12_x86_64.macosx_10_11_x86_64.macosx_10_10_x86_64.whl
- Upload date:
- Size: 39.2 kB
- Tags: CPython 2.7m, macOS 10.10+ x86-64, macOS 10.11+ x86-64, macOS 10.12+ x86-64, macOS 10.13+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0adb028a2a234959c92f7c9c9645ca7d679dd01c9b3ad2638082017bf2358a10 |
|
MD5 | 0db43dcf6ecc0d0dc4d0692d15bb4ec2 |
|
BLAKE2b-256 | b54aa245953043c4a98c98638b7c1f639f956e11d92d2a73992fa315a4c58a00 |