Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2015, 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/service_io.dart'; | |
| 7 import 'package:unittest/unittest.dart'; | |
| 8 import 'test_helper.dart'; | |
| 9 | |
| 10 class Pair { | |
| 11 var x, y; | |
| 12 } | |
| 13 | |
| 14 var p1; | |
| 15 var p2; | |
| 16 | |
| 17 buildGraph() { | |
| 18 p1 = new Pair(); | |
| 19 p2 = new Pair(); | |
| 20 | |
| 21 // Adds to both reachable and retained size. | |
| 22 p1.x = new List(); | |
| 23 p2.x = new List(); | |
| 24 | |
| 25 // Adds to reachable size only. | |
| 26 p1.y = p2.y = new List(); | |
| 27 } | |
| 28 | |
| 29 getReachableSize(ServiceObject obj) { | |
| 30 return obj.isolate.getReachableSize(obj).then((Instance obj) { | |
| 31 return int.parse(obj.valueAsString); | |
| 32 }); | |
| 33 } | |
| 34 | |
| 35 getRetainedSize(ServiceObject obj) { | |
| 36 return obj.isolate.getRetainedSize(obj).then((Instance obj) { | |
| 37 return int.parse(obj.valueAsString); | |
| 38 }); | |
| 39 } | |
| 40 | |
| 41 var tests = [ | |
| 42 (Isolate isolate) async { | |
| 43 var rootLib = await isolate.rootLibrary.load(); | |
| 44 | |
| 45 fieldValue(String fieldName) async { | |
|
Cutch
2015/11/18 15:00:20
Maybe rename:
getIsolateGlobalVariableValue(Isola
rmacnak
2015/11/18 18:07:29
Done.
| |
| 46 var field = rootLib.variables.singleWhere((v) => v.name == fieldName); | |
| 47 await field.load(); | |
| 48 return field.staticValue; | |
| 49 } | |
| 50 | |
| 51 Instance p1 = await fieldValue("p1"); | |
| 52 await p1.load(); | |
| 53 Instance p2 = await fieldValue("p2"); | |
| 54 await p2.load(); | |
| 55 | |
| 56 // In general, shallow <= retained <= reachable. In this program, | |
| 57 // 0 < shallow < retained < reachable. | |
| 58 | |
| 59 int p1_shallow = p1.size; | |
| 60 int p1_retained = await getRetainedSize(p1); | |
| 61 int p1_reachable = await getReachableSize(p1); | |
| 62 | |
| 63 expect(0, lessThan(p1_shallow)); | |
| 64 expect(p1_shallow, lessThan(p1_retained)); | |
| 65 expect(p1_retained, lessThan(p1_reachable)); | |
| 66 | |
| 67 int p2_shallow = p2.size; | |
| 68 int p2_retained = await getRetainedSize(p2); | |
| 69 int p2_reachable = await getReachableSize(p2); | |
| 70 | |
| 71 expect(0, lessThan(p2_shallow)); | |
| 72 expect(p2_shallow, lessThan(p2_retained)); | |
| 73 expect(p2_retained, lessThan(p2_reachable)); | |
| 74 | |
| 75 expect(p1_shallow, equals(p2_shallow)); | |
| 76 expect(p1_retained, equals(p2_retained)); | |
| 77 expect(p1_reachable, equals(p2_reachable)); | |
| 78 }, | |
| 79 ]; | |
| 80 | |
| 81 main(args) => runIsolateTests(args, tests, testeeBefore: buildGraph); | |
| OLD | NEW |