#!/usr/bin/env python # 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 subprocess import sys import tempfile from string import Template _TEMPLATE = """

Deep Memory Profiler Visualizer

""" def main(argv): # Read json data. with open(argv[1]) as data_file: data = data_file.read() # Fill in the template of index.js. dmprof_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) html_dir = os.path.join(dmprof_path, 'graphs') if not os.path.exists(html_dir): os.mkdir(html_dir) html_handle, html_path = tempfile.mkstemp('.html', 'graph', html_dir) 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 sys.platform.startswith('linux'): try: subprocess.call(['xdg-open', html_path]) except OSError, exception: print >> sys.stderr, 'xdg-open failed:', exception print 'generated html file is at ' + html_path else: print 'generated html file is at ' + html_path if __name__ == '__main__': sys.exit(main(sys.argv))