Login

Timing Django Requests

Author:
metajack
Posted:
June 12, 2008
Language:
Python
Version:
.96
Score:
3 (after 3 ratings)

Adds an 'X-Django-Request-Time' HTTP response header that times how long django spent processing the request.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
from time import time

class TimerMiddleware:
    def process_request(self, request):
        request._tm_start_time = time()

    def process_response(self, request, response):
        if not hasattr(request, "_tm_start_time"):
            return

        total = time() - request._tm_start_time

        response['X-Django-Request-Time'] = '%fs' % total
        return response

More like this

  1. codigo alto nivel by MrRocklion 3 days, 5 hours ago
  2. Load template from specific app by Krzysiek555 3 weeks, 2 days ago
  3. PostgreSQL JSON subqueries by dolamroth 3 weeks, 4 days ago
  4. "Magic Link" Management Command by webology 6 months ago
  5. Closest ORM models to a latitude/longitude point by simonw 6 months ago

Comments

Please login first before commenting.