Skip to content

Commit

Permalink
Warn when file is not growing
Browse files Browse the repository at this point in the history
  • Loading branch information
aBozowski committed Oct 24, 2023
1 parent 1451a02 commit 12bb816
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
import multiprocessing

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

Expand All @@ -30,9 +31,14 @@ def __init__(self, platform: "Android"):
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)

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

async def stop(self):
self.logcat_proc.stop_command()
self.observer_proc.kill()
self.observer_proc.join()
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ async def prepare_screen_recording(self) -> None:
# async with asyncio.timeout_at(asyncio.get_running_loop().time() + 20.0):
screen_on = self.check_screen()
while not screen_on:
await asyncio.sleep(2)
await asyncio.sleep(4)
screen_on = self.check_screen()
if not screen_on:
self.logger.error("Please turn the screen on so screen recording can start!")
self.logger.error("Please turn the screen on so screen recording can start or check connection!")

# except TimeoutError:
# self.logger.error("Screen recording timeout")
Expand Down Expand Up @@ -104,4 +104,5 @@ async def stop(self):
self.logger.info("Stopping screen proc")
if self.screen_proc is not None:
self.screen_proc.kill()
self.screen_proc.join()
await self.pull_screen_recording()
28 changes: 27 additions & 1 deletion src/tools/interop/idt/capture/utils/artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#

import multiprocessing
import os
import time
from multiprocessing import Process
from pathlib import Path
from . import log

logger = log.get_logger(__file__)


def create_file_timestamp() -> str:
Expand All @@ -33,3 +37,25 @@ def create_standard_log_name(name: str, ext: str, parent: str = "") -> str:

def safe_mkdir(dir_name: str) -> None:
Path(dir_name).mkdir(parents=True, exist_ok=True)


def multiproc_size_observer(file_name: str) -> None:
"""
Warn if a file is not growing over time
Intended to be run as multiproc target
"""
time.sleep(15) # Give some time for the file to show up
last_size = 0
while True:
if not os.path.exists(file_name):
logger.error(f"Streamed file not on disk yet, this may be normal at the start of execution! {file_name}")
else:
new_size = os.path.getsize(file_name)
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)


def get_observer_proc(file_name: str) -> Process:
return multiprocessing.Process(target=multiproc_size_observer, args=(file_name,))
1 change: 1 addition & 0 deletions src/tools/interop/idt/scripts/alias.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ alias idt_vars="idt_go && source idt/scripts/vars.sh"
alias idt_clean_artifacts="idt_go && source idt/scripts/clean_artifacts.sh"
alias idt_clean_all="idt_go && source idt/scripts/clean_all.sh"
alias idt_create_vars="idt_go && source idt/scripts/create_vars.sh"
alias idt_check_child="idt_go && source idt/scripts/check_child.sh"

alias idt="idt_go && \
if [ -z $PYTHONPYCACHEPREFIX ]; then export PYTHONPYCACHEPREFIX=$IDT_SRC_PARENT/idt/pycache; fi && \
Expand Down
18 changes: 18 additions & 0 deletions src/tools/interop/idt/scripts/check_child.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
# Copyright (c) 2023 Project CHIP Authors
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

sudo ps -auxf | grep -E "(tcpd|adb)"

0 comments on commit 12bb816

Please sign in to comment.