|
2 | 2 | // for details. All rights reserved. Use of this source code is governed by a
|
3 | 3 | // BSD-style license that can be found in the LICENSE file.
|
4 | 4 |
|
| 5 | +import 'dart:convert'; |
5 | 6 | import 'dart:io';
|
6 | 7 |
|
7 | 8 | import 'package:test/test.dart';
|
8 | 9 |
|
9 | 10 | import 'package:vm_snapshot_analysis/instruction_sizes.dart'
|
10 | 11 | as instruction_sizes;
|
11 | 12 | import 'package:vm_snapshot_analysis/program_info.dart';
|
| 13 | +import 'package:vm_snapshot_analysis/treemap.dart'; |
12 | 14 | import 'package:vm_snapshot_analysis/utils.dart';
|
13 | 15 |
|
14 | 16 | import 'utils.dart';
|
@@ -641,6 +643,40 @@ void main() async {
|
641 | 643 | });
|
642 | 644 | });
|
643 | 645 | });
|
| 646 | + |
| 647 | + test('treemap', () async { |
| 648 | + await withV8Profile('treemap', testSource, (profileJson) async { |
| 649 | + final infoJson = await loadJson(File(profileJson)); |
| 650 | + final info = await loadProgramInfoFromJson(infoJson, |
| 651 | + collapseAnonymousClosures: true); |
| 652 | + final treemap = treemapFromInfo(info); |
| 653 | + |
| 654 | + List<Map<String, dynamic>> childrenOf(Map<String, dynamic> node) => |
| 655 | + (node['children'] as List).cast(); |
| 656 | + |
| 657 | + String nameOf(Map<String, dynamic> node) => node['n']; |
| 658 | + |
| 659 | + Map<String, dynamic> findChild(Map<String, dynamic> node, String name) { |
| 660 | + return childrenOf(node) |
| 661 | + .firstWhere((child) => nameOf(child) == name, orElse: () => null); |
| 662 | + } |
| 663 | + |
| 664 | + Set<String> childrenNames(Map<String, dynamic> node) { |
| 665 | + return childrenOf(node).map(nameOf).toSet(); |
| 666 | + } |
| 667 | + |
| 668 | + // Verify that we don't include package names twice into paths |
| 669 | + // while building the treemap. |
| 670 | + if (Platform.isWindows) { |
| 671 | + // Note: in Windows we don't consider main.dart part of package:input |
| 672 | + // for some reason. |
| 673 | + expect(findChild(treemap, 'package:input/input.dart'), isNotNull); |
| 674 | + } else { |
| 675 | + expect(childrenNames(findChild(treemap, 'package:input')), |
| 676 | + equals({'<self>', 'main.dart', 'input.dart'})); |
| 677 | + } |
| 678 | + }); |
| 679 | + }); |
644 | 680 | });
|
645 | 681 | }
|
646 | 682 |
|
|
0 commit comments