Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(269)

Side by Side Diff: chrome/common/extensions/docs/server2/app_engine_handler.py

Issue 108213010: Docserver: Add per-request profiling. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add github crash thing Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 from appengine_wrappers import webapp2 5 from appengine_wrappers import webapp2
6 from handler import Handler 6 from handler import Handler
7 from servlet import Request 7 from servlet import Request
8 8
9 class AppEngineHandler(webapp2.RequestHandler): 9 class AppEngineHandler(webapp2.RequestHandler):
10 '''Top-level handler for AppEngine requests. Just converts them into our 10 '''Top-level handler for AppEngine requests. Just converts them into our
11 internal Servlet architecture. 11 internal Servlet architecture.
12 ''' 12 '''
13
13 def get(self): 14 def get(self):
14 request = Request(self.request.path, 15 profile_mode = self.request.get('profile')
15 self.request.url[:-len(self.request.path)], 16 if profile_mode:
16 self.request.headers) 17 import cProfile, pstats, StringIO
17 response = Handler(request).Get() 18 pr = cProfile.Profile()
18 self.response.out.write(response.content.ToString()) 19 pr.enable()
19 self.response.headers.update(response.headers) 20
20 self.response.status = response.status 21 try:
22 request = Request(self.request.path,
23 self.request.url[:-len(self.request.path)],
24 self.request.headers)
25 response = Handler(request).Get()
26 finally:
27 if profile_mode:
28 pr.disable()
29 s = StringIO.StringIO()
30 pstats.Stats(pr, stream=s).sort_stats(profile_mode).print_stats()
31 self.response.out.write(s.getvalue())
32 self.response.headers['Content-Type'] = 'text/plain'
33 self.response.status = 200
34 else:
35 self.response.out.write(response.content.ToString())
36 self.response.headers.update(response.headers)
37 self.response.status = response.status
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698