Skip to content

Commit

Permalink
Make logcat resiliant
Browse files Browse the repository at this point in the history
  • Loading branch information
aBozowski committed Oct 24, 2023
1 parent 12bb816 commit 4683b34
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#

import multiprocessing
import time

from capture.utils.artifact import create_standard_log_name, get_observer_proc
from typing import TYPE_CHECKING
from ..base import AndroidStream

from capture.utils import log

logger = log.get_logger(__file__)

if TYPE_CHECKING:
from capture.platform.android import Android
Expand All @@ -28,17 +33,34 @@
class LogcatStreamer(AndroidStream):

def __init__(self, platform: "Android"):
self.logger = logger
self.platform = platform
self.logcat_artifact = create_standard_log_name("logcat", "txt", parent=platform.artifact_dir)
self.logcat_command = f"logcat -T 1 >> {self.logcat_artifact}"
self.logcat_proc = platform.get_adb_background_command(self.logcat_command)
self.observer_proc = get_observer_proc(self.logcat_artifact)
self.runner_proc = multiprocessing.Process(target=self.restart_logcat_as_needed)
self.was_ever_running = False

def restart_logcat_as_needed(self) -> None:
while True:
if not self.logcat_proc.command_is_running():
self.logcat_proc = self.platform.get_adb_background_command(self.logcat_command)
self.logcat_proc.start_command()
if self.was_ever_running:
self.logger.critical("Had to start logcat again!!!")
else:
self.was_ever_running = True
time.sleep(10)

async def start(self):
self.logcat_proc.start_command()
if not self.runner_proc.is_alive():
self.runner_proc.start()
if not self.observer_proc.is_alive():
self.observer_proc.start()

async def stop(self):
self.logcat_proc.stop_command()
self.runner_proc.kill()
self.observer_proc.kill()
self.runner_proc.join()
self.observer_proc.join()
3 changes: 2 additions & 1 deletion src/tools/interop/idt/capture/utils/artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#

import multiprocessing
import os
import time
Expand Down Expand Up @@ -54,7 +55,7 @@ def multiproc_size_observer(file_name: str) -> None:
if not new_size > last_size:
logger.critical(f"Streamed file is not growing; check your connection! {file_name}")
last_size = new_size
time.sleep(20)
time.sleep(10)


def get_observer_proc(file_name: str) -> Process:
Expand Down

0 comments on commit 4683b34

Please sign in to comment.