OLD | NEW |
| (Empty) |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | |
2 // for details. All rights reserved. Use of this source code is governed by a | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 // VMOptions=--error_on_bad_type --error_on_bad_override | |
5 | |
6 import 'package:observatory/heap_snapshot.dart'; | |
7 import 'package:observatory/object_graph.dart'; | |
8 import 'package:observatory/service_io.dart'; | |
9 import 'package:unittest/unittest.dart'; | |
10 import 'test_helper.dart'; | |
11 | |
12 class Foo { | |
13 Object left; | |
14 Object right; | |
15 } | |
16 Foo r; | |
17 | |
18 List lst; | |
19 | |
20 void script() { | |
21 // Create 3 instances of Foo, with out-degrees | |
22 // 0 (for b), 1 (for a), and 2 (for staticFoo). | |
23 r = new Foo(); | |
24 var a = new Foo(); | |
25 var b = new Foo(); | |
26 r.left = a; | |
27 r.right = b; | |
28 a.left = b; | |
29 | |
30 lst = new List(2); | |
31 lst[0] = lst; // Self-loop. | |
32 // Larger than any other fixed-size list in a fresh heap. | |
33 lst[1] = new List(123456); | |
34 } | |
35 | |
36 int fooId; | |
37 | |
38 var tests = [ | |
39 | |
40 (Isolate isolate) async { | |
41 Library lib = await isolate.rootLibrary.load(); | |
42 expect(lib.classes.length, equals(1)); | |
43 Class fooClass = lib.classes.first; | |
44 fooId = fooClass.vmCid; | |
45 | |
46 RawHeapSnapshot raw = await isolate.fetchHeapSnapshot(false).last; | |
47 HeapSnapshot snapshot = new HeapSnapshot(); | |
48 await snapshot.loadProgress(isolate, raw).last; | |
49 ObjectGraph graph = snapshot.graph; | |
50 | |
51 expect(fooId, isNotNull); | |
52 Iterable<ObjectVertex> foos = graph.vertices.where( | |
53 (ObjectVertex obj) => obj.vmCid == fooId); | |
54 expect(foos.length, equals(3)); | |
55 expect(foos.where((obj) => obj.successors.length == 0).length, | |
56 equals(1)); | |
57 expect(foos.where((obj) => obj.successors.length == 1).length, | |
58 equals(1)); | |
59 expect(foos.where((obj) => obj.successors.length == 2).length, | |
60 equals(1)); | |
61 | |
62 ObjectVertex bVertex = foos.where( | |
63 (ObjectVertex obj) => obj.successors.length == 0).first; | |
64 ObjectVertex aVertex = foos.where( | |
65 (ObjectVertex obj) => obj.successors.length == 1).first; | |
66 ObjectVertex rVertex = foos.where( | |
67 (ObjectVertex obj) => obj.successors.length == 2).first; | |
68 | |
69 // TODO(koda): Check actual byte sizes. | |
70 | |
71 expect(aVertex.retainedSize, equals(aVertex.shallowSize)); | |
72 expect(bVertex.retainedSize, equals(bVertex.shallowSize)); | |
73 expect(rVertex.retainedSize, equals(aVertex.shallowSize + | |
74 bVertex.shallowSize + | |
75 rVertex.shallowSize)); | |
76 | |
77 Library corelib = | |
78 isolate.libraries.singleWhere((lib) => lib.uri == 'dart:core'); | |
79 await corelib.load(); | |
80 Class _List = | |
81 corelib.classes.singleWhere((cls) => cls.vmName.startsWith('_List')); | |
82 int kArrayCid = _List.vmCid; | |
83 // startsWith to ignore the private mangling | |
84 List<ObjectVertex> lists = new List.from(graph.vertices.where( | |
85 (ObjectVertex obj) => obj.vmCid == kArrayCid)); | |
86 expect(lists.length >= 2, isTrue); | |
87 // Order by decreasing retained size. | |
88 lists.sort((u, v) => v.retainedSize - u.retainedSize); | |
89 ObjectVertex first = lists[0]; | |
90 ObjectVertex second = lists[1]; | |
91 // Check that the short list retains more than the long list inside. | |
92 expect(first.successors.length, | |
93 equals(2 + second.successors.length)); | |
94 // ... and specifically, that it retains exactly itself + the long one. | |
95 expect(first.retainedSize, | |
96 equals(first.shallowSize + second.shallowSize)); | |
97 }, | |
98 | |
99 ]; | |
100 | |
101 main(args) => runIsolateTests(args, tests, testeeBefore: script); | |
OLD | NEW |