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

Unified Diff: tracing/tracing/metrics/media_metric.html

Issue 3002623002: [WIP] Port media metrics to TBMv2 (Closed)
Patch Set: Change console.time to performance.mark Created 3 years, 4 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
« no previous file with comments | « tracing/tracing/metrics/all_metrics.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tracing/tracing/metrics/media_metric.html
diff --git a/tracing/tracing/metrics/media_metric.html b/tracing/tracing/metrics/media_metric.html
new file mode 100644
index 0000000000000000000000000000000000000000..0b6e74061e8a05ce97144187611fffacd39244cf
--- /dev/null
+++ b/tracing/tracing/metrics/media_metric.html
@@ -0,0 +1,91 @@
+<!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/metrics/metric_registry.html">
+<link rel="import" href="/tracing/value/histogram.html">
+
+<script>
+'use strict';
+
+tr.exportTo('tr.metrics', function() {
+ function mediaMetric(histograms, model) {
+ let playStart;
+ let timeToPlay;
+ let playEnd;
+ let duration;
+
+ const seekStarts = [];
+ const seekEnds = [];
+ const seekLabels = [];
+
+ for (const event of model.getDescendantEvents()) {
+ if (!event.title) {
+ continue;
+ }
+ if (event.title.startsWith('seekLabel-')) {
+ seekLabels.push(event);
+ } else if (event.title.startsWith('duration-')) {
+ duration = Number(event.title.substring(9));
+ } else if (event.title === 'EventDispatch') {
+ const type = event.args.data.type;
+ if (type === 'willPlay') {
+ playStart = event.start;
+ } else if (type === 'play' || type === 'loadedmetadata') {
+ if (playStart === undefined) {
+ playStart = event.start;
+ }
+ } else if (type === 'playing') {
+ if (playStart !== undefined && timeToPlay === undefined) {
+ timeToPlay = event.start - playStart;
+ addTimeValue(histograms, 'time_to_play', timeToPlay);
+ }
+ } else if (type === 'ended') {
+ playEnd = event.start;
+ } else if (type === 'willSeek') {
+ seekStarts.push(event.start);
+ } else if (type === 'seeked') {
+ seekEnds[seekStarts.length - 1] = event.start;
+ }
+ }
+ }
+
+ if (playStart !== undefined && timeToPlay !== undefined &&
+ playEnd !== undefined && duration !== undefined) {
+ addTimeValue(histograms, 'buffering_time',
+ playEnd - playStart - timeToPlay - 1000 * duration);
+ }
+
+ for (let i = 0; i < seekStarts.length; i++) {
+ if (seekEnds[i] === undefined) {
+ continue;
+ }
+ let name = 'seek';
+ for (const seekLabel of seekLabels) {
+ const time = seekLabel.start;
+ if (time >= seekStarts[i] && time <= seekEnds[i]) {
+ name = seekLabel.title.substring(10);
+ break;
+ }
+ }
+ addTimeValue(histograms, name, seekEnds[i] - seekStarts[i]);
+ }
+ }
+
+ function addTimeValue(histograms, name, value) {
+ const hist = new tr.v.Histogram(name,
+ tr.b.Unit.byName.timeDurationInMs_smallerIsBetter);
+ hist.addSample(value);
+ histograms.addHistogram(hist);
+ }
+
+ tr.metrics.MetricRegistry.register(mediaMetric);
+
+ return {
+ mediaMetric,
+ };
+});
+</script>
« no previous file with comments | « tracing/tracing/metrics/all_metrics.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698