Easily add cProfile profiling to django views.
Project description
# django-cprofile-middleware
[![pypi-version]][pypi]
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](http://www.slideshare.net/zeeg/django-con-high-performance-django-presentation) and modified it to support sorting.
## Installing
```bash
$ 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](https://docs.djangoproject.com/en/1.10/topics/http/middleware/).
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](http://docs.python.org/2/library/profile.html#pstats.Stats.sort_stats).
**download:** Download profile file, that can be visualized in multiple viewers, e.g. [SnakeViz](https://github.com/jiffyclub/snakeviz/) or [RunSnakeRun](http://www.vrplumber.com/programming/runsnakerun/)
## Enjoy!
Email me with any questions: [omar.bohsali@gmail.com](omar.bohsali@gmail.com).
[pypi]: https://pypi.org/project/django-cprofile-middleware/
[pypi-version]: https://img.shields.io/pypi/v/django-cprofile-middleware.svg
[![pypi-version]][pypi]
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](http://www.slideshare.net/zeeg/django-con-high-performance-django-presentation) and modified it to support sorting.
## Installing
```bash
$ 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](https://docs.djangoproject.com/en/1.10/topics/http/middleware/).
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](http://docs.python.org/2/library/profile.html#pstats.Stats.sort_stats).
**download:** Download profile file, that can be visualized in multiple viewers, e.g. [SnakeViz](https://github.com/jiffyclub/snakeviz/) or [RunSnakeRun](http://www.vrplumber.com/programming/runsnakerun/)
## Enjoy!
Email me with any questions: [omar.bohsali@gmail.com](omar.bohsali@gmail.com).
[pypi]: https://pypi.org/project/django-cprofile-middleware/
[pypi-version]: https://img.shields.io/pypi/v/django-cprofile-middleware.svg
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
Close
Hashes for django-cprofile-middleware-1.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66165aecd9e83905066a4927d59b0f8a645e388caa9e6a3038e5084a8c09b940 |
|
MD5 | 7752f90fa09485b5dae6851855c9fbfd |
|
BLAKE2b-256 | 3bc20cb878b0018b54444849d4569c6b36e0688eb1316e363e356228bb5d1b0f |