1 # Copyright (c) 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 """This measurement runs a blink performance test and reports the results."""
10 from telemetry
.core
import util
11 from telemetry
.page
import page_measurement
12 from telemetry
.page
import page_set
15 def CreatePageSetFromPath(path
):
16 assert os
.path
.exists(path
)
18 page_set_dict
= {'pages': []}
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 page_set_dict
['serving_dirs'] = [os
.path
.dirname(os
.path
.dirname(path
))]
26 page_set_dict
['pages'].append({'url':
27 'file://' + path
.replace('\\', '/')})
29 def _AddDir(dir_path
, skipped
):
30 for candidate_path
in os
.listdir(dir_path
):
31 if candidate_path
== 'resources':
33 candidate_path
= os
.path
.join(dir_path
, candidate_path
)
34 if candidate_path
.startswith(tuple([os
.path
.join(path
, s
)
37 if os
.path
.isdir(candidate_path
):
38 _AddDir(candidate_path
, skipped
)
40 _AddPage(candidate_path
)
42 if os
.path
.isdir(path
):
44 skipped_file
= os
.path
.join(path
, 'Skipped')
45 if os
.path
.exists(skipped_file
):
46 for line
in open(skipped_file
, 'r').readlines():
48 if line
and not line
.startswith('#'):
49 skipped
.append(line
.replace('/', os
.sep
))
50 _AddDir(path
, skipped
)
53 return page_set
.PageSet
.FromDict(page_set_dict
, os
.getcwd() + os
.sep
)
56 class BlinkPerf(page_measurement
.PageMeasurement
):
58 super(BlinkPerf
, self
).__init
__('')
59 with
open(os
.path
.join(os
.path
.dirname(__file__
),
60 'blink_perf.js'), 'r') as f
:
61 self
._blink
_perf
_js
= f
.read()
63 def CreatePageSet(self
, args
, options
):
65 print 'Must specify a file or directory to run.'
68 page_set_arg
= args
[1]
70 if not os
.path
.exists(page_set_arg
):
71 print '%s does not exist.' % page_set_arg
74 return CreatePageSetFromPath(page_set_arg
)
77 def results_are_the_same_on_every_page(self
):
80 def WillNavigateToPage(self
, page
, tab
):
81 page
.script_to_evaluate_on_commit
= self
._blink
_perf
_js
83 def CustomizeBrowserOptions(self
, options
):
84 options
.AppendExtraBrowserArgs([
85 '--js-flags=--expose_gc',
86 '--enable-experimental-web-platform-features'
89 def MeasurePage(self
, page
, tab
, results
):
91 return tab
.EvaluateJavaScript('testRunner.isDone')
92 util
.WaitFor(_IsDone
, 600)
94 log
= tab
.EvaluateJavaScript('document.getElementById("log").innerHTML')
96 for line
in log
.splitlines():
97 if not line
.startswith('values '):
100 values
= [float(v
.replace(',', '')) for v
in parts
[1:-1]]
102 metric
= page
.display_name
.split('.')[0].replace('/', '_')
103 results
.Add(metric
, units
, values
)