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

Тел: +7 965 3737 888





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

Ответы (10):

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

Very cool, thanks!

Ответ полезен? Да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()

Ответ полезен? Да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.

Ответ полезен? Да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

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

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

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

To simultaneous profile SQL queries (in DEBUG mode):

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

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

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

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

Ответ полезен? Да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] )

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

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