Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Side by Side Diff: build/android/pylib/perf/perf_test_instance.py

Issue 2012323002: [Android] Implement perf tests to platform mode. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: [Android] Implement perf tests to platform mode. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 # Copyright 2016 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.
4
5 import json
6 import logging
7 import os
8 import pickle
9 import re
10
11 from devil.utils import cmd_helper
12 from pylib import constants
13 from pylib.base import base_test_result
14 from pylib.base import test_instance
15 from pylib.constants import exit_codes
16 from pylib.constants import host_paths
17
18
19 _GIT_CR_POS_RE = re.compile(r'^Cr-Commit-Position: refs/heads/master@{#(\d+)}$')
20
21
22 def _GetPersistedResult(test_name):
23 file_name = os.path.join(constants.PERF_OUTPUT_DIR, test_name)
24 if not os.path.exists(file_name):
25 logging.error('File not found %s', file_name)
26 return None
27
28 with file(file_name, 'r') as f:
29 return pickle.loads(f.read())
30
31
32 def _GetChromiumRevision():
33 # pylint: disable=line-too-long
34 """Get the git hash and commit position of the chromium master branch.
35
36 See:
37 https://chromium.googlesource.com/chromium/tools/build/+/master/scripts/slave/ runtest.py#212
mikecase (-- gone --) 2016/07/12 18:33:14 You can optionally pick a specific revision to lin
rnephew (Reviews Here) 2016/07/12 18:55:26 Done.
38
39 Returns:
40 A dictionary with 'revision' and 'commit_pos' keys.
41 """
42 # pylint: enable=line-too-long
43 status, output = cmd_helper.GetCmdStatusAndOutput(
44 ['git', 'log', '-n', '1', '--pretty=format:%H%n%B', 'HEAD'],
45 cwd=host_paths.DIR_SOURCE_ROOT)
46 revision = None
47 commit_pos = None
48 if not status:
49 lines = output.splitlines()
50 revision = lines[0]
51 for line in reversed(lines):
52 m = _GIT_CR_POS_RE.match(line.strip())
53 if m:
54 commit_pos = int(m.group(1))
55 break
56 return {'revision': revision, 'commit_pos': commit_pos}
57
58
59 class PerfTestInstance(test_instance.TestInstance):
60 def __init__(self, args, _):
61 super(PerfTestInstance, self).__init__()
62
63 if args.single_step:
64 args.single_step = ' '.join(args.single_step_command)
65
66 self._collect_chartjson_data = args.collect_chartjson_data
67 self._dry_run = args.dry_run
68 self._flaky_steps = args.flaky_steps
69 self._output_dir_archive_path = args.output_dir_archive_path
70 self._known_devices_file = args.known_devices_file
71 self._max_battery_temp = args.max_battery_temp
72 self._min_battery_level = args.min_battery_level
73 self._no_timeout = args.no_timeout
74 self._output_chartjson_data = args.output_chartjson_data
75 self._output_json_list = args.output_json_list
76 self._print_step = args.print_step
77 self._single_step = args.single_step
jbudorick 2016/07/12 18:45:10 nit: Why isn't this just: self._single_step = '
rnephew (Reviews Here) 2016/07/12 21:05:47 Done.
78 self._steps = args.steps
79 self._test_filter = args.test_filter
80 self._write_buildbot_json = args.write_buildbot_json
81
82 def SetUp(self):
83 pass
84
85 def TearDown(self):
86 pass
87
88 def OutputJsonList(self):
89 try:
90 with file(self._steps, 'r') as i:
91 all_steps = json.load(i)
92
93 step_values = []
94 for k, v in all_steps['steps'].iteritems():
95 data = {'test': k, 'device_affinity': v['device_affinity']}
96
97 persisted_result = _GetPersistedResult(k)
98 if persisted_result:
99 data['start_time'] = persisted_result['start_time']
100 data['end_time'] = persisted_result['end_time']
101 data['total_time'] = persisted_result['total_time']
102 data['has_archive'] = persisted_result['archive_bytes'] is not None
103 step_values.append(data)
104
105 with file(self._output_json_list, 'w') as o:
106 o.write(json.dumps(step_values))
107 return base_test_result.ResultType.PASS
108 except KeyError:
109 logging.exception('Persistent results file missing key.')
110 return base_test_result.ResultType.FAIL
111
112 def PrintTestOutput(self):
113 """Helper method to print the output of previously executed test_name.
114
115 Test_name is passed from the command line as print_step
116
117 Returns:
118 exit code generated by the test step.
119 """
120 persisted_result = _GetPersistedResult(self._print_step)
121 if not persisted_result:
122 return exit_codes.INFRA
jbudorick 2016/07/12 18:45:10 This needs to raise an infra error, not return w/
rnephew (Reviews Here) 2016/07/12 21:05:47 Done.
123 logging.info('*' * 80)
124 logging.info('Output from:')
125 logging.info(persisted_result['cmd'])
126 logging.info('*' * 80)
127
128 output_formatted = ''
129 persisted_outputs = persisted_result['output']
130 for i in xrange(len(persisted_outputs)):
131 output_formatted += '\n\nOutput from run #%d:\n\n%s' % (
132 i, persisted_outputs[i])
133 print output_formatted
134
135 if self._output_chartjson_data:
136 with file(self._output_chartjson_data, 'w') as f:
137 f.write(persisted_result['chartjson'])
138
139 if self._output_dir_archive_path:
140 if persisted_result['archive_bytes'] is not None:
141 with file(self._output_dir_archive_path, 'wb') as f:
142 f.write(persisted_result['archive_bytes'])
143 else:
144 logging.error('The output dir was not archived.')
145 if persisted_result['exit_code'] == 0:
146 return base_test_result.ResultType.PASS
147 return base_test_result.ResultType.FAIL
148
149 #override
150 def TestType(self):
151 return 'perf'
152
153 @staticmethod
154 def ReadChartjsonOutput(output_dir):
155 if not output_dir:
156 return ''
157 json_output_path = os.path.join(output_dir, 'results-chart.json')
158 try:
159 with open(json_output_path) as f:
160 return f.read()
161 except IOError:
162 logging.exception('Exception when reading chartjson.')
163 logging.error('This usually means that telemetry did not run, so it could'
164 ' not generate the file. Please check the device running'
165 ' the test.')
166 return ''
167
168 def WriteBuildBotJson(self, output_dir):
169 """Write metadata about the buildbot environment to the output dir."""
170 if not output_dir or not self._write_buildbot_json:
171 return
172 data = {
173 'chromium': _GetChromiumRevision(),
174 'environment': dict(os.environ)
175 }
176 with open(os.path.join(output_dir, 'buildbot.json'), 'w') as f:
177 json.dump(data, f, sort_keys=True, separators=(',', ': '))
178
179 @property
180 def collect_chartjson_data(self):
181 return self._collect_chartjson_data
182
183 @property
184 def dry_run(self):
185 return self._dry_run
186
187 @property
188 def flaky_steps(self):
189 return self._flaky_steps
190
191 @property
192 def known_devices_file(self):
193 return self._known_devices_file
194
195 @property
196 def max_battery_temp(self):
197 return self._max_battery_temp
198
199 @property
200 def min_battery_level(self):
201 return self._min_battery_level
202
203 @property
204 def no_timeout(self):
205 return self._no_timeout
206
207 @property
208 def output_chartjson_data(self):
209 return self._output_chartjson_data
210
211 @property
212 def output_dir_archive_path(self):
213 return self._output_dir_archive_path
214
215 @property
216 def output_json_list(self):
217 return self._output_json_list
218
219 @property
220 def print_step(self):
221 return self._print_step
222
223 @property
224 def single_step(self):
225 return self._single_step
226
227 @property
228 def steps(self):
229 return self._steps
230
231 @property
232 def test_filter(self):
233 return self._test_filter
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698