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

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: address comments in ps5 Created 4 years, 6 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
10 from pylib import constants
11 from pylib.base import test_instance
12 from pylib.constants import exit_codes
13
14
15 def _GetPersistedResult(test_name):
16 file_name = os.path.join(constants.PERF_OUTPUT_DIR, test_name)
17 if not os.path.exists(file_name):
18 logging.error('File not found %s', file_name)
19 return None
20
21 with file(file_name, 'r') as f:
22 return pickle.loads(f.read())
23
24
25 class PerfTestInstance(test_instance.TestInstance):
26 def __init__(self, args, _):
27 super(PerfTestInstance, self).__init__()
28
29 if args.single_step:
30 args.single_step = ' '.join(args.single_step_command)
31
32 self._collect_chartjson_data = args.collect_chartjson_data
33 self._dry_run = args.dry_run
34 self._flaky_steps = args.flaky_steps
35 self._get_output_dir_archive = args.get_output_dir_archive
36 self._known_devices_file = args.known_devices_file
37 self._max_battery_temp = args.max_battery_temp
38 self._min_battery_level = args.min_battery_level
39 self._no_timeout = args.no_timeout
40 self._output_chartjson_data = args.output_chartjson_data
41 self._output_json_list = args.output_json_list
42 self._print_step = args.print_step
43 self._single_step = args.single_step
44 self._steps = args.steps
45 self._test_filter = args.test_filter
46
47 def SetUp(self):
48 pass
49
50 def TearDown(self):
51 pass
52
53 def OutputJsonList(self):
54 with file(self._steps, 'r') as i:
55 all_steps = json.load(i)
56
57 step_values = []
58 for k, v in all_steps['steps'].iteritems():
59 data = {'test': k, 'device_affinity': v['device_affinity']}
60
61 persisted_result = _GetPersistedResult(k)
62 if persisted_result:
63 data['start_time'] = persisted_result['start_time']
64 data['end_time'] = persisted_result['end_time']
65 data['total_time'] = persisted_result['total_time']
66 data['has_archive'] = persisted_result['archive_bytes'] is not None
67 step_values.append(data)
68
69 with file(self._output_json_list, 'w') as o:
70 o.write(json.dumps(step_values))
71 return 0
72
73 def PrintTestOutput(self):
74 """Helper method to print the output of previously executed test_name.
75
76 Test_name is passed from the command line as print_step
77
78 Returns:
79 exit code generated by the test step.
80 """
81 persisted_result = _GetPersistedResult(self._print_step)
82 if not persisted_result:
83 return exit_codes.INFRA
84 logging.info('*' * 80)
85 logging.info('Output from:')
86 logging.info(persisted_result['cmd'])
87 logging.info('*' * 80)
88
89 output_formatted = ''
90 persisted_outputs = persisted_result['output']
91 for i in xrange(len(persisted_outputs)):
92 output_formatted += '\n\nOutput from run #%d:\n\n%s' % (
93 i, persisted_outputs[i])
94 print output_formatted
95
96 if self._output_chartjson_data:
97 with file(self._output_chartjson_data, 'w') as f:
98 f.write(persisted_result['chartjson'])
99
100 if self._get_output_dir_archive:
101 if persisted_result['archive_bytes'] is not None:
102 with file(self._get_output_dir_archive, 'wb') as f:
103 f.write(persisted_result['archive_bytes'])
104 else:
105 logging.error('The output dir was not archived.')
106
107 return persisted_result['exit_code']
108
109 #override
110 def TestType(self):
111 return 'Perf'
112
113 @staticmethod
114 def ReadChartjsonOutput(output_dir):
115 if not output_dir:
116 return ''
117 json_output_path = os.path.join(output_dir, 'results-chart.json')
118 try:
119 with open(json_output_path) as f:
120 return f.read()
121 except IOError:
122 logging.exception('Exception when reading chartjson.')
123 logging.error('This usually means that telemetry did not run, so it could'
124 ' not generate the file. Please check the device running'
125 ' the test.')
126 return ''
127
128
129 @property
130 def collect_chartjson_data(self):
131 return self._collect_chartjson_data
132
133 @property
134 def dry_run(self):
135 return self._dry_run
136
137 @property
138 def flaky_steps(self):
139 return self._flaky_steps
140
141 @property
142 def get_output_dir_archive(self):
143 return self._get_output_dir_archive
144
145 @property
146 def known_devices_file(self):
147 return self._known_devices_file
148
149 @property
150 def max_battery_temp(self):
151 return self._max_battery_temp
152
153 @property
154 def min_battery_level(self):
155 return self._min_battery_level
156
157 @property
158 def no_timeout(self):
159 return self._no_timeout
160
161 @property
162 def output_chartjson_data(self):
163 return self._output_chartjson_data
164
165 @property
166 def output_json_list(self):
167 return self._output_json_list
168
169 @property
170 def print_step(self):
171 return self._print_step
172
173 @property
174 def single_step(self):
175 return self._single_step
176
177 @property
178 def steps(self):
179 return self._steps
180
181 @property
182 def test_filter(self):
183 return self._test_filter
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698