| OLD | NEW |
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import json | 5 import json |
| 6 import logging | 6 import logging |
| 7 import sys | 7 import sys |
| 8 | 8 |
| 9 from lib.bucket import BUCKET_ID, COMMITTED, ALLOC_COUNT, FREE_COUNT | 9 from lib.bucket import BUCKET_ID, COMMITTED, ALLOC_COUNT, FREE_COUNT |
| 10 from lib.ordered_dict import OrderedDict | 10 from lib.ordered_dict import OrderedDict |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 alternative_dirs_dict[target_path] = host_path | 36 alternative_dirs_dict[target_path] = host_path |
| 37 (bucket_set, dumps) = SubCommand.load_basic_files( | 37 (bucket_set, dumps) = SubCommand.load_basic_files( |
| 38 dump_path, True, alternative_dirs=alternative_dirs_dict) | 38 dump_path, True, alternative_dirs=alternative_dirs_dict) |
| 39 | 39 |
| 40 # Load all sorters. | 40 # Load all sorters. |
| 41 sorters = SorterSet() | 41 sorters = SorterSet() |
| 42 | 42 |
| 43 json_root = OrderedDict() | 43 json_root = OrderedDict() |
| 44 json_root['version'] = 1 | 44 json_root['version'] = 1 |
| 45 json_root['run_id'] = None | 45 json_root['run_id'] = None |
| 46 for dump in dumps: | |
| 47 if json_root['run_id'] and json_root['run_id'] != dump.run_id: | |
| 48 LOGGER.error('Inconsistent heap profile dumps.') | |
| 49 json_root['run_id'] = '' | |
| 50 break | |
| 51 json_root['run_id'] = dump.run_id | |
| 52 json_root['roots'] = [] | 46 json_root['roots'] = [] |
| 53 for sorter in sorters: | 47 for sorter in sorters: |
| 54 if sorter.root: | 48 if sorter.root: |
| 55 json_root['roots'].append([sorter.world, sorter.name]) | 49 json_root['roots'].append([sorter.world, sorter.name]) |
| 56 json_root['default_template'] = 'l2' | 50 json_root['default_template'] = 'l2' |
| 57 json_root['templates'] = sorters.templates.as_dict() | 51 json_root['templates'] = sorters.templates.as_dict() |
| 58 | 52 |
| 59 orders = OrderedDict() | 53 orders = OrderedDict() |
| 60 orders['worlds'] = OrderedDict() | 54 orders['worlds'] = OrderedDict() |
| 61 for world in ['vm', 'malloc']: | 55 for world in ['vm', 'malloc']: |
| 62 orders['worlds'][world] = OrderedDict() | 56 orders['worlds'][world] = OrderedDict() |
| 63 orders['worlds'][world]['breakdown'] = OrderedDict() | 57 orders['worlds'][world]['breakdown'] = OrderedDict() |
| 64 for sorter in sorters.iter_world(world): | 58 for sorter in sorters.iter_world(world): |
| 65 order = [] | 59 order = [] |
| 66 for rule in sorter.iter_rule(): | 60 for rule in sorter.iter_rule(): |
| 67 if rule.name not in order: | 61 if rule.name not in order: |
| 68 order.append(rule.name) | 62 order.append(rule.name) |
| 69 orders['worlds'][world]['breakdown'][sorter.name] = order | 63 orders['worlds'][world]['breakdown'][sorter.name] = order |
| 70 json_root['orders'] = orders | 64 json_root['orders'] = orders |
| 71 | 65 |
| 72 json_root['snapshots'] = [] | 66 json_root['snapshots'] = [] |
| 73 | 67 |
| 74 for dump in dumps: | 68 for dump in dumps: |
| 69 if json_root['run_id'] and json_root['run_id'] != dump.run_id: |
| 70 LOGGER.error('Inconsistent heap profile dumps.') |
| 71 json_root['run_id'] = '' |
| 72 else: |
| 73 json_root['run_id'] = dump.run_id |
| 74 |
| 75 LOGGER.info('Sorting a dump %s...' % dump.path) | 75 LOGGER.info('Sorting a dump %s...' % dump.path) |
| 76 json_root['snapshots'].append( | 76 json_root['snapshots'].append( |
| 77 self._fill_snapshot(dump, bucket_set, sorters)) | 77 self._fill_snapshot(dump, bucket_set, sorters)) |
| 78 | 78 |
| 79 if options.indent: | 79 if options.indent: |
| 80 json.dump(json_root, sys.stdout, indent=2) | 80 json.dump(json_root, sys.stdout, indent=2) |
| 81 else: | 81 else: |
| 82 json.dump(json_root, sys.stdout) | 82 json.dump(json_root, sys.stdout) |
| 83 print '' | 83 print '' |
| 84 | 84 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 int(words[ALLOC_COUNT]), | 186 int(words[ALLOC_COUNT]), |
| 187 int(words[FREE_COUNT]), | 187 int(words[FREE_COUNT]), |
| 188 bucket) | 188 bucket) |
| 189 elif not bucket: | 189 elif not bucket: |
| 190 # 'Not-found' buckets are all assumed as malloc buckets. | 190 # 'Not-found' buckets are all assumed as malloc buckets. |
| 191 yield MallocUnit(int(words[BUCKET_ID]), | 191 yield MallocUnit(int(words[BUCKET_ID]), |
| 192 int(words[COMMITTED]), | 192 int(words[COMMITTED]), |
| 193 int(words[ALLOC_COUNT]), | 193 int(words[ALLOC_COUNT]), |
| 194 int(words[FREE_COUNT]), | 194 int(words[FREE_COUNT]), |
| 195 None) | 195 None) |
| OLD | NEW |