1# Copyright 2015 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
6from telemetry.web_perf.metrics import timeline_based_metric
7from telemetry.web_perf.metrics.trace_event_stats import TraceEventStats
8from telemetry.web_perf.metrics.trace_event_stats import TraceEventStatsInput
9
10
11class IndexedDBTimelineMetric(timeline_based_metric.TimelineBasedMetric):
12  """Metrics for IndexedDB operations.
13  """
14
15  def __init__(self):
16    super(IndexedDBTimelineMetric, self).__init__()
17    self._stats = TraceEventStats()
18
19    self._stats.AddInput(TraceEventStatsInput(
20      event_category='IndexedDB',
21      event_name='IndexedDBDatabase::GetOperation',
22      metric_name='idb-gets',
23      metric_description='The duration of all "get" ops in IndexedDB',
24      units='ms',
25      process_name='Browser'))
26
27    self._stats.AddInput(TraceEventStatsInput(
28      event_category='IndexedDB',
29      event_name='IndexedDBDatabase::PutOperation',
30      metric_name='idb-puts',
31      metric_description='The duration of all "put" ops in IndexedDB',
32      units='ms',
33      process_name='Browser'))
34
35    self._stats.AddInput(TraceEventStatsInput(
36      event_category='IndexedDB',
37      event_name='IndexedDBFactoryImpl::Open',
38      metric_name='idb-opens',
39      metric_description='The duration of all "open" ops in IndexedDB',
40      units='ms',
41      process_name='Browser'))
42
43    self._stats.AddInput(TraceEventStatsInput(
44      event_category='IndexedDB',
45      event_name='IndexedDBTransaction::Commit',
46      metric_name='idb-transaction-commits',
47      metric_description=('The duration of all "commit" ops of ' +
48                               'transactions in IndexedDB.'),
49      units='ms',
50      process_name='Browser'))
51
52    self._stats.AddInput(TraceEventStatsInput(
53      event_category='IndexedDB',
54      event_name='IndexedDBFactoryImpl::DeleteDatabase',
55      metric_name='idb-database-deletes',
56      metric_description=('The duration of all "delete" ops of ' +
57                               'IndexedDB databases.'),
58      units='ms',
59      process_name='Browser'))
60
61    self._stats.AddInput(TraceEventStatsInput(
62      event_category='IndexedDB',
63      event_name='IndexedDBDatabase::OpenCursorOperation',
64      metric_name='idb-cursor-opens',
65      metric_description=('The duration of all "open" ops of ' +
66                               'IndexedDB cursors.'),
67      units='ms',
68      process_name='Browser'))
69
70    self._stats.AddInput(TraceEventStatsInput(
71      event_category='IndexedDB',
72      event_name='IndexedDBCursor::CursorIterationOperation',
73      metric_name='idb-cursor-iterations',
74      metric_description=('The duration of all "iteration" ops of ' +
75                               'IndexedDB cursors.'),
76      units='ms',
77      process_name='Browser'))
78
79  def AddResults(self, model, renderer_process, interactions, results):
80    self._stats.AddResults(model, renderer_process, interactions, results)
81