OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2017, 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 'dart:developer'; |
| 7 import 'package:observatory/models.dart' as M; |
| 8 import 'package:observatory/service_io.dart'; |
| 9 import 'package:observatory/cpu_profile.dart'; |
| 10 import 'package:unittest/unittest.dart'; |
| 11 import 'service_test_common.dart'; |
| 12 import 'test_helper.dart'; |
| 13 |
| 14 void verifyHelper(var root, bool exclusive) { |
| 15 if (root.children.length == 0) { |
| 16 return; |
| 17 } |
| 18 |
| 19 int inclusiveAllocations = 0; |
| 20 int exclusiveAllocations = 0; |
| 21 |
| 22 for (int i = 0; i < root.children.length; i++) { |
| 23 inclusiveAllocations += |
| 24 root.children[i].inclusiveNativeAllocations; |
| 25 exclusiveAllocations += |
| 26 root.children[i].exclusiveNativeAllocations; |
| 27 } |
| 28 |
| 29 int rootMemory; |
| 30 if (exclusive) { |
| 31 rootMemory = root.inclusiveNativeAllocations + exclusiveAllocations; |
| 32 } else { |
| 33 rootMemory = root.inclusiveNativeAllocations - root.exclusiveNativeAllocatio
ns; |
| 34 } |
| 35 |
| 36 expect(inclusiveAllocations == rootMemory, isTrue); |
| 37 for (int i = 0; i < root.children.length; i++) { |
| 38 verifyHelper(root.children[i], exclusive); |
| 39 } |
| 40 } |
| 41 |
| 42 void verify(var tree, bool exclusive) { |
| 43 var node = tree.root; |
| 44 expect(node, isNotNull); |
| 45 expect(node.children.length >= 0, isTrue); |
| 46 for (int i = 0; i < node.children.length; i++) { |
| 47 verifyHelper(node.children[i], exclusive); |
| 48 } |
| 49 } |
| 50 |
| 51 var tests = [ |
| 52 // Verify inclusive tries. |
| 53 (VM vm) async { |
| 54 var response = await vm.invokeRpc('_getNativeAllocationSamples', {'tags': |
| 55 'None'}); |
| 56 CpuProfile cpuProfile = new CpuProfile(); |
| 57 await cpuProfile.load(vm, response); |
| 58 var codeTree = cpuProfile.loadCodeTree(M.ProfileTreeDirection.inclusive); |
| 59 var functionTree = |
| 60 cpuProfile.loadFunctionTree(M.ProfileTreeDirection.inclusive); |
| 61 verify(codeTree, false); |
| 62 verify(functionTree, false); |
| 63 }, |
| 64 // Verify exclusive tries. |
| 65 (VM vm) async { |
| 66 var response = await vm.invokeRpc('_getNativeAllocationSamples', {'tags': |
| 67 'None'}); |
| 68 CpuProfile cpuProfile = new CpuProfile(); |
| 69 await cpuProfile.load(vm, response); |
| 70 var codeTreeExclusive = |
| 71 cpuProfile.loadCodeTree(M.ProfileTreeDirection.exclusive); |
| 72 var functionTreeExclusive= |
| 73 cpuProfile.loadFunctionTree(M.ProfileTreeDirection.exclusive); |
| 74 verify(codeTreeExclusive, true); |
| 75 verify(functionTreeExclusive, true); |
| 76 } |
| 77 ]; |
| 78 |
| 79 main(args) async => runVMTests(args, tests); |
OLD | NEW |