diff options
author | peria@chromium.org <peria@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-08 12:04:04 +0000 |
---|---|---|
committer | peria@chromium.org <peria@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-08 12:04:04 +0000 |
commit | b3cb61a748f6f2dbaa6cc145af7257b35970a9ae (patch) | |
tree | da8ce3de44073fecc3aec335e4831b83d6fddf13 /tools/deep_memory_profiler/graph.py | |
parent | 1634b9102959a317f4d6a0f1547a2680ddfb7f5d (diff) | |
download | chromium_src-b3cb61a748f6f2dbaa6cc145af7257b35970a9ae.zip chromium_src-b3cb61a748f6f2dbaa6cc145af7257b35970a9ae.tar.gz chromium_src-b3cb61a748f6f2dbaa6cc145af7257b35970a9ae.tar.bz2 |
Make a graph tool of dmprof useful.
1. Change the graph from bar-chart to area chat.
Now x-axis shows time line. It is instinctive.
2. Enable to choose policies in GUI.
It is a waste of time to apply many policies and make different HTML files.
Now it can be done with clicks. No need to specify a policy in converting json to HTML.
Usage:
$ dmprof /path/to/first.heap > temp.json
$ graph.py temp.json > graph.html # no need to specify a poilcy
$ chrome graph.html # open the HTML file in Chrome
BUG=None
NOTRY=true
Review URL: https://codereview.chromium.org/189623009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@255764 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/deep_memory_profiler/graph.py')
-rwxr-xr-x | tools/deep_memory_profiler/graph.py | 114 |
1 files changed, 70 insertions, 44 deletions
diff --git a/tools/deep_memory_profiler/graph.py b/tools/deep_memory_profiler/graph.py index 4d5d3fe..543aaf9 100755 --- a/tools/deep_memory_profiler/graph.py +++ b/tools/deep_memory_profiler/graph.py @@ -9,60 +9,86 @@ 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 - ); +_HTML_TEMPLATE = """<!DOCTYPE html> +<script src="https://www.google.com/jsapi"></script> +<script> +var all_data = $ALL_DATA; +google.load('visualization', '1', {packages:['corechart', 'table']}); +google.setOnLoadCallback(drawVisualization); +function drawVisualization() { + // Apply policy 'l2' by default. + var default_policy = 'l2'; + document.getElementById(default_policy).style.fontWeight = 'bold'; + turnOn(default_policy); +} - var charOptions = { - title: 'DMP Graph', - vAxis: {title: 'Timestamp', titleTextStyle: {color: 'red'}}, - isStacked : true - }; +function turnOn(policy) { + var data = google.visualization.arrayToDataTable(all_data[policy]); + var charOptions = { + title: 'DMP Graph (Policy: ' + policy + ')', + vAxis: {title: 'Timestamp', titleTextStyle: {color: 'red'}}, + isStacked : true + }; + var chart = new google.visualization.AreaChart( + document.getElementById('chart_div')); + chart.draw(data, charOptions); + var table = new google.visualization.Table( + document.getElementById('table_div')); + table.draw(data); +} - 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); +window.onload = function() { + var ul = document.getElementById('policies'); + for (var i = 0; i < ul.children.length; ++i) { + var li = ul.children[i]; + li.onclick = function() { + for (var j = 0; j < ul.children.length; ++j) { + var my_li = ul.children[j]; + my_li.style.fontWeight = 'normal'; } - </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> + this.style.fontWeight = 'bold'; + turnOn(this.id); + } + } +}; +</script> +<style> +#policies li { + display: inline-block; + padding: 5px 10px; +} +</style> +Click to change an applied policy. +<ul id="policies">$POLICIES</ul> +<div id="chart_div" style="width: 1024px; height: 640px;"></div> +<div id="table_div" style="width: 1024px; height: 640px;"></div> """ -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 +def _GenerateGraph(json_data): + policies = list(json_data['policies']) + policies = "".join(map(lambda x: '<li id="'+x+'">'+x+'</li>', policies)) + + all_data = {} + for policy in json_data['policies']: + 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 + all_data[policy] = [legends] + data + print Template(_HTML_TEMPLATE).safe_substitute( - {'JSON_ARRAY': json.dumps([legends] + data)}) + {'POLICIES': policies, + 'ALL_DATA': json.dumps(all_data)}) def main(argv): - _GenerateGraph(json.load(file(argv[1], 'r')), argv[2]) + _GenerateGraph(json.load(file(argv[1], 'r'))) if __name__ == '__main__': sys.exit(main(sys.argv)) - - |