네이티브 앱 성능 (CLI 전용)
목표: xctrace를 통해 Time Profiler를 기록하고, 샘플을 추출하여 심볼화한 후, Instruments를 열지 않고도 핫스팟을 제안합니다.
빠른 시작 (CLI)
- Time Profiler 기록 (프로세스에 연결):
# 앱을 직접 실행한 후 연결합니다
xcrun xctrace record --template 'Time Profiler' --time-limit 90s --output /tmp/App.trace --attach <pid>
- Time Profiler 기록 (앱 실행):
xcrun xctrace record --template 'Time Profiler' --time-limit 90s --output /tmp/App.trace --launch -- /path/App.app/Contents/MacOS/App
- 시간 샘플 추출:
scripts/extract_time_samples.py --trace /tmp/App.trace --output /tmp/time-sample.xml
- 심볼화를 위한 로드 주소 확인:
# 앱이 실행 중일 때
vmmap <pid> | rg -m1 "__TEXT" -n
- 심볼화 + 핫스팟 순위 산출:
scripts/top_hotspots.py --samples /tmp/time-sample.xml \
--binary /path/App.app/Contents/MacOS/App \
--load-address 0x100000000 --top 30
워크플로 참고 사항
- 항상 올바른 바이너리를 프로파일링하고 있는지 확인하세요 (로컬 빌드 vs
/Applications).--launch사용 시에는 직접 바이너리 경로를 선호합니다. - 캡처 중에 느린 경로를 트리거해야 합니다 (메뉴 열기/닫기, 새로고침 등).
- 스택이 비어 있으면 더 길게 캡처하거나 유휴 구간을 피하세요.
xcrun xctrace help record및xcrun xctrace help export명령어로 올바른 플래그를 확인할 수 있습니다.
포함된 스크립트
scripts/record_time_profiler.sh: 연결 또는 실행 방식을 통해 기록합니다.scripts/extract_time_samples.py: 트레이스에서 time-sample XML을 내보냅니다.scripts/top_hotspots.py: 심볼화하고 상위 앱 프레임을 순위별로 정렬합니다.
문제 해결 팁
- ASLR로 인해
vmmap에서 얻은 런타임__TEXT로드 주소를 사용해야 합니다. - 새 빌드를 사용한다면
--binary경로를 업데이트하세요. 심볼이 트레이스와 일치해야 합니다. - CLI 전용 워크플로:
atos를 통해 스택이 심볼화되면 Instruments를 열 필요가 없습니다.