| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 import collections | 4 import collections |
| 5 import logging | 5 import logging |
| 6 from collections import defaultdict | 6 from collections import defaultdict |
| 7 | 7 |
| 8 from tracing.metrics import metric_runner | 8 from tracing.metrics import metric_runner |
| 9 | 9 |
| 10 from telemetry.timeline import chrome_trace_category_filter |
| 10 from telemetry.timeline import model as model_module | 11 from telemetry.timeline import model as model_module |
| 11 from telemetry.timeline import tracing_category_filter | |
| 12 from telemetry.timeline import tracing_config | 12 from telemetry.timeline import tracing_config |
| 13 from telemetry.value import trace | 13 from telemetry.value import trace |
| 14 from telemetry.value import common_value_helpers | 14 from telemetry.value import common_value_helpers |
| 15 from telemetry.web_perf.metrics import timeline_based_metric | 15 from telemetry.web_perf.metrics import timeline_based_metric |
| 16 from telemetry.web_perf.metrics import blob_timeline | 16 from telemetry.web_perf.metrics import blob_timeline |
| 17 from telemetry.web_perf.metrics import jitter_timeline | 17 from telemetry.web_perf.metrics import jitter_timeline |
| 18 from telemetry.web_perf.metrics import webrtc_rendering_timeline | 18 from telemetry.web_perf.metrics import webrtc_rendering_timeline |
| 19 from telemetry.web_perf.metrics import gpu_timeline | 19 from telemetry.web_perf.metrics import gpu_timeline |
| 20 from telemetry.web_perf.metrics import indexeddb_timeline | 20 from telemetry.web_perf.metrics import indexeddb_timeline |
| 21 from telemetry.web_perf.metrics import layout | 21 from telemetry.web_perf.metrics import layout |
| 22 from telemetry.web_perf.metrics import memory_timeline | 22 from telemetry.web_perf.metrics import memory_timeline |
| 23 from telemetry.web_perf.metrics import smoothness | 23 from telemetry.web_perf.metrics import smoothness |
| 24 from telemetry.web_perf.metrics import text_selection | 24 from telemetry.web_perf.metrics import text_selection |
| 25 from telemetry.web_perf import smooth_gesture_util | 25 from telemetry.web_perf import smooth_gesture_util |
| 26 from telemetry.web_perf import story_test | 26 from telemetry.web_perf import story_test |
| 27 from telemetry.web_perf import timeline_interaction_record as tir_module | 27 from telemetry.web_perf import timeline_interaction_record as tir_module |
| 28 | 28 |
| 29 # TimelineBasedMeasurement considers all instrumentation as producing a single | 29 # TimelineBasedMeasurement considers all instrumentation as producing a single |
| 30 # timeline. But, depending on the amount of instrumentation that is enabled, | 30 # timeline. But, depending on the amount of instrumentation that is enabled, |
| 31 # overhead increases. The user of the measurement must therefore chose between | 31 # overhead increases. The user of the measurement must therefore chose between |
| 32 # a few levels of instrumentation. | 32 # a few levels of instrumentation. |
| 33 NO_OVERHEAD_LEVEL = 'no-overhead' | 33 LOW_OVERHEAD_LEVEL = 'low-overhead' |
| 34 MINIMAL_OVERHEAD_LEVEL = 'minimal-overhead' | 34 DEFAULT_OVERHEAD_LEVEL = 'default-overhead' |
| 35 DEBUG_OVERHEAD_LEVEL = 'debug-overhead' | 35 DEBUG_OVERHEAD_LEVEL = 'debug-overhead' |
| 36 | 36 |
| 37 ALL_OVERHEAD_LEVELS = [ | 37 ALL_OVERHEAD_LEVELS = [ |
| 38 NO_OVERHEAD_LEVEL, | 38 LOW_OVERHEAD_LEVEL, |
| 39 MINIMAL_OVERHEAD_LEVEL, | 39 DEFAULT_OVERHEAD_LEVEL, |
| 40 DEBUG_OVERHEAD_LEVEL | 40 DEBUG_OVERHEAD_LEVEL, |
| 41 ] | 41 ] |
| 42 | 42 |
| 43 | 43 |
| 44 def _GetAllLegacyTimelineBasedMetrics(): | 44 def _GetAllLegacyTimelineBasedMetrics(): |
| 45 # TODO(nednguyen): use discovery pattern to return all the instances of | 45 # TODO(nednguyen): use discovery pattern to return all the instances of |
| 46 # all TimelineBasedMetrics class in web_perf/metrics/ folder. | 46 # all TimelineBasedMetrics class in web_perf/metrics/ folder. |
| 47 # This cannot be done until crbug.com/460208 is fixed. | 47 # This cannot be done until crbug.com/460208 is fixed. |
| 48 return (smoothness.SmoothnessMetric(), | 48 return (smoothness.SmoothnessMetric(), |
| 49 layout.LayoutMetric(), | 49 layout.LayoutMetric(), |
| 50 gpu_timeline.GPUTimelineMetric(), | 50 gpu_timeline.GPUTimelineMetric(), |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 | 152 |
| 153 | 153 |
| 154 class Options(object): | 154 class Options(object): |
| 155 """A class to be used to configure TimelineBasedMeasurement. | 155 """A class to be used to configure TimelineBasedMeasurement. |
| 156 | 156 |
| 157 This is created and returned by | 157 This is created and returned by |
| 158 Benchmark.CreateTimelineBasedMeasurementOptions. | 158 Benchmark.CreateTimelineBasedMeasurementOptions. |
| 159 | 159 |
| 160 By default, all the timeline based metrics in telemetry/web_perf/metrics are | 160 By default, all the timeline based metrics in telemetry/web_perf/metrics are |
| 161 used (see _GetAllLegacyTimelineBasedMetrics above). | 161 used (see _GetAllLegacyTimelineBasedMetrics above). |
| 162 To customize your metric needs, use SetTimelineBasedMetric(). | 162 To customize your metric needs, use SetTimelineBasedMetrics(). |
| 163 """ | 163 """ |
| 164 | 164 |
| 165 def __init__(self, overhead_level=NO_OVERHEAD_LEVEL): | 165 def __init__(self, overhead_level=LOW_OVERHEAD_LEVEL): |
| 166 """As the amount of instrumentation increases, so does the overhead. | 166 """As the amount of instrumentation increases, so does the overhead. |
| 167 The user of the measurement chooses the overhead level that is appropriate, | 167 The user of the measurement chooses the overhead level that is appropriate, |
| 168 and the tracing is filtered accordingly. | 168 and the tracing is filtered accordingly. |
| 169 | 169 |
| 170 overhead_level: Can either be a custom TracingCategoryFilter object or | 170 overhead_level: Can either be a custom ChromeTraceCategoryFilter object or |
| 171 one of NO_OVERHEAD_LEVEL, MINIMAL_OVERHEAD_LEVEL or | 171 one of LOW_OVERHEAD_LEVEL, DEFAULT_OVERHEAD_LEVEL or |
| 172 DEBUG_OVERHEAD_LEVEL. | 172 DEBUG_OVERHEAD_LEVEL. |
| 173 """ | 173 """ |
| 174 self._config = tracing_config.TracingConfig() | 174 self._config = tracing_config.TracingConfig() |
| 175 self._config.enable_chrome_trace = True | 175 self._config.enable_chrome_trace = True |
| 176 self._config.enable_platform_display_trace = False | 176 self._config.enable_platform_display_trace = False |
| 177 | 177 |
| 178 if isinstance(overhead_level, | 178 if isinstance(overhead_level, |
| 179 tracing_category_filter.TracingCategoryFilter): | 179 chrome_trace_category_filter.ChromeTraceCategoryFilter): |
| 180 self._config.chrome_trace_config.SetTracingCategoryFilter(overhead_level) | 180 self._config.chrome_trace_config.SetCategoryFilter(overhead_level) |
| 181 elif overhead_level in ALL_OVERHEAD_LEVELS: | 181 elif overhead_level in ALL_OVERHEAD_LEVELS: |
| 182 if overhead_level == NO_OVERHEAD_LEVEL: | 182 if overhead_level == LOW_OVERHEAD_LEVEL: |
| 183 self._config.chrome_trace_config.SetNoOverheadFilter() | 183 self._config.chrome_trace_config.SetLowOverheadFilter() |
| 184 elif overhead_level == MINIMAL_OVERHEAD_LEVEL: | 184 elif overhead_level == DEFAULT_OVERHEAD_LEVEL: |
| 185 self._config.chrome_trace_config.SetMinimalOverheadFilter() | 185 self._config.chrome_trace_config.SetDefaultOverheadFilter() |
| 186 else: | 186 else: |
| 187 self._config.chrome_trace_config.SetDebugOverheadFilter() | 187 self._config.chrome_trace_config.SetDebugOverheadFilter() |
| 188 else: | 188 else: |
| 189 raise Exception("Overhead level must be a TracingCategoryFilter object" | 189 raise Exception("Overhead level must be a ChromeTraceCategoryFilter " |
| 190 " or valid overhead level string." | 190 "object or valid overhead level string. Given overhead " |
| 191 " Given overhead level: %s" % overhead_level) | 191 "level: %s" % overhead_level) |
| 192 | 192 |
| 193 self._timeline_based_metric = None | 193 self._timeline_based_metrics = None |
| 194 self._legacy_timeline_based_metrics = [] | 194 self._legacy_timeline_based_metrics = [] |
| 195 | 195 |
| 196 | 196 |
| 197 def ExtendTraceCategoryFilter(self, filters): | 197 def ExtendTraceCategoryFilter(self, filters): |
| 198 category_filter = self._config.chrome_trace_config.tracing_category_filter | 198 category_filter = self._config.chrome_trace_config.category_filter |
| 199 for new_category_filter in filters: | 199 for new_category_filter in filters: |
| 200 category_filter.AddIncludedCategory(new_category_filter) | 200 category_filter.AddIncludedCategory(new_category_filter) |
| 201 | 201 |
| 202 @property | 202 @property |
| 203 def category_filter(self): | 203 def category_filter(self): |
| 204 return self._config.chrome_trace_config.tracing_category_filter | 204 return self._config.chrome_trace_config.category_filter |
| 205 | 205 |
| 206 @property | 206 @property |
| 207 def config(self): | 207 def config(self): |
| 208 return self._config | 208 return self._config |
| 209 | 209 |
| 210 def SetTimelineBasedMetric(self, metric): | 210 def SetTimelineBasedMetrics(self, metrics): |
| 211 """Sets the new-style (TBMv2) metric to run. | 211 """Sets the new-style (TBMv2) metrics to run. |
| 212 | 212 |
| 213 Metrics are assumed to live in //tracing/tracing/metrics, so the path | 213 Metrics are assumed to live in //tracing/tracing/metrics, so the path you |
| 214 should be relative to that. For example, to specify sample_metric.html, | 214 pass in should be relative to that. For example, to specify |
| 215 you would pass 'sample_metric.html'. | 215 sample_metric.html, you should pass in ['sample_metric.html']. |
| 216 | 216 |
| 217 Args: | 217 Args: |
| 218 metric: A string metric path under //tracing/tracing/metrics. | 218 metrics: A list of strings giving metric paths under |
| 219 //tracing/tracing/metrics. |
| 219 """ | 220 """ |
| 220 assert isinstance(metric, basestring) | 221 assert isinstance(metrics, list) |
| 221 self._timeline_based_metric = metric | 222 for metric in metrics: |
| 223 assert isinstance(metric, basestring) |
| 224 self._timeline_based_metrics = metrics |
| 222 | 225 |
| 223 def GetTimelineBasedMetric(self): | 226 def GetTimelineBasedMetrics(self): |
| 224 return self._timeline_based_metric | 227 return self._timeline_based_metrics |
| 225 | 228 |
| 226 def SetLegacyTimelineBasedMetrics(self, metrics): | 229 def SetLegacyTimelineBasedMetrics(self, metrics): |
| 227 assert isinstance(metrics, collections.Iterable) | 230 assert isinstance(metrics, collections.Iterable) |
| 228 for m in metrics: | 231 for m in metrics: |
| 229 assert isinstance(m, timeline_based_metric.TimelineBasedMetric) | 232 assert isinstance(m, timeline_based_metric.TimelineBasedMetric) |
| 230 self._legacy_timeline_based_metrics = metrics | 233 self._legacy_timeline_based_metrics = metrics |
| 231 | 234 |
| 232 def GetLegacyTimelineBasedMetrics(self): | 235 def GetLegacyTimelineBasedMetrics(self): |
| 233 return self._legacy_timeline_based_metrics | 236 return self._legacy_timeline_based_metrics |
| 234 | 237 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 raise Exception('Not supported') | 275 raise Exception('Not supported') |
| 273 platform.tracing_controller.StartTracing(self._tbm_options.config) | 276 platform.tracing_controller.StartTracing(self._tbm_options.config) |
| 274 | 277 |
| 275 def Measure(self, platform, results): | 278 def Measure(self, platform, results): |
| 276 """Collect all possible metrics and added them to results.""" | 279 """Collect all possible metrics and added them to results.""" |
| 277 platform.tracing_controller.iteration_info = results.iteration_info | 280 platform.tracing_controller.iteration_info = results.iteration_info |
| 278 trace_result = platform.tracing_controller.StopTracing() | 281 trace_result = platform.tracing_controller.StopTracing() |
| 279 trace_value = trace.TraceValue(results.current_page, trace_result) | 282 trace_value = trace.TraceValue(results.current_page, trace_result) |
| 280 results.AddValue(trace_value) | 283 results.AddValue(trace_value) |
| 281 | 284 |
| 282 if self._tbm_options.GetTimelineBasedMetric(): | 285 if self._tbm_options.GetTimelineBasedMetrics(): |
| 283 self._ComputeTimelineBasedMetric(results, trace_value) | 286 self._ComputeTimelineBasedMetrics(results, trace_value) |
| 284 # Legacy metrics can be computed, but only if explicitly specified. | 287 # Legacy metrics can be computed, but only if explicitly specified. |
| 285 if self._tbm_options.GetLegacyTimelineBasedMetrics(): | 288 if self._tbm_options.GetLegacyTimelineBasedMetrics(): |
| 286 self._ComputeLegacyTimelineBasedMetrics(results, trace_result) | 289 self._ComputeLegacyTimelineBasedMetrics(results, trace_result) |
| 287 else: | 290 else: |
| 288 # Run all TBMv1 metrics if no other metric is specified (legacy behavior) | 291 # Run all TBMv1 metrics if no other metric is specified (legacy behavior) |
| 289 if not self._tbm_options.GetLegacyTimelineBasedMetrics(): | 292 if not self._tbm_options.GetLegacyTimelineBasedMetrics(): |
| 290 logging.warn('Please specify the TBMv1 metrics you are interested in ' | 293 logging.warn('Please specify the TBMv1 metrics you are interested in ' |
| 291 'explicitly. This implicit functionality will be removed ' | 294 'explicitly. This implicit functionality will be removed ' |
| 292 'on July 17, 2016.') | 295 'on July 17, 2016.') |
| 293 self._tbm_options.SetLegacyTimelineBasedMetrics( | 296 self._tbm_options.SetLegacyTimelineBasedMetrics( |
| 294 _GetAllLegacyTimelineBasedMetrics()) | 297 _GetAllLegacyTimelineBasedMetrics()) |
| 295 self._ComputeLegacyTimelineBasedMetrics(results, trace_result) | 298 self._ComputeLegacyTimelineBasedMetrics(results, trace_result) |
| 296 | 299 |
| 297 def DidRunStory(self, platform): | 300 def DidRunStory(self, platform): |
| 298 """Clean up after running the story.""" | 301 """Clean up after running the story.""" |
| 299 if platform.tracing_controller.is_tracing_running: | 302 if platform.tracing_controller.is_tracing_running: |
| 300 platform.tracing_controller.StopTracing() | 303 platform.tracing_controller.StopTracing() |
| 301 | 304 |
| 302 def _ComputeTimelineBasedMetric(self, results, trace_value): | 305 def _ComputeTimelineBasedMetrics(self, results, trace_value): |
| 303 metric = self._tbm_options.GetTimelineBasedMetric() | 306 metrics = self._tbm_options.GetTimelineBasedMetrics() |
| 304 extra_import_options = { | 307 extra_import_options = { |
| 305 'trackDetailedModelStats': True | 308 'trackDetailedModelStats': True |
| 306 } | 309 } |
| 307 | 310 |
| 308 mre_result = metric_runner.RunMetric( | 311 mre_result = metric_runner.RunMetric( |
| 309 trace_value.filename, metric, extra_import_options) | 312 trace_value.filename, metrics, extra_import_options) |
| 310 page = results.current_page | 313 page = results.current_page |
| 311 | 314 |
| 312 failure_dicts = mre_result.failures | 315 failure_dicts = mre_result.failures |
| 313 for d in failure_dicts: | 316 for d in failure_dicts: |
| 314 results.AddValue( | 317 results.AddValue( |
| 315 common_value_helpers.TranslateMreFailure(d, page)) | 318 common_value_helpers.TranslateMreFailure(d, page)) |
| 316 | 319 |
| 317 value_dicts = mre_result.pairs.get('values', []) | 320 value_dicts = mre_result.pairs.get('values', []) |
| 318 results.value_set.extend(value_dicts) | 321 results.value_set.extend(value_dicts) |
| 319 for d in value_dicts: | 322 for d in value_dicts: |
| (...skipping 16 matching lines...) Expand all Loading... |
| 336 | 339 |
| 337 for renderer_thread, interaction_records in ( | 340 for renderer_thread, interaction_records in ( |
| 338 threads_to_records_map.iteritems()): | 341 threads_to_records_map.iteritems()): |
| 339 meta_metrics = _TimelineBasedMetrics( | 342 meta_metrics = _TimelineBasedMetrics( |
| 340 model, renderer_thread, interaction_records, self._results_wrapper, | 343 model, renderer_thread, interaction_records, self._results_wrapper, |
| 341 all_metrics) | 344 all_metrics) |
| 342 meta_metrics.AddResults(results) | 345 meta_metrics.AddResults(results) |
| 343 | 346 |
| 344 for metric in all_metrics: | 347 for metric in all_metrics: |
| 345 metric.AddWholeTraceResults(model, results) | 348 metric.AddWholeTraceResults(model, results) |
| OLD | NEW |