Home | History | Annotate | Download | only in v8
      1 <!DOCTYPE html>
      2 <!--
      3 Copyright 2016 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/extras/importer/trace_event_importer.html">
     10 <link rel="import" href="/tracing/metrics/v8/gc_metric.html">
     11 <link rel="import" href="/tracing/model/slice_group.html">
     12 <link rel="import" href="/tracing/value/value_set.html">
     13 
     14 <script>
     15 'use strict';
     16 
     17 tr.b.unittest.testSuite(function() {
     18 
     19   function createModel(start, end, slices) {
     20     var opts = {
     21       customizeModelCallback: function(model) {
     22         var process = model.getOrCreateProcess(1);
     23         var thread = process.getOrCreateThread(2);
     24         var group = thread.sliceGroup;
     25         slices.forEach(function(slice) {
     26           group.pushSlice(tr.c.TestUtils.newSliceEx(slice));
     27         });
     28         group.createSubSlices();
     29       }
     30     };
     31     var model = tr.c.TestUtils.newModelWithEvents([], opts);
     32     return model;
     33   }
     34 
     35   function constructName(name, suffix) {
     36     return name + '_' + suffix;
     37   }
     38 
     39   function run(slices) {
     40     var values = new tr.v.ValueSet();
     41     var startTime = slices.reduce((acc, slice) => (Math.min(acc, slice.start)));
     42     var endTime = slices.reduce((acc, slice) => (Math.max(acc, slice.end)));
     43     var model = createModel(startTime - 1, endTime + 1, slices);
     44     tr.metrics.v8.gcMetric(values, model);
     45     return values;
     46   }
     47 
     48   test('topEvents', function() {
     49     var events = {
     50       'V8.GCCompactor': 'v8-gc-full-mark-compactor',
     51       'V8.GCFinalizeMC': 'v8-gc-latency-mark-compactor',
     52       'V8.GCFinalizeMCReduceMemory': 'v8-gc-memory-mark-compactor',
     53       'V8.GCIncrementalMarking': 'v8-gc-incremental-step',
     54       'V8.GCIncrementalMarkingFinalize': 'v8-gc-incremental-finalize',
     55       'V8.GCIncrementalMarkingStart': 'v8-gc-incremental-start',
     56       'V8.GCPhantomHandleProcessingCallback' : 'v8-gc-phantom-handle-callback',
     57       'V8.GCScavenger': 'v8-gc-scavenger'
     58     };
     59     tr.b.iterItems(events, function(timelineName, telemetryName) {
     60       var slices = [
     61         {
     62           title: timelineName, args: {}, start: 100, end: 200,
     63           cpuStart: 100, cpuEnd: 200
     64         }
     65       ];
     66       var actual = run(slices);
     67 
     68       var value = tr.b.getOnlyElement(actual.getValuesNamed(telemetryName));
     69       assert.strictEqual(value.running.sum, 100);
     70       assert.strictEqual(value.numValues, 1);
     71       assert.strictEqual(value.average, 100);
     72       assert.strictEqual(value.running.max, 100);
     73       assert.closeTo(value.getApproximatePercentile(0.90), 100, 1);
     74 
     75       value = tr.b.getOnlyElement(actual.getValuesNamed(
     76           telemetryName + '_idle_deadline_overrun'));
     77       assert.strictEqual(value.running.sum, 0);
     78       assert.strictEqual(value.numValues, 1);
     79       assert.strictEqual(value.average, 0);
     80       assert.strictEqual(value.running.max, 0);
     81 
     82       value = tr.b.getOnlyElement(actual.getValuesNamed(
     83           telemetryName + '_outside_idle'));
     84       assert.strictEqual(value.running.sum, 100);
     85       assert.strictEqual(value.numValues, 1);
     86       assert.strictEqual(value.average, 100);
     87 
     88       value = tr.b.getOnlyElement(actual.getValuesNamed(
     89           telemetryName + '_percentage_idle'));
     90       assert.strictEqual(value.average, 0);
     91     });
     92   });
     93 
     94   test('idleTimes', function() {
     95     var values = new tr.v.ValueSet();
     96     var slices = [
     97       {
     98         title: 'SingleThreadIdleTaskRunner::RunTask',
     99         args: {'allotted_time_ms' : 100}, start: 100, end: 200,
    100         cpuStart: 100, cpuEnd: 200
    101       },
    102       {
    103         title: 'V8.GCFinalizeMC', args: {}, start: 110, end: 190,
    104         cpuStart: 110, cpuEnd: 190
    105       }
    106     ];
    107     var actual = run(slices);
    108 
    109     var value = tr.b.getOnlyElement(actual.getValuesNamed(
    110           'v8-gc-latency-mark-compactor'));
    111     assert.strictEqual(value.running.sum, 80);
    112     assert.strictEqual(value.numValues, 1);
    113     assert.strictEqual(value.average, 80);
    114     assert.strictEqual(value.running.max, 80);
    115 
    116     value = tr.b.getOnlyElement(actual.getValuesNamed(
    117         'v8-gc-latency-mark-compactor_idle_deadline_overrun'));
    118     assert.strictEqual(value.running.sum, 0);
    119     assert.strictEqual(value.average, 0);
    120     assert.strictEqual(value.running.max, 0);
    121 
    122     value = tr.b.getOnlyElement(actual.getValuesNamed(
    123         'v8-gc-latency-mark-compactor_outside_idle'));
    124     assert.strictEqual(value.running.sum, 0);
    125     assert.strictEqual(value.average, 0);
    126     assert.strictEqual(value.running.max, 0);
    127 
    128     value = tr.b.getOnlyElement(actual.getValuesNamed(
    129         'v8-gc-latency-mark-compactor_percentage_idle'));
    130     assert.strictEqual(value.average, 1);
    131   });
    132 
    133   test('idleTimeOverrun', function() {
    134     var values = new tr.v.ValueSet();
    135     var slices = [
    136       {
    137         title: 'SingleThreadIdleTaskRunner::RunTask',
    138         args: {'allotted_time_ms' : 10}, start: 100, end: 200,
    139         cpuStart: 100, cpuEnd: 200
    140       },
    141       {
    142         title: 'V8.GCFinalizeMC', args: {}, start: 110, end: 190,
    143         cpuStart: 110, cpuEnd: 190
    144       }
    145     ];
    146     var actual = run(slices);
    147 
    148     var value = tr.b.getOnlyElement(actual.getValuesNamed(
    149           'v8-gc-latency-mark-compactor'));
    150     assert.strictEqual(value.running.sum, 80);
    151     assert.strictEqual(value.numValues, 1);
    152     assert.strictEqual(value.average, 80);
    153     assert.strictEqual(value.running.max, 80);
    154 
    155     value = tr.b.getOnlyElement(actual.getValuesNamed(
    156         'v8-gc-latency-mark-compactor_idle_deadline_overrun'));
    157     assert.strictEqual(value.running.sum, 70);
    158     assert.strictEqual(value.average, 70);
    159     assert.strictEqual(value.running.max, 70);
    160 
    161     value = tr.b.getOnlyElement(actual.getValuesNamed(
    162         'v8-gc-latency-mark-compactor_outside_idle'));
    163     assert.strictEqual(value.running.sum, 70);
    164     assert.strictEqual(value.average, 70);
    165     assert.strictEqual(value.running.max, 70);
    166 
    167     value = tr.b.getOnlyElement(actual.getValuesNamed(
    168         'v8-gc-latency-mark-compactor_percentage_idle'));
    169     assert.closeTo(value.average, 1 / 8, 1e-6);
    170   });
    171 
    172   test('subEvents', function() {
    173     var values = new tr.v.ValueSet();
    174     var slices = [
    175       {
    176         title: 'V8.GCFinalizeMC', args: {}, start: 100, end: 200,
    177         cpuStart: 100, cpuEnd: 200
    178       },
    179       {
    180         title: 'V8.GC_MC_MARK', args: {}, start: 110, end: 190,
    181         cpuStart: 110, cpuEnd: 190
    182       },
    183     ];
    184     var actual = run(slices);
    185     var telemetryName = 'v8-gc-latency-mark-compactor-mark';
    186     var value = tr.b.getOnlyElement(actual.getValuesNamed(telemetryName));
    187     assert.strictEqual(value.average, 80);
    188     assert.strictEqual(value.running.max, 80);
    189     assert.closeTo(value.getApproximatePercentile(0.90), 80, 1);
    190   });
    191 
    192   test('total', function() {
    193     var values = new tr.v.ValueSet();
    194     var slices = [
    195       {
    196         title: 'V8.GCFinalizeMC', args: {}, start: 100, end: 200,
    197         cpuStart: 100, cpuEnd: 200
    198       },
    199       {
    200         title: 'V8.GCIncrementalMarking', args: {}, start: 210, end: 290,
    201         cpuStart: 210, cpuEnd: 290
    202       }
    203     ];
    204     var actual = run(slices);
    205 
    206     var value = tr.b.getOnlyElement(actual.getValuesNamed('v8-gc-total'));
    207     assert.strictEqual(value.running.sum, 180);
    208     assert.strictEqual(value.numValues, 2);
    209     assert.strictEqual(value.average, 90);
    210     assert.strictEqual(value.running.max, 100);
    211 
    212     value = tr.b.getOnlyElement(actual.getValuesNamed(
    213         'v8-gc-total_idle_deadline_overrun'));
    214     assert.strictEqual(value.running.sum, 0);
    215     assert.strictEqual(value.average, 0);
    216     assert.strictEqual(value.running.max, 0);
    217 
    218     value = tr.b.getOnlyElement(actual.getValuesNamed(
    219         'v8-gc-total_outside_idle'));
    220     assert.strictEqual(value.running.sum, 180);
    221     assert.strictEqual(value.average, 90);
    222     assert.strictEqual(value.running.max, 100);
    223 
    224     value = tr.b.getOnlyElement(actual.getValuesNamed(
    225         'v8-gc-total_percentage_idle'));
    226     assert.strictEqual(value.average, 0);
    227   });
    228 
    229   test('percentageInV8Execute', function() {
    230     var values = new tr.v.ValueSet();
    231     var slices = [
    232       {
    233         title: 'V8.Execute',
    234         args: {}, start: 100, end: 200,
    235         cpuStart: 100, cpuEnd: 200
    236       },
    237       {
    238         title: 'V8.GCFinalizeMC', args: {}, start: 110, end: 190,
    239         cpuStart: 110, cpuEnd: 190
    240       },
    241       {
    242         title: 'V8.GCFinalizeMC', args: {}, start: 210, end: 220,
    243         cpuStart: 210, cpuEnd: 220
    244       }
    245     ];
    246     var actual = run(slices);
    247     var value = tr.b.getOnlyElement(actual.getValuesNamed(
    248         'v8-gc-latency-mark-compactor_percentage_in_v8_execute'));
    249     assert.strictEqual(value.average,
    250         (190 - 110) / ((190 - 110) + (220 - 210)));
    251   });
    252 
    253   test('mutatorUtilization', function() {
    254     var values = new tr.v.ValueSet();
    255     var slices = [
    256       {
    257         title: 'V8.Execute', args: {}, start: 100, end: 200,
    258         cpuStart: 100, cpuEnd: 200
    259       },
    260       {
    261         title: 'V8.GCFinalizeMC', args: {}, start: 150, end: 160,
    262         cpuStart: 150, cpuEnd: 160
    263       },
    264       {
    265         title: 'V8.Execute', args: {}, start: 1000, end: 1200,
    266         cpuStart: 1000, cpuEnd: 1200
    267       },
    268       {
    269         title: 'V8.GCIncrementalMarking', args: {}, start: 1010, end: 1020,
    270         cpuStart: 1010, cpuEnd: 1020
    271       }
    272     ];
    273     var mutatorUtilization = tr.metrics.v8.utils.mutatorUtilization(
    274         0, 300, tr.metrics.v8.WINDOW_SIZE_MS,
    275         [{start: 50, end: 60}, {start: 110, end: 120}]);
    276     var actual = run(slices);
    277 
    278     var value = tr.b.getOnlyElement(actual.getValuesNamed(
    279         'v8-execute-mutator-utilization_pct_095'));
    280     assert.closeTo(value.average,
    281         mutatorUtilization.percentile(1 - 0.95), 1e-2);
    282 
    283     value = tr.b.getOnlyElement(actual.getValuesNamed(
    284         'v8-execute-mutator-utilization_pct_099'));
    285     assert.closeTo(value.average,
    286         mutatorUtilization.percentile(1 - 0.99), 1e-2);
    287  });
    288 });
    289 </script>
    290