Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(127)

Unified Diff: tools/memory_inspector/strip_memory_dumps_from_trace.py

Issue 2792693002: Add a tool that strips all but the first memory dump from a trace.
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/memory_inspector/strip_memory_dumps_from_trace.py
diff --git a/tools/memory_inspector/strip_memory_dumps_from_trace.py b/tools/memory_inspector/strip_memory_dumps_from_trace.py
new file mode 100755
index 0000000000000000000000000000000000000000..8f7ecf174e8822a4f32998ec2a92a986a836e49c
--- /dev/null
+++ b/tools/memory_inspector/strip_memory_dumps_from_trace.py
@@ -0,0 +1,63 @@
+#!/usr/bin/env python
+# Copyright 2017 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.
+
+"""
+Removes all memory dump trace events that are not associated with the first,
+detailed dump.
+"""
+
+import argparse
+import json
+import sys
+
+
+def main():
+ parser = argparse.ArgumentParser()
+ parser.add_argument('input_file',
+ help = 'The file to process. Should be in json.')
+ parser.add_argument('output_file',
+ help = 'The file to emit. Will be in json.')
+ parser_args = parser.parse_args()
+
+ f = open(parser_args.input_file, 'r')
+ contents = f.read()
+ json_contents = json.loads(contents)
+
+ def IsMemoryDumpEvent(event):
+ return event['ph'] == 'v'
+
+ def IsDetailed(event):
+ if not IsMemoryDumpEvent(event):
+ return False
+ level = event['args']['dumps']['level_of_detail']
+ return level == "detailed"
+
+ def IsLight(event):
+ if not IsMemoryDumpEvent(event):
+ return False
+ level = event['args']['dumps']['level_of_detail']
+ return level != "detailed"
+
+ # Find the id associated with the first detailed memory dump.
+ identifier = None
+ for event in json_contents['traceEvents']:
+ if IsDetailed(event):
+ identifier = event['id']
+ break
+
+ trace_events = []
+ for event in json_contents['traceEvents']:
+ if IsDetailed(event) and event['id'] != identifier:
+ continue
+ if IsLight(event):
+ continue
+ trace_events.append(event)
+
+ json_contents['traceEvents'] = trace_events
+ f2 = open(parser_args.output_file, 'w')
+ f2.write(json.dumps(json_contents))
+
+if __name__ == '__main__':
+ sys.exit(main())
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698