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

Side by Side Diff: build/android/pylib/android/logdog_logcat_monitor.py

Issue 2537813003: Insert logcat as part of test result for android instrumentation tests. (Closed)
Patch Set: insert sawrming_client to the front Created 4 years 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 | « build/android/pylib/android/__init__.py ('k') | build/android/pylib/base/base_test_result.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 os
6 import logging
7 import sys
8
9 from devil.android import logcat_monitor
10 from devil.utils import reraiser_thread
11 from pylib import constants
12
13 sys.path.insert(0, os.path.abspath(os.path.join(
14 constants.DIR_SOURCE_ROOT, 'tools', 'swarming_client')))
15 from libs.logdog import bootstrap # pylint: disable=import-error
16
17 class LogdogLogcatMonitor(logcat_monitor.LogcatMonitor):
18 """Logcat monitor that writes logcat to a logdog stream.
19 The logdog stream client will return a url, where contains the logcat.
20 """
21 def __init__(self, adb, stream_name, clear=True, filter_specs=None):
22 super(LogdogLogcatMonitor, self).__init__(adb, clear, filter_specs)
23 self._logcat_url = ''
24 self._logdog_stream = None
25 self._stream_client = None
26 self._stream_name = stream_name
27 try:
28 self._stream_client = bootstrap.ButlerBootstrap.probe().stream_client()
29 self._logdog_stream = self._stream_client.open_text(self._stream_name)
30 except bootstrap.NotBootstrappedError:
31 logging.exception('Error not bootstrapped. Failed to start logdog')
32
33 def GetLogcatURL(self):
34 """Return logcat url.
35
36 The default logcat url is '', if failed to create stream_client.
37 """
38 return self._logcat_url
39
40 def Stop(self):
41 """Stops the logcat monitor.
42
43 Close the logdog stream as well.
44 """
45 super(LogdogLogcatMonitor, self)._StopRecording()
46 if self._logdog_stream:
47 self._logcat_url = self._stream_client.get_viewer_url(self._stream_name)
48 self._logdog_stream.close()
49
50 def Start(self):
51 """Starts the logdog logcat monitor.
52
53 Clears the logcat if |clear| was set in |__init__|.
54 """
55 if self._clear:
56 self._adb.Logcat(clear=True)
57 self._StartRecording()
58
59 def _StartRecording(self):
60 """Starts recording logcat to file.
61
62 Write logcat to stream at the same time.
63 """
64 def record_to_stream():
65 if self._logdog_stream:
66 for data in self._adb.Logcat(filter_specs=self._filter_specs,
67 logcat_format='threadtime'):
68 if self._stop_recording_event.isSet():
69 return
70 self._logdog_stream.write(data + '\n')
71
72 self._stop_recording_event.clear()
73 if not self._record_thread:
74 self._record_thread = reraiser_thread.ReraiserThread(record_to_stream)
75 self._record_thread.start()
76
77 def Close(self):
78 """Override parent's close method."""
79 pass
80
81 def __del__(self):
82 """Override parent's delete method."""
83 pass
OLDNEW
« no previous file with comments | « build/android/pylib/android/__init__.py ('k') | build/android/pylib/base/base_test_result.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698