Skip to content

Instantly share code, notes, and snippets.

@matthewhochler
Forked from madhukar93/flask_profiler.py
Created August 3, 2016 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewhochler/6b523d18f48fd45dafb6057dbcb4a236 to your computer and use it in GitHub Desktop.
Save matthewhochler/6b523d18f48fd45dafb6057dbcb4a236 to your computer and use it in GitHub Desktop.
A profiler for Flask apps
"""
This module provides a simple WSGI profiler middleware for finding
bottlenecks in web application. It uses the profile or cProfile
module to do the profiling and writes the stats to the stream provided
To use, run `flask_profiler.py` instead of `app.py`
see: http://werkzeug.pocoo.org/docs/0.9/contrib/profiler/
and: http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-xvi-debugging-testing-and-profiling
"""
from werkzeug.contrib.profiler import ProfilerMiddleware
from app import app
app.config['PROFILE'] = True
app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions = [30])
app.run(debug = True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment