| 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 /* if (!(root is FunctionCallTreeNode)) { | |
| 20 print('${root.profileCode.code.name}'); | |
| 21 } else { | |
| 22 print('${root.profileFunction.function.name}'); | |
| 23 } | |
| 24 */ | |
| 25 int inclusiveAllocations = 0; | |
| 26 int exclusiveAllocations = 0; | |
| 27 | |
| 28 for (int i = 0; i < root.children.length; i++) { | |
| 29 inclusiveAllocations += root.children[i].inclusiveNativeAllocations; | |
| 30 exclusiveAllocations += root.children[i].exclusiveNativeAllocations; | |
| 31 } | |
| 32 | |
| 33 int rootMemory; | |
| 34 if (exclusive) { | |
| 35 rootMemory = root.inclusiveNativeAllocations + exclusiveAllocations; | |
| 36 } else { | |
| 37 rootMemory = | |
| 38 root.inclusiveNativeAllocations - root.exclusiveNativeAllocations; | |
| 39 } | |
| 40 | |
| 41 expect(inclusiveAllocations == rootMemory, isTrue); | |
| 42 for (int i = 0; i < root.children.length; i++) { | |
| 43 verifyHelper(root.children[i], exclusive); | |
| 44 } | |
| 45 } | |
| 46 | |
| 47 void verify(var tree, bool exclusive) { | |
| 48 var node = tree.root; | |
| 49 expect(node, isNotNull); | |
| 50 expect(node.children.length >= 0, isTrue); | |
| 51 | |
| 52 for (int i = 0; i < node.children.length; i++) { | |
| 53 verifyHelper(node.children[i], exclusive); | |
| 54 } | |
| 55 } | |
| 56 | |
| 57 var tests = [ | |
| 58 // Verify inclusive tries. | |
| 59 (VM vm) async { | |
| 60 var response = | |
| 61 await vm.invokeRpc('_getNativeAllocationSamples', {'tags': 'None'}); | |
| 62 CpuProfile cpuProfile = new CpuProfile(); | |
| 63 await cpuProfile.load(vm, response); | |
| 64 var codeTree = cpuProfile.loadCodeTree(M.ProfileTreeDirection.inclusive); | |
| 65 var functionTree = | |
| 66 cpuProfile.loadFunctionTree(M.ProfileTreeDirection.inclusive); | |
| 67 verify(codeTree, false); | |
| 68 verify(functionTree, false); | |
| 69 }, | |
| 70 // Verify exclusive tries. | |
| 71 (VM vm) async { | |
| 72 var response = | |
| 73 await vm.invokeRpc('_getNativeAllocationSamples', {'tags': 'None'}); | |
| 74 CpuProfile cpuProfile = new CpuProfile(); | |
| 75 await cpuProfile.load(vm, response); | |
| 76 var codeTreeExclusive = | |
| 77 cpuProfile.loadCodeTree(M.ProfileTreeDirection.exclusive); | |
| 78 var functionTreeExclusive = | |
| 79 cpuProfile.loadFunctionTree(M.ProfileTreeDirection.exclusive); | |
| 80 verify(codeTreeExclusive, true); | |
| 81 verify(functionTreeExclusive, true); | |
| 82 } | |
| 83 ]; | |
| 84 | |
| 85 main(args) async => runVMTests(args, tests); | |
| OLD | NEW |