Giter Club home page Giter Club logo

django-cprofile-middleware's Introduction

django-cprofile-middleware

pypi-version

This is a simple profiling middleware for Django applications. I wrote it because I got tired of printing "start" "stop" "stop 2" in my programs to find the bottlenecks.

I found a simple example on @dcramer's slideshare and modified it to support sorting.

Installing

$ pip install django-cprofile-middleware

Then add django_cprofile_middleware.middleware.ProfilerMiddleware to the end your MIDDLEWARE in settings.py. This option was called MIDDLEWARE_CLASSES in versions of Django before 1.10.

For example:

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'startup.do.work.FindProductMarketFitMiddleware',
    ...
    'django_cprofile_middleware.middleware.ProfilerMiddleware'
)

Running & Sorting Results

Once you've installed it, log in as a user who has staff privileges and add ?prof to any URL to see the profiler's stats. For example to see profile stats for http://localhost:8000/foo/, visit http://localhost:8000/foo/?prof.

You can also pass some options:

count: The number of results you'd like to see. Default is 100.

sort: The field you'd like to sort results by. Default is time. For all the options you can pass, see the docs for pstats.

download: Download profile file, that can be visualized in multiple viewers, e.g. SnakeViz or RunSnakeRun

Enjoy!

Email me with any questions: [email protected].

django-cprofile-middleware's People

Contributors

omarish avatar hobbestigrou avatar alxfv avatar ahumeau avatar alexsanduk avatar skyl avatar josven avatar

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.