Notion에서 보기
ftrace란?
커널이 호출하는 함수를 추적할 수 있는 기능
- 활성화 시키는 방법mount -t debugfs nodev /sys/kernel/debug
- debugfs 파일 시스템을 /sys/kernel/debug에 마운트 시키기 :
1. 주요 기능
- dynamic kernel function tracing
- : stack usage, call graph, counting, filter
- latency tracing
- : interrupts, wake-up
- static trace points를 사용한 event tracing
- : scheduling, interrupts, file systems, virtual guest connections
2. 특징
- 리눅스 커널 2.6.27에서 메인라인에 합류
- 적은 오버헤드 (10%)
- tracepoint와 kprobes를 trace source로 사용
3. Tracer Plugins
- function: 임의의 기간동안 커널 내부 함수의 호출관계를 분석
- function_graph: 그래프 형식의 함수 관계 분석
- wakeup, wakeup_dl, wakeup_rt: wake up latency 분석
- mmiotrace: 메모리 맵의 I/O에 대한 분석
- irqsoff: interrupt latency 분석
- nop: 디버깅 기능 off
4. How to use
1) 활성화 시키기
$ mount -t debugfs nodev /sys/kernel/debug
1) trace filter 함수 설정
$ echo [필터링 하고 싶은 함수 이름] >> set_ftrace_filter
$cat set_ftrace_filter
- default 는 모든 함수를 trace한다.
2) trace 결과 설정
$ echo [원하는 옵션] > current_tracer
- 자주 사용하는 옵션
- function : trace결과를 함수형으로 저장한다.
- function_graph : trace 결과를 함수형 그래프로 저장한다.
- nop : trace하지 않는다.
3) trace 결과
$ cat trace
4) option
- available_filter_functions : 추적 가능한 함수 목록
- 함수이름 [함수소속] 으로 출력된다.
$ cat available_filter_functions | grep [추적하고 싶은 관련 함수]
참고 : https://lwn.net/Articles/548894/
"sudo ./b -m m -t t" 실행 결과
- (m,t) = (1,1)
- THP 활성화after echo "always" > /sys/kernel/mm/transparent_hugepage/defrag
- average page fault time : 1.5714 microsecs
- average page fault time : 1.87847 microsecs
- THP 비활성화after echo "never" > /sys/kernel/mm/transparent_hugepage/defrag
- average page fault time : 1.79323 microsecs
- average page fault time : 1.83915 microsecs
- (m,t) = (5,1)
- THP 활성화after echo "always" > /sys/kernel/mm/transparent_hugepage/defrag
- average page fault time : 1.60306 microsecs
- average page fault time : 1.66424 microsecs
- THP 비활성화after echo "never" > /sys/kernel/mm/transparent_hugepage/defrag
- average page fault time : 2.01453 microsecs
- average page fault time : 1.79188 microsecs
- (m,t) = (5,12)
- THP 활성화after echo "always" > /sys/kernel/mm/transparent_hugepage/defrag
- average page fault time : 0.667436 microsecs
- average page fault time : 0.798839 microsecs
- THP 비활성화after echo "never" > /sys/kernel/mm/transparent_hugepage/defrag
- average page fault time : 0.562111 microsecs
- average page fault time : microsecs
- (m,t) = (10,1)
- THP 활성화after echo "always" > /sys/kernel/mm/transparent_hugepage/defrag
- average page fault time : 1.85184 microsecs
- average page fault time : 1.75024 microsecs
- THP 비활성화after echo "never" > /sys/kernel/mm/transparent_hugepage/defrag
- average page fault time : 1.98813 microsecs
- average page fault time : 1.73554 microsecs
- (m,t) = (10,4)
- THP 활성화after echo "always" > /sys/kernel/mm/transparent_hugepage/defrag
- average page fault time : 1.52186 microsecs
- average page fault time : 1.46946 microsecs
- THP 비활성화after echo "never" > /sys/kernel/mm/transparent_hugepage/defrag
- average page fault time : 1.47785 microsecs
- average page fault time : 1.48445 microsecs
- (m,t) = (10,12)
- THP 활성화after echo "always" > /sys/kernel/mm/transparent_hugepage/defrag
- average page fault time : 0.987232 microsecs
- average page fault time : 1.05875 microsecs
- THP 비활성화after echo "never" > /sys/kernel/mm/transparent_hugepage/defrag
- average page fault time : 1.04561 microsecs
- average page fault time : 1.00398 microsecs