| Index: tracing/tracing/metrics/v8/utils_test.html
|
| diff --git a/tracing/tracing/metrics/v8/utils_test.html b/tracing/tracing/metrics/v8/utils_test.html
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..3cbcf5b22bb5a6b5327780357272baa14baaa05e
|
| --- /dev/null
|
| +++ b/tracing/tracing/metrics/v8/utils_test.html
|
| @@ -0,0 +1,158 @@
|
| +<!DOCTYPE html>
|
| +<!--
|
| +Copyright 2016 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/v8/utils.html">
|
| +
|
| +<script>
|
| +'use strict';
|
| +
|
| +tr.b.unittest.testSuite(function() {
|
| +
|
| + function interval(start, end) {
|
| + return {start: start, end: end};
|
| + }
|
| +
|
| + /**
|
| + * Brute force computation of the mutator utilization.
|
| + * The function steps from the start to the end and for each step
|
| + * computes the mutator utilization.
|
| + */
|
| + function mutatorUtilizationSlow(start, end, timeWindow, intervals) {
|
| + var STEP = 0.001;
|
| + function timeToIndex(time) {
|
| + return Math.floor((time - start) / STEP);
|
| + };
|
| + var N = timeToIndex(end) + 1;
|
| + // bitmap[i] === true means that GC is active at time i.
|
| + var bitmap = new Array(N + 1);
|
| + for (var i = 0; i <= N; i++) {
|
| + bitmap[i] = false;
|
| + }
|
| + intervals.forEach(function(interval) {
|
| + var start = timeToIndex(interval.start);
|
| + var end = timeToIndex(interval.end);
|
| + for (var i = start; i < end; i++) {
|
| + bitmap[i] = true;
|
| + }
|
| + });
|
| + var pause = new Array(N);
|
| + for (var i = 0; i <= N; i++) {
|
| + pause[i] = (i > 0 ? pause[i - 1] : 0) + (bitmap[i] ? 1 : 0);
|
| + }
|
| + var windowWidth = timeToIndex(timeWindow);
|
| + var mu = new Array();
|
| + for (var i = 0; i + windowWidth <= N; i++) {
|
| + var value = pause[i + windowWidth] - pause[i];
|
| + mu.push(1.0 - value / windowWidth);
|
| + }
|
| + mu.sort((a, b) => a - b);
|
| + var max = mu.reduce((acc, x) => Math.max(acc, x), 0);
|
| + return {
|
| + average: function() {
|
| + return mu.reduce((acc, x) => (acc + x), 0) / mu.length;
|
| + },
|
| + min: function() {
|
| + return mu.reduce((acc, x) => Math.min(acc, x), 0);
|
| + },
|
| + max: function() {
|
| + return mu.reduce((acc, x) => Math.max(acc, x), 0);
|
| + },
|
| + percentile: function(percent) {
|
| + return mu[Math.floor(percent * (mu.length - 1))];
|
| + }
|
| + };
|
| + }
|
| +
|
| + test('unionOfIntervals', function() {
|
| + var list, union;
|
| + list = [];
|
| + union = [];
|
| + assert.deepEqual(union, tr.metrics.v8.utils.unionOfIntervals(list));
|
| + list = [interval(1, 1)];
|
| + union = [interval(1, 1)];
|
| + assert.deepEqual(union, tr.metrics.v8.utils.unionOfIntervals(list));
|
| + list = [interval(0, 1), interval(1, 2), interval(2, 3)];
|
| + union = [interval(0, 3)];
|
| + assert.deepEqual(union, tr.metrics.v8.utils.unionOfIntervals(list));
|
| + list = [interval(0, 1), interval(1, 2), interval(3, 3)];
|
| + union = [interval(0, 2), interval(3, 3)];
|
| + assert.deepEqual(union, tr.metrics.v8.utils.unionOfIntervals(list));
|
| + list = [interval(0, 10), interval(1, 2), interval(3, 3)];
|
| + union = [interval(0, 10)];
|
| + assert.deepEqual(union, tr.metrics.v8.utils.unionOfIntervals(list));
|
| + list = [interval(0, 10), interval(1, 2), interval(3, 11)];
|
| + union = [interval(0, 11)];
|
| + assert.deepEqual(union, tr.metrics.v8.utils.unionOfIntervals(list));
|
| + list = [interval(3, 10), interval(1, 2), interval(11, 11)];
|
| + union = [interval(1, 2), interval(3, 10), interval(11, 11)];
|
| + assert.deepEqual(union, tr.metrics.v8.utils.unionOfIntervals(list));
|
| + });
|
| +
|
| + test('PiecewiseLinearFunction', function() {
|
| + var f = new tr.metrics.v8.utils.PiecewiseLinearFunction();
|
| + f.push(0, 0.0, 10, 1.0);
|
| + f.push(10, 1.0, 20, 0.0);
|
| + f.push(20, 0.0, 30, 0.0);
|
| + assert.equal(1.0, f.max());
|
| + assert.equal(0.0, f.min());
|
| + assert.closeTo(20 * 1 / 2.0 / 30, f.average(), 1e-6);
|
| + assert.closeTo(0.0, f.percentile(1.0 / 3.0), 1e-6);
|
| + assert.closeTo(0.5, f.percentile(2.0 / 3.0), 1e-6);
|
| + });
|
| +
|
| + test('basicMutatorUtilization', function() {
|
| + var pauses, actual, expected;
|
| + pauses = [interval(10, 20)];
|
| + actual = tr.metrics.v8.utils.mutatorUtilization(0, 40, 10, pauses);
|
| + expected = new tr.metrics.v8.utils.PiecewiseLinearFunction();
|
| + expected.push(0, 1.0, 10, 0.0);
|
| + expected.push(10, 0.0, 20, 1.0);
|
| + expected.push(20, 1.0, 30, 1.0);
|
| + assert.deepEqual(expected, actual);
|
| + pauses = [interval(10, 15)];
|
| + actual = tr.metrics.v8.utils.mutatorUtilization(0, 40, 10, pauses);
|
| + expected = new tr.metrics.v8.utils.PiecewiseLinearFunction();
|
| + expected.push(0, 1.0, 5, 0.5);
|
| + expected.push(5, 0.5, 10, 0.5);
|
| + expected.push(10, 0.5, 15, 1.0);
|
| + expected.push(15, 1.0, 30, 1.0);
|
| + assert.deepEqual(expected, actual);
|
| + pauses = [interval(30, 35), interval(40, 45)];
|
| + actual = tr.metrics.v8.utils.mutatorUtilization(0, 60, 20, pauses);
|
| + expected = new tr.metrics.v8.utils.PiecewiseLinearFunction();
|
| + expected.push(0, 1.0, 10, 1.0);
|
| + expected.push(10, 1.0, 15, 0.75);
|
| + expected.push(15, 0.75, 20, 0.75);
|
| + expected.push(20, 0.75, 25, 0.5);
|
| + expected.push(25, 0.5, 30, 0.5);
|
| + expected.push(30, 0.5, 35, 0.75);
|
| + expected.push(35, 0.75, 40, 0.75);
|
| + assert.equal(JSON.stringify(expected), JSON.stringify(actual));
|
| + assert.deepEqual(expected, actual);
|
| + });
|
| +
|
| + test('mutatorUtilization', function() {
|
| + var pauses, actual, expected;
|
| + pauses = [interval(10, 20),
|
| + interval(15, 23),
|
| + interval(30, 31),
|
| + interval(33, 34),
|
| + interval(60, 61),
|
| + interval(61, 63),
|
| + interval(80, 88)];
|
| + actual = tr.metrics.v8.utils.mutatorUtilization(0, 100, 7, pauses);
|
| + expected = mutatorUtilizationSlow(0, 100, 7, pauses);
|
| + assert.closeTo(expected.average(), actual.average(), 1e-3);
|
| + assert.closeTo(expected.max(), actual.max(), 1e-3);
|
| + assert.closeTo(expected.min(), actual.min(), 1e-3);
|
| + assert.closeTo(expected.percentile(0.5), actual.percentile(0.5), 1e-3);
|
| + assert.closeTo(expected.percentile(0.9), actual.percentile(0.9), 1e-3);
|
| + });
|
| +
|
| +});
|
| +</script>
|
|
|