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

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

Issue 1911603002: LayoutTree machinery (Closed) Base URL: https://chromium.googlesource.com/external/github.com/catapult-project/catapult.git@master
Patch Set: oops Created 4 years, 7 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') | tracing/tracing/ui/analysis/layout_tree_sub_view.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>
« no previous file with comments | « tracing/tracing/metrics/all_metrics.html ('k') | tracing/tracing/ui/analysis/layout_tree_sub_view.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698