Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 # | |
|
Dai Mikurube (NOT FULLTIME)
2013/09/04 07:39:48
We don't need an empty line here.
junjianx
2013/09/04 07:55:36
Done.
| |
| 3 # Copyright 2013 The Chromium Authors. All rights reserved. | |
| 4 # Use of this source code is governed by a BSD-style license that can be | |
| 5 # found in the LICENSE file. | |
| 6 | |
| 7 import os | |
| 8 import sys | |
|
Dai Mikurube (NOT FULLTIME)
2013/09/04 07:39:48
import subprocess should be before import sys in a
junjianx
2013/09/04 07:55:36
Done.
| |
| 9 import subprocess | |
| 10 import tempfile | |
|
Dai Mikurube (NOT FULLTIME)
2013/09/04 07:39:48
nit: an empty line after 'import tempfile'
junjianx
2013/09/04 07:55:36
Done.
| |
| 11 from string import Template | |
| 12 | |
| 13 | |
| 14 _TEMPLATE = """ | |
|
Dai Mikurube (NOT FULLTIME)
2013/09/04 07:39:48
The generated html starts with an empty line while
junjianx
2013/09/04 07:55:36
Done.
| |
| 15 <!DOCTYPE html> | |
| 16 <meta charset="utf-8"> | |
| 17 <link rel="stylesheet" href="../visualizer/index.css"> | |
| 18 <link rel="stylesheet" href="../visualizer/third_party/jqTree/jqtree.css"> | |
| 19 | |
| 20 <script src="../../../third_party/flot/jquery.min.js"></script> | |
| 21 <script src="../../../third_party/flot/jquery.flot.min.js"></script> | |
| 22 <script src="../../../third_party/flot/jquery.flot.stack.min.js"></script> | |
| 23 <script src="../visualizer/third_party/jqTree/tree.jquery.js"></script> | |
| 24 <script src="../visualizer/utility.js"></script> | |
| 25 <script src="../visualizer/profiler.js"></script> | |
| 26 <script src="../visualizer/graph-view.js"></script> | |
| 27 <script src="../visualizer/dropdown-view.js"></script> | |
| 28 <script src="../visualizer/menu-view.js"></script> | |
| 29 <script type="text/javascript"> | |
| 30 $(function() { | |
| 31 var data = $DATA; | |
| 32 var profiler = new Profiler(data); | |
| 33 var graphView = new GraphView(profiler); | |
| 34 var dropdownView = new DropdownView(profiler); | |
| 35 var menuView = new MenuView(profiler); | |
| 36 | |
| 37 profiler.reparse(); | |
| 38 }); | |
| 39 </script> | |
| 40 | |
| 41 <body> | |
| 42 <h2>Deep Memory Profiler Visulaizer</h2> | |
| 43 <div id="graph-div"></div> | |
| 44 <div id="info-div"> | |
| 45 <div id="subs-dropdown"></div> | |
| 46 <div id="category-menu"></div> | |
| 47 </div> | |
| 48 </body> | |
| 49 """ | |
| 50 | |
|
Dai Mikurube (NOT FULLTIME)
2013/09/04 07:39:48
nit: two empty lines here. (a top-level item means
junjianx
2013/09/04 07:55:36
Done.
| |
| 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 dmp_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
|
Dai Mikurube (NOT FULLTIME)
2013/09/04 07:39:48
nit: I recommend s/dmp/dmprof/. "dmp" is ambiguous
junjianx
2013/09/04 07:55:36
Done.
| |
| 59 html_dir = os.path.join(dmp_path, 'graphs') | |
| 60 if not os.path.exists(html_dir): | |
| 61 os.mkdir(html_dir) | |
| 62 | |
| 63 html_handle, html_path = tempfile.mkstemp('.html', 'graphs', html_dir) | |
|
Dai Mikurube (NOT FULLTIME)
2013/09/04 07:39:48
A generated html has a single graph. Just 'graph'
junjianx
2013/09/04 07:55:36
Done.
| |
| 64 html_file = os.fdopen(html_handle, 'w') | |
| 65 html_file.write(Template(_TEMPLATE).safe_substitute({ 'DATA': data })) | |
| 66 html_file.close() | |
| 67 | |
| 68 # Open index page in chrome automatically if permitted. | |
| 69 if os.name == 'posix': | |
|
Dai Mikurube (NOT FULLTIME)
2013/09/04 07:39:48
To check the platform, 'sys.platform' is better.
h
junjianx
2013/09/04 07:55:36
Done.
| |
| 70 try: | |
| 71 subprocess.call(['xdg-open', html_path]) | |
| 72 except OSError, exception: | |
| 73 print 'xdg-open failed:', exception | |
|
Dai Mikurube (NOT FULLTIME)
2013/09/04 07:39:48
This 'print' should go to stderr since it's clearl
junjianx
2013/09/04 07:55:36
Done.
| |
| 74 print 'generated html file is at ' + html_path | |
| 75 else: | |
| 76 print 'generated html file is at ' + html_path | |
| 77 | |
|
Dai Mikurube (NOT FULLTIME)
2013/09/04 07:39:48
nit: two empty lines here.
junjianx
2013/09/04 07:55:36
Done.
| |
| 78 if __name__ == '__main__': | |
| 79 sys.exit(main(sys.argv)) | |
| OLD | NEW |