blob: a0ece9461f95612dd69485876f487817d6d6214c [file] [log] [blame]
Chris Craik93216d02015-03-05 13:58:42 -08001<!DOCTYPE html>
2<!--
3Copyright (c) 2013 The Chromium Authors. All rights reserved.
4Use of this source code is governed by a BSD-style license that can be
5found in the LICENSE file.
6-->
7
8<link rel="import" href="/extras/tcmalloc/heap.html">
9
10<script>
11'use strict';
12
13tv.b.unittest.testSuite(function() {
14 var HeapSnapshot = tv.e.tcmalloc.HeapSnapshot;
15
16 // Tests total allocation count.
17 test('totals', function() {
18 var snapshot = new HeapSnapshot({}, 1, [
19 {
20 'current_allocs': 10,
21 'total_allocs': 100,
22 'current_bytes': 10000,
23 'trace': '',
24 'total_bytes': 100000
25 },
26 {
27 'current_allocs': 2,
28 'total_allocs': 22,
29 'current_bytes': 200,
30 'trace': 'TestObject::TestMethod ',
31 'total_bytes': 2200
32 }
33 ]);
34 snapshot.preInitialize();
35 snapshot.initialize();
36
37 // Base class got the timestamp.
38 assertEquals(1, snapshot.ts);
39
40 // The first entry in the list is for totals.
41 assertEquals(10, snapshot.total_.currentAllocs);
42 assertEquals(10000, snapshot.total_.currentBytes);
43 });
44
45 // Tests multi-level trace stacks.
46 test('multiLevel', function() {
47 var snapshot = new HeapSnapshot({}, 1, [
48 {
49 'current_allocs': 10,
50 'total_allocs': 100,
51 'current_bytes': 10000,
52 'trace': '',
53 'total_bytes': 100000
54 },
55 {
56 'current_allocs': 2,
57 'total_allocs': 22,
58 'current_bytes': 200,
59 'trace': 'TestObject::TestMethod ',
60 'total_bytes': 2200
61 },
62 {
63 'current_allocs': 3,
64 'total_allocs': 33,
65 'current_bytes': 300,
66 'trace': 'TestObject2::TestMethod2 ',
67 'total_bytes': 3300
68 },
69 {
70 'current_allocs': 5,
71 'total_allocs': 55,
72 'current_bytes': 500,
73 'trace': 'TestObject2::TestMethod2 TestObject3::TestMethod3 ',
74 'total_bytes': 5500
75 }
76 ]);
77 snapshot.preInitialize();
78 snapshot.initialize();
79
80 // Our heap has two top-level stacks.
81 var heap = snapshot.heap_;
82 var childKeys = Object.keys(heap.children);
83 assertEquals(2, childKeys.length);
84 // Both methods exist as children.
85 assertNotEquals(-1, childKeys.indexOf('TestObject::TestMethod'));
86 assertNotEquals(-1, childKeys.indexOf('TestObject2::TestMethod2'));
87
88 // Verify the first trace entry stack.
89 var trace = heap.children['TestObject::TestMethod'];
90 assertEquals(2, trace.currentAllocs);
91 assertEquals(200, trace.currentBytes);
92 // One child for "(here)".
93 assertEquals(1, Object.keys(trace.children).length);
94 assertNotNull(trace.children['(here)']);
95
96 // Verify the second trace entry stack.
97 trace = heap.children['TestObject2::TestMethod2'];
98 // Memory should have summed up.
99 assertEquals(8, trace.currentAllocs);
100 assertEquals(800, trace.currentBytes);
101 // Two children, "(here)" and another stack.
102 assertEquals(2, Object.keys(trace.children).length);
103 assertNotNull(trace.children['TestObject3::TestMethod3']);
104 assertNotNull(trace.children['(here)']);
105
106 trace = trace.children['TestObject3::TestMethod3'];
107 assertEquals(5, trace.currentAllocs);
108 assertEquals(500, trace.currentBytes);
109 assertEquals(1, Object.keys(trace.children).length);
110 });
111});
112</script>