| 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())
|
|
|