stopwatch.py 553 B

12345678910111213141516
  1. from django.conf import settings
  2. from misago.stopwatch import Stopwatch
  3. class StopwatchMiddleware(object):
  4. def process_request(self, request):
  5. request.stopwatch = Stopwatch()
  6. def process_response(self, request, response):
  7. try:
  8. if settings.STOPWATCH_LOG:
  9. stat_file = open(settings.STOPWATCH_LOG, 'a')
  10. stat_file.write("%s %s s\n" % (request.path_info, request.stopwatch.time()))
  11. stat_file.close()
  12. except AttributeError:
  13. pass
  14. return response