Skip to main content

WSGI middleware for line-by-line profiling

Project description

PyPI version Build Status

wsgi_lineprof is a WSGI middleware for line-by-line profiling.

wsgi_lineprof shows results of line-by-line profiling per request. You can use this project with many WSGI-compatible applications and frameworks:

  • Django

  • Pyramid

  • Flask

  • Bottle

  • etc…

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.

The results are outputted to stdout by default. You can see the results like this:

... (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.3

  • Python 3.4

  • Python 3.5

  • Python 3.6

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 some useful filters in wsgi_lineprof.filters.

Stream

By using stream option, you can output results to a file. For example, you can output logs to lineprof.log.

FIXME & add very simple example .. code-block:: python

f = open(“lineprof.log”, “w”) app = LineProfilerMiddleware(app, stream=f) bottle.run(app=app)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wsgi_lineprof-0.4.0.tar.gz (46.1 kB view details)

Uploaded Source

Built Distributions

wsgi_lineprof-0.4.0-cp36-cp36m-manylinux1_x86_64.whl (124.0 kB view details)

Uploaded CPython 3.6m

wsgi_lineprof-0.4.0-cp36-cp36m-manylinux1_i686.whl (115.7 kB view details)

Uploaded CPython 3.6m

wsgi_lineprof-0.4.0-cp36-cp36m-macosx_10_12_x86_64.whl (34.3 kB view details)

Uploaded CPython 3.6m macOS 10.12+ x86-64

wsgi_lineprof-0.4.0-cp35-cp35m-manylinux1_x86_64.whl (120.9 kB view details)

Uploaded CPython 3.5m

wsgi_lineprof-0.4.0-cp35-cp35m-manylinux1_i686.whl (112.9 kB view details)

Uploaded CPython 3.5m

wsgi_lineprof-0.4.0-cp35-cp35m-macosx_10_12_x86_64.whl (34.0 kB view details)

Uploaded CPython 3.5m macOS 10.12+ x86-64

wsgi_lineprof-0.4.0-cp34-cp34m-manylinux1_x86_64.whl (123.8 kB view details)

Uploaded CPython 3.4m

wsgi_lineprof-0.4.0-cp34-cp34m-manylinux1_i686.whl (114.6 kB view details)

Uploaded CPython 3.4m

wsgi_lineprof-0.4.0-cp34-cp34m-macosx_10_12_x86_64.whl (34.7 kB view details)

Uploaded CPython 3.4m macOS 10.12+ x86-64

wsgi_lineprof-0.4.0-cp33-cp33m-manylinux1_x86_64.whl (115.6 kB view details)

Uploaded CPython 3.3m

wsgi_lineprof-0.4.0-cp33-cp33m-manylinux1_i686.whl (107.5 kB view details)

Uploaded CPython 3.3m

wsgi_lineprof-0.4.0-cp33-cp33m-macosx_10_10_x86_64.whl (34.6 kB view details)

Uploaded CPython 3.3m macOS 10.10+ x86-64

wsgi_lineprof-0.4.0-cp27-cp27mu-manylinux1_x86_64.whl (110.3 kB view details)

Uploaded CPython 2.7mu

wsgi_lineprof-0.4.0-cp27-cp27mu-manylinux1_i686.whl (103.7 kB view details)

Uploaded CPython 2.7mu

wsgi_lineprof-0.4.0-cp27-cp27m-manylinux1_x86_64.whl (110.3 kB view details)

Uploaded CPython 2.7m

wsgi_lineprof-0.4.0-cp27-cp27m-manylinux1_i686.whl (103.7 kB view details)

Uploaded CPython 2.7m

wsgi_lineprof-0.4.0-cp27-cp27m-macosx_10_12_x86_64.whl (34.7 kB view details)

Uploaded CPython 2.7m macOS 10.12+ x86-64

File details

Details for the file wsgi_lineprof-0.4.0.tar.gz.

File metadata

File hashes

Hashes for wsgi_lineprof-0.4.0.tar.gz
Algorithm Hash digest
SHA256 b9e081c50b2538ef23ceea713fa5fd9f1e46f5b28301d544cda8e49181bdaf9f
MD5 0766e31afbd9b498cf5a2d8263eb732c
BLAKE2b-256 f8ff551c0dedcf58b622fa359c0698a03ab1e11efb5dfbf6fee12f8de568c4c7

See more details on using hashes here.

Provenance

File details

Details for the file wsgi_lineprof-0.4.0-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for wsgi_lineprof-0.4.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 d59a56be0efaab602bf3e9e644055cdc9d7aec425859e285bb40de281f93bd19
MD5 7707440cdaf40a7c08e15af258d05663
BLAKE2b-256 36f4b50809957fee998c6557fa2996f940b39b6fcea69688da5638463d71efca

See more details on using hashes here.

Provenance

File details

Details for the file wsgi_lineprof-0.4.0-cp36-cp36m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for wsgi_lineprof-0.4.0-cp36-cp36m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 12d5db911c31d01df7bccb65235d63c16919407198778b34d8aa0b8120ed30e2
MD5 2158ee310a078fd54200b6d896c5b452
BLAKE2b-256 900c5581d7854d0aa44fb3ebce85deebd4c34c3e3431ce5db5820c783705d5d3

See more details on using hashes here.

Provenance

File details

Details for the file wsgi_lineprof-0.4.0-cp36-cp36m-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for wsgi_lineprof-0.4.0-cp36-cp36m-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 1acf9411b33a74bbf424599fae7dd1e97417683e276d919d839b3af60a6056f9
MD5 4a6e88cb4a2e2e750dd0a2fd5885c296
BLAKE2b-256 55304ad00a31ba18029c3668e88f1a1bdd0878f2ca944f56b5c8ff9a9ccb8bed

See more details on using hashes here.

Provenance

File details

Details for the file wsgi_lineprof-0.4.0-cp35-cp35m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for wsgi_lineprof-0.4.0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 03c75c43cf81f657a2141fdb5eb3aa4dd1ba9bfde8bc66c6ee1a440e806f8498
MD5 24b5bc7371523a340dcabfb019a4c89f
BLAKE2b-256 c297d777a9935029a962cbd6c960324bd6b0bf871d5eb148a6246095b5400dd2

See more details on using hashes here.

Provenance

File details

Details for the file wsgi_lineprof-0.4.0-cp35-cp35m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for wsgi_lineprof-0.4.0-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 2cd058fdc4a62f31e655b73b2ad61532e7755c8e02ac18b906bba3ed0cd84e47
MD5 86179a1938a42f7c38255afea97d5cdc
BLAKE2b-256 729380de57667bbd4bdce8cdcf364cabb178aadf1541db2c4a329601986c51b2

See more details on using hashes here.

Provenance

File details

Details for the file wsgi_lineprof-0.4.0-cp35-cp35m-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for wsgi_lineprof-0.4.0-cp35-cp35m-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 a674b99185890a5febf88525fa05211a7007967bfd87e11b3747f91485e040a5
MD5 cb5d0b4936729c77a9838837799cf3ae
BLAKE2b-256 de7f7b2d11305673bcbcfc1c2a7a5f1b90523c1ceaa9dfddd4f0b011b8bfb49d

See more details on using hashes here.

Provenance

File details

Details for the file wsgi_lineprof-0.4.0-cp34-cp34m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for wsgi_lineprof-0.4.0-cp34-cp34m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 184fe5fbf0defeb8a3f6767ad9e88adb889b3f3997314a3ec6adc05f9af90250
MD5 89b94102a44c3aa77cce3cba49f9cd9b
BLAKE2b-256 7307e42c8452ba4d9221f09eecec7e3ddabc03628ee353194994cda0e706a0b3

See more details on using hashes here.

Provenance

File details

Details for the file wsgi_lineprof-0.4.0-cp34-cp34m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for wsgi_lineprof-0.4.0-cp34-cp34m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 defc2ec4d64f7f62280fdc37dd1a0c9f109d32389c950eb7946880d3ea16b713
MD5 a953f7b21f086bdc74d7ca5df9626753
BLAKE2b-256 90934858dd0fab0759d994f4619454c57518e54c9774ba3bf174ba1ffc5259e1

See more details on using hashes here.

Provenance

File details

Details for the file wsgi_lineprof-0.4.0-cp34-cp34m-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for wsgi_lineprof-0.4.0-cp34-cp34m-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 a3855ba7446967b5dccaeb112e9a11ea9203628208fcf2cf0c0ea3992270dd9f
MD5 f41e6c5c8d96b5bdacfcb91d6942b35e
BLAKE2b-256 a70f087a47bef6ba92bb66fe01fd6b06f762c9123a21215d182177492e570f86

See more details on using hashes here.

Provenance

File details

Details for the file wsgi_lineprof-0.4.0-cp33-cp33m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for wsgi_lineprof-0.4.0-cp33-cp33m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 5cb3ba6b497fa6b0e9e6e73def104d429ed3ceb3d366eb59372f975a5f010856
MD5 6640d174f327f1e010568c15142295ad
BLAKE2b-256 02e1af7341b1680d703d87159d14864e4885c8c1ad37729fc45bbe29480a07a7

See more details on using hashes here.

Provenance

File details

Details for the file wsgi_lineprof-0.4.0-cp33-cp33m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for wsgi_lineprof-0.4.0-cp33-cp33m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 973c36d0c7111442c2111df23118075d8b588fbce9dfe256d04984fbd728c940
MD5 66185902a2d09f62a7a6b57f929c736a
BLAKE2b-256 99551da63054da326568bed95a6167c8546af4fff763bb0d409dbb4709f8fbdd

See more details on using hashes here.

Provenance

File details

Details for the file wsgi_lineprof-0.4.0-cp33-cp33m-macosx_10_10_x86_64.whl.

File metadata

File hashes

Hashes for wsgi_lineprof-0.4.0-cp33-cp33m-macosx_10_10_x86_64.whl
Algorithm Hash digest
SHA256 cab7cab50043da5519a0c933238d0078081d4695ae4188387c6d3bb9e34c6f31
MD5 aa8823e3396483dfada78c6ed4b6e853
BLAKE2b-256 b6f62cd0b22fb8b129da63f7420b066d07d69c709c9cf9bac0e421979e6eaf6f

See more details on using hashes here.

Provenance

File details

Details for the file wsgi_lineprof-0.4.0-cp27-cp27mu-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for wsgi_lineprof-0.4.0-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 5ec10840473ec9a27e2868676955aba46dd0de8950893baf2eca177ce9f78064
MD5 d6fd2e1b226db7bd6915cbea693519c5
BLAKE2b-256 e657937f37e2a0e3af2c65a27869198b1864e52d68d9cc7e32037f70987ac15f

See more details on using hashes here.

Provenance

File details

Details for the file wsgi_lineprof-0.4.0-cp27-cp27mu-manylinux1_i686.whl.

File metadata

File hashes

Hashes for wsgi_lineprof-0.4.0-cp27-cp27mu-manylinux1_i686.whl
Algorithm Hash digest
SHA256 f01f84614125e79df6a6407074a99afda71bef7b8b740c512851ba4f747db869
MD5 f87c3fcce18eb09ab469422f42d705bf
BLAKE2b-256 a85215d4eff47a15114190d8b9f57f7c1456651415860bee37540efb49e9e1d0

See more details on using hashes here.

Provenance

File details

Details for the file wsgi_lineprof-0.4.0-cp27-cp27m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for wsgi_lineprof-0.4.0-cp27-cp27m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 417f8bc81d846fee1cba9da3243dfa13d52682f9ac439cb20c724c5e46a081fd
MD5 e2e9dfc1b60891f274de10e165d32bc5
BLAKE2b-256 b8265c472598a911d2e14a4c8249eed9a7d991d134eaf18b33a2d756b1003f4e

See more details on using hashes here.

Provenance

File details

Details for the file wsgi_lineprof-0.4.0-cp27-cp27m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for wsgi_lineprof-0.4.0-cp27-cp27m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 b243f085159d4bdf14b5e34defe41183103f32d86d25b0b644513fdbf4ed632d
MD5 5c62aa594cdbbf417ab2c89754fe2d2a
BLAKE2b-256 4517c8c6362488f20c1304d2bb322dbd11ec6923996f19695dd3afa788641518

See more details on using hashes here.

Provenance

File details

Details for the file wsgi_lineprof-0.4.0-cp27-cp27m-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for wsgi_lineprof-0.4.0-cp27-cp27m-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 66b4d44548e9872eae8db63be71c1d50596eedf069a7b259145beb8e6f9f02c3
MD5 7a841e3867169349abdf9745fdd6219c
BLAKE2b-256 ad89041ddc61148d06a70067b5d858b90f4b39f41d267b173514cde8c5c20de3

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page