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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
# Copyright (c) 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.
import os
from telemetry import test
from telemetry.core import util
from telemetry.page import page_measurement
from telemetry.page import page as page_module
from telemetry.page import page_set
class BlinkPerfPageSet(page_set.PageSet):
def __init__(self, file_path, page_urls, serving_dirs):
super(BlinkPerfPageSet, self).__init__(file_path=file_path,
serving_dirs=serving_dirs)
for url in page_urls:
self.AddPage(page_module.PageWithDefaultRunNavigate(
url, page_set=self, base_dir=self._base_dir))
self._InitializeArchive()
def _CreatePageSetFromPath(path):
assert os.path.exists(path)
page_urls = []
serving_dirs = set()
def _AddPage(path):
if not path.endswith('.html'):
return
if '../' in open(path, 'r').read():
# If the page looks like it references its parent dir, include it.
serving_dirs.add(os.path.dirname(os.path.dirname(path)))
page_urls.append('file://' + path.replace('\\', '/'))
def _AddDir(dir_path, skipped):
for candidate_path in os.listdir(dir_path):
if candidate_path == 'resources':
continue
candidate_path = os.path.join(dir_path, candidate_path)
if candidate_path.startswith(tuple([os.path.join(path, s)
for s in skipped])):
continue
if os.path.isdir(candidate_path):
_AddDir(candidate_path, skipped)
else:
_AddPage(candidate_path)
if os.path.isdir(path):
skipped = []
skipped_file = os.path.join(path, 'Skipped')
if os.path.exists(skipped_file):
for line in open(skipped_file, 'r').readlines():
line = line.strip()
if line and not line.startswith('#'):
skipped.append(line.replace('/', os.sep))
_AddDir(path, skipped)
else:
_AddPage(path)
return BlinkPerfPageSet(os.getcwd() + os.sep, page_urls, serving_dirs)
class _BlinkPerfMeasurement(page_measurement.PageMeasurement):
"""Tuns a blink performance test and reports the results."""
def __init__(self):
super(_BlinkPerfMeasurement, self).__init__('')
with open(os.path.join(os.path.dirname(__file__),
'blink_perf.js'), 'r') as f:
self._blink_perf_js = f.read()
@property
def results_are_the_same_on_every_page(self):
return False
def WillNavigateToPage(self, page, tab):
page.script_to_evaluate_on_commit = self._blink_perf_js
def CustomizeBrowserOptions(self, options):
options.AppendExtraBrowserArgs([
'--js-flags=--expose_gc',
'--enable-experimental-web-platform-features'
])
def MeasurePage(self, page, tab, results):
tab.WaitForJavaScriptExpression('testRunner.isDone', 600)
log = tab.EvaluateJavaScript('document.getElementById("log").innerHTML')
for line in log.splitlines():
if not line.startswith('values '):
continue
parts = line.split()
values = [float(v.replace(',', '')) for v in parts[1:-1]]
units = parts[-1]
metric = page.display_name.split('.')[0].replace('/', '_')
results.Add(metric, units, values)
break
print log
class BlinkPerfAll(test.Test):
tag = 'all'
test = _BlinkPerfMeasurement
def CreatePageSet(self, options):
path = os.path.join(util.GetChromiumSrcDir(),
'third_party', 'WebKit', 'PerformanceTests')
return _CreatePageSetFromPath(path)
class BlinkPerfAnimation(test.Test):
tag = 'animation'
test = _BlinkPerfMeasurement
def CreatePageSet(self, options):
path = os.path.join(util.GetChromiumSrcDir(),
'third_party', 'WebKit', 'PerformanceTests', 'Animation')
return _CreatePageSetFromPath(path)
class BlinkPerfWebAnimations(test.Test):
tag = 'web_animations'
test = _BlinkPerfMeasurement
def CreatePageSet(self, options):
path = os.path.join(util.GetChromiumSrcDir(),
'third_party', 'WebKit', 'PerformanceTests', 'Animation')
return _CreatePageSetFromPath(path)
def CustomizeBrowserOptions(self, options):
options.AppendExtraBrowserArgs('--enable-web-animations-css')
|