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:
25 from metrics
import memory
26 from metrics
import power
27 from metrics
import v8_object_stats
28 from telemetry
import benchmark
29 from telemetry
.core
import util
30 from telemetry
.page
import page_set
31 from telemetry
.page
import page_test
32 from telemetry
.value
import scalar
35 'V8.OsMemoryAllocated',
38 class _IndexedDbMeasurement(page_test
.PageTest
):
39 def __init__(self
, *args
, **kwargs
):
40 super(_IndexedDbMeasurement
, self
).__init
__(*args
, **kwargs
)
41 self
._memory
_metric
= None
42 self
._power
_metric
= None
43 self
._v
8_object
_stats
_metric
= None
45 def WillStartBrowser(self
, browser
):
46 """Initialize metrics once right before the browser has been launched."""
47 self
._power
_metric
= power
.PowerMetric(browser
)
49 def DidStartBrowser(self
, browser
):
50 """Initialize metrics once right after the browser has been launched."""
51 self
._memory
_metric
= memory
.MemoryMetric(browser
)
52 self
._v
8_object
_stats
_metric
= (
53 v8_object_stats
.V8ObjectStatsMetric(_V8_COUNTER_NAMES
))
55 def DidNavigateToPage(self
, page
, tab
):
56 self
._memory
_metric
.Start(page
, tab
)
57 self
._power
_metric
.Start(page
, tab
)
58 self
._v
8_object
_stats
_metric
.Start(page
, tab
)
60 def ValidateAndMeasurePage(self
, page
, tab
, results
):
61 tab
.WaitForDocumentReadyStateToBeComplete()
62 tab
.WaitForJavaScriptExpression(
63 'window.document.cookie.indexOf("__done=1") >= 0', 600)
65 self
._power
_metric
.Stop(page
, tab
)
66 self
._memory
_metric
.Stop(page
, tab
)
67 self
._v
8_object
_stats
_metric
.Stop(page
, tab
)
69 self
._memory
_metric
.AddResults(tab
, results
)
70 self
._power
_metric
.AddResults(tab
, results
)
71 self
._v
8_object
_stats
_metric
.AddResults(tab
, results
)
73 js_get_results
= "JSON.stringify(automation.getResults());"
74 result_dict
= json
.loads(tab
.EvaluateJavaScript(js_get_results
))
76 for key
in result_dict
:
77 if key
== 'OverallTestDuration':
79 msec
= float(result_dict
[key
])
80 results
.AddValue(scalar
.ScalarValue(
81 results
.current_page
, key
, 'ms', msec
, important
=False))
84 results
.AddValue(scalar
.ScalarValue(
85 results
.current_page
, 'Total Perf', 'ms', total
))
88 def CustomizeBrowserOptions(self
, options
):
89 memory
.MemoryMetric
.CustomizeBrowserOptions(options
)
90 power
.PowerMetric
.CustomizeBrowserOptions(options
)
91 v8_object_stats
.V8ObjectStatsMetric
.CustomizeBrowserOptions(options
)
93 class IndexedDb(benchmark
.Benchmark
):
94 """Chromium's IndexedDB Performance tests."""
95 test
= _IndexedDbMeasurement
97 def CreatePageSet(self
, options
):
98 indexeddb_dir
= os
.path
.join(util
.GetChromiumSrcDir(), 'chrome', 'test',
100 ps
= page_set
.PageSet(file_path
=indexeddb_dir
)
101 ps
.AddPageWithDefaultRunNavigate('file://perf_test.html')