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

Side by Side 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, 8 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright 2017 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 """
7 Removes all memory dump trace events that are not associated with the first,
8 detailed dump.
9 """
10
11 import argparse
12 import json
13 import sys
14
15
16 def main():
17 parser = argparse.ArgumentParser()
18 parser.add_argument('input_file',
19 help = 'The file to process. Should be in json.')
20 parser.add_argument('output_file',
21 help = 'The file to emit. Will be in json.')
22 parser_args = parser.parse_args()
23
24 f = open(parser_args.input_file, 'r')
25 contents = f.read()
26 json_contents = json.loads(contents)
27
28 def IsMemoryDumpEvent(event):
29 return event['ph'] == 'v'
30
31 def IsDetailed(event):
32 if not IsMemoryDumpEvent(event):
33 return False
34 level = event['args']['dumps']['level_of_detail']
35 return level == "detailed"
36
37 def IsLight(event):
38 if not IsMemoryDumpEvent(event):
39 return False
40 level = event['args']['dumps']['level_of_detail']
41 return level != "detailed"
42
43 # Find the id associated with the first detailed memory dump.
44 identifier = None
45 for event in json_contents['traceEvents']:
46 if IsDetailed(event):
47 identifier = event['id']
48 break
49
50 trace_events = []
51 for event in json_contents['traceEvents']:
52 if IsDetailed(event) and event['id'] != identifier:
53 continue
54 if IsLight(event):
55 continue
56 trace_events.append(event)
57
58 json_contents['traceEvents'] = trace_events
59 f2 = open(parser_args.output_file, 'w')
60 f2.write(json.dumps(json_contents))
61
62 if __name__ == '__main__':
63 sys.exit(main())
OLDNEW
« 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