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

Unified 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 side-by-side diff with in-line comments
Download patch
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..3d413999dd2406c8b3442fb5a5561180974e6260
--- /dev/null
+++ b/tracing/tracing/metrics/blink/leak_detection_metric_test.html
@@ -0,0 +1,173 @@
+<!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(newAllocatorDump(renderer,
+ 'blink_objects/' + BLINK_OBJECT_LIST[i], { numerics:
+ { object_count: values[i] }}));
+ }
+ return blinkObjectCountList;
+ }
+
+ function createBlinkObjectCount(renderer, name, value) {
+ return newAllocatorDump(renderer, 'blink_objects/' + name, { numerics:
+ { object_count: value }});
+ }
+
+ 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);
+ for (let i = 0; i++; i < BLINK_OBJECT_LIST.length) {
+ const obj = BLINK_OBJECT_LIST[i];
+ assert.strictEqual(histograms.getHistogramNamed(obj), 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);
+ for (let i = 0; i++; i < BLINK_OBJECT_LIST.length) {
+ const obj = BLINK_OBJECT_LIST[i];
+ if (obj === BLINK_OBJECT_LIST[1]) {
+ assert.strictEqual(histograms.getHistogramNamed(obj), 1);
+ } else {
+ assert.strictEqual(histograms.getHistogramNamed(obj), 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);
+ for (let i = 0; i++; i < BLINK_OBJECT_LIST.length) {
+ const obj = BLINK_OBJECT_LIST[i];
+ assert.strictEqual(histograms.getHistogramNamed(obj), 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);
+ for (let i = 0; i++; i < BLINK_OBJECT_LIST.length) {
+ const obj = BLINK_OBJECT_LIST[i];
+ assert.strictEqual(histograms.getHistogramNamed(obj), 2);
+ }
+ });
+});
+</script>
« 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