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.
7 from metrics
import Metric
8 from telemetry
.value
import scalar
11 class IOMetric(Metric
):
12 """IO-related metrics, obtained via telemetry.core.Browser."""
15 def CustomizeBrowserOptions(cls
, options
):
16 # TODO(tonyg): This is the host platform, so not totally correct.
17 if sys
.platform
not in ('darwin', 'win32'):
18 # TODO(playmobil): Get rid of this on all platforms crbug.com/361049.
19 options
.AppendExtraBrowserArgs('--no-sandbox')
21 def Start(self
, page
, tab
):
22 raise NotImplementedError()
24 def Stop(self
, page
, tab
):
25 raise NotImplementedError()
27 def AddResults(self
, tab
, results
):
28 # This metric currently only returns summary results, not per-page results.
29 raise NotImplementedError()
31 def AddSummaryResults(self
, browser
, results
):
32 """Add summary results to the results object."""
33 io_stats
= browser
.io_stats
34 if not io_stats
['Browser']:
37 def AddSummariesForProcessType(process_type_io
, process_type_trace
):
38 """For a given process type, add all relevant summary results.
41 process_type_io: Type of process (eg Browser or Renderer).
42 process_type_trace: String to be added to the trace name in the results.
45 def AddSummaryForOperation(operation_name
, trace_name_prefix
, units
,
47 """Adds summary results for an operation in a process.
50 operation_name: The name of the operation, e.g. 'ReadOperationCount'
51 trace_name_prefix: The prefix for the trace name.
53 if operation_name
in io_stats
[process_type_io
]:
54 value
= io_stats
[process_type_io
][operation_name
]
57 results
.AddSummaryValue(
58 scalar
.ScalarValue(None, trace_name_prefix
+ process_type_trace
,
59 units
, value
, important
=False,
60 description
=description
))
62 AddSummaryForOperation('ReadOperationCount', 'read_operations_', 'count',
63 'Number of IO read operations.')
64 AddSummaryForOperation('WriteOperationCount', 'write_operations_',
65 'count', 'Number of IO write operations.')
66 AddSummaryForOperation('ReadTransferCount', 'read_bytes_', 'kb',
67 'Number of IO bytes read.')
68 AddSummaryForOperation('WriteTransferCount', 'write_bytes_', 'kb',
69 'Number of IO bytes written.')
71 AddSummariesForProcessType('Browser', 'browser')
72 AddSummariesForProcessType('Renderer', 'renderer')
73 AddSummariesForProcessType('Gpu', 'gpu')