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

Side by Side Diff: tracing/tracing/metrics/blink/leak_detection_metric_test.html

Issue 3012153002: Add leakDetectionMetric for tracing (Closed)
Patch Set: Bug fix Created 3 years, 3 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 unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <!--
3 Copyright 2017 The Chromium Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style license that can be
5 found in the LICENSE file.
6 -->
7
8 <link rel="import" href="/tracing/core/test_utils.html">
9 <link rel="import" href="/tracing/metrics/blink/leak_detection_metric.html">
10 <link rel="import" href="/tracing/model/memory_dump_test_utils.html">
11 <link rel="import" href="/tracing/value/histogram_set.html">
12
13 <script>
14 'use strict';
15
16 tr.b.unittest.testSuite(function() {
17 const BLINK_OBJECT_LIST = ['AudioHandler', 'Document', 'Frame',
18 'JSEventListener', 'LayoutObject', 'MediaKeys', 'MediaKeySession', 'Node',
19 'Resource', 'ScriptPromise', 'SuspendableObject', 'V8PerContextData',
20 'WorkerGlobalScope'];
21 const addProcessMemoryDump =
22 tr.model.MemoryDumpTestUtils.addProcessMemoryDump;
23 const addGlobalMemoryDump = tr.model.MemoryDumpTestUtils.addGlobalMemoryDump;
24 const newAllocatorDump = tr.model.MemoryDumpTestUtils.newAllocatorDump;
25 const allZeroArray = new Array(BLINK_OBJECT_LIST.length).fill(0);
26 const leakingResultArray = new Array(BLINK_OBJECT_LIST.length).fill(1);
27
28 function createProcessWithName(model, name) {
29 const uniquePid =
30 Math.max.apply(null, Object.keys(model.processes).concat([0])) + 1;
31 const process = model.getOrCreateProcess(uniquePid);
32 process.name = name;
33 process.getOrCreateThread(1).name = 'Cr' + name + 'Main';
34 return process;
35 }
36
37 function createTimestamp(model, browser, renderer, values, timestamp) {
38 const gmd1 = addGlobalMemoryDump(model, {ts: timestamp});
39 const pmdBrowser1 = addProcessMemoryDump(gmd1, browser, {ts: timestamp});
40 const pmdRenderer1 = addProcessMemoryDump(gmd1, renderer, {ts: timestamp});
41 pmdRenderer1.memoryAllocatorDumps = [
42 newAllocatorDump(pmdRenderer1, 'blink_objects', { children:
43 createBlinkObjectCountList(pmdRenderer1, values)})];
44 }
45
46 function createBlinkObjectCountList(renderer, values) {
47 const blinkObjectCountList = [];
48 for (let i = 0; i++; i < values.length) {
49 blinkObjectCountList.push(createBlinkObjectCount(
50 renderer, BLINK_OBJECT_LIST[i], values[i]));
51 }
52 return blinkObjectCountList;
53 }
54
55 function createBlinkObjectCount(renderer, name, value) {
benjhayden 2017/09/14 19:18:51 This looks short enough that you can inline it to
yuzuchan 2017/09/15 08:32:25 Done.
56 return newAllocatorDump(renderer, 'blink_objects/' + name, { numerics:
57 { object_count: value }});
58 }
59
60 function createMapFromHistograms(histograms) {
benjhayden 2017/09/14 19:18:51 Please let the tests test the histograms directly
yuzuchan 2017/09/15 08:32:25 Done.
61 const countMap = {};
62 for (let i = 0; i++; i < BLINK_OBJECT_LIST.length) {
63 const obj = BLINK_OBJECT_LIST[i];
64 countMap[obj] = histograms.getHistogramNamed(obj);
65 }
66 return countMap;
67 }
68
69 test('testNoBrowser', function() {
70 const model = tr.c.TestUtils.newModel(function(model) {
71 createProcessWithName(model, 'Renderer');
72 });
73 const histograms = new tr.v.HistogramSet();
74 assert.throws(
75 function() {tr.metrics.blink.leakDetectionMetric(histograms, model);},
76 Error);
77 });
78
79 test('testNoRenderer', function() {
80 const model = tr.c.TestUtils.newModel(function(model) {
81 createProcessWithName(model, 'Browser');
82 });
83 const histograms = new tr.v.HistogramSet();
84 assert.throws(
85 function() {tr.metrics.blink.leakDetectionMetric(histograms, model);},
86 Error);
87 });
88
89 test('testZeroDump', function() {
90 const model = tr.c.TestUtils.newModel(function(model) {
91 createProcessWithName(model, 'Browser');
92 createProcessWithName(model, 'Renderer');
93 });
94 const histograms = new tr.v.HistogramSet();
95 assert.throws(
96 function() {tr.metrics.blink.leakDetectionMetric(histograms, model);},
97 Error);
98 });
99
100 test('testOnlyOneDump', function() {
101 const model = tr.c.TestUtils.newModel(function(model) {
102 const browser = createProcessWithName(model, 'Browser');
103 const renderer = createProcessWithName(model, 'Renderer');
104 createTimestamp(model, browser, renderer, allZeroArray, 40);
105 });
106 const histograms = new tr.v.HistogramSet();
107 assert.throws(
108 function() {tr.metrics.blink.leakDetectionMetric(histograms, model);},
109 Error);
110 });
111
112 test('testNoLeak', function() {
113 const model = tr.c.TestUtils.newModel(function(model) {
114 const browser = createProcessWithName(model, 'Browser');
115 const renderer = createProcessWithName(model, 'Renderer');
116 createTimestamp(model, browser, renderer, allZeroArray, 20);
117 createTimestamp(model, browser, renderer, allZeroArray, 40);
118 });
119 const histograms = new tr.v.HistogramSet();
120 tr.metrics.blink.leakDetectionMetric(histograms, model);
121 const countMap = createMapFromHistograms(histograms);
122 for (const key in countMap) {
123 assert.strictEqual(countMap[key], 0);
124 }
125 });
126
127 test('testOneLeakDetection', function() {
128 const model = tr.c.TestUtils.newModel(function(model) {
129 const browser = createProcessWithName(model, 'Browser');
130 const renderer = createProcessWithName(model, 'Renderer');
131 const leakingResultArray = allZeroArray;
132 leakingResultArray[1] = 1;
133 createTimestamp(model, browser, renderer, allZeroArray, 20);
134 createTimestamp(model, browser, renderer, leakingResultArray, 40);
135 });
136 const histograms = new tr.v.HistogramSet();
137 tr.metrics.blink.leakDetectionMetric(histograms, model);
138 const countMap = createMapFromHistograms(histograms);
139 for (const key in countMap) {
140 if (key === 'Document') {
141 assert.strictEqual(countMap[key], 1);
142 } else {
143 assert.strictEqual(countMap[key], 0);
144 }
145 }
146 });
147
148 test('testMultipleLeakDetections', function() {
149 const model = tr.c.TestUtils.newModel(function(model) {
150 const browser = createProcessWithName(model, 'Browser');
151 const renderer = createProcessWithName(model, 'Renderer');
152 createTimestamp(model, browser, renderer, allZeroArray, 20);
153 createTimestamp(model, browser, renderer, leakingResultArray, 40);
154 });
155 const histograms = new tr.v.HistogramSet();
156 tr.metrics.blink.leakDetectionMetric(histograms, model);
157 const countMap = createMapFromHistograms(histograms);
158 for (const key in countMap) {
159 assert.strictEqual(countMap[key], 1);
160 }
161 });
162
163 test('testMultipleRendererWithLeaks', function() {
164 const model = tr.c.TestUtils.newModel(function(model) {
165 const browser = createProcessWithName(model, 'Browser');
166 const renderer1 = createProcessWithName(model, 'Renderer');
167 const renderer2 = createProcessWithName(model, 'Renderer');
168 createTimestamp(model, browser, renderer1, allZeroArray, 20);
169 createTimestamp(model, browser, renderer2, allZeroArray, 20);
170 createTimestamp(model, browser, renderer1, leakingResultArray, 40);
171 createTimestamp(model, browser, renderer2, leakingResultArray, 40);
172 });
173 const histograms = new tr.v.HistogramSet();
174 tr.metrics.blink.leakDetectionMetric(histograms, model);
175 const countMap = createMapFromHistograms(histograms);
176 for (const key in countMap) {
177 assert.strictEqual(countMap[key], 2);
178 }
179 });
180 });
181 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698