Index: build/android/pylib/local/device/local_device_environment.py |
diff --git a/build/android/pylib/local/device/local_device_environment.py b/build/android/pylib/local/device/local_device_environment.py |
index 56e867862bcd264e4b36f588afc055945b6c0662..8493257d345aed589cdc4714cc590549c53fe445 100644 |
--- a/build/android/pylib/local/device/local_device_environment.py |
+++ b/build/android/pylib/local/device/local_device_environment.py |
@@ -8,6 +8,8 @@ import os |
import shutil |
import tempfile |
import threading |
+import subprocess |
+import uuid |
from devil.android import device_blacklist |
from devil.android import device_errors |
@@ -44,6 +46,7 @@ class LocalDeviceEnvironment(environment.Environment): |
self._skip_clear_data = args.skip_clear_data |
self._target_devices_file = args.target_devices_file |
self._tool_name = args.tool |
+ self._logdog_butler_dir = args.logdog_butler_dir |
#override |
def SetUp(self): |
@@ -117,6 +120,7 @@ class LocalDeviceEnvironment(environment.Environment): |
# Write the cache even when not using it so that it will be ready the first |
# time that it is enabled. Writing it every time is also necessary so that |
# an invalid cache can be flushed just by disabling it for one run. |
+ |
jbudorick
2016/07/08 02:50:40
?
|
for d in self._devices: |
cache_path = _DeviceCachePath(d) |
with open(cache_path, 'w') as f: |
@@ -125,12 +129,63 @@ class LocalDeviceEnvironment(environment.Environment): |
for m in self._logcat_monitors: |
m.Stop() |
m.Close() |
+ #Might be redundant with usage of logdog |
jbudorick
2016/07/08 02:50:40
Remove this.
|
if self._logcat_output_file: |
file_utils.MergeFiles( |
self._logcat_output_file, |
[m.output_file for m in self._logcat_monitors]) |
shutil.rmtree(self._logcat_output_dir) |
+ #if the logdog_butler is pushed onto the swarming slave, |
+ #use it to output the device logcats in a unified view |
+ elif self._logcat_output_dir and self._logdog_butler_dir: |
+ temp_dir = tempfile.mkdtemp() |
+ temp_file = os.path.join(temp_dir, 'logcat') |
+ # add device serial to each line of logcat output |
+ for m in self._logcat_monitors: |
jbudorick
2016/07/08 02:50:40
Can we run this in parallel? https://codesearch.ch
|
+ device_serial = (m._adb).__str__() |
jbudorick
2016/07/08 02:50:41
1) The linter should have been unhappy about this,
|
+ add_device_args = ['sed', '-i', '-e', |
jbudorick
2016/07/08 02:50:40
Do this in-process rather than calling out to sed.
|
+ 's/^/device({0}) /'.format(device_serial), |
+ m.output_file] |
+ subprocess.check_call(add_device_args) |
jbudorick
2016/07/08 02:50:40
Use cmd_helper instead of subprocess: https://code
|
+ file_utils.MergeFiles(temp_file, |
+ [m.output_file for m in self._logcat_monitors]) |
+ butler_location = os.path.join(self._logdog_butler_dir, 'logdog_butler') |
+ prefix = str(uuid.uuid4()) |
+ # will be used once recipes are intergrated |
jbudorick
2016/07/08 02:50:40
1) Commented-out code shouldn't be here.
2) What i
|
+ # prefix = "/".join(["swarming", |
+ # os.environ['SWARMING_TASK_ID']]) |
+ name = temp_file |
+ project = 'chromium' |
+ logdog_args = [butler_location, '-log-level', 'debug', '-project', |
jbudorick
2016/07/08 02:50:41
This knows way too much about logdog and how to ru
|
+ project, '-prefix', prefix, |
+ '-output', 'logdog,host=luci-logdog-dev.appspot.com', |
+ 'stream', "-source", os.path.abspath(temp_file), |
+ '-stream', 'name=testing1234'] |
+ |
+ def url_constructor(project, prefix, name): |
+ # Constucts and returns the url of where the logcats will |
+ # be stored once logdog has streamed them to |
+ # luci-logdog.appspot.com |
+ |
+ def construct_prefix(prefix): |
+ # Constructs the logdog prefix in URL form |
+ return prefix.replace('/', '%2F') |
+ |
+ def construct_name(name): |
+ # Constructs the logdog streamname in URL form |
+ return 'file:{0}'.format(name.replace('/', '_', 20)) |
+ |
+ return 'luci-logdog-dev.appspot.com/v/?s={0}%2F{1}%2F%2B%2F{2}'.format( |
+ project, construct_prefix(prefix), construct_name(name)) |
+ |
+ #surpress logdog output to not clutter stdout |
+ FNULL = open(os.devnull, 'w') |
+ subprocess.check_call(logdog_args, stdout=FNULL, stderr=subprocess.STDOUT) |
+ |
+ print 'Logcats are located at {0}'.format(url_constructor(project, prefix, name)) |
jbudorick
2016/07/08 02:50:40
No prints, please. If you want to log something, u
|
+ shutil.rmtree(temp_dir) |
+ |
def BlacklistDevice(self, device, reason='local_device_failure'): |
device_serial = device.adb.GetDeviceSerial() |
if self._blacklist: |