Chromium Code Reviews| Index: build/android/pylib/android/logdog_logcat_monitor.py |
| diff --git a/build/android/pylib/android/logdog_logcat_monitor.py b/build/android/pylib/android/logdog_logcat_monitor.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f1466cf8e4565dbddb272efe5945748562dd0b5e |
| --- /dev/null |
| +++ b/build/android/pylib/android/logdog_logcat_monitor.py |
| @@ -0,0 +1,69 @@ |
| +# 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( |
|
jbudorick
2016/11/23 16:25:20
nit: +1 blank line here
BigBossZhiling
2016/11/29 00:40:42
Done.
|
| + constants.DIR_SOURCE_ROOT, 'tools', 'swarming_client'))) |
| +from libs.logdog import bootstrap |
| + |
| + |
| +class LogdogLogcatMonitor(logcat_monitor.LogcatMonitor): |
|
jbudorick
2016/11/23 16:25:21
This is still doing a lot with _record_file that i
BigBossZhiling
2016/11/29 00:40:42
Done.
|
| + """Logcat monitor that writes logcat to a logdog stream. |
| + The logdog stream client will return a url, where contains the logcat. |
| + """ |
| + def __init__(self, adb, stream_name): |
| + super(LogdogLogcatMonitor, self).__init__(adb) |
| + self.logcat_url = '' |
|
jbudorick
2016/11/23 16:25:21
These should be prefixed w/ _ (e.g. self._logcat_u
BigBossZhiling
2016/11/29 00:40:42
Done.
|
| + 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 as well. |
| + """ |
| + super(LogdogLogcatMonitor, self).Stop() |
|
jbudorick
2016/11/23 16:25:20
LogcatMonitor.Stop calls _StopRecording and does a
BigBossZhiling
2016/11/29 00:40:42
Done.
|
| + 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(): |
|
jbudorick
2016/11/23 16:25:20
nit: record_to_stream?
BigBossZhiling
2016/11/29 00:40:42
Done.
|
| + # 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: |
|
jbudorick
2016/11/23 16:25:21
I don't think this should have to grab the _record
BigBossZhiling
2016/11/29 00:40:42
Done.
|
| + if self._stop_recording_event.isSet(): |
| + return |
| + 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() |