Chromium Code Reviews| Index: tools/deep_memory_profiler/visualizer/template.py |
| diff --git a/tools/deep_memory_profiler/visualizer/template.py b/tools/deep_memory_profiler/visualizer/template.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..f65e2df6bf3b3f51564d649142a365a90c1aac9e |
| --- /dev/null |
| +++ b/tools/deep_memory_profiler/visualizer/template.py |
| @@ -0,0 +1,79 @@ |
| +#!/usr/bin/env python |
| +# |
|
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.
|
| +# 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 os |
| +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.
|
| +import subprocess |
| +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.
|
| +from string import Template |
| + |
| + |
| +_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.
|
| +<!DOCTYPE html> |
| +<meta charset="utf-8"> |
| +<link rel="stylesheet" href="../visualizer/index.css"> |
| +<link rel="stylesheet" href="../visualizer/third_party/jqTree/jqtree.css"> |
| + |
| +<script src="../../../third_party/flot/jquery.min.js"></script> |
| +<script src="../../../third_party/flot/jquery.flot.min.js"></script> |
| +<script src="../../../third_party/flot/jquery.flot.stack.min.js"></script> |
| +<script src="../visualizer/third_party/jqTree/tree.jquery.js"></script> |
| +<script src="../visualizer/utility.js"></script> |
| +<script src="../visualizer/profiler.js"></script> |
| +<script src="../visualizer/graph-view.js"></script> |
| +<script src="../visualizer/dropdown-view.js"></script> |
| +<script src="../visualizer/menu-view.js"></script> |
| +<script type="text/javascript"> |
| + $(function() { |
| + var data = $DATA; |
| + var profiler = new Profiler(data); |
| + var graphView = new GraphView(profiler); |
| + var dropdownView = new DropdownView(profiler); |
| + var menuView = new MenuView(profiler); |
| + |
| + profiler.reparse(); |
| +}); |
| +</script> |
| + |
| +<body> |
| + <h2>Deep Memory Profiler Visulaizer</h2> |
| + <div id="graph-div"></div> |
| + <div id="info-div"> |
| + <div id="subs-dropdown"></div> |
| + <div id="category-menu"></div> |
| + </div> |
| +</body> |
| +""" |
| + |
|
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.
|
| +def main(argv): |
| + # Read json data. |
| + data_file = open(argv[1], 'r') |
| + data = data_file.read() |
| + data_file.close() |
| + |
| + # Fill in the template of index.js. |
| + 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.
|
| + html_dir = os.path.join(dmp_path, 'graphs') |
| + if not os.path.exists(html_dir): |
| + os.mkdir(html_dir) |
| + |
| + 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.
|
| + html_file = os.fdopen(html_handle, 'w') |
| + html_file.write(Template(_TEMPLATE).safe_substitute({ 'DATA': data })) |
| + html_file.close() |
| + |
| + # Open index page in chrome automatically if permitted. |
| + 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.
|
| + try: |
| + subprocess.call(['xdg-open', html_path]) |
| + except OSError, exception: |
| + 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.
|
| + print 'generated html file is at ' + html_path |
| + else: |
| + print 'generated html file is at ' + html_path |
| + |
|
Dai Mikurube (NOT FULLTIME)
2013/09/04 07:39:48
nit: two empty lines here.
junjianx
2013/09/04 07:55:36
Done.
|
| +if __name__ == '__main__': |
| + sys.exit(main(sys.argv)) |