Chromium Code Reviews| Index: tracing/tracing/metrics/blink/leak_detection_metric_test.html |
| diff --git a/tracing/tracing/metrics/blink/leak_detection_metric_test.html b/tracing/tracing/metrics/blink/leak_detection_metric_test.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..fc3f8462135dde9182978d5174b1cf175805b0fc |
| --- /dev/null |
| +++ b/tracing/tracing/metrics/blink/leak_detection_metric_test.html |
| @@ -0,0 +1,181 @@ |
| +<!DOCTYPE html> |
| +<!-- |
| +Copyright 2017 The Chromium Authors. All rights reserved. |
| +Use of this source code is governed by a BSD-style license that can be |
| +found in the LICENSE file. |
| +--> |
| + |
| +<link rel="import" href="/tracing/core/test_utils.html"> |
| +<link rel="import" href="/tracing/metrics/blink/leak_detection_metric.html"> |
| +<link rel="import" href="/tracing/model/memory_dump_test_utils.html"> |
| +<link rel="import" href="/tracing/value/histogram_set.html"> |
| + |
| +<script> |
| +'use strict'; |
| + |
| +tr.b.unittest.testSuite(function() { |
| + const BLINK_OBJECT_LIST = ['AudioHandler', 'Document', 'Frame', |
| + 'JSEventListener', 'LayoutObject', 'MediaKeys', 'MediaKeySession', 'Node', |
| + 'Resource', 'ScriptPromise', 'SuspendableObject', 'V8PerContextData', |
| + 'WorkerGlobalScope']; |
| + const addProcessMemoryDump = |
| + tr.model.MemoryDumpTestUtils.addProcessMemoryDump; |
| + const addGlobalMemoryDump = tr.model.MemoryDumpTestUtils.addGlobalMemoryDump; |
| + const newAllocatorDump = tr.model.MemoryDumpTestUtils.newAllocatorDump; |
| + const allZeroArray = new Array(BLINK_OBJECT_LIST.length).fill(0); |
| + const leakingResultArray = new Array(BLINK_OBJECT_LIST.length).fill(1); |
| + |
| + function createProcessWithName(model, name) { |
| + const uniquePid = |
| + Math.max.apply(null, Object.keys(model.processes).concat([0])) + 1; |
| + const process = model.getOrCreateProcess(uniquePid); |
| + process.name = name; |
| + process.getOrCreateThread(1).name = 'Cr' + name + 'Main'; |
| + return process; |
| + } |
| + |
| + function createTimestamp(model, browser, renderer, values, timestamp) { |
| + const gmd1 = addGlobalMemoryDump(model, {ts: timestamp}); |
| + const pmdBrowser1 = addProcessMemoryDump(gmd1, browser, {ts: timestamp}); |
| + const pmdRenderer1 = addProcessMemoryDump(gmd1, renderer, {ts: timestamp}); |
| + pmdRenderer1.memoryAllocatorDumps = [ |
| + newAllocatorDump(pmdRenderer1, 'blink_objects', { children: |
| + createBlinkObjectCountList(pmdRenderer1, values)})]; |
| + } |
| + |
| + function createBlinkObjectCountList(renderer, values) { |
| + const blinkObjectCountList = []; |
| + for (let i = 0; i++; i < values.length) { |
| + blinkObjectCountList.push(createBlinkObjectCount( |
| + renderer, BLINK_OBJECT_LIST[i], values[i])); |
| + } |
| + return blinkObjectCountList; |
| + } |
| + |
| + 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.
|
| + return newAllocatorDump(renderer, 'blink_objects/' + name, { numerics: |
| + { object_count: value }}); |
| + } |
| + |
| + 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.
|
| + const countMap = {}; |
| + for (let i = 0; i++; i < BLINK_OBJECT_LIST.length) { |
| + const obj = BLINK_OBJECT_LIST[i]; |
| + countMap[obj] = histograms.getHistogramNamed(obj); |
| + } |
| + return countMap; |
| + } |
| + |
| + test('testNoBrowser', function() { |
| + const model = tr.c.TestUtils.newModel(function(model) { |
| + createProcessWithName(model, 'Renderer'); |
| + }); |
| + const histograms = new tr.v.HistogramSet(); |
| + assert.throws( |
| + function() {tr.metrics.blink.leakDetectionMetric(histograms, model);}, |
| + Error); |
| + }); |
| + |
| + test('testNoRenderer', function() { |
| + const model = tr.c.TestUtils.newModel(function(model) { |
| + createProcessWithName(model, 'Browser'); |
| + }); |
| + const histograms = new tr.v.HistogramSet(); |
| + assert.throws( |
| + function() {tr.metrics.blink.leakDetectionMetric(histograms, model);}, |
| + Error); |
| + }); |
| + |
| + test('testZeroDump', function() { |
| + const model = tr.c.TestUtils.newModel(function(model) { |
| + createProcessWithName(model, 'Browser'); |
| + createProcessWithName(model, 'Renderer'); |
| + }); |
| + const histograms = new tr.v.HistogramSet(); |
| + assert.throws( |
| + function() {tr.metrics.blink.leakDetectionMetric(histograms, model);}, |
| + Error); |
| + }); |
| + |
| + test('testOnlyOneDump', function() { |
| + const model = tr.c.TestUtils.newModel(function(model) { |
| + const browser = createProcessWithName(model, 'Browser'); |
| + const renderer = createProcessWithName(model, 'Renderer'); |
| + createTimestamp(model, browser, renderer, allZeroArray, 40); |
| + }); |
| + const histograms = new tr.v.HistogramSet(); |
| + assert.throws( |
| + function() {tr.metrics.blink.leakDetectionMetric(histograms, model);}, |
| + Error); |
| + }); |
| + |
| + test('testNoLeak', function() { |
| + const model = tr.c.TestUtils.newModel(function(model) { |
| + const browser = createProcessWithName(model, 'Browser'); |
| + const renderer = createProcessWithName(model, 'Renderer'); |
| + createTimestamp(model, browser, renderer, allZeroArray, 20); |
| + createTimestamp(model, browser, renderer, allZeroArray, 40); |
| + }); |
| + const histograms = new tr.v.HistogramSet(); |
| + tr.metrics.blink.leakDetectionMetric(histograms, model); |
| + const countMap = createMapFromHistograms(histograms); |
| + for (const key in countMap) { |
| + assert.strictEqual(countMap[key], 0); |
| + } |
| + }); |
| + |
| + test('testOneLeakDetection', function() { |
| + const model = tr.c.TestUtils.newModel(function(model) { |
| + const browser = createProcessWithName(model, 'Browser'); |
| + const renderer = createProcessWithName(model, 'Renderer'); |
| + const leakingResultArray = allZeroArray; |
| + leakingResultArray[1] = 1; |
| + createTimestamp(model, browser, renderer, allZeroArray, 20); |
| + createTimestamp(model, browser, renderer, leakingResultArray, 40); |
| + }); |
| + const histograms = new tr.v.HistogramSet(); |
| + tr.metrics.blink.leakDetectionMetric(histograms, model); |
| + const countMap = createMapFromHistograms(histograms); |
| + for (const key in countMap) { |
| + if (key === 'Document') { |
| + assert.strictEqual(countMap[key], 1); |
| + } else { |
| + assert.strictEqual(countMap[key], 0); |
| + } |
| + } |
| + }); |
| + |
| + test('testMultipleLeakDetections', function() { |
| + const model = tr.c.TestUtils.newModel(function(model) { |
| + const browser = createProcessWithName(model, 'Browser'); |
| + const renderer = createProcessWithName(model, 'Renderer'); |
| + createTimestamp(model, browser, renderer, allZeroArray, 20); |
| + createTimestamp(model, browser, renderer, leakingResultArray, 40); |
| + }); |
| + const histograms = new tr.v.HistogramSet(); |
| + tr.metrics.blink.leakDetectionMetric(histograms, model); |
| + const countMap = createMapFromHistograms(histograms); |
| + for (const key in countMap) { |
| + assert.strictEqual(countMap[key], 1); |
| + } |
| + }); |
| + |
| + test('testMultipleRendererWithLeaks', function() { |
| + const model = tr.c.TestUtils.newModel(function(model) { |
| + const browser = createProcessWithName(model, 'Browser'); |
| + const renderer1 = createProcessWithName(model, 'Renderer'); |
| + const renderer2 = createProcessWithName(model, 'Renderer'); |
| + createTimestamp(model, browser, renderer1, allZeroArray, 20); |
| + createTimestamp(model, browser, renderer2, allZeroArray, 20); |
| + createTimestamp(model, browser, renderer1, leakingResultArray, 40); |
| + createTimestamp(model, browser, renderer2, leakingResultArray, 40); |
| + }); |
| + const histograms = new tr.v.HistogramSet(); |
| + tr.metrics.blink.leakDetectionMetric(histograms, model); |
| + const countMap = createMapFromHistograms(histograms); |
| + for (const key in countMap) { |
| + assert.strictEqual(countMap[key], 2); |
| + } |
| + }); |
| +}); |
| +</script> |