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

Тел: +7 965 3737 888

477

Просмотров

10

Ответов

Extended Profiling Middleware

Modified version of Profiling Middleware

Prints profile results for method, additionally groups results by files and by modules (for django uses top level modules as groups). Works for Windows.

Usage: append ?prof or &prof= to any URL pointing to django application after adding ProfileMiddleware to middlewares in yours settings.py.

NOTICE: ProfileMiddleware uses hotshot profiler which is not thread safe.

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

Ответы (10):

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

Very cool, thanks!

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

I've found this snippet a bit weird in that it reuses the old response object. This works fine except when the content type is not html, e.g. looking at XML output. A quick fix to this problem is to add:

response['Content-Type'] = 'text/html'

to the end of process_response()

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

You can replace the tiercary operator mentionned above with

res += "%4.1f%% %7.3f %s\n" % ( sum and 100*item[0]/sum or 0, item[0], item[1] )

So it run on python 2.4

And to have a (little) more info on SQL request, you could extend the code of andrew with this :

response.content += '\n%d SQL Queries in %.3f seconds :\n' %(
    len(connection.queries), sum([ float(i.get('time', 0)) for i in connection.queries ]))
response.content += pprint.pformat(connection.queries)

in the process_response file.

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

For this to work with >= 1.0 you need to change the multiple occurances of 'request.has_key' to this:

'prof' in request.GET

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

I get this error when i go to the admin area with this middleware: 'WSGIRequest' object has no attribute 'user'

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

To simultaneous profile SQL queries (in DEBUG mode):

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

To handle views with alternative mimetypes (such as XML), you should assign to response['content-type'] on line 112

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

This might expose my lack of understanding of this, but how come my application code doesn't show up in the profile?

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

Python 2.4 throws an invalid syntax error on the "if" in line 57 : res += "%4.1f%% %7.3f %s\n" % ( 100*item[0]/sum if sum else 0, item[0], item[1] )

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

And don't forget to put the SQL request debug code in [HTML_REMOVED]