summaryrefslogtreecommitdiffstats
path: root/chromium/third_party/catapult/tracing/tracing_build/strip_memory_infra_trace.py
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2019-03-05 17:34:47 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2019-03-06 10:04:14 +0000
commiteaf1da4d961fbbda9455f9af3b23d1af777f43fa (patch)
tree95970599ecee31c4f7f940bc97ac98c61a3d0cad /chromium/third_party/catapult/tracing/tracing_build/strip_memory_infra_trace.py
parent38a9a29f4f9436cace7f0e7abf9c586057df8a4e (diff)
BASELINE: Update Chromium to 73.0.3683.64
Change-Id: I76517dc277ba4e16bfd7e098fda3d079656b3b9f Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'chromium/third_party/catapult/tracing/tracing_build/strip_memory_infra_trace.py')
-rwxr-xr-xchromium/third_party/catapult/tracing/tracing_build/strip_memory_infra_trace.py102
1 files changed, 102 insertions, 0 deletions
diff --git a/chromium/third_party/catapult/tracing/tracing_build/strip_memory_infra_trace.py b/chromium/third_party/catapult/tracing/tracing_build/strip_memory_infra_trace.py
new file mode 100755
index 00000000000..4e897727f3e
--- /dev/null
+++ b/chromium/third_party/catapult/tracing/tracing_build/strip_memory_infra_trace.py
@@ -0,0 +1,102 @@
+# Copyright 2016 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.
+
+"""Filters a big trace keeping only the last memory-infra dumps."""
+
+from __future__ import print_function
+
+import collections
+import gzip
+import json
+
+
+def FormatBytes(value):
+ units = ['B', 'KiB', 'MiB', 'GiB']
+ while abs(value) >= 1024 and len(units) > 1:
+ value /= 1024
+ units = units.pop(0)
+ return '%3.1f %s' % (value, units[0])
+
+
+def Main(argv):
+ if len(argv) < 2:
+ print('Usage: %s trace.json[.gz]' % argv[0])
+ return 1
+
+ in_path = argv[1]
+ if in_path.lower().endswith('.gz'):
+ fin = gzip.open(in_path, 'rb')
+ else:
+ fin = open(in_path, 'r')
+ with fin:
+ print('Loading trace (can take 1 min on a z620 for a 1GB trace)...')
+ trace = json.load(fin)
+ print('Done. Read ' + FormatBytes(fin.tell()))
+
+ print('Filtering events')
+ phase_count = collections.defaultdict(int)
+ out_events = []
+ global_dumps = collections.OrderedDict()
+ if isinstance(trace, dict):
+ in_events = trace.get('traceEvents', [])
+ elif isinstance(trace, list) and isinstance(trace[0], dict):
+ in_events = trace
+
+ for evt in in_events:
+ phase = evt.get('ph', '?')
+ phase_count[phase] += 1
+
+ # Drop all diagnostic events for memory-infra debugging.
+ if phase not in ('v', 'V') and evt.get('cat', '').endswith('memory-infra'):
+ continue
+
+ # pass-through all the other non-memory-infra events
+ if phase != 'v':
+ out_events.append(evt)
+ continue
+
+ # Recreate the global dump groups
+ event_id = evt['id']
+ global_dumps.setdefault(event_id, [])
+ global_dumps[event_id].append(evt)
+
+
+ print('Detected %d memory-infra global dumps' % len(global_dumps))
+ if global_dumps:
+ max_procs = max(len(x) for x in global_dumps.values())
+ print('Max number of processes seen: %d' % max_procs)
+
+ ndumps = 2
+ print('Preserving the last %d memory-infra dumps' % ndumps)
+ detailed_dumps = []
+ non_detailed_dumps = []
+ for global_dump in global_dumps.values():
+ try:
+ level_of_detail = global_dump[0]['args']['dumps']['level_of_detail']
+ except KeyError:
+ level_of_detail = None
+ if level_of_detail == 'detailed':
+ detailed_dumps.append(global_dump)
+ else:
+ non_detailed_dumps.append(global_dump)
+
+ dumps_to_preserve = detailed_dumps[-ndumps:]
+ ndumps -= len(dumps_to_preserve)
+ if ndumps:
+ dumps_to_preserve += non_detailed_dumps[-ndumps:]
+
+ for global_dump in dumps_to_preserve:
+ out_events += global_dump
+
+ print('\nEvents histogram for the original trace (count by phase)')
+ print('--------------------------------------------------------')
+ for phase, count in sorted(phase_count.items(), key=lambda x: x[1]):
+ print('%s %d' % (phase, count))
+
+ out_path = in_path.split('.json')[0] + '-filtered.json'
+ print('\nWriting filtered trace to ' + out_path, end='')
+ with open(out_path, 'w') as fout:
+ json.dump({'traceEvents': out_events}, fout)
+ num_bytes_written = fout.tell()
+ print(' (%s written)' % FormatBytes(num_bytes_written))