26.2. perf circular buffers를 사용하여 성능 병목 현상을 모니터링하기 위해 특정 데이터를 수집합니다.

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> ]

    이 예제에서는 실행 파일을 시작하고 -e 옵션 뒤에 지정된 cpu 사이클을 수집합니다. perf 가 uprobe를 탐지할 때까지 --switch-output-event 옵션 뒤에 지정된 트리거 이벤트입니다. 이 시점에서 perf 는 순환 버퍼에 있는 모든 데이터의 스냅샷을 사용하여 타임스탬프로 식별되는 고유한 perf.data 파일에 저장합니다. 이 예제에서는 총 2개의 스냅샷을 생성했으며 마지막 perf.data 파일은 Ctrl+c 를 눌러 강제 실행되었습니다.