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

Side by Side Diff: runtime/observatory/tests/service/graph_test.dart

Issue 1124153006: Heap snapshot visualizations (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: sync Created 5 years, 7 months 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
« no previous file with comments | « runtime/observatory/tests/service/dominator_tree_test.dart ('k') | runtime/vm/object_graph.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // VMOptions=--compile-all --error_on_bad_type --error_on_bad_override 4 // VMOptions=--compile-all --error_on_bad_type --error_on_bad_override
5 5
6 import 'dart:async'; 6 import 'dart:async';
7 import 'package:observatory/object_graph.dart'; 7 import 'package:observatory/object_graph.dart';
8 import 'package:observatory/service_io.dart'; 8 import 'package:observatory/service_io.dart';
9 import 'package:unittest/unittest.dart'; 9 import 'package:unittest/unittest.dart';
10 import 'test_helper.dart'; 10 import 'test_helper.dart';
(...skipping 19 matching lines...) Expand all
30 lst = new List(2); 30 lst = new List(2);
31 lst[0] = lst; // Self-loop. 31 lst[0] = lst; // Self-loop.
32 // Larger than any other fixed-size list in a fresh heap. 32 // Larger than any other fixed-size list in a fresh heap.
33 lst[1] = new List(123456); 33 lst[1] = new List(123456);
34 } 34 }
35 35
36 int fooId; 36 int fooId;
37 37
38 var tests = [ 38 var tests = [
39 39
40 (Isolate isolate) { 40 (Isolate isolate) async {
41 Completer completer = new Completer(); 41 Library lib = await isolate.rootLibrary.load();
42 isolate.vm.getEventStream('_Graph').listen((ServiceEvent event) { 42 expect(lib.classes.length, equals(1));
43 if (event.eventType == ServiceEvent.kGraph) { 43 Class fooClass = lib.classes.first;
44 ReadStream reader = new ReadStream(event.data); 44 fooId = fooClass.vmCid;
45 ObjectGraph graph = new ObjectGraph(reader);
46 expect(fooId, isNotNull);
47 Iterable<ObjectVertex> foos = graph.vertices.where(
48 (ObjectVertex obj) => obj.classId == fooId);
49 expect(foos.length, equals(3));
50 expect(foos.where(
51 (ObjectVertex obj) => obj.succ.length == 0).length, equals(1));
52 expect(foos.where(
53 (ObjectVertex obj) => obj.succ.length == 1).length, equals(1));
54 expect(foos.where(
55 (ObjectVertex obj) => obj.succ.length == 2).length, equals(1));
56 45
57 ObjectVertex bVertex = foos.where( 46 HeapSnapshot snapshot = await isolate.fetchHeapSnapshot().last;
58 (ObjectVertex obj) => obj.succ.length == 0).first; 47 ObjectGraph graph = snapshot.graph;
59 ObjectVertex aVertex = foos.where(
60 (ObjectVertex obj) => obj.succ.length == 1).first;
61 ObjectVertex rVertex = foos.where(
62 (ObjectVertex obj) => obj.succ.length == 2).first;
63 48
64 // TODO(koda): Check actual byte sizes. 49 expect(fooId, isNotNull);
50 Iterable<ObjectVertex> foos = graph.vertices.where(
51 (ObjectVertex obj) => obj.vmCid == fooId);
52 expect(foos.length, equals(3));
53 expect(foos.where((obj) => obj.successors.length == 0).length,
54 equals(1));
55 expect(foos.where((obj) => obj.successors.length == 1).length,
56 equals(1));
57 expect(foos.where((obj) => obj.successors.length == 2).length,
58 equals(1));
65 59
66 expect(aVertex.retainedSize, equals(aVertex.shallowSize)); 60 ObjectVertex bVertex = foos.where(
67 expect(bVertex.retainedSize, equals(bVertex.shallowSize)); 61 (ObjectVertex obj) => obj.successors.length == 0).first;
68 expect(rVertex.retainedSize, equals(aVertex.shallowSize + 62 ObjectVertex aVertex = foos.where(
69 bVertex.shallowSize + 63 (ObjectVertex obj) => obj.successors.length == 1).first;
70 rVertex.shallowSize)); 64 ObjectVertex rVertex = foos.where(
65 (ObjectVertex obj) => obj.successors.length == 2).first;
71 66
72 const int fixedSizeListCid = 61; 67 // TODO(koda): Check actual byte sizes.
73 List<ObjectVertex> lists = new List.from(graph.vertices.where( 68
74 (ObjectVertex obj) => obj.classId == fixedSizeListCid)); 69 expect(aVertex.retainedSize, equals(aVertex.shallowSize));
75 expect(lists.length >= 2, isTrue); 70 expect(bVertex.retainedSize, equals(bVertex.shallowSize));
76 // Order by decreasing retained size. 71 expect(rVertex.retainedSize, equals(aVertex.shallowSize +
77 lists.sort((u, v) => v.retainedSize - u.retainedSize); 72 bVertex.shallowSize +
78 ObjectVertex first = lists[0]; 73 rVertex.shallowSize));
79 ObjectVertex second = lists[1]; 74
80 // Check that the short list retains more than the long list inside. 75 const int fixedSizeListCid = 61;
81 expect(first.succ.length, equals(2 + second.succ.length)); 76 List<ObjectVertex> lists = new List.from(graph.vertices.where(
82 // ... and specifically, that it retains exactly itself + the long one. 77 (ObjectVertex obj) => obj.vmCid == fixedSizeListCid));
83 expect(first.retainedSize, 78 expect(lists.length >= 2, isTrue);
84 equals(first.shallowSize + second.shallowSize)); 79 // Order by decreasing retained size.
85 completer.complete(); 80 lists.sort((u, v) => v.retainedSize - u.retainedSize);
86 } 81 ObjectVertex first = lists[0];
87 }); 82 ObjectVertex second = lists[1];
88 return isolate.rootLibrary.load().then((Library lib) { 83 // Check that the short list retains more than the long list inside.
89 expect(lib.classes.length, equals(1)); 84 expect(first.successors.length,
90 Class fooClass = lib.classes.first; 85 equals(2 + second.successors.length));
91 fooId = fooClass.vmCid; 86 // ... and specifically, that it retains exactly itself + the long one.
92 isolate.invokeRpcNoUpgrade('requestHeapSnapshot', {}); 87 expect(first.retainedSize,
93 return completer.future; 88 equals(first.shallowSize + second.shallowSize));
94 });
95 }, 89 },
96 90
97 ]; 91 ];
98 92
99 main(args) => runIsolateTests(args, tests, testeeBefore: script); 93 main(args) => runIsolateTests(args, tests, testeeBefore: script);
OLDNEW
« no previous file with comments | « runtime/observatory/tests/service/dominator_tree_test.dart ('k') | runtime/vm/object_graph.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698