Skip to content

Commit

Permalink
Add request timer for Flask requests.
Browse files Browse the repository at this point in the history
Times between before_request and after_request and outputs to log level
info.
  • Loading branch information
brew committed Jun 14, 2016
1 parent 77a436e commit 871eeb8
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ckan/config/middleware/flask_app.py
@@ -1,6 +1,7 @@
# encoding: utf-8

import os
import time
import itertools

from flask import Flask
Expand Down Expand Up @@ -96,11 +97,18 @@ def save_session(self, app, session, response):

@app.before_request
def ckan_before_request():
c._request_timer = time.time()
identify_user()

@app.after_request
def ckan_after_request(response):
set_cors_headers_for_response(response)

# log time between before and after view
r_time = time.time() - c._request_timer
url = request.environ['CKAN_CURRENT_URL'].split('?')[0]
log.info('{url} render time {r_time:.3f} seconds'.format(
url=url, r_time=r_time))
return response

# Template context processors
Expand Down

0 comments on commit 871eeb8

Please sign in to comment.