Chromium Code Reviews| Index: tools/telemetry/telemetry/wait_interaction.py |
| diff --git a/tools/telemetry/telemetry/wait_interaction.py b/tools/telemetry/telemetry/wait_interaction.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..dde37121c938e773ba736669170231134251432b |
| --- /dev/null |
| +++ b/tools/telemetry/telemetry/wait_interaction.py |
| @@ -0,0 +1,58 @@ |
| +# Copyright (c) 2012 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. |
| +from telemetry import page_interaction |
| +from telemetry import util |
| + |
| +class WaitInteraction(page_interaction.PageInteraction): |
| + def __init__(self, attributes=None): |
| + super(WaitInteraction, self).__init__(attributes) |
| + |
| + def PerformInteraction(self, page, tab): |
| + duration = 10 |
| + if hasattr(self, 'duration'): |
| + duration = self.duration |
| + |
| + wait_js = """ |
| + window.__renderingStatsDeltas = null; |
| + |
| + var getTimeMs = (function() { |
| + if (window.performance) |
| + return (performance.now || |
| + performance.mozNow || |
| + performance.msNow || |
| + performance.oNow || |
| + performance.webkitNow).bind(window.performance); |
| + else |
| + return function() { return new Date().getTime(); }; |
| + })(); |
| + |
| + var getRenderingStats = function() { |
| + var renderingStats = {}; |
| + if (chrome && |
| + chrome.gpuBenchmarking && |
| + chrome.gpuBenchmarking.renderingStats) |
| + renderingStats = chrome.gpuBenchmarking.renderingStats(); |
| + renderingStats.totalTimeInSeconds = getTimeMs() / 1000; |
|
hartmanng
2013/01/04 15:34:35
This may fail on legacy builds. We check for numFr
|
| + return renderingStats; |
| + } |
| + |
| + var initialStats = getRenderingStats(); |
| + |
| + var waitFinishedCallback = function(init) { |
| + return function() { |
| + var final = getRenderingStats(); |
| + for (var key in final) |
| + final[key] -= init[key]; |
| + window.__renderingStatsDeltas = final; |
| + }; |
| + } |
| + |
| + window.setTimeout(waitFinishedCallback(initialStats), %d); |
| + """ % (int(duration) * 1000) |
| + |
| + tab.runtime.Evaluate(wait_js) |
| + |
| + # Poll for scroll benchmark completion. |
| + util.WaitFor(lambda: tab.runtime.Evaluate( |
| + 'window.__renderingStatsDeltas'), 60) |