Chromium Code Reviews| Index: tools/deep_memory_profiler/visualizer/app.py |
| diff --git a/tools/deep_memory_profiler/visualizer/app.py b/tools/deep_memory_profiler/visualizer/app.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..cd1170dd2095d383edbd352dca91d8b23d3b8d63 |
| --- /dev/null |
| +++ b/tools/deep_memory_profiler/visualizer/app.py |
| @@ -0,0 +1,74 @@ |
| +# Copyright 2013 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +import jinja2 |
| +import os |
| +import urllib |
| +import webapp2 |
| + |
| +from google.appengine.ext import blobstore |
| +from google.appengine.ext.webapp import blobstore_handlers |
| + |
| +import services |
| + |
| + |
| +JINJA_ENVIRONMENT = jinja2.Environment( |
| + loader=jinja2.FileSystemLoader(os.path.dirname(__file__)), |
| + extensions=['jinja2.ext.autoescape']) |
| + |
| + |
| +class MainPage(webapp2.RequestHandler): |
| + """Show breakdown with received profiler-id and template-id. If nothing was |
| + received, show blank page waiting user to upload file.""" |
| + def get(self): |
| + page_template = JINJA_ENVIRONMENT.get_template('index.html') |
| + upload_url = blobstore.create_upload_url('/upload') |
| + |
| + # Get profiler id and template id from url query. |
| + run_id = self.request.get('run_id') |
| + tmpl_id = self.request.get('tmpl_id') |
| + upload_msg = self.request.get('upload_msg') |
| + |
| + template_values = { |
| + 'upload_url': upload_url, |
| + 'upload_msg': upload_msg |
| + } |
| + |
| + if run_id and tmpl_id: |
|
Dai Mikurube (NOT FULLTIME)
2013/09/24 10:13:09
It looks you added 'null' ones in Patch Set 5. Wer
junjianx
2013/09/24 10:25:20
I moved verification of these two variables to the
|
| + template_values['json'] = services.GetProfiler(run_id) |
| + template_values['template'] = services.GetTemplate(tmpl_id) |
| + |
| + self.response.write(page_template.render(template_values)) |
| + |
| + |
| +class UploadHandler(blobstore_handlers.BlobstoreUploadHandler): |
| + """Handle file uploading with BlobstoreUploadHandler. BlobstoreUploadHandler |
| + can deal with files overweighing size limitation within one HTTP connection so |
| + that user can upload large json file.""" |
| + def post(self): |
| + blob_info = self.get_uploads('file')[0] |
| + |
| + run_id = services.CreateProfiler(blob_info) |
| + default_key = services.CreateTemplates(blob_info) |
| + |
| + # TODO(junjianx): Validation of uploaded file should be done separately. |
| + if not default_key: |
| + # Jump to home page with error message. |
| + req_params = { |
| + 'upload_msg': 'No default key was found.' |
|
sullivan
2013/09/24 12:29:21
Maybe 'No default template key was found'? FWIW, I
|
| + } |
| + else: |
| + # Jump to new graph page using default template. |
| + req_params = { |
| + 'run_id': run_id, |
| + 'tmpl_id': default_key.urlsafe() |
| + } |
| + |
| + self.redirect('/?' + urllib.urlencode(req_params)) |
| + |
| + |
| +application = webapp2.WSGIApplication([ |
| + ('/', MainPage), |
| + ('/upload', UploadHandler) |
| +], debug=True) |