Skip to content

Commit 50e6dfe

Browse files
matouskozakCopilot
andcommitted
Address review: scope makedirs and filter crash logs
- Wrap os.makedirs into the same try/except as the crash copy so a diagnostic-path failure cannot mask the original CalledProcessError from the failed app kill. - Prune the systemCrashLogs copy after devicectl to entries relevant to this iteration: keep files matching the bundle name or with mtime >= the iteration's log-collect start. Drops dozens of unrelated .ips files (WiFiLQMMetrics, wifip2pd, old crashes, etc.) per upload. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 411b0f3 commit 50e6dfe

1 file changed

Lines changed: 30 additions & 11 deletions

File tree

src/scenarios/shared/runner.py

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -861,20 +861,39 @@ def run(self):
861861
make_archive(archive_base, 'zip', root_dir=logarchive_filename)
862862
except Exception as upload_ex:
863863
getLogger().warning(f"Failed to save logarchive for diagnosis: {upload_ex}")
864-
# Pull any iOS crash reports (.ips) for our bundle from the device into the upload root.
865-
# The systemCrashLogs domain on devicectl exposes /var/mobile/Library/Logs/CrashReporter/.
866-
crash_dest = os.path.join(upload_root, f'iteration{i}_crashlogs')
867-
os.makedirs(crash_dest, exist_ok=True)
868-
crashCopyCmd = [
869-
'xcrun', 'devicectl', 'device', 'copy', 'from',
870-
'--device', deviceUDID,
871-
'--domain-type', 'systemCrashLogs',
872-
'--source', '/',
873-
'--destination', crash_dest,
874-
]
864+
# Pull iOS crash reports (.ips) from the device into the upload root, then prune
865+
# to entries relevant to this iteration (matching bundle name OR generated since
866+
# the iteration started). The systemCrashLogs domain exposes /var/mobile/Library/
867+
# Logs/CrashReporter/, which on shared devices accumulates unrelated reports.
875868
try:
869+
crash_dest = os.path.join(upload_root, f'iteration{i}_crashlogs')
870+
os.makedirs(crash_dest, exist_ok=True)
871+
crashCopyCmd = [
872+
'xcrun', 'devicectl', 'device', 'copy', 'from',
873+
'--device', deviceUDID,
874+
'--domain-type', 'systemCrashLogs',
875+
'--source', '/',
876+
'--destination', crash_dest,
877+
]
876878
getLogger().info(f"Copying device crash logs to {crash_dest} for diagnosis.")
877879
RunCommand(crashCopyCmd, verbose=True).run()
880+
bundle_name = os.path.splitext(os.path.basename(os.path.normpath(self.packagepath)))[0]
881+
iteration_start_ts = runCmdTimestamp.timestamp()
882+
kept = removed = 0
883+
for root, _, files in os.walk(crash_dest):
884+
for fname in files:
885+
fpath = os.path.join(root, fname)
886+
try:
887+
is_bundle_match = bool(bundle_name) and bundle_name in fname
888+
is_recent = os.path.getmtime(fpath) >= iteration_start_ts
889+
if is_bundle_match or is_recent:
890+
kept += 1
891+
else:
892+
os.remove(fpath)
893+
removed += 1
894+
except OSError:
895+
pass
896+
getLogger().info(f"Kept {kept} crash log(s) relevant to {bundle_name!r} or this iteration; pruned {removed}.")
878897
except Exception as crash_ex:
879898
getLogger().warning(f"Failed to copy device crash logs for diagnosis: {crash_ex}")
880899
raise

0 commit comments

Comments
 (0)