Chromium Code Reviews| Index: build/android/pylib/android/logcat_monitor_with_logdog.py |
| diff --git a/build/android/pylib/android/logcat_monitor_with_logdog.py b/build/android/pylib/android/logcat_monitor_with_logdog.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e562d598ff7978f86f7080d7fe78b5e337516d3f |
| --- /dev/null |
| +++ b/build/android/pylib/android/logcat_monitor_with_logdog.py |
| @@ -0,0 +1,68 @@ |
| +# Copyright 2016 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +import os |
| +import logging |
| +import sys |
| + |
| +from devil.android import logcat_monitor |
| +from devil.utils import reraiser_thread |
| +from pylib import constants |
| +sys.path.append(os.path.abspath(os.path.join( |
| + constants.DIR_SOURCE_ROOT, 'tools', 'swarming_client'))) |
| +from libs.logdog import bootstrap |
| + |
| + |
| +class LogcatMonitorWithLogdog(logcat_monitor.LogcatMonitor): |
|
jbudorick
2016/11/22 14:40:14
Rename this LogdogLogcatMonitor.
BigBossZhiling
2016/11/23 00:28:07
Done.
|
| + """Logcat monitor that writes logcat to a logdog stream. |
| + The logdog stream client will return a url, where contains the logcat. |
|
jbudorick
2016/11/22 14:40:14
nit: docstrings should either be
"""Summary lin
BigBossZhiling
2016/11/23 00:28:07
Done.
|
| + """ |
| + def __init__(self, adb, stream_name): |
| + super(LogcatMonitorWithLogdog, self).__init__(adb) |
| + self.logcat_url = '' |
| + self.logdog_stream = None |
| + self.stream_client = None |
| + self.stream_name = stream_name |
| + try: |
| + self.stream_client = bootstrap.ButlerBootstrap.probe().stream_client() |
| + self.logdog_stream = self.stream_client.open_text(self.stream_name) |
| + except bootstrap.NotBootstrappedError: |
| + logging.exception('Error not bootstrapped. Failed to start logdog') |
| + |
| + def GetLogcatURL(self): |
| + """Return logcat url. |
| + The default logcat url is '', if failed to create stream_client. |
| + """ |
| + return self.logcat_url |
| + |
| + def Stop(self): |
| + """Stops the logcat monitor. |
| + Close the logdog stream. |
| + """ |
| + super(LogcatMonitorWithLogdog, self).Stop() |
| + if self.logdog_stream: |
| + self.logcat_url = self.stream_client.get_viewer_url(self.stream_name) |
| + self.logdog_stream.close() |
| + |
| + def _StartRecording(self): |
| + """Starts recording logcat to file. |
| + Write logcat to stream at the same time. |
| + """ |
| + def record_to_file(): |
| + # Write the log with line buffering so the consumer sees each individual |
| + # line. |
| + for data in self._adb.Logcat(filter_specs=self._filter_specs, |
| + logcat_format='threadtime'): |
| + with self._record_file_lock: |
| + if self._stop_recording_event.isSet(): |
| + return |
| + if self._record_file and not self._record_file.closed: |
| + self._record_file.write(data + '\n') |
|
jbudorick
2016/11/22 14:40:14
Why should this continue writing to file?
BigBossZhiling
2016/11/23 00:28:07
Done.
|
| + if self.logdog_stream: |
| + self.logdog_stream.write(data + '\n') |
| + |
| + self._stop_recording_event.clear() |
| + if not self._record_thread: |
| + self._record_thread = reraiser_thread.ReraiserThread(record_to_file) |
| + self._record_thread.start() |