Commit 18d8eef0 authored by nduca@chromium.org's avatar nduca@chromium.org

[telemetry] Clean up image decoding benchmark

The image decoding benchmark still contained some logic for navigation/test
control. The image_decoding_benchmark should measure image decodign times. Critically, the
logic to make chrome/test/data/image_decoding/image_decoding.html do its work
should be handled by the page runner, not the benchmark. To make this
separation happen, three changes are made...

First, page runner now notifies the test that naivgation will happen. This
allows us to begin recording the timeline right before navigation. This is when timeline
recording should begin for image decode tests.

Second, this adds a post_navigate_javascript_to_execute method to the page. This allows us to
call runBenchmark() on the image decoding benchmarks after we navigate.

Finally, the benchmark uses the standard wait_for_javascript_expression to poll
the isDone variable.The old code actually did this in python.

R=tonyg
NOTRY=True

Review URL: https://chromiumcodereview.appspot.com/11753023

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@175404 0039d316-1c4b-4281-b951-d872f2087c98
parent b448570b
{
"description": "A directed benchmark of image decoding performance",
"pages": [
{
"url": "file:///../../../chrome/test/data/image_decoding/image_decoding.html?gif",
"post_navigate_javascript_to_execute": "runBenchmark();",
"wait_for_javascript_expression": "isDone",
"image_decoding_benchmark_limit_results_to_min_iterations": true
},
{
"url": "file:///../../../chrome/test/data/image_decoding/image_decoding.html?jpg",
"post_navigate_javascript_to_execute": "runBenchmark();",
"wait_for_javascript_expression": "isDone",
"image_decoding_benchmark_limit_results_to_min_iterations": true
},
{
"url": "file:///../../../chrome/test/data/image_decoding/image_decoding.html?png",
"post_navigate_javascript_to_execute": "runBenchmark();",
"wait_for_javascript_expression": "isDone",
"image_decoding_benchmark_limit_results_to_min_iterations": true
}
]
}
{
"description": "A collection of image-heavy sites.",
"user_agent_type": "desktop",
"pages": [
{
"url": "http://www.free-pictures-photos.com/aviation/airplane-306.jpg"
},
{
"url": "http://upload.wikimedia.org/wikipedia/commons/c/cb/General_history%2C_Alaska_Yukon_Pacific_Exposition%2C_fully_illustrated_-_meet_me_in_Seattle_1909_-_Page_78.jpg"
}
]
}
{
"description": "A collection of image decoding performance tests",
"description": "**THIS IS OBSOLETE, EDIT image_decoding_benchmark.json instead***",
"pages": [
{"url": "file:///../../../chrome/test/data/image_decoding/image_decoding.html?gif"},
{"url": "file:///../../../chrome/test/data/image_decoding/image_decoding.html?jpg"},
{"url": "file:///../../../chrome/test/data/image_decoding/image_decoding.html?png"}
{
"url": "file:///../../../chrome/test/data/image_decoding/image_decoding.html?gif",
"post_navigate_javascript_to_execute": "runBenchmark();",
"wait_for_javascript_expression": "isDone",
"image_decoding_benchmark_limit_results_to_min_iterations": true
},
{
"url": "file:///../../../chrome/test/data/image_decoding/image_decoding.html?jpg",
"post_navigate_javascript_to_execute": "runBenchmark();",
"wait_for_javascript_expression": "isDone",
"image_decoding_benchmark_limit_results_to_min_iterations": true
},
{
"url": "file:///../../../chrome/test/data/image_decoding/image_decoding.html?png",
"post_navigate_javascript_to_execute": "runBenchmark();",
"wait_for_javascript_expression": "isDone",
"image_decoding_benchmark_limit_results_to_min_iterations": true
}
]
}
......@@ -3,20 +3,30 @@
# found in the LICENSE file.
from telemetry import multi_page_benchmark
from telemetry import util
class ImageDecoding(multi_page_benchmark.MultiPageBenchmark):
def MeasurePage(self, _, tab, results):
def WillNavigateToPage(self, page, tab):
tab.timeline.Start()
def MeasurePage(self, page, tab, results):
tab.timeline.Stop()
def _IsDone():
return tab.runtime.Evaluate('isDone')
with tab.timeline.Recorder(tab.timeline):
tab.runtime.Execute('runBenchmark()')
util.WaitFor(_IsDone, 60)
iterations = tab.runtime.Evaluate('minIterations')
decode_image = tab.timeline.timeline_events.GetAllOfType('DecodeImage')
elapsed_times = [d.elapsed_time for d in decode_image[-iterations:]]
decode_image_events = \
tab.timeline.timeline_events.GetAllOfType('DecodeImage')
# If it is a real image benchmark, then store only the last-minIterations
# decode tasks.
if (hasattr(page,
'image_decoding_benchmark_limit_results_to_min_iterations') and
page.image_decoding_benchmark_limit_results_to_min_iterations):
assert _IsDone()
min_iterations = tab.runtime.Evaluate('minIterations')
decode_image_events = decode_image_events[-min_iterations:]
elapsed_times = [d.elapsed_time for d in decode_image_events]
if not elapsed_times:
results.Add('ImageDecoding_avg', 'ms', 'unsupported')
return
......
......@@ -67,6 +67,9 @@ class Page(object):
@staticmethod
def WaitForPageToLoad(obj, tab, timeout, poll_interval=0.1):
"""Waits for various wait conditions present in obj."""
if hasattr(obj, 'post_navigate_javascript_to_execute'):
tab.runtime.Evaluate(obj.post_navigate_javascript_to_execute)
if hasattr(obj, 'wait_seconds'):
time.sleep(obj.wait_seconds)
if hasattr(obj, 'wait_for_element_with_text'):
......
......@@ -155,7 +155,7 @@ http://goto/read-src-internal, or create a new archive using record_wpr.
page_state = PageState()
try:
did_prepare = self._PreparePage(page, tab, page_state, results)
did_prepare = self._PreparePage(page, tab, page_state, test, results)
except util.TimeoutException, ex:
logging.warning('Timed out waiting for reply on %s. This is unusual.',
page.url)
......@@ -245,7 +245,7 @@ http://goto/read-src-internal, or create a new archive using record_wpr.
trace_file.write(trace)
logging.info('Trace saved.')
def _PreparePage(self, page, tab, page_state, results):
def _PreparePage(self, page, tab, page_state, test, results):
parsed_url = urlparse.urlparse(page.url)
if parsed_url[0] == 'file':
dirname, filename = page.url_base_dir_and_file
......@@ -264,13 +264,16 @@ http://goto/read-src-internal, or create a new archive using record_wpr.
results.AddFailure(page, msg, "")
return False
test.WillNavigateToPage(page, tab)
tab.page.Navigate(target_side_url)
test.DidNavigateToPage(page, tab)
# Wait for unpredictable redirects.
if page.wait_time_after_navigate:
time.sleep(page.wait_time_after_navigate)
page.WaitToLoad(tab, 60)
tab.WaitForDocumentReadyStateToBeInteractiveOrBetter()
return True
def _CleanUpPage(self, page, tab, page_state): # pylint: disable=R0201
......
......@@ -65,6 +65,15 @@ class PageTest(object):
"""Override to customize if the test can be ran for the given page."""
return True
def WillNavigateToPage(self, page, tab):
"""Override to do operations before the page is navigated."""
pass
def DidNavigateToPage(self, page, tab):
"""Override to do operations right after the page is navigated, but before
any waiting for completion has occurred."""
pass
def WillRunInteraction(self, page, tab):
"""Override to do operations before running the interaction on the page."""
pass
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment