19.2. perf circular buffer를 사용하여 성능 병목 현상을 모니터링할 특정 데이터 수집
perf 툴을 사용하면 순환 버퍼를 생성할 수 있습니다. 이는 관심 있는 데이터만 수집하도록 지정하는 이벤트에 의해 트리거됩니다. 이벤트 관련 데이터를 수집하는 순환 버퍼를 생성하려면 perf 에 대해 --overwrite 및 --switch-output-event 옵션을 사용합니다.
사전 요구 사항
-
perf사용자 공간 도구가 설치되어 있어야 합니다. 자세한 내용은 perf 설치를 참조하십시오. 프로세스 또는 애플리케이션 내의 관심 위치에서 모니터링에 관심이 있는 프로세스 또는 애플리케이션에
uprobe를 배치했습니다.# perf probe -x </path/to/executable> -a function Added new event: probe_executable:function (on function in /path/to/executable) You can now use it in all perf tools, such as: perf record -e probe_executable:function -aR sleep 1
프로세스
uprobe를 트리거 이벤트로 사용하여 원형 버퍼를 생성합니다.# perf record --overwrite -e cycles --switch-output-event probe_executable:function ./executable [ perf record: dump data: Woken up 1 times ] [ perf record: Dump perf.data.2021021012231959 ] [ perf record: dump data: Woken up 1 times ] [ perf record: Dump perf.data.2021021012232008 ] ^C[ perf record: dump data: Woken up 1 times ] [ perf record: Dump perf.data.2021021012232082 ] [ perf record: Captured and wrote 5.621 MB perf.data.<timestamp> ]이 명령은 실행 파일을 시작하고
--switch-output-event옵션 뒤에 지정된 트리거 이벤트인uprobe를 감지할 때까지-e옵션 뒤에 지정된 cpu 사이클을 수집합니다.이때perf는 순환 버퍼의 모든 데이터의 스냅샷을 가져와서 타임스탬프로 식별된 고유한perf.data파일에 저장합니다. 이 예에서는 총 2개의 스냅샷이 생성되었으며, Ctrl+C 를 누르면 마지막perf.data파일이 강제 적용되었습니다.