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.
11 from string
import Template
14 _TEMPLATE
= """<!DOCTYPE html>
15 <meta charset="utf-8">
16 <link rel="stylesheet" href="../visualizer/static/index.css">
17 <link rel="stylesheet"
18 href="../visualizer/static/third_party/jqTree/jqtree.css">
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/static/third_party/jqTree/tree.jquery.js"></script>
24 <script src="../visualizer/static/utility.js"></script>
25 <script src="../visualizer/static/profiler.js"></script>
26 <script src="../visualizer/static/graph-view.js"></script>
27 <script src="../visualizer/static/dropdown-view.js"></script>
28 <script src="../visualizer/static/menu-view.js"></script>
29 <script type="text/javascript">
32 var profiler = new Profiler(data);
33 var graphView = new GraphView(profiler);
34 var dropdownView = new DropdownView(profiler);
35 var menuView = new MenuView(profiler);
42 <h2>Deep Memory Profiler Visualizer</h2>
43 <div id="graph-div"></div>
45 <div id="category-menu"></div>
46 <div id="subs-dropdown"></div>
54 with
open(argv
[1]) as data_file
:
55 data
= data_file
.read()
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
):
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
}))
68 # Open index page in chrome automatically if permitted.
69 if sys
.platform
.startswith('linux'):
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
76 print 'generated html file is at ' + html_path
79 if __name__
== '__main__':
80 sys
.exit(main(sys
.argv
))