Roll src/third_party/WebKit f36d5e0:68b67cd (svn 193299:193303)
[chromium-blink-merge.git] / tools / perf / benchmarks / indexeddb_perf.py
blob65a8710f44f4c1a79dfeaf0aad7922f01872df0c
1 # Copyright 2013 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.
5 """Runs Chromium's IndexedDB performance test. These test:
7 Databases:
8 create/delete
9 Keys:
10 create/delete
11 Indexes:
12 create/delete
13 Data access:
14 Random read/write
15 Read cache
16 Cursors:
17 Read & random writes
18 Walking multiple
19 Seeking.
20 """
22 import json
23 import os
25 from telemetry import benchmark
26 from telemetry.core import util
27 from telemetry import page as page_module
28 from telemetry.page import page_set
29 from telemetry.page import page_test
30 from telemetry.value import scalar
32 from metrics import memory
33 from metrics import power
36 class _IndexedDbMeasurement(page_test.PageTest):
37 def __init__(self):
38 super(_IndexedDbMeasurement, self).__init__()
39 self._memory_metric = None
40 self._power_metric = None
42 def WillStartBrowser(self, platform):
43 """Initialize metrics once right before the browser has been launched."""
44 self._power_metric = power.PowerMetric(platform)
46 def DidStartBrowser(self, browser):
47 """Initialize metrics once right after the browser has been launched."""
48 self._memory_metric = memory.MemoryMetric(browser)
50 def DidNavigateToPage(self, page, tab):
51 self._memory_metric.Start(page, tab)
52 self._power_metric.Start(page, tab)
54 def ValidateAndMeasurePage(self, page, tab, results):
55 tab.WaitForDocumentReadyStateToBeComplete()
56 tab.WaitForJavaScriptExpression(
57 'window.document.cookie.indexOf("__done=1") >= 0', 600)
59 self._power_metric.Stop(page, tab)
60 self._memory_metric.Stop(page, tab)
62 self._memory_metric.AddResults(tab, results)
63 self._power_metric.AddResults(tab, results)
65 js_get_results = "JSON.stringify(automation.getResults());"
66 result_dict = json.loads(tab.EvaluateJavaScript(js_get_results))
67 total = 0.0
68 for key in result_dict:
69 if key == 'OverallTestDuration':
70 continue
71 msec = float(result_dict[key])
72 results.AddValue(scalar.ScalarValue(
73 results.current_page, key, 'ms', msec, important=False))
75 total += msec
76 results.AddValue(scalar.ScalarValue(
77 results.current_page, 'Total Perf', 'ms', total))
80 def CustomizeBrowserOptions(self, options):
81 memory.MemoryMetric.CustomizeBrowserOptions(options)
82 power.PowerMetric.CustomizeBrowserOptions(options)
84 class IndexedDb(benchmark.Benchmark):
85 """Chromium's IndexedDB Performance tests."""
86 test = _IndexedDbMeasurement
88 @classmethod
89 def Name(cls):
90 return 'indexeddb_perf'
92 def CreatePageSet(self, options):
93 indexeddb_dir = os.path.join(util.GetChromiumSrcDir(), 'chrome', 'test',
94 'data', 'indexeddb')
95 ps = page_set.PageSet(file_path=indexeddb_dir)
96 ps.AddUserStory(page_module.Page('file://perf_test.html', ps, ps.base_dir))
97 return ps