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

Side by Side Diff: build/android/pylib/local/device/local_device_perf_test_run.py

Issue 2182563002: [Android] Add heartbeat of platform mode perf test runner. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2016 The Chromium Authors. All rights reserved. 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 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import io 5 import io
6 import json 6 import json
7 import logging 7 import logging
8 import os 8 import os
9 import pickle 9 import pickle
10 import shutil 10 import shutil
11 import tempfile 11 import tempfile
12 import threading
12 import time 13 import time
13 import zipfile 14 import zipfile
14 15
15 from devil.android import battery_utils 16 from devil.android import battery_utils
16 from devil.android import device_errors 17 from devil.android import device_errors
17 from devil.android import device_list 18 from devil.android import device_list
18 from devil.android import device_utils 19 from devil.android import device_utils
19 from devil.android import forwarder 20 from devil.android import forwarder
20 from devil.android.tools import device_recovery 21 from devil.android.tools import device_recovery
21 from devil.android.tools import device_status 22 from devil.android.tools import device_status
22 from devil.utils import cmd_helper 23 from devil.utils import cmd_helper
23 from devil.utils import parallelizer 24 from devil.utils import parallelizer
24 from pylib import constants 25 from pylib import constants
25 from pylib.base import base_test_result 26 from pylib.base import base_test_result
26 from pylib.constants import host_paths 27 from pylib.constants import host_paths
27 from pylib.local.device import local_device_test_run 28 from pylib.local.device import local_device_test_run
28 29
29 30
31 class HeartBeat(object):
32
33 def __init__(self, shard, wait_time=60*10):
mikecase (-- gone --) 2016/07/25 17:01:27 nit: Add some documentation. Specifically, to just
rnephew (Reviews Here) 2016/07/25 17:06:42 Done.
34 self._shard = shard
35 self._running = False
36 self._timer = None
37 self._wait_time = wait_time
38
39 def Start(self):
40 if not self._running:
41 self._timer = threading.Timer(self._wait_time, self._LogMessage)
42 self._timer.start()
43 self._running = True
44
45 def Stop(self):
46 if self._running:
47 self._timer.cancel()
48 self._running = False
49
50 def _LogMessage(self):
51 logging.info('Currently working on test %s', self._shard.current_test)
52 self._timer = threading.Timer(self._wait_time, self._LogMessage)
53 self._timer.start()
54
55
30 class TestShard(object): 56 class TestShard(object):
31 def __init__( 57 def __init__(
32 self, env, test_instance, device, index, tests, retries=3, timeout=None): 58 self, env, test_instance, device, index, tests, retries=3, timeout=None):
33 logging.info('Create shard %s for device %s to run the following tests:', 59 logging.info('Create shard %s for device %s to run the following tests:',
34 index, device) 60 index, device)
35 for t in tests: 61 for t in tests:
36 logging.info(' %s', t) 62 logging.info(' %s', t)
37 self._battery = battery_utils.BatteryUtils(device) 63 self._battery = battery_utils.BatteryUtils(device)
64 self._current_test = None
38 self._device = device 65 self._device = device
39 self._env = env 66 self._env = env
40 self._index = index 67 self._index = index
41 self._output_dir = None 68 self._output_dir = None
42 self._retries = retries 69 self._retries = retries
43 self._test_instance = test_instance 70 self._test_instance = test_instance
44 self._tests = tests 71 self._tests = tests
45 self._timeout = timeout 72 self._timeout = timeout
73 self._heart_beat = HeartBeat(self)
46 74
47 @local_device_test_run.handle_shard_failures 75 @local_device_test_run.handle_shard_failures
48 def RunTestsOnShard(self): 76 def RunTestsOnShard(self):
49 results = base_test_result.TestRunResults() 77 results = base_test_result.TestRunResults()
50 for test in self._tests: 78 for test in self._tests:
51 tries_left = self._retries 79 tries_left = self._retries
52 result_type = None 80 result_type = None
53 while (result_type != base_test_result.ResultType.PASS 81 while (result_type != base_test_result.ResultType.PASS
54 and tries_left > 0): 82 and tries_left > 0):
55 try: 83 try:
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 self._battery.LetBatteryCoolToTemperature( 117 self._battery.LetBatteryCoolToTemperature(
90 self._test_instance.max_battery_temp) 118 self._test_instance.max_battery_temp)
91 119
92 if not self._device.IsScreenOn(): 120 if not self._device.IsScreenOn():
93 self._device.SetScreen(True) 121 self._device.SetScreen(True)
94 122
95 if (self._test_instance.collect_chartjson_data 123 if (self._test_instance.collect_chartjson_data
96 or self._tests[test].get('archive_output_dir')): 124 or self._tests[test].get('archive_output_dir')):
97 self._output_dir = tempfile.mkdtemp() 125 self._output_dir = tempfile.mkdtemp()
98 126
127 self._current_test = test
128 self._heart_beat.Start()
129
99 def _RunSingleTest(self, test): 130 def _RunSingleTest(self, test):
100 self._test_instance.WriteBuildBotJson(self._output_dir) 131 self._test_instance.WriteBuildBotJson(self._output_dir)
101 132
102 timeout = self._tests[test].get('timeout', self._timeout) 133 timeout = self._tests[test].get('timeout', self._timeout)
103 cmd = self._CreateCmd(test) 134 cmd = self._CreateCmd(test)
104 cwd = os.path.abspath(host_paths.DIR_SOURCE_ROOT) 135 cwd = os.path.abspath(host_paths.DIR_SOURCE_ROOT)
105 136
106 logging.debug("Running %s with command '%s' on shard %d with timeout %d", 137 logging.debug("Running %s with command '%s' on shard %d with timeout %d",
107 test, cmd, self._index, timeout) 138 test, cmd, self._index, timeout)
108 139
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 228
198 def _TestTearDown(self): 229 def _TestTearDown(self):
199 if self._output_dir: 230 if self._output_dir:
200 shutil.rmtree(self._output_dir, ignore_errors=True) 231 shutil.rmtree(self._output_dir, ignore_errors=True)
201 self._output_dir = None 232 self._output_dir = None
202 try: 233 try:
203 logging.info('Unmapping device ports for %s.', self._device) 234 logging.info('Unmapping device ports for %s.', self._device)
204 forwarder.Forwarder.UnmapAllDevicePorts(self._device) 235 forwarder.Forwarder.UnmapAllDevicePorts(self._device)
205 except Exception: # pylint: disable=broad-except 236 except Exception: # pylint: disable=broad-except
206 logging.exception('Exception when resetting ports.') 237 logging.exception('Exception when resetting ports.')
238 finally:
239 self._heart_beat.Stop()
240 self._current_test = None
207 241
242 @property
243 def current_test(self):
244 return self._current_test
208 245
209 class LocalDevicePerfTestRun(local_device_test_run.LocalDeviceTestRun): 246 class LocalDevicePerfTestRun(local_device_test_run.LocalDeviceTestRun):
210 247
211 _DEFAULT_TIMEOUT = 60 * 60 248 _DEFAULT_TIMEOUT = 60 * 60
212 _CONFIG_VERSION = 1 249 _CONFIG_VERSION = 1
213 250
214 def __init__(self, env, test_instance): 251 def __init__(self, env, test_instance):
215 super(LocalDevicePerfTestRun, self).__init__(env, test_instance) 252 super(LocalDevicePerfTestRun, self).__init__(env, test_instance)
216 self._devices = None 253 self._devices = None
217 self._env = env 254 self._env = env
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 # override 410 # override
374 def _RunTest(self, _device, _test): 411 def _RunTest(self, _device, _test):
375 raise NotImplementedError 412 raise NotImplementedError
376 413
377 414
378 class TestDictVersionError(Exception): 415 class TestDictVersionError(Exception):
379 pass 416 pass
380 417
381 class PerfTestRunGetStepsError(Exception): 418 class PerfTestRunGetStepsError(Exception):
382 pass 419 pass
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698