summaryrefslogtreecommitdiffstats
path: root/tools/perf/benchmarks/indexeddb_perf.py
blob: 5949f36272f0a705de3d138286637ef750173a14 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# Copyright 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""Runs Chromium's IndexedDB performance test. These test:

Databases:
  create/delete
Keys:
  create/delete
Indexes:
  create/delete
Data access:
  Random read/write
  Read cache
Cursors:
  Read & random writes
  Walking multiple
  Seeking.
"""

import json
import os

from metrics import memory
from metrics import power
from metrics import v8_object_stats
from telemetry import test
from telemetry.core import util
from telemetry.page import page_measurement
from telemetry.page import page_set

_V8_COUNTER_NAMES = [
    'V8.OsMemoryAllocated',
  ]

class _IndexedDbMeasurement(page_measurement.PageMeasurement):
  def __init__(self, *args, **kwargs):
    super(_IndexedDbMeasurement, self).__init__(*args, **kwargs)
    self._memory_metric = None
    self._power_metric = power.PowerMetric()
    self._v8_object_stats_metric = None

  def DidStartBrowser(self, browser):
    """Initialize metrics once right after the browser has been launched."""
    self._memory_metric = memory.MemoryMetric(browser)
    self._v8_object_stats_metric = (
      v8_object_stats.V8ObjectStatsMetric(_V8_COUNTER_NAMES))

  def DidNavigateToPage(self, page, tab):
    self._memory_metric.Start(page, tab)
    self._power_metric.Start(page, tab)
    self._v8_object_stats_metric.Start(page, tab)

  def MeasurePage(self, page, tab, results):
    tab.WaitForDocumentReadyStateToBeComplete()
    tab.WaitForJavaScriptExpression(
        'window.document.cookie.indexOf("__done=1") >= 0', 600)

    self._power_metric.Stop(page, tab)
    self._memory_metric.Stop(page, tab)
    self._v8_object_stats_metric.Stop(page, tab)

    self._memory_metric.AddResults(tab, results)
    self._power_metric.AddResults(tab, results)
    self._v8_object_stats_metric.AddResults(tab, results)

    js_get_results = "JSON.stringify(automation.getResults());"
    result_dict = json.loads(tab.EvaluateJavaScript(js_get_results))
    total = 0.0
    for key in result_dict:
      if key == 'OverallTestDuration':
        continue
      msec = float(result_dict[key])
      results.Add(key, 'ms', msec, data_type='unimportant')
      total += msec
    results.Add('Total Perf', 'ms', total)

  def CustomizeBrowserOptions(self, options):
    memory.MemoryMetric.CustomizeBrowserOptions(options)
    power.PowerMetric.CustomizeBrowserOptions(options)
    v8_object_stats.V8ObjectStatsMetric.CustomizeBrowserOptions(options)

class IndexedDb(test.Test):
  """Chromium's IndexedDB Performance tests."""
  test = _IndexedDbMeasurement

  def CreatePageSet(self, options):
    indexeddb_dir = os.path.join(util.GetChromiumSrcDir(), 'chrome', 'test',
                                 'data', 'indexeddb')
    ps = page_set.PageSet(file_path=indexeddb_dir)
    ps.AddPageWithDefaultRunNavigate('file://perf_test.html')
    return ps