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

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

Issue 3012153002: Add leakDetectionMetric for tracing (Closed)
Patch Set: Reflect comments 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(newAllocatorDump(renderer,
50 'blink_objects/' + BLINK_OBJECT_LIST[i], { numerics:
51 { object_count: values[i] }}));
52 }
53 return blinkObjectCountList;
54 }
55
56 function createBlinkObjectCount(renderer, name, value) {
57 return newAllocatorDump(renderer, 'blink_objects/' + name, { numerics:
58 { object_count: value }});
59 }
60
61 test('testNoBrowser', function() {
62 const model = tr.c.TestUtils.newModel(function(model) {
63 createProcessWithName(model, 'Renderer');
64 });
65 const histograms = new tr.v.HistogramSet();
66 assert.throws(
67 function() {tr.metrics.blink.leakDetectionMetric(histograms, model);},
68 Error);
69 });
70
71 test('testNoRenderer', function() {
72 const model = tr.c.TestUtils.newModel(function(model) {
73 createProcessWithName(model, 'Browser');
74 });
75 const histograms = new tr.v.HistogramSet();
76 assert.throws(
77 function() {tr.metrics.blink.leakDetectionMetric(histograms, model);},
78 Error);
79 });
80
81 test('testZeroDump', function() {
82 const model = tr.c.TestUtils.newModel(function(model) {
83 createProcessWithName(model, 'Browser');
84 createProcessWithName(model, 'Renderer');
85 });
86 const histograms = new tr.v.HistogramSet();
87 assert.throws(
88 function() {tr.metrics.blink.leakDetectionMetric(histograms, model);},
89 Error);
90 });
91
92 test('testOnlyOneDump', function() {
93 const model = tr.c.TestUtils.newModel(function(model) {
94 const browser = createProcessWithName(model, 'Browser');
95 const renderer = createProcessWithName(model, 'Renderer');
96 createTimestamp(model, browser, renderer, allZeroArray, 40);
97 });
98 const histograms = new tr.v.HistogramSet();
99 assert.throws(
100 function() {tr.metrics.blink.leakDetectionMetric(histograms, model);},
101 Error);
102 });
103
104 test('testNoLeak', function() {
105 const model = tr.c.TestUtils.newModel(function(model) {
106 const browser = createProcessWithName(model, 'Browser');
107 const renderer = createProcessWithName(model, 'Renderer');
108 createTimestamp(model, browser, renderer, allZeroArray, 20);
109 createTimestamp(model, browser, renderer, allZeroArray, 40);
110 });
111 const histograms = new tr.v.HistogramSet();
112 tr.metrics.blink.leakDetectionMetric(histograms, model);
113 for (let i = 0; i++; i < BLINK_OBJECT_LIST.length) {
114 const obj = BLINK_OBJECT_LIST[i];
115 assert.strictEqual(histograms.getHistogramNamed(obj), 0);
116 }
117 });
118
119 test('testOneLeakDetection', function() {
120 const model = tr.c.TestUtils.newModel(function(model) {
121 const browser = createProcessWithName(model, 'Browser');
122 const renderer = createProcessWithName(model, 'Renderer');
123 const leakingResultArray = allZeroArray;
124 leakingResultArray[1] = 1;
125 createTimestamp(model, browser, renderer, allZeroArray, 20);
126 createTimestamp(model, browser, renderer, leakingResultArray, 40);
127 });
128 const histograms = new tr.v.HistogramSet();
129 tr.metrics.blink.leakDetectionMetric(histograms, model);
130 for (let i = 0; i++; i < BLINK_OBJECT_LIST.length) {
131 const obj = BLINK_OBJECT_LIST[i];
132 if (obj === BLINK_OBJECT_LIST[1]) {
133 assert.strictEqual(histograms.getHistogramNamed(obj), 1);
134 } else {
135 assert.strictEqual(histograms.getHistogramNamed(obj), 0);
136 }
137 }
138 });
139
140 test('testMultipleLeakDetections', function() {
141 const model = tr.c.TestUtils.newModel(function(model) {
142 const browser = createProcessWithName(model, 'Browser');
143 const renderer = createProcessWithName(model, 'Renderer');
144 createTimestamp(model, browser, renderer, allZeroArray, 20);
145 createTimestamp(model, browser, renderer, leakingResultArray, 40);
146 });
147 const histograms = new tr.v.HistogramSet();
148 tr.metrics.blink.leakDetectionMetric(histograms, model);
149 for (let i = 0; i++; i < BLINK_OBJECT_LIST.length) {
150 const obj = BLINK_OBJECT_LIST[i];
151 assert.strictEqual(histograms.getHistogramNamed(obj), 1);
152 }
153 });
154
155 test('testMultipleRendererWithLeaks', function() {
156 const model = tr.c.TestUtils.newModel(function(model) {
157 const browser = createProcessWithName(model, 'Browser');
158 const renderer1 = createProcessWithName(model, 'Renderer');
159 const renderer2 = createProcessWithName(model, 'Renderer');
160 createTimestamp(model, browser, renderer1, allZeroArray, 20);
161 createTimestamp(model, browser, renderer2, allZeroArray, 20);
162 createTimestamp(model, browser, renderer1, leakingResultArray, 40);
163 createTimestamp(model, browser, renderer2, leakingResultArray, 40);
164 });
165 const histograms = new tr.v.HistogramSet();
166 tr.metrics.blink.leakDetectionMetric(histograms, model);
167 for (let i = 0; i++; i < BLINK_OBJECT_LIST.length) {
168 const obj = BLINK_OBJECT_LIST[i];
169 assert.strictEqual(histograms.getHistogramNamed(obj), 2);
170 }
171 });
172 });
173 </script>
OLDNEW
« no previous file with comments | « tracing/tracing/metrics/blink/leak_detection_metric.html ('k') | tracing/tracing/metrics/system_health/memory_metric.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698