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

Side by Side Diff: runtime/bin/vmservice/observatory/test/graph_test.dart

Issue 777693002: Compute retained size for every object, using dominator trees. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'dart:async'; 5 import 'dart:async';
6 import 'package:observatory/object_graph.dart'; 6 import 'package:observatory/object_graph.dart';
7 import 'package:observatory/service_io.dart'; 7 import 'package:observatory/service_io.dart';
8 import 'package:unittest/unittest.dart'; 8 import 'package:unittest/unittest.dart';
9 import 'test_helper.dart'; 9 import 'test_helper.dart';
10 10
11 class Foo { 11 class Foo {
12 Object left; 12 Object left;
13 Object right; 13 Object right;
14 } 14 }
15 Foo root; 15 Foo r;
16
17 List lst;
16 18
17 void script() { 19 void script() {
18 // Create 3 instances of Foo, with out-degrees 0 (for b), 1 (for a), and 2 (fo r root). 20 // Create 3 instances of Foo, with out-degrees 0 (for b), 1 (for a), and 2 (fo r staticFoo).
Cutch 2014/12/04 18:34:54 Over 80 column limit here and elsewhere
koda 2014/12/04 19:27:27 Done.
19 root = new Foo(); 21 r = new Foo();
20 var a = new Foo(); 22 var a = new Foo();
21 var b = new Foo(); 23 var b = new Foo();
22 root.left = a; 24 r.left = a;
23 root.right = b; 25 r.right = b;
24 a.left = b; 26 a.left = b;
27
28 lst = new List(2);
29 lst[0] = lst; // Self-loop.
30 lst[1] = new List(123456); // Larger than any other fixed-size list in a fresh heap.
Cutch 2014/12/04 18:34:54 Over 80 column limit here and elsewhere
koda 2014/12/04 19:27:27 Done.
25 } 31 }
26 32
27 int fooId; 33 int fooId;
28 34
29 var tests = [ 35 var tests = [
30 36
31 (Isolate isolate) { 37 (Isolate isolate) {
32 Completer completer = new Completer(); 38 Completer completer = new Completer();
33 isolate.vm.events.stream.listen((ServiceEvent event) { 39 isolate.vm.events.stream.listen((ServiceEvent event) {
34 if (event.eventType == '_Graph') { 40 if (event.eventType == '_Graph') {
35 ReadStream reader = new ReadStream(event.data); 41 ReadStream reader = new ReadStream(event.data);
36 ObjectGraph graph = new ObjectGraph(reader); 42 ObjectGraph graph = new ObjectGraph(reader);
37 expect(fooId, isNotNull); 43 expect(fooId, isNotNull);
38 Iterable<ObjectVertex> foos = graph.vertices.where((ObjectVertex obj) => o bj.classId == fooId); 44 Iterable<ObjectVertex> foos = graph.vertices.where((ObjectVertex obj) => o bj.classId == fooId);
39 expect(foos.length, equals(3)); 45 expect(foos.length, equals(3));
40 expect(foos.where((ObjectVertex obj) => obj.succ.length == 0).length, equa ls(1)); 46 expect(foos.where((ObjectVertex obj) => obj.succ.length == 0).length, equa ls(1));
41 expect(foos.where((ObjectVertex obj) => obj.succ.length == 1).length, equa ls(1)); 47 expect(foos.where((ObjectVertex obj) => obj.succ.length == 1).length, equa ls(1));
42 expect(foos.where((ObjectVertex obj) => obj.succ.length == 2).length, equa ls(1)); 48 expect(foos.where((ObjectVertex obj) => obj.succ.length == 2).length, equa ls(1));
49
50 ObjectVertex bVertex = foos.where((ObjectVertex obj) => obj.succ.length == 0).first;
51 ObjectVertex aVertex = foos.where((ObjectVertex obj) => obj.succ.length == 1).first;
52 ObjectVertex rVertex = foos.where((ObjectVertex obj) => obj.succ.length == 2).first;
53
54 // TODO(koda): Check actual byte sizes after implementing "architecture" i n VM.
55
56 expect(aVertex.retainedSize, equals(aVertex.shallowSize));
57 expect(bVertex.retainedSize, equals(bVertex.shallowSize));
58 expect(rVertex.retainedSize, equals(aVertex.shallowSize +
59 bVertex.shallowSize +
60 rVertex.shallowSize));
61
62 const int fixedSizeListCid = 62;
63 List<ObjectVertex> lists = new List.from(
64 graph.vertices.where((ObjectVertex obj) => obj.classId == fixedSizeLis tCid));
65 expect(lists.length >= 2, isTrue);
66 // Order by decreasing retained size.
67 lists.sort((u, v) => v.retainedSize - u.retainedSize);
68 ObjectVertex first = lists[0];
69 ObjectVertex second = lists[1];
70 // Check that the short list 'lst' retains more than the long list inside it.
71 expect(first.succ.length, equals(2 + second.succ.length));
72 // ... and specifically, that it retains exactly itself + the long one.
73 expect(first.retainedSize, equals(first.shallowSize + second.shallowSize)) ;
43 completer.complete(); 74 completer.complete();
44 } 75 }
45 }); 76 });
46 return isolate.rootLib.load().then((Library lib) { 77 return isolate.rootLib.load().then((Library lib) {
47 expect(lib.classes.length, equals(1)); 78 expect(lib.classes.length, equals(1));
48 // Extract the numerical class id of 'Foo', used in the event listener above . 79 // Extract the numerical class id of 'Foo', used in the event listener above .
49 Class fooClass = lib.classes.first; 80 Class fooClass = lib.classes.first;
50 String prefix = "classes/"; 81 String prefix = "classes/";
51 // TODO(koda): Add method on Class to get numerical id. 82 // TODO(koda): Add method on Class to get numerical id.
52 fooId = int.parse(fooClass.id.substring(prefix.length)); 83 fooId = int.parse(fooClass.id.substring(prefix.length));
53 isolate.get('graph'); 84 isolate.get('graph');
54 return completer.future; 85 return completer.future;
55 }); 86 });
56 }, 87 },
57 88
58 ]; 89 ];
59 90
60 main(args) => runIsolateTests(args, tests, testeeBefore: script); 91 main(args) => runIsolateTests(args, tests, testeeBefore: script);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698