Задать вопрос

Тел: +7 965 3737 888

698

Просмотров

3

Ответов

Simple profile middleware

<h2>Intall</h2>
<p>In your settings.py, set it in MIDDLEWARE_CLASSES. Default all the profile files will be save in ./profile folder(if there is no this directory, it'll automatically create one), and you can set a PROFILE_DATA_DIR option in settings.py, so that the profile files can be saved in this folder.</p>
<h2>How does it works</h2>
<p>Record every request in a profile file. As you can see in the code:</p>
profname = "%s.prof" % (request.path.strip("/").replace('/', '.'))

<p>so if you request an url multi-times, only the last request will be saved, because previous profile files will be overriden. And you can find a commentted line, it'll save each request in different file according the time, so if you like that you can change the code.</p>
#        profname = "%s.%.3f.prof" % (request.path.strip("/").replace('/', '.'), time.time())

<p>and if you want to see the output, you can run below code, but you should change the filename value:</p>
import hotshot, hotshot.stats
stats = hotshot.stats.load(filename)
#stats.strip_dirs()
#stats.sort_stats('time', 'calls')
stats.print_stats()

Вопрос полезен? Да0/Нет0
file_3887.py(1.2Кб)
None

Ответы (3):

Ответlimodou:02.04.2007
Ответ полезен? Да0/Нет0

No, You don't need to install third package, see the example:

import hotshot, hotshot.stats
stats = hotshot.stats.load(filename)
#stats.strip_dirs()
#stats.sort_stats('time', 'calls')
stats.print_stats()

But this middleware seems has bug in current version now, I don't know why.

Ответpolarbear:31.03.2007
Ответ полезен? Да0/Нет0

Problem with hotshot.stats:

>>> import hotshot, hotshot.stats
    Traceback (most recent call last):
    File "<stdin>", line 1, in ?
    File "hotshot/stats.py", line 3, in ?
    ImportError: No module named profile

Should I install something?

Ответpolarbear:31.03.2007
Ответ полезен? Да0/Нет0

How should I see, analyze this generated *.prof files?