Wednesday, May 15, 2013

Profiling Django


1. Install django-extensions:

pip install django-extensions

2. Add to `local.py`:

INSTALLED_APPS += ('django_extensions',)

3. Run the profiling server passing the directory where profiling data will be saved for each request:

./manage.py runprofileserver --use-cprofile --prof-path=/tmp/my-profile-data

4. Make some requests to the server via browser or other client.

5. Download gprof2dot.py and generate graphs for all the profiled requests:

for prof_file in /tmp/my-profile-data/*.prof; do python gprof2dot.py -f pstats "$prof_file" | dot -Tpng -o `basename $prof_file .prof`; done

6. Now in the current directory you have a set of .png files with profiling graphs.

No comments:

Post a Comment