OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <!-- |
| 3 Copyright 2017 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/metrics/metric_registry.html"> |
| 9 <link rel="import" href="/tracing/value/histogram.html"> |
| 10 |
| 11 <script> |
| 12 'use strict'; |
| 13 |
| 14 tr.exportTo('tr.metrics', function() { |
| 15 function mediaMetric(histograms, model) { |
| 16 let playStart; |
| 17 let timeToPlay; |
| 18 let playEnd; |
| 19 let duration; |
| 20 |
| 21 const seekStarts = []; |
| 22 const seekEnds = []; |
| 23 const seekLabels = []; |
| 24 |
| 25 for (const event of model.getDescendantEvents()) { |
| 26 if (!event.title) { |
| 27 continue; |
| 28 } |
| 29 if (event.title.startsWith('seekLabel-')) { |
| 30 seekLabels.push(event); |
| 31 } else if (event.title.startsWith('duration-')) { |
| 32 duration = Number(event.title.substring(9)); |
| 33 } else if (event.title === 'EventDispatch') { |
| 34 const type = event.args.data.type; |
| 35 if (type === 'willPlay') { |
| 36 playStart = event.start; |
| 37 } else if (type === 'play' || type === 'loadedmetadata') { |
| 38 if (playStart === undefined) { |
| 39 playStart = event.start; |
| 40 } |
| 41 } else if (type === 'playing') { |
| 42 if (playStart !== undefined && timeToPlay === undefined) { |
| 43 timeToPlay = event.start - playStart; |
| 44 addTimeValue(histograms, 'time_to_play', timeToPlay); |
| 45 } |
| 46 } else if (type === 'ended') { |
| 47 playEnd = event.start; |
| 48 } else if (type === 'willSeek') { |
| 49 seekStarts.push(event.start); |
| 50 } else if (type === 'seeked') { |
| 51 seekEnds[seekStarts.length - 1] = event.start; |
| 52 } |
| 53 } |
| 54 } |
| 55 |
| 56 if (playStart !== undefined && timeToPlay !== undefined && |
| 57 playEnd !== undefined && duration !== undefined) { |
| 58 addTimeValue(histograms, 'buffering_time', |
| 59 playEnd - playStart - timeToPlay - 1000 * duration); |
| 60 } |
| 61 |
| 62 for (let i = 0; i < seekStarts.length; i++) { |
| 63 if (seekEnds[i] === undefined) { |
| 64 continue; |
| 65 } |
| 66 let name = 'seek'; |
| 67 for (const seekLabel of seekLabels) { |
| 68 const time = seekLabel.start; |
| 69 if (time >= seekStarts[i] && time <= seekEnds[i]) { |
| 70 name = seekLabel.title.substring(10); |
| 71 break; |
| 72 } |
| 73 } |
| 74 addTimeValue(histograms, name, seekEnds[i] - seekStarts[i]); |
| 75 } |
| 76 } |
| 77 |
| 78 function addTimeValue(histograms, name, value) { |
| 79 const hist = new tr.v.Histogram(name, |
| 80 tr.b.Unit.byName.timeDurationInMs_smallerIsBetter); |
| 81 hist.addSample(value); |
| 82 histograms.addHistogram(hist); |
| 83 } |
| 84 |
| 85 tr.metrics.MetricRegistry.register(mediaMetric); |
| 86 |
| 87 return { |
| 88 mediaMetric, |
| 89 }; |
| 90 }); |
| 91 </script> |
OLD | NEW |