|
| 1 | +#!/bin/bash |
| 2 | +# Start or restart iOS simulator log streams and resource monitor (sourced by boot-simulator.sh). |
| 3 | +set -uo pipefail |
| 4 | + |
| 5 | +restart_simulator_logging() { |
| 6 | + local with_stdout="${RNFB_SIM_LOG_STDOUT:-0}" |
| 7 | + local log_dir="${RNFB_SIM_LOG_DIR:-.}" |
| 8 | + local simulator_log="${log_dir}/simulator.log" |
| 9 | + local testing_log="${log_dir}/testing.log" |
| 10 | + local springboard_log="${log_dir}/springboard-invertase.log" |
| 11 | + local resource_log="${log_dir}/resource-monitor.log" |
| 12 | + local repo_root="${RNFB_REPO_ROOT:-$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd)}" |
| 13 | + |
| 14 | + if ! xcrun simctl list devices booted 2>/dev/null | grep -q Booted; then |
| 15 | + echo "[boot-status] phase=log_streams skipped=no_booted_simulator" |
| 16 | + return 1 |
| 17 | + fi |
| 18 | + |
| 19 | + echo "[boot-status] phase=log_streams_restart ts=$(date -u +%Y-%m-%dT%H:%M:%SZ) stdout=${with_stdout} dir=${log_dir}" |
| 20 | + |
| 21 | + pkill -f 'simctl spawn booted log stream' 2>/dev/null || true |
| 22 | + pkill -f 'simctl io booted recordVideo' 2>/dev/null || true |
| 23 | + pkill -f resource-monitor.sh 2>/dev/null || true |
| 24 | + sleep 1 |
| 25 | + |
| 26 | + { |
| 27 | + echo "" |
| 28 | + echo "=== log stream restarted $(date -u +%Y-%m-%dT%H:%M:%SZ) ===" |
| 29 | + } >>"$simulator_log" 2>/dev/null || : >"$simulator_log" |
| 30 | + { |
| 31 | + echo "" |
| 32 | + echo "=== log stream restarted $(date -u +%Y-%m-%dT%H:%M:%SZ) ===" |
| 33 | + } >>"$testing_log" 2>/dev/null || : >"$testing_log" |
| 34 | + { |
| 35 | + echo "" |
| 36 | + echo "=== log stream restarted $(date -u +%Y-%m-%dT%H:%M:%SZ) ===" |
| 37 | + } >>"$springboard_log" 2>/dev/null || : >"$springboard_log" |
| 38 | + |
| 39 | + if [[ "$with_stdout" == "1" ]]; then |
| 40 | + xcrun simctl io booted recordVideo --codec=h264 -f "${log_dir}/simulator.mp4" 2>&1 & |
| 41 | + xcrun simctl spawn booted log stream --level debug --style compact 2>&1 | tee -a "$simulator_log" & |
| 42 | + xcrun simctl spawn booted log stream --level debug --style compact \ |
| 43 | + --predicate 'process == "testing"' 2>&1 | tee -a "$testing_log" & |
| 44 | + xcrun simctl spawn booted log stream --level debug --style compact \ |
| 45 | + --predicate 'process == "SpringBoard" AND eventMessage CONTAINS "invertase"' 2>&1 | tee -a "$springboard_log" & |
| 46 | + else |
| 47 | + nohup sh -c "xcrun simctl io booted recordVideo --codec=h264 -f '${log_dir}/simulator.mp4' 2>&1 &" >/dev/null 2>&1 & |
| 48 | + nohup sh -c "xcrun simctl spawn booted log stream --level debug --style compact >>'${simulator_log}' 2>&1 &" >/dev/null 2>&1 & |
| 49 | + nohup sh -c "xcrun simctl spawn booted log stream --level debug --style compact --predicate 'process == \"testing\"' >>'${testing_log}' 2>&1 &" >/dev/null 2>&1 & |
| 50 | + nohup sh -c "xcrun simctl spawn booted log stream --level debug --style compact --predicate 'process == \"SpringBoard\" AND eventMessage CONTAINS \"invertase\"' >>'${springboard_log}' 2>&1 &" >/dev/null 2>&1 & |
| 51 | + fi |
| 52 | + |
| 53 | + chmod +x "${repo_root}/.github/workflows/scripts/resource-monitor.sh" |
| 54 | + RNFB_RESOURCE_MONITOR_LOG="$resource_log" nohup "${repo_root}/.github/workflows/scripts/resource-monitor.sh" >/dev/null 2>&1 & |
| 55 | + |
| 56 | + echo "[boot-status] phase=log_streams_started video=${log_dir}/simulator.mp4 monitor=${resource_log}" |
| 57 | +} |
0 commit comments