diff options
author | bulach@chromium.org <bulach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-07 16:20:21 +0000 |
---|---|---|
committer | bulach@chromium.org <bulach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-07 16:20:21 +0000 |
commit | 1d5f74348d5e93af007fb588ca84bd201099dc67 (patch) | |
tree | 4edfe367f6c58e81b9529e8026bce3e7eb66c96e /tools/deep_memory_profiler/graph.py | |
parent | d1ec750ffbad84d9b5ae7462aa4d44fe2d5b50c0 (diff) | |
download | chromium_src-1d5f74348d5e93af007fb588ca84bd201099dc67.zip chromium_src-1d5f74348d5e93af007fb588ca84bd201099dc67.tar.gz chromium_src-1d5f74348d5e93af007fb588ca84bd201099dc67.tar.bz2 |
Generate graph visualization from dmp json file.
BUG=244506
Review URL: https://chromiumcodereview.appspot.com/16101008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@204856 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/deep_memory_profiler/graph.py')
-rwxr-xr-x | tools/deep_memory_profiler/graph.py | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/tools/deep_memory_profiler/graph.py b/tools/deep_memory_profiler/graph.py new file mode 100755 index 0000000..4d5d3fe --- /dev/null +++ b/tools/deep_memory_profiler/graph.py @@ -0,0 +1,68 @@ +#!/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 json +import sys +from string import Template + + +_HTML_TEMPLATE = """ +<html> + <head> + <script type='text/javascript' src='https://www.google.com/jsapi'></script> + <script type='text/javascript'> + google.load('visualization', '1', {packages:['corechart', 'table']}); + google.setOnLoadCallback(drawVisualization); + function drawVisualization() { + var data = google.visualization.arrayToDataTable( + $JSON_ARRAY + ); + + var charOptions = { + title: 'DMP Graph', + vAxis: {title: 'Timestamp', titleTextStyle: {color: 'red'}}, + isStacked : true + }; + + var chart = new google.visualization.BarChart( + document.getElementById('chart_div')); + chart.draw(data, charOptions); + + var table = new google.visualization.Table( + document.getElementById('table_div')); + table.draw(data); + } + </script> + </head> + <body> + <div id='chart_div' style="width: 1024px; height: 800px;"></div> + <div id='table_div' style="width: 1024px; height: 640px;"></div> + </body> +</html> +""" + +def _GenerateGraph(json_data, policy): + legends = list(json_data['policies'][policy]['legends']) + legends = ['second'] + legends[legends.index('FROM_HERE_FOR_TOTAL') + 1: + legends.index('UNTIL_HERE_FOR_TOTAL')] + data = [] + for snapshot in json_data['policies'][policy]['snapshots']: + data.append([0] * len(legends)) + for k, v in snapshot.iteritems(): + if k in legends: + data[-1][legends.index(k)] = v + print Template(_HTML_TEMPLATE).safe_substitute( + {'JSON_ARRAY': json.dumps([legends] + data)}) + + +def main(argv): + _GenerateGraph(json.load(file(argv[1], 'r')), argv[2]) + + +if __name__ == '__main__': + sys.exit(main(sys.argv)) + + |