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

Unified Diff: runtime/observatory/tests/service/get_native_allocation_samples_test.dart

Issue 2748403002: Added page to Observatory to display native memory allocation information. (Closed)
Patch Set: Added tests to verify sample tries inclusive/exclusive allocations. Element now displays memory con… Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: runtime/observatory/tests/service/get_native_allocation_samples_test.dart
diff --git a/runtime/observatory/tests/service/get_native_allocation_samples_test.dart b/runtime/observatory/tests/service/get_native_allocation_samples_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..06d0d760662d9ba5fe6a196fed6a5de4d1a271e7
--- /dev/null
+++ b/runtime/observatory/tests/service/get_native_allocation_samples_test.dart
@@ -0,0 +1,79 @@
+// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+// VMOptions=--error_on_bad_type --error_on_bad_override
+
+import 'dart:developer';
+import 'package:observatory/models.dart' as M;
+import 'package:observatory/service_io.dart';
+import 'package:observatory/cpu_profile.dart';
+import 'package:unittest/unittest.dart';
+import 'service_test_common.dart';
+import 'test_helper.dart';
+
+void verifyHelper(var root, bool exclusive) {
+ if (root.children.length == 0) {
+ return;
+ }
+
+ int inclusiveAllocations = 0;
+ int exclusiveAllocations = 0;
+
+ for (int i = 0; i < root.children.length; i++) {
+ inclusiveAllocations +=
+ root.children[i].inclusiveNativeAllocations;
+ exclusiveAllocations +=
+ root.children[i].exclusiveNativeAllocations;
+ }
+
+ int rootMemory;
+ if (exclusive) {
+ rootMemory = root.inclusiveNativeAllocations + exclusiveAllocations;
+ } else {
+ rootMemory = root.inclusiveNativeAllocations - root.exclusiveNativeAllocations;
+ }
+
+ expect(inclusiveAllocations == rootMemory, isTrue);
+ for (int i = 0; i < root.children.length; i++) {
+ verifyHelper(root.children[i], exclusive);
+ }
+}
+
+void verify(var tree, bool exclusive) {
+ var node = tree.root;
+ expect(node, isNotNull);
+ expect(node.children.length >= 0, isTrue);
+ for (int i = 0; i < node.children.length; i++) {
+ verifyHelper(node.children[i], exclusive);
+ }
+}
+
+var tests = [
+ // Verify inclusive tries.
+ (VM vm) async {
+ var response = await vm.invokeRpc('_getNativeAllocationSamples', {'tags':
+ 'None'});
+ CpuProfile cpuProfile = new CpuProfile();
+ await cpuProfile.load(vm, response);
+ var codeTree = cpuProfile.loadCodeTree(M.ProfileTreeDirection.inclusive);
+ var functionTree =
+ cpuProfile.loadFunctionTree(M.ProfileTreeDirection.inclusive);
+ verify(codeTree, false);
+ verify(functionTree, false);
+ },
+ // Verify exclusive tries.
+ (VM vm) async {
+ var response = await vm.invokeRpc('_getNativeAllocationSamples', {'tags':
+ 'None'});
+ CpuProfile cpuProfile = new CpuProfile();
+ await cpuProfile.load(vm, response);
+ var codeTreeExclusive =
+ cpuProfile.loadCodeTree(M.ProfileTreeDirection.exclusive);
+ var functionTreeExclusive=
+ cpuProfile.loadFunctionTree(M.ProfileTreeDirection.exclusive);
+ verify(codeTreeExclusive, true);
+ verify(functionTreeExclusive, true);
+ }
+];
+
+main(args) async => runVMTests(args, tests);

Powered by Google App Engine
This is Rietveld 408576698