| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <!-- | 2 <!-- |
| 3 Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 4 Use of this source code is governed by a BSD-style license that can be |
| 5 found in the LICENSE file. | 5 found in the LICENSE file. |
| 6 --> | 6 --> |
| 7 | 7 |
| 8 <link rel="import" href="/tracing/base/range.html"> | 8 <link rel="import" href="/tracing/base/range.html"> |
| 9 <link rel="import" href="/tracing/base/unit.html"> | 9 <link rel="import" href="/tracing/base/unit.html"> |
| 10 <link rel="import" href="/tracing/metrics/metric_registry.html"> | 10 <link rel="import" href="/tracing/metrics/metric_registry.html"> |
| 11 <link rel="import" href="/tracing/metrics/v8/utils.html"> | 11 <link rel="import" href="/tracing/metrics/v8/utils.html"> |
| 12 <link rel="import" href="/tracing/value/histogram.html"> | 12 <link rel="import" href="/tracing/value/histogram.html"> |
| 13 <link rel="import" href="/tracing/value/value.html"> | |
| 14 | 13 |
| 15 <script> | 14 <script> |
| 16 'use strict'; | 15 'use strict'; |
| 17 | 16 |
| 18 tr.exportTo('tr.metrics.blink', function() { | 17 tr.exportTo('tr.metrics.blink', function() { |
| 19 // Maps the Blink GC events in timeline to telemetry friendly names. | 18 // Maps the Blink GC events in timeline to telemetry friendly names. |
| 20 var BLINK_GC_EVENTS = { | 19 var BLINK_GC_EVENTS = { |
| 21 'BlinkGCMarking': 'blink-gc-marking', | 20 'BlinkGCMarking': 'blink-gc-marking', |
| 22 'ThreadState::completeSweep': 'blink-gc-complete-sweep', | 21 'ThreadState::completeSweep': 'blink-gc-complete-sweep', |
| 23 'ThreadState::performIdleLazySweep': 'blink-gc-idle-lazy-sweep' | 22 'ThreadState::performIdleLazySweep': 'blink-gc-idle-lazy-sweep' |
| (...skipping 19 matching lines...) Expand all Loading... |
| 43 var timeDurationInMs_smallerIsBetter = | 42 var timeDurationInMs_smallerIsBetter = |
| 44 tr.b.Unit.byName.timeDurationInMs_smallerIsBetter; | 43 tr.b.Unit.byName.timeDurationInMs_smallerIsBetter; |
| 45 var percentage_biggerIsBetter = | 44 var percentage_biggerIsBetter = |
| 46 tr.b.Unit.byName.normalizedPercentage_biggerIsBetter; | 45 tr.b.Unit.byName.normalizedPercentage_biggerIsBetter; |
| 47 | 46 |
| 48 // 0.1 steps from 0 to 20 since it is the most common range. | 47 // 0.1 steps from 0 to 20 since it is the most common range. |
| 49 // Exponentially increasing steps from 20 to 200. | 48 // Exponentially increasing steps from 20 to 200. |
| 50 var CUSTOM_BOUNDARIES = tr.v.HistogramBinBoundaries.createLinear(0, 20, 200) | 49 var CUSTOM_BOUNDARIES = tr.v.HistogramBinBoundaries.createLinear(0, 20, 200) |
| 51 .addExponentialBins(200, 100); | 50 .addExponentialBins(200, 100); |
| 52 | 51 |
| 53 function createNumericForTopEventTime() { | 52 function createNumericForTopEventTime(name) { |
| 54 var n = new tr.v.Histogram( | 53 var n = new tr.v.Histogram(name, |
| 55 timeDurationInMs_smallerIsBetter, CUSTOM_BOUNDARIES); | 54 timeDurationInMs_smallerIsBetter, CUSTOM_BOUNDARIES); |
| 56 n.customizeSummaryOptions({ | 55 n.customizeSummaryOptions({ |
| 57 avg: true, | 56 avg: true, |
| 58 count: true, | 57 count: true, |
| 59 max: true, | 58 max: true, |
| 60 min: false, | 59 min: false, |
| 61 std: true, | 60 std: true, |
| 62 sum: true, | 61 sum: true, |
| 63 percentile: [0.90]}); | 62 percentile: [0.90]}); |
| 64 return n; | 63 return n; |
| 65 } | 64 } |
| 66 | 65 |
| 67 function createNumericForIdleTime() { | 66 function createNumericForIdleTime(name) { |
| 68 var n = new tr.v.Histogram( | 67 var n = new tr.v.Histogram(name, |
| 69 timeDurationInMs_smallerIsBetter, CUSTOM_BOUNDARIES); | 68 timeDurationInMs_smallerIsBetter, CUSTOM_BOUNDARIES); |
| 70 n.customizeSummaryOptions({ | 69 n.customizeSummaryOptions({ |
| 71 avg: true, | 70 avg: true, |
| 72 count: false, | 71 count: false, |
| 73 max: true, | 72 max: true, |
| 74 min: false, | 73 min: false, |
| 75 std: false, | 74 std: false, |
| 76 sum: true, | 75 sum: true, |
| 77 percentile: [] | 76 percentile: [] |
| 78 }); | 77 }); |
| 79 return n; | 78 return n; |
| 80 } | 79 } |
| 81 | 80 |
| 82 function createPercentage(numerator, denominator) { | 81 function createPercentage(name, numerator, denominator) { |
| 83 var histogram = new tr.v.Histogram(percentage_biggerIsBetter); | 82 var histogram = new tr.v.Histogram(name, percentage_biggerIsBetter); |
| 84 if (denominator === 0) | 83 if (denominator === 0) |
| 85 histogram.addSample(0); | 84 histogram.addSample(0); |
| 86 else | 85 else |
| 87 histogram.addSample(numerator / denominator); | 86 histogram.addSample(numerator / denominator); |
| 88 return histogram; | 87 return histogram; |
| 89 } | 88 } |
| 90 | 89 |
| 91 /** | 90 /** |
| 92 * Example output: | 91 * Example output: |
| 93 * - blink-gc-marking. | 92 * - blink-gc-marking. |
| 94 */ | 93 */ |
| 95 function addDurationOfTopEvents(values, model) { | 94 function addDurationOfTopEvents(values, model) { |
| 96 tr.metrics.v8.utils.groupAndProcessEvents(model, | 95 tr.metrics.v8.utils.groupAndProcessEvents(model, |
| 97 isBlinkGarbageCollectionEvent, | 96 isBlinkGarbageCollectionEvent, |
| 98 blinkGarbageCollectionEventName, | 97 blinkGarbageCollectionEventName, |
| 99 function(name, events) { | 98 function(name, events) { |
| 100 var cpuDuration = createNumericForTopEventTime(); | 99 var cpuDuration = createNumericForTopEventTime(name); |
| 101 events.forEach(function(event) { | 100 events.forEach(function(event) { |
| 102 cpuDuration.addSample(event.cpuDuration); | 101 cpuDuration.addSample(event.cpuDuration); |
| 103 }); | 102 }); |
| 104 values.addValue(new tr.v.NumericValue(name, cpuDuration)); | 103 values.addHistogram(cpuDuration); |
| 105 } | 104 } |
| 106 ); | 105 ); |
| 107 } | 106 } |
| 108 | 107 |
| 109 /** | 108 /** |
| 110 * Example output: | 109 * Example output: |
| 111 * - blink-gc-total | 110 * - blink-gc-total |
| 112 */ | 111 */ |
| 113 function addTotalDurationOfTopEvents(values, model) { | 112 function addTotalDurationOfTopEvents(values, model) { |
| 114 tr.metrics.v8.utils.groupAndProcessEvents(model, | 113 tr.metrics.v8.utils.groupAndProcessEvents(model, |
| 115 isBlinkGarbageCollectionEvent, | 114 isBlinkGarbageCollectionEvent, |
| 116 event => 'blink-gc-total', | 115 event => 'blink-gc-total', |
| 117 function(name, events) { | 116 function(name, events) { |
| 118 var cpuDuration = createNumericForTopEventTime(); | 117 var cpuDuration = createNumericForTopEventTime(name); |
| 119 events.forEach(function(event) { | 118 events.forEach(function(event) { |
| 120 cpuDuration.addSample(event.cpuDuration); | 119 cpuDuration.addSample(event.cpuDuration); |
| 121 }); | 120 }); |
| 122 values.addValue(new tr.v.NumericValue(name, cpuDuration)); | 121 values.addHistogram(cpuDuration); |
| 123 } | 122 } |
| 124 ); | 123 ); |
| 125 } | 124 } |
| 126 | 125 |
| 127 /** | 126 /** |
| 128 * Example output: | 127 * Example output: |
| 129 * - blink-gc-marking_idle_deadline_overrun, | 128 * - blink-gc-marking_idle_deadline_overrun, |
| 130 * - blink-gc-marking_outside_idle, | 129 * - blink-gc-marking_outside_idle, |
| 131 * - blink-gc-marking_percentage_idle. | 130 * - blink-gc-marking_percentage_idle. |
| 132 */ | 131 */ |
| (...skipping 17 matching lines...) Expand all Loading... |
| 150 tr.metrics.v8.utils.groupAndProcessEvents(model, | 149 tr.metrics.v8.utils.groupAndProcessEvents(model, |
| 151 isBlinkGarbageCollectionEvent, | 150 isBlinkGarbageCollectionEvent, |
| 152 event => 'blink-gc-total', | 151 event => 'blink-gc-total', |
| 153 function(name, events) { | 152 function(name, events) { |
| 154 addIdleTimes(values, model, name, events); | 153 addIdleTimes(values, model, name, events); |
| 155 } | 154 } |
| 156 ); | 155 ); |
| 157 } | 156 } |
| 158 | 157 |
| 159 function addIdleTimes(values, model, name, events) { | 158 function addIdleTimes(values, model, name, events) { |
| 160 var cpuDuration = createNumericForIdleTime(); | 159 var cpuDuration = createNumericForIdleTime(name + '_cpu'); |
| 161 var insideIdle = createNumericForIdleTime(); | 160 var insideIdle = createNumericForIdleTime(name + '_inside_idle'); |
| 162 var outsideIdle = createNumericForIdleTime(); | 161 var outsideIdle = createNumericForIdleTime(name + '_outside_idle'); |
| 163 var idleDeadlineOverrun = createNumericForIdleTime(); | 162 var idleDeadlineOverrun = createNumericForIdleTime( |
| 163 name + '_idle_deadline_overrun'); |
| 164 events.forEach(function(event) { | 164 events.forEach(function(event) { |
| 165 var idleTask = tr.metrics.v8.utils.findParent( | 165 var idleTask = tr.metrics.v8.utils.findParent( |
| 166 event, tr.metrics.v8.utils.isIdleTask); | 166 event, tr.metrics.v8.utils.isIdleTask); |
| 167 var inside = 0; | 167 var inside = 0; |
| 168 var overrun = 0; | 168 var overrun = 0; |
| 169 if (idleTask) { | 169 if (idleTask) { |
| 170 var allottedTime = idleTask['args']['allotted_time_ms']; | 170 var allottedTime = idleTask['args']['allotted_time_ms']; |
| 171 if (event.duration > allottedTime) { | 171 if (event.duration > allottedTime) { |
| 172 overrun = event.duration - allottedTime; | 172 overrun = event.duration - allottedTime; |
| 173 // Don't count time over the deadline as being inside idle time. | 173 // Don't count time over the deadline as being inside idle time. |
| 174 // Since the deadline should be relative to wall clock we | 174 // Since the deadline should be relative to wall clock we |
| 175 // compare allotted_time_ms with wall duration instead of thread | 175 // compare allotted_time_ms with wall duration instead of thread |
| 176 // duration, and then assume the thread duration was inside idle | 176 // duration, and then assume the thread duration was inside idle |
| 177 // for the same percentage of time. | 177 // for the same percentage of time. |
| 178 inside = event.cpuDuration * allottedTime / event.duration; | 178 inside = event.cpuDuration * allottedTime / event.duration; |
| 179 } else { | 179 } else { |
| 180 inside = event.cpuDuration; | 180 inside = event.cpuDuration; |
| 181 } | 181 } |
| 182 } | 182 } |
| 183 cpuDuration.addSample(event.cpuDuration); | 183 cpuDuration.addSample(event.cpuDuration); |
| 184 insideIdle.addSample(inside); | 184 insideIdle.addSample(inside); |
| 185 outsideIdle.addSample(event.cpuDuration - inside); | 185 outsideIdle.addSample(event.cpuDuration - inside); |
| 186 idleDeadlineOverrun.addSample(overrun); | 186 idleDeadlineOverrun.addSample(overrun); |
| 187 }); | 187 }); |
| 188 values.addValue(new tr.v.NumericValue( | 188 values.addHistogram(idleDeadlineOverrun); |
| 189 name + '_idle_deadline_overrun', | 189 values.addHistogram(outsideIdle); |
| 190 idleDeadlineOverrun)); | 190 var percentage = createPercentage( |
| 191 values.addValue(new tr.v.NumericValue( | 191 name + '_percentage_idle', insideIdle.sum, cpuDuration.sum); |
| 192 name + '_outside_idle', outsideIdle)); | 192 values.addHistogram(percentage); |
| 193 var percentage = createPercentage(insideIdle.sum, | |
| 194 cpuDuration.sum); | |
| 195 values.addValue(new tr.v.NumericValue( | |
| 196 name + '_percentage_idle', percentage)); | |
| 197 } | 193 } |
| 198 | 194 |
| 199 return { | 195 return { |
| 200 blinkGcMetric: blinkGcMetric | 196 blinkGcMetric: blinkGcMetric |
| 201 }; | 197 }; |
| 202 }); | 198 }); |
| 203 </script> | 199 </script> |
| OLD | NEW |