| OLD | NEW |
| 1 # Copyright 2012 The Chromium Authors. All rights reserved. | 1 # Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 from telemetry.page import legacy_page_test | 5 from telemetry.page import legacy_page_test |
| 6 from telemetry.timeline import model | 6 from telemetry.timeline import model |
| 7 from telemetry.timeline import tracing_config | 7 from telemetry.timeline import tracing_config |
| 8 from telemetry.value import scalar | 8 from telemetry.value import scalar |
| 9 | 9 |
| 10 from metrics import power | 10 from metrics import power |
| 11 | 11 |
| 12 | 12 |
| 13 class ImageDecoding(legacy_page_test.LegacyPageTest): | 13 class ImageDecoding(legacy_page_test.LegacyPageTest): |
| 14 | 14 |
| 15 def __init__(self): | 15 def __init__(self): |
| 16 super(ImageDecoding, self).__init__() | 16 super(ImageDecoding, self).__init__() |
| 17 self._power_metric = None | 17 self._power_metric = None |
| 18 | 18 |
| 19 def CustomizeBrowserOptions(self, options): | 19 def CustomizeBrowserOptions(self, options): |
| 20 options.AppendExtraBrowserArgs('--enable-gpu-benchmarking') | 20 options.AppendExtraBrowserArgs('--enable-gpu-benchmarking') |
| 21 power.PowerMetric.CustomizeBrowserOptions(options) | 21 power.PowerMetric.CustomizeBrowserOptions(options) |
| 22 | 22 |
| 23 def WillStartBrowser(self, platform): | 23 def WillStartBrowser(self, platform): |
| 24 self._power_metric = power.PowerMetric(platform) | 24 self._power_metric = power.PowerMetric(platform) |
| 25 | 25 |
| 26 def WillNavigateToPage(self, page, tab): | 26 def WillNavigateToPage(self, page, tab): |
| 27 tab.ExecuteJavaScript2(""" | 27 tab.ExecuteJavaScript(""" |
| 28 if (window.chrome && | 28 if (window.chrome && |
| 29 chrome.gpuBenchmarking && | 29 chrome.gpuBenchmarking && |
| 30 chrome.gpuBenchmarking.clearImageCache) { | 30 chrome.gpuBenchmarking.clearImageCache) { |
| 31 chrome.gpuBenchmarking.clearImageCache(); | 31 chrome.gpuBenchmarking.clearImageCache(); |
| 32 } | 32 } |
| 33 """) | 33 """) |
| 34 self._power_metric.Start(page, tab) | 34 self._power_metric.Start(page, tab) |
| 35 | 35 |
| 36 config = tracing_config.TracingConfig() | 36 config = tracing_config.TracingConfig() |
| 37 # FIXME: Remove the timeline category when impl-side painting is on | 37 # FIXME: Remove the timeline category when impl-side painting is on |
| 38 # everywhere. | 38 # everywhere. |
| 39 # FIXME: Remove webkit.console when blink.console lands in chromium and | 39 # FIXME: Remove webkit.console when blink.console lands in chromium and |
| 40 # the ref builds are updated. crbug.com/386847 | 40 # the ref builds are updated. crbug.com/386847 |
| 41 # FIXME: Remove the devtools.timeline category when impl-side painting is | 41 # FIXME: Remove the devtools.timeline category when impl-side painting is |
| 42 # on everywhere. | 42 # on everywhere. |
| 43 config.chrome_trace_config.category_filter.AddDisabledByDefault( | 43 config.chrome_trace_config.category_filter.AddDisabledByDefault( |
| 44 'disabled-by-default-devtools.timeline') | 44 'disabled-by-default-devtools.timeline') |
| 45 for c in ['blink', 'devtools.timeline', 'webkit.console', 'blink.console']: | 45 for c in ['blink', 'devtools.timeline', 'webkit.console', 'blink.console']: |
| 46 config.chrome_trace_config.category_filter.AddIncludedCategory(c) | 46 config.chrome_trace_config.category_filter.AddIncludedCategory(c) |
| 47 config.enable_chrome_trace = True | 47 config.enable_chrome_trace = True |
| 48 tab.browser.platform.tracing_controller.StartTracing(config) | 48 tab.browser.platform.tracing_controller.StartTracing(config) |
| 49 | 49 |
| 50 def StopBrowserAfterPage(self, browser, page): | 50 def StopBrowserAfterPage(self, browser, page): |
| 51 del page # unused | 51 del page # unused |
| 52 return not browser.tabs[0].ExecuteJavaScript2(""" | 52 return not browser.tabs[0].ExecuteJavaScript(""" |
| 53 window.chrome && | 53 window.chrome && |
| 54 chrome.gpuBenchmarking && | 54 chrome.gpuBenchmarking && |
| 55 chrome.gpuBenchmarking.clearImageCache; | 55 chrome.gpuBenchmarking.clearImageCache; |
| 56 """) | 56 """) |
| 57 | 57 |
| 58 def ValidateAndMeasurePage(self, page, tab, results): | 58 def ValidateAndMeasurePage(self, page, tab, results): |
| 59 timeline_data = tab.browser.platform.tracing_controller.StopTracing() | 59 timeline_data = tab.browser.platform.tracing_controller.StopTracing() |
| 60 timeline_model = model.TimelineModel(timeline_data) | 60 timeline_model = model.TimelineModel(timeline_data) |
| 61 self._power_metric.Stop(page, tab) | 61 self._power_metric.Stop(page, tab) |
| 62 self._power_metric.AddResults(tab, results) | 62 self._power_metric.AddResults(tab, results) |
| 63 | 63 |
| 64 def _IsDone(): | 64 def _IsDone(): |
| 65 return tab.EvaluateJavaScript2('isDone') | 65 return tab.EvaluateJavaScript('isDone') |
| 66 | 66 |
| 67 decode_image_events = timeline_model.GetAllEventsOfName( | 67 decode_image_events = timeline_model.GetAllEventsOfName( |
| 68 'ImageFrameGenerator::decode') | 68 'ImageFrameGenerator::decode') |
| 69 # FIXME: Remove this when impl-side painting is on everywhere. | 69 # FIXME: Remove this when impl-side painting is on everywhere. |
| 70 if not decode_image_events: | 70 if not decode_image_events: |
| 71 decode_image_events = timeline_model.GetAllEventsOfName('Decode Image') | 71 decode_image_events = timeline_model.GetAllEventsOfName('Decode Image') |
| 72 | 72 |
| 73 # If it is a real image page, then store only the last-minIterations | 73 # If it is a real image page, then store only the last-minIterations |
| 74 # decode tasks. | 74 # decode tasks. |
| 75 if (hasattr( | 75 if (hasattr( |
| 76 page, | 76 page, |
| 77 'image_decoding_measurement_limit_results_to_min_iterations') and | 77 'image_decoding_measurement_limit_results_to_min_iterations') and |
| 78 page.image_decoding_measurement_limit_results_to_min_iterations): | 78 page.image_decoding_measurement_limit_results_to_min_iterations): |
| 79 assert _IsDone() | 79 assert _IsDone() |
| 80 min_iterations = tab.EvaluateJavaScript2('minIterations') | 80 min_iterations = tab.EvaluateJavaScript('minIterations') |
| 81 decode_image_events = decode_image_events[-min_iterations:] | 81 decode_image_events = decode_image_events[-min_iterations:] |
| 82 | 82 |
| 83 durations = [d.duration for d in decode_image_events] | 83 durations = [d.duration for d in decode_image_events] |
| 84 assert durations, 'Failed to find image decode trace events.' | 84 assert durations, 'Failed to find image decode trace events.' |
| 85 | 85 |
| 86 image_decoding_avg = sum(durations) / len(durations) | 86 image_decoding_avg = sum(durations) / len(durations) |
| 87 results.AddValue(scalar.ScalarValue( | 87 results.AddValue(scalar.ScalarValue( |
| 88 results.current_page, 'ImageDecoding_avg', 'ms', image_decoding_avg, | 88 results.current_page, 'ImageDecoding_avg', 'ms', image_decoding_avg, |
| 89 description='Average decode time for images in 4 different ' | 89 description='Average decode time for images in 4 different ' |
| 90 'formats: gif, png, jpg, and webp. The image files are ' | 90 'formats: gif, png, jpg, and webp. The image files are ' |
| 91 'located at chrome/test/data/image_decoding.')) | 91 'located at chrome/test/data/image_decoding.')) |
| 92 results.AddValue(scalar.ScalarValue( | 92 results.AddValue(scalar.ScalarValue( |
| 93 results.current_page, 'ImageLoading_avg', 'ms', | 93 results.current_page, 'ImageLoading_avg', 'ms', |
| 94 tab.EvaluateJavaScript2('averageLoadingTimeMs()'))) | 94 tab.EvaluateJavaScript('averageLoadingTimeMs()'))) |
| 95 | 95 |
| 96 def DidRunPage(self, platform): | 96 def DidRunPage(self, platform): |
| 97 self._power_metric.Close() | 97 self._power_metric.Close() |
| 98 if platform.tracing_controller.is_tracing_running: | 98 if platform.tracing_controller.is_tracing_running: |
| 99 platform.tracing_controller.StopTracing() | 99 platform.tracing_controller.StopTracing() |
| OLD | NEW |