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 3 # found in the LICENSE file. 4 5 from metrics import Metric 6 from telemetry.value import scalar 7 8 9 class IOMetric(Metric): 10 """IO-related metrics, obtained via telemetry.core.Browser.""" 11 12 @classmethod 13 def CustomizeBrowserOptions(cls, options): 14 if options.platform.GetOSName() != 'mac': 15 # FIXME: Get rid of this on all platforms - http://crbug.com/361049 . 16 options.AppendExtraBrowserArgs('--no-sandbox') 17 18 def Start(self, page, tab): 19 raise NotImplementedError() 20 21 def Stop(self, page, tab): 22 raise NotImplementedError() 23 24 def AddResults(self, tab, results): 25 # This metric currently only returns summary results, not per-page results. 26 raise NotImplementedError() 27 28 def AddSummaryResults(self, browser, results): 29 """Add summary results to the results object.""" 30 io_stats = browser.io_stats 31 if not io_stats['Browser']: 32 return 33 34 def AddSummariesForProcessType(process_type_io, process_type_trace): 35 """For a given process type, add all relevant summary results. 36 37 Args: 38 process_type_io: Type of process (eg Browser or Renderer). 39 process_type_trace: String to be added to the trace name in the results. 40 """ 41 42 def AddSummaryForOperation(operation_name, trace_name_prefix, units): 43 """Adds summary results for an operation in a process. 44 45 Args: 46 operation_name: The name of the operation, e.g. 'ReadOperationCount' 47 trace_name_prefix: The prefix for the trace name. 48 """ 49 if operation_name in io_stats[process_type_io]: 50 value = io_stats[process_type_io][operation_name] 51 if units == 'kb': 52 value = value / 1024 53 results.AddSummaryValue( 54 scalar.ScalarValue(None, trace_name_prefix + process_type_trace, 55 units, value, important=False)) 56 57 AddSummaryForOperation('ReadOperationCount', 'read_operations_', 'count') 58 AddSummaryForOperation('WriteOperationCount', 'write_operations_', 59 'count') 60 AddSummaryForOperation('ReadTransferCount', 'read_bytes_', 'kb') 61 AddSummaryForOperation('WriteTransferCount', 'write_bytes_', 'kb') 62 63 AddSummariesForProcessType('Browser', 'browser') 64 AddSummariesForProcessType('Renderer', 'renderer') 65 AddSummariesForProcessType('Gpu', 'gpu') 66