Mittwoch, 28. Februar 2007

Profiling Django: hotshot

Today I've discovered an article about profiling Django with hotshot. After some minutes of googling 'hotspot' I recognized my fault and found the right python doc.
As I didn't want to setup my apache just for a little profiling session, I did the following:
to settings.py I've added
import hotshot
PROF = hotshot.Profile("plik.prof")
every view-method that should be profiled got:
from settings import PROF
PROF.start()
(...)
PROF.stop()

and finally this came to my 'viewstat'-view:
import hotshot.stats
stats = hotshot.stats.load("plik.prof")
stats.strip_dirs()
stats.sort_stats('time', 'calls')
stats.print_stats(20)

And that's how I've become happy today. Wish me good luck for my cold.
- baum

It's fair to say that this probably won't run in a production-setup because of multithreading.



Keine Kommentare: