Giter Site home page Giter Site logo

ymyzk / wsgi_lineprof Goto Github PK

View Code? Open in Web Editor NEW
49.0 4.0 3.0 578 KB

WSGI middleware for line-by-line profiling

Home Page: https://wsgi-lineprof.readthedocs.io/

License: Other

Python 78.90% C 4.77% HTML 3.82% Cython 12.51%
python wsgi-middleware profiler wsgi line-profiler cython hacktoberfest

wsgi_lineprof's Introduction

wsgi_lineprof

PyPI version PyPI Supported Python Versions GitHub Actions (Tests) Documentation Status

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

Apply wsgi_lineprof to the existing WSGI web application:

from wsgi_lineprof.middleware import LineProfilerMiddleware
app = LineProfilerMiddleware(app)

Start the web application and access the application. 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) ...

Also, you can check the result on your web browser by accessing the special endpoint /wsgi_lineprof/.

Please check the documentation for more details.

wsgi_lineprof's People

Contributors

denzow avatar dependabot[bot] avatar ymyzk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

wsgi_lineprof's Issues

Ad-hoc profiling

By specifying a query parameter, enable profiling and return result via HTTP.

For example, /fib?wsgi_lineprof returns a profiling result when processing a request to /fib

'LineProfilerMiddleware' object has no attribute 'route' : Issue with Flask

I have a simple Flask app:

from flask import Flask
from wsgi_lineprof.middleware import LineProfilerMiddleware

app = Flask('zapp')
app = LineProfilerMiddleware(app)

@app.route('/')
def index():
    return 'Hello'

if __name__ == '__main__':
    app.run(port=8000)

Running it gives the following error message:

» python app.py
Traceback (most recent call last):
  File "app.py", line 13, in <module>
    @app.route('/')
AttributeError: 'LineProfilerMiddleware' object has no attribute 'route'

I tried changing app = LineProfilerMiddleware(app) to app = LineProfilerMiddleware(app).app. This lets me run the app but I no longer get any profiling results.


Other info:

Flask==1.1.1
wsgi-lineprof==0.8.0
Python 3.7.4

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.