summaryrefslogtreecommitdiffstats
path: root/tools/deep_memory_profiler
diff options
context:
space:
mode:
authordmikurube@chromium.org <dmikurube@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-11 06:36:42 +0000
committerdmikurube@chromium.org <dmikurube@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-11 06:36:42 +0000
commitc818cae983e18807d089fd98da20417c05b18010 (patch)
tree68dc5acf62da72ba8b6f8d170d34afad399c59fa /tools/deep_memory_profiler
parentf6f43d0d6af9db43dcbb8dc79874e3c076e0d32b (diff)
downloadchromium_src-c818cae983e18807d089fd98da20417c05b18010.zip
chromium_src-c818cae983e18807d089fd98da20417c05b18010.tar.gz
chromium_src-c818cae983e18807d089fd98da20417c05b18010.tar.bz2
Add JSON output in dmprof.py.
BUG=122119 TEST=none Review URL: http://codereview.chromium.org/10011001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@131722 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/deep_memory_profiler')
-rwxr-xr-xtools/deep_memory_profiler/dmprof.py25
1 files changed, 21 insertions, 4 deletions
diff --git a/tools/deep_memory_profiler/dmprof.py b/tools/deep_memory_profiler/dmprof.py
index 0162b0b..e9c642c 100755
--- a/tools/deep_memory_profiler/dmprof.py
+++ b/tools/deep_memory_profiler/dmprof.py
@@ -5,6 +5,8 @@
"""The deep heap profiler script for Chrome."""
+from datetime import datetime
+import json
import os
import re
import subprocess
@@ -622,6 +624,7 @@ def parse_policy(policy_path):
def main():
if (len(sys.argv) < 4) or (not (sys.argv[1] in ['--csv',
+ '--json',
'--expand',
'--list',
'--stacktrace',
@@ -631,6 +634,7 @@ def main():
Options:
--csv Output result in csv format
+ --json Output result in json format
--stacktrace Convert raw address to symbol names
--list Lists components and their sizes
--expand Show all stacktraces in the specified component
@@ -640,6 +644,7 @@ Options:
Examples:
dmprof --csv Debug/chrome dmpolicy hprof.12345.0001.heap > result.csv
+ dmprof --json Debug/chrome dmpolicy hprof.12345.0001.heap > result.json
dmprof --list Debug/chrome dmpolicy hprof.12345.0012.heap
dmprof --expand Debug/chrome dmpolicy hprof.12345.0012.heap tc-webkit 4
dmprof --pprof Debug/chrome dmpolicy hprof.12345.0012.heap > for_pprof.txt
@@ -686,7 +691,7 @@ Examples:
log_path_list = [log_path]
- if action == '--csv':
+ if action in ('--csv', '--json'):
# search for the sequence of files
n = int(log_path[len(log_path) - 9 : len(log_path) - 5])
n += 1 # skip current file
@@ -698,9 +703,7 @@ Examples:
break
n += 1
- logs = []
- for path in log_path_list:
- logs.append(Log(path, buckets))
+ logs = [Log(path, buckets) for path in log_path_list]
sys.stderr.write('getting symbols\n')
update_symbols(symbol_path, maps_lines, chrome_path)
@@ -724,6 +727,20 @@ Examples:
sys.stdout.write(','.join(s))
sys.stdout.write('\n')
+ elif action == '--json':
+ json_base = {
+ 'version': 'JSON_DEEP_1',
+ 'legends': components,
+ 'snapshots': [],
+ }
+ for log in logs:
+ component_sizes = log.apply_policy(policy_list, buckets, logs[0].log_time)
+ component_sizes['log_path'] = log.log_path
+ component_sizes['log_time'] = datetime.fromtimestamp(
+ log.log_time).strftime('%Y-%m-%d %H:%M:%S')
+ json_base['snapshots'].append(component_sizes)
+ json.dump(json_base, sys.stdout, indent=2, sort_keys=True)
+
elif action == '--list':
component_sizes = logs[0].apply_policy(
policy_list, buckets, logs[0].log_time)