Wednesday, May 15, 2013

Profiling Django

1. Install django-extensions:

pip install django-extensions

2. Add to ``:

INSTALLED_APPS += ('django_extensions',)

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

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

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

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

for prof_file in /tmp/my-profile-data/*.prof; do python -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