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.
7 from telemetry
import benchmark
8 from telemetry
.core
import util
9 from telemetry
.page
import page_set
10 from telemetry
.page
import page_test
11 from telemetry
.value
import list_of_scalar_values
14 def _CreatePageSetFromPath(path
):
15 assert os
.path
.exists(path
)
21 if not path
.endswith('.html'):
23 if '../' in open(path
, 'r').read():
24 # If the page looks like it references its parent dir, include it.
25 serving_dirs
.add(os
.path
.dirname(os
.path
.dirname(path
)))
26 page_urls
.append('file://' + path
.replace('\\', '/'))
28 def _AddDir(dir_path
, skipped
):
29 for candidate_path
in os
.listdir(dir_path
):
30 if candidate_path
== 'resources':
32 candidate_path
= os
.path
.join(dir_path
, candidate_path
)
33 if candidate_path
.startswith(tuple([os
.path
.join(path
, s
)
36 if os
.path
.isdir(candidate_path
):
37 _AddDir(candidate_path
, skipped
)
39 _AddPage(candidate_path
)
41 if os
.path
.isdir(path
):
43 skipped_file
= os
.path
.join(path
, 'Skipped')
44 if os
.path
.exists(skipped_file
):
45 for line
in open(skipped_file
, 'r').readlines():
47 if line
and not line
.startswith('#'):
48 skipped
.append(line
.replace('/', os
.sep
))
49 _AddDir(path
, skipped
)
52 ps
= page_set
.PageSet(file_path
=os
.getcwd()+os
.sep
, serving_dirs
=serving_dirs
)
54 ps
.AddPageWithDefaultRunNavigate(url
)
58 class _BlinkPerfMeasurement(page_test
.PageTest
):
59 """Tuns a blink performance test and reports the results."""
61 super(_BlinkPerfMeasurement
, self
).__init
__('')
62 with
open(os
.path
.join(os
.path
.dirname(__file__
),
63 'blink_perf.js'), 'r') as f
:
64 self
._blink
_perf
_js
= f
.read()
66 def WillNavigateToPage(self
, page
, tab
):
67 page
.script_to_evaluate_on_commit
= self
._blink
_perf
_js
69 def CustomizeBrowserOptions(self
, options
):
70 options
.AppendExtraBrowserArgs([
71 '--js-flags=--expose_gc',
72 '--enable-experimental-web-platform-features',
73 '--disable-gesture-requirement-for-media-playback'
76 def ValidateAndMeasurePage(self
, page
, tab
, results
):
77 tab
.WaitForJavaScriptExpression('testRunner.isDone', 600)
79 log
= tab
.EvaluateJavaScript('document.getElementById("log").innerHTML')
81 for line
in log
.splitlines():
82 if not line
.startswith('values '):
85 values
= [float(v
.replace(',', '')) for v
in parts
[1:-1]]
87 metric
= page
.display_name
.split('.')[0].replace('/', '_')
88 results
.AddValue(list_of_scalar_values
.ListOfScalarValues(
89 results
.current_page
, metric
, units
, values
))
96 class BlinkPerfAll(benchmark
.Benchmark
):
98 test
= _BlinkPerfMeasurement
100 def CreatePageSet(self
, options
):
101 path
= os
.path
.join(util
.GetChromiumSrcDir(),
102 'third_party', 'WebKit', 'PerformanceTests')
103 return _CreatePageSetFromPath(path
)
107 class BlinkPerfAnimation(benchmark
.Benchmark
):
109 test
= _BlinkPerfMeasurement
111 def CreatePageSet(self
, options
):
112 path
= os
.path
.join(util
.GetChromiumSrcDir(),
113 'third_party', 'WebKit', 'PerformanceTests', 'Animation')
114 return _CreatePageSetFromPath(path
)