text: 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.
  - Author:
  - hauser
  - Posted:
  - February 17, 2008
  - Language:
  - Python
  - hotshot middleware profile
  - Score:
  - 3 (after 3 ratings)
  Very cool, thanks!
  #
  Python 2.4 throws an invalid syntax error on the "if" in line 57 : res += "%4.1f%% %7.3f %sn" % ( 100*item[0]/sum if sum else 0, item[0], item[1] )
  #
  This might expose my lack of understanding of this, but how come my application code doesn't show up in the profile?
  #
  To handle views with alternative mimetypes (such as XML), you should assign to response['content-type'] on line 112
  #
  To simultaneous profile SQL queries (in DEBUG mode):
  with your other imports, add
  from django.db import connection
  import pprint
  in process_request, add:
  connection.queries = []
  in process_response, add:
  response.content += '\n%d SQL Queries:\n' % len(connection.queries)
  response.content += pprint.pformat(connection.queries)
  #
  I get this error when i go to the admin area with this middleware: 'WSGIRequest' object has no attribute 'user'
  #
  For this to work with >= 1.0 you need to change the multiple occurances of 'request.has_key' to this:
  #
  You can replace the tiercary operator mentionned above with
  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 :
  in the process_response file.
  #
  And don't forget to put the SQL request debug code in
  #
  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:
  to the end of process_response()
  #