Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 # Copyright 2013 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 import os | |
| 7 import subprocess | |
| 8 import sys | |
| 9 import tempfile | |
| 10 | |
| 11 from string import Template | |
| 12 | |
| 13 | |
| 14 _TEMPLATE = """<!DOCTYPE html> | |
| 15 <meta charset="utf-8"> | |
| 16 <link rel="stylesheet" href="../visualizer/index.css"> | |
| 17 <link rel="stylesheet" href="../visualizer/third_party/jqTree/jqtree.css"> | |
| 18 | |
| 19 <script src="../../../third_party/flot/jquery.min.js"></script> | |
| 20 <script src="../../../third_party/flot/jquery.flot.min.js"></script> | |
| 21 <script src="../../../third_party/flot/jquery.flot.stack.min.js"></script> | |
| 22 <script src="../visualizer/third_party/jqTree/tree.jquery.js"></script> | |
| 23 <script src="../visualizer/utility.js"></script> | |
| 24 <script src="../visualizer/profiler.js"></script> | |
| 25 <script src="../visualizer/graph-view.js"></script> | |
| 26 <script src="../visualizer/dropdown-view.js"></script> | |
| 27 <script src="../visualizer/menu-view.js"></script> | |
| 28 <script type="text/javascript"> | |
| 29 $(function() { | |
| 30 var data = $DATA; | |
| 31 var profiler = new Profiler(data); | |
| 32 var graphView = new GraphView(profiler); | |
| 33 var dropdownView = new DropdownView(profiler); | |
| 34 var menuView = new MenuView(profiler); | |
| 35 | |
| 36 profiler.reparse(); | |
| 37 }); | |
| 38 </script> | |
| 39 | |
| 40 <body> | |
| 41 <h2>Deep Memory Profiler Visulaizer</h2> | |
| 42 <div id="graph-div"></div> | |
| 43 <div id="info-div"> | |
| 44 <div id="subs-dropdown"></div> | |
| 45 <div id="category-menu"></div> | |
| 46 </div> | |
| 47 </body> | |
| 48 """ | |
| 49 | |
| 50 | |
| 51 def main(argv): | |
| 52 # Read json data. | |
| 53 data_file = open(argv[1], 'r') | |
| 54 data = data_file.read() | |
| 55 data_file.close() | |
| 56 | |
| 57 # Fill in the template of index.js. | |
| 58 dmprof_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
| 59 html_dir = os.path.join(dmprof_path, 'graphs') | |
| 60 if not os.path.exists(html_dir): | |
| 61 os.mkdir(html_dir) | |
| 62 | |
| 63 html_handle, html_path = tempfile.mkstemp('.html', 'graph', html_dir) | |
| 64 html_file = os.fdopen(html_handle, 'w') | |
| 65 html_file.write(Template(_TEMPLATE).safe_substitute({ 'DATA': data })) | |
|
sullivan
2013/09/04 14:15:23
Are there any concerns about XSS here? For example
| |
| 66 html_file.close() | |
| 67 | |
| 68 # Open index page in chrome automatically if permitted. | |
| 69 if sys.platform.startswith('linux'): | |
| 70 try: | |
| 71 subprocess.call(['xdg-open', html_path]) | |
| 72 except OSError, exception: | |
| 73 print >> sys.stderr, 'xdg-open failed:', exception | |
| 74 print 'generated html file is at ' + html_path | |
| 75 else: | |
| 76 print 'generated html file is at ' + html_path | |
| 77 | |
| 78 | |
| 79 if __name__ == '__main__': | |
| 80 sys.exit(main(sys.argv)) | |
| OLD | NEW |