| Index: tracing/tracing/metrics/puf_metric.html
|
| diff --git a/tracing/tracing/metrics/puf_metric.html b/tracing/tracing/metrics/puf_metric.html
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..56ab7855ef0da1d8e3a6590f49b7b851793fe4a2
|
| --- /dev/null
|
| +++ b/tracing/tracing/metrics/puf_metric.html
|
| @@ -0,0 +1,98 @@
|
| +<!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/base/range.html">
|
| +<link rel="import" href="/tracing/metrics/metric_registry.html">
|
| +<link rel="import" href="/tracing/value/numeric.html">
|
| +<link rel="import" href="/tracing/value/value.html">
|
| +
|
| +<script>
|
| +'use strict';
|
| +
|
| +tr.exportTo('tr.metrics', function() {
|
| + function findAdLayoutObjects(model) {
|
| + var modelHelper = model.getOrCreateHelper(
|
| + tr.model.helpers.ChromeModelHelper);
|
| + var browserHelper = modelHelper.browserHelper;
|
| + var adLayoutObjects = [];
|
| +
|
| + var ftnis = browserHelper.process.objects.getAllInstancesNamed(
|
| + 'FrameTreeNode');
|
| + ftnis.forEach(function(ftni) {
|
| + if (!ftni.snapshots.length) return;
|
| + var ftns = ftni.snapshots[ftni.snapshots.length - 1];
|
| + if (ftns.args.parent) return;
|
| + var frame = ftns.args.RenderFrame;
|
| + if (!frame) return;
|
| + var layoutTreeSnapshot = frame.args.LayoutTree;
|
| + if (!layoutTreeSnapshot) return;
|
| + layoutTreeSnapshot.rootLayoutObject.traverseTree(function(layoutObject) {
|
| + if (!TODO(easylist, layoutObject.source)) return;
|
| + adLayoutObjects.push(layoutObject);
|
| + });
|
| + });
|
| +
|
| + return adLayoutObjects;
|
| + }
|
| +
|
| + var unitless = tr.v.Unit.byName.unitlessNumber;
|
| + var normalizedPercentage = tr.v.Unit.byName.normalizedPercentage;
|
| +
|
| + function PUFMetric(valueList, model) {
|
| + var ads = findAdLayoutObjects(model);
|
| + if (ads.length == 0) return;
|
| +
|
| + var options = {description: 'Percent of page area that is ads'};
|
| + var groupingKeys = {};
|
| + var diagnostics = {ads: []};
|
| +
|
| + var rootLayoutObject =
|
| + ads[0].snapshot.rootLayoutTreeSnapshot.rootLayoutObject;
|
| + var adPixels = 0;
|
| +
|
| + ads.forEach(function(adLayoutObject) {
|
| + if (adLayoutObject.snapshot.rootLayoutTreeSnapshot.rootLayoutObject !==
|
| + rootLayoutObject) {
|
| + console.warn('Oops, I should not have assumed that ' +
|
| + 'there was only one tab open!');
|
| + return;
|
| + }
|
| +
|
| + adPixels += adLayoutObject.width * adLayoutObject.height;
|
| +
|
| + diagnostics.ads.push({
|
| + source: adLayoutObject.source,
|
| + width: adLayoutObject.width,
|
| + height: adLayoutObject.height,
|
| + x: adLayoutObject.viewportRelativeRect.x,
|
| + y: adLayoutObject.viewportRelativeRect.y
|
| + });
|
| + });
|
| +
|
| + var pagePixels = rootLayoutObject.width * rootLayoutObject.height;
|
| + diagnostics.page = {
|
| + width: rootLayoutObject.width, height:
|
| + rootLayoutObject.height
|
| + };
|
| + var density = adPixels / pagePixels;
|
| +
|
| + valueList.addValue(new tr.v.NumericValue(
|
| + model.canonicalUrl, 'ads density', new tr.v.ScalarNumeric(
|
| + normalizedPercentage, density),
|
| + options, groupingKeys, diagnostics));
|
| + }
|
| +
|
| + PUFMetric.prototype = {
|
| + __proto__: Function.prototype
|
| + };
|
| +
|
| + tr.metrics.MetricRegistry.register(PUFMetric);
|
| +
|
| + return {
|
| + PUFMetric: PUFMetric
|
| + };
|
| +});
|
| +</script>
|
|
|