← Documents Documentation/trace/boottime-trace.rst GitHub 원문 ↗

Linux 6.18.37 · Tracing

부팅 시간 추적(Boot-time tracing)

bootconfig로 ftrace 전역·인스턴스·이벤트·히스토그램을 구성하고 initcall 지연, 다중 tracer, 함수 그래프 trigger와 legacy 커널 매개변수를 부팅 단계에서 적용하는 방법을 설명합니다.

Source pathDocumentation/trace/boottime-trace.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약·해설

boottime-trace.rst:1-301

bootconfig로 ftrace 전역·인스턴스·이벤트·히스토그램을 구성하고 initcall 지연, 다중 tracer, 함수 그래프 trigger와 legacy 커널 매개변수를 부팅 단계에서 적용하는 방법을 설명합니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

원문 전체 펼치기
1 .. SPDX-License-Identifier: GPL-2.0
2
3 =================
4 Boot-time tracing
5 =================
6
7 :Author: Masami Hiramatsu <[email protected]>
8
9 Overview
10 ========
11
12 Boot-time tracing allows users to trace boot-time process including
13 device initialization with full features of ftrace including per-event
14 filter and actions, histograms, kprobe-events and synthetic-events,
15 and trace instances.
16 Since kernel command line is not enough to control these complex features,
17 this uses bootconfig file to describe tracing feature programming.
18
19 Options in the Boot Config
20 ==========================
21
22 Here is the list of available options for boot time tracing in
23 boot config file [1]_. All options are under "ftrace." or "kernel."
24 prefix. See kernel parameters for the options which starts
25 with "kernel." prefix [2]_.
26
27 .. [1] See :ref:`Documentation/admin-guide/bootconfig.rst <bootconfig>`
28 .. [2] See :ref:`Documentation/admin-guide/kernel-parameters.rst <kernelparameters>`
29
30 Ftrace Global Options
31 ---------------------
32
33 Ftrace global options have "kernel." prefix in boot config, which means
34 these options are passed as a part of kernel legacy command line.
35
36 kernel.tp_printk
37 Output trace-event data on printk buffer too.
38
39 kernel.dump_on_oops [= MODE]
40 Dump ftrace on Oops. If MODE = 1 or omitted, dump trace buffer
41 on all CPUs. If MODE = 2, dump a buffer on a CPU which kicks Oops.
42
43 kernel.traceoff_on_warning
44 Stop tracing if WARN_ON() occurs.
45
46 kernel.fgraph_max_depth = MAX_DEPTH
47 Set MAX_DEPTH to maximum depth of fgraph tracer.
48
49 kernel.fgraph_filters = FILTER[, FILTER2...]
50 Add fgraph tracing function filters.
51
52 kernel.fgraph_notraces = FILTER[, FILTER2...]
53 Add fgraph non-tracing function filters.
54
55
56 Ftrace Per-instance Options
57 ---------------------------
58
59 These options can be used for each instance including global ftrace node.
60
61 ftrace.[instance.INSTANCE.]options = OPT1[, OPT2[...]]
62 Enable given ftrace options.
63
64 ftrace.[instance.INSTANCE.]tracing_on = 0|1
65 Enable/Disable tracing on this instance when starting boot-time tracing.
66 (you can enable it by the "traceon" event trigger action)
67
68 ftrace.[instance.INSTANCE.]trace_clock = CLOCK
69 Set given CLOCK to ftrace's trace_clock.
70
71 ftrace.[instance.INSTANCE.]buffer_size = SIZE
72 Configure ftrace buffer size to SIZE. You can use "KB" or "MB"
73 for that SIZE.
74
75 ftrace.[instance.INSTANCE.]alloc_snapshot
76 Allocate snapshot buffer.
77
78 ftrace.[instance.INSTANCE.]cpumask = CPUMASK
79 Set CPUMASK as trace cpu-mask.
80
81 ftrace.[instance.INSTANCE.]events = EVENT[, EVENT2[...]]
82 Enable given events on boot. You can use a wild card in EVENT.
83
84 ftrace.[instance.INSTANCE.]tracer = TRACER
85 Set TRACER to current tracer on boot. (e.g. function)
86
87 ftrace.[instance.INSTANCE.]ftrace.filters
88 This will take an array of tracing function filter rules.
89
90 ftrace.[instance.INSTANCE.]ftrace.notraces
91 This will take an array of NON-tracing function filter rules.
92
93
94 Ftrace Per-Event Options
95 ------------------------
96
97 These options are setting per-event options.
98
99 ftrace.[instance.INSTANCE.]event.GROUP.EVENT.enable
100 Enable GROUP:EVENT tracing.
101
102 ftrace.[instance.INSTANCE.]event.GROUP.enable
103 Enable all event tracing within GROUP.
104
105 ftrace.[instance.INSTANCE.]event.enable
106 Enable all event tracing.
107
108 ftrace.[instance.INSTANCE.]event.GROUP.EVENT.filter = FILTER
109 Set FILTER rule to the GROUP:EVENT.
110
111 ftrace.[instance.INSTANCE.]event.GROUP.EVENT.actions = ACTION[, ACTION2[...]]
112 Set ACTIONs to the GROUP:EVENT.
113
114 ftrace.[instance.INSTANCE.]event.kprobes.EVENT.probes = PROBE[, PROBE2[...]]
115 Defines new kprobe event based on PROBEs. It is able to define
116 multiple probes on one event, but those must have same type of
117 arguments. This option is available only for the event which
118 group name is "kprobes".
119
120 ftrace.[instance.INSTANCE.]event.synthetic.EVENT.fields = FIELD[, FIELD2[...]]
121 Defines new synthetic event with FIELDs. Each field should be
122 "type varname".
123
124 Note that kprobe and synthetic event definitions can be written under
125 instance node, but those are also visible from other instances. So please
126 take care for event name conflict.
127
128 Ftrace Histogram Options
129 ------------------------
130
131 Since it is too long to write a histogram action as a string for per-event
132 action option, there are tree-style options under per-event 'hist' subkey
133 for the histogram actions. For the detail of the each parameter,
134 please read the event histogram document (Documentation/trace/histogram.rst)
135
136 ftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.[N.]keys = KEY1[, KEY2[...]]
137 Set histogram key parameters. (Mandatory)
138 The 'N' is a digit string for the multiple histogram. You can omit it
139 if there is one histogram on the event.
140
141 ftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.[N.]values = VAL1[, VAL2[...]]
142 Set histogram value parameters.
143
144 ftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.[N.]sort = SORT1[, SORT2[...]]
145 Set histogram sort parameter options.
146
147 ftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.[N.]size = NR_ENTRIES
148 Set histogram size (number of entries).
149
150 ftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.[N.]name = NAME
151 Set histogram name.
152
153 ftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.[N.]var.VARIABLE = EXPR
154 Define a new VARIABLE by EXPR expression.
155
156 ftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.[N.]<pause|continue|clear>
157 Set histogram control parameter. You can set one of them.
158
159 ftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.[N.]onmatch.[M.]event = GROUP.EVENT
160 Set histogram 'onmatch' handler matching event parameter.
161 The 'M' is a digit string for the multiple 'onmatch' handler. You can omit it
162 if there is one 'onmatch' handler on this histogram.
163
164 ftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.[N.]onmatch.[M.]trace = EVENT[, ARG1[...]]
165 Set histogram 'trace' action for 'onmatch'.
166 EVENT must be a synthetic event name, and ARG1... are parameters
167 for that event. Mandatory if 'onmatch.event' option is set.
168
169 ftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.[N.]onmax.[M.]var = VAR
170 Set histogram 'onmax' handler variable parameter.
171
172 ftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.[N.]onchange.[M.]var = VAR
173 Set histogram 'onchange' handler variable parameter.
174
175 ftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.[N.]<onmax|onchange>.[M.]save = ARG1[, ARG2[...]]
176 Set histogram 'save' action parameters for 'onmax' or 'onchange' handler.
177 This option or below 'snapshot' option is mandatory if 'onmax.var' or
178 'onchange.var' option is set.
179
180 ftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.[N.]<onmax|onchange>.[M.]snapshot
181 Set histogram 'snapshot' action for 'onmax' or 'onchange' handler.
182 This option or above 'save' option is mandatory if 'onmax.var' or
183 'onchange.var' option is set.
184
185 ftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.filter = FILTER_EXPR
186 Set histogram filter expression. You don't need 'if' in the FILTER_EXPR.
187
188 Note that this 'hist' option can conflict with the per-event 'actions'
189 option if the 'actions' option has a histogram action.
190
191
192 When to Start
193 =============
194
195 All boot-time tracing options starting with ``ftrace`` will be enabled at the
196 end of core_initcall. This means you can trace the events from postcore_initcall.
197 Most of the subsystems and architecture dependent drivers will be initialized
198 after that (arch_initcall or subsys_initcall). Thus, you can trace those with
199 boot-time tracing.
200 If you want to trace events before core_initcall, you can use the options
201 starting with ``kernel``. Some of them will be enabled earlier than the initcall
202 processing (for example, ``kernel.ftrace=function`` and ``kernel.trace_event``
203 will start before the initcall.)
204
205
206 Examples
207 ========
208
209 For example, to add filter and actions for each event, define kprobe
210 events, and synthetic events with histogram, write a boot config like
211 below::
212
213 ftrace.event {
214 task.task_newtask {
215 filter = "pid < 128"
216 enable
217 }
218 kprobes.vfs_read {
219 probes = "vfs_read $arg1 $arg2"
220 filter = "common_pid < 200"
221 enable
222 }
223 synthetic.initcall_latency {
224 fields = "unsigned long func", "u64 lat"
225 hist {
226 keys = func.sym, lat
227 values = lat
228 sort = lat
229 }
230 }
231 initcall.initcall_start.hist {
232 keys = func
233 var.ts0 = common_timestamp.usecs
234 }
235 initcall.initcall_finish.hist {
236 keys = func
237 var.lat = common_timestamp.usecs - $ts0
238 onmatch {
239 event = initcall.initcall_start
240 trace = initcall_latency, func, $lat
241 }
242 }
243 }
244
245 Also, boot-time tracing supports "instance" node, which allows us to run
246 several tracers for different purpose at once. For example, one tracer
247 is for tracing functions starting with "user\_", and others tracing
248 "kernel\_" functions, you can write boot config as below::
249
250 ftrace.instance {
251 foo {
252 tracer = "function"
253 ftrace.filters = "user_*"
254 }
255 bar {
256 tracer = "function"
257 ftrace.filters = "kernel_*"
258 }
259 }
260
261 The instance node also accepts event nodes so that each instance
262 can customize its event tracing.
263
264 With the trigger action and kprobes, you can trace function-graph while
265 a function is called. For example, this will trace all function calls in
266 the pci_proc_init()::
267
268 ftrace {
269 tracing_on = 0
270 tracer = function_graph
271 event.kprobes {
272 start_event {
273 probes = "pci_proc_init"
274 actions = "traceon"
275 }
276 end_event {
277 probes = "pci_proc_init%return"
278 actions = "traceoff"
279 }
280 }
281 }
282
283
284 This boot-time tracing also supports ftrace kernel parameters via boot
285 config.
286 For example, following kernel parameters::
287
288 trace_options=sym-addr trace_event=initcall:* tp_printk trace_buf_size=1M ftrace=function ftrace_filter="vfs*"
289
290 This can be written in boot config like below::
291
292 kernel {
293 trace_options = sym-addr
294 trace_event = "initcall:*"
295 tp_printk
296 trace_buf_size = 1M
297 ftrace = function
298 ftrace_filter = "vfs*"
299 }
300
301 Note that parameters start with "kernel" prefix instead of "ftrace".
302

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

개요: bootconfig로 ftrace 기능 프로그래밍

1-18

이 문서는 GPL-2.0 라이선스를 사용하며 Masami Hiramatsu가 작성했다. Boot-time tracing은 장치 초기화를 포함한 부팅 과정을 추적한다.

이 기능은 이벤트별 filter와 action, histogram, kprobe event, synthetic event, trace instance를 포함한 ftrace의 전체 기능을 부팅 단계에서 사용할 수 있게 한다. 커널 명령줄만으로는 이런 복잡한 기능을 제어하기 어려우므로 bootconfig 파일에 추적 프로그램을 기술한다.

부팅 추적 구성
bootconfig fileftrace programming
Kernel bootTrace instances and events
Device initializationFilters, actions, histograms

복잡한 ftrace 설정을 bootconfig 트리로 전달해 초기화 과정에서 적용한다.

사용 가능한 ftrace 기능
기능용도
Per-event filter / action이벤트 선택과 trigger 동작
Histogram키·값·정렬·handler 기반 집계
kprobe / synthetic event동적 probe와 조합 이벤트 정의
Trace instance목적별 독립 tracer와 buffer

커널 명령줄 대신 bootconfig로 함께 구성할 수 있는 기능이다.

.. SPDX-License-Identifier: GPL-2.0

=================
Boot-time tracing
=================

:Author: Masami Hiramatsu <[email protected]>

Overview
========

Boot-time tracing allows users to trace boot-time process including
device initialization with full features of ftrace including per-event
filter and actions, histograms, kprobe-events and synthetic-events,
and trace instances.
Since kernel command line is not enough to control these complex features,
this uses bootconfig file to describe tracing feature programming.

Boot Config 옵션 접두어와 참고 문서

19-29

부팅 시간 추적 옵션은 bootconfig 파일에서 `ftrace.` 또는 `kernel.` 접두어 아래에 둔다. `kernel.`로 시작하는 옵션은 커널 매개변수 설명을 함께 확인해야 한다.

bootconfig 문법은 `Documentation/admin-guide/bootconfig.rst`, 커널 매개변수는 `Documentation/admin-guide/kernel-parameters.rst`를 참조한다.

옵션 namespace
Prefix역할참고
ftrace.boot-time tracing 트리형 기능 설정이 문서의 instance·event·hist 옵션
kernel.legacy kernel command line의 일부로 전달kernel-parameters.rst

접두어에 따라 설정 전달 시점과 해석 경로가 달라진다.

Options in the Boot Config
==========================

Here is the list of available options for boot time tracing in
boot config file [1]_. All options are under "ftrace." or "kernel."
prefix. See kernel parameters for the options which starts
with "kernel." prefix [2]_.

.. [1] See :ref:`Documentation/admin-guide/bootconfig.rst <bootconfig>`
.. [2] See :ref:`Documentation/admin-guide/kernel-parameters.rst <kernelparameters>`

ftrace 전역 옵션

30-55

ftrace 전역 옵션은 bootconfig에서 `kernel.` 접두어를 사용하며 legacy kernel command line의 일부로 전달된다.

`kernel.tp_printk`는 trace event 데이터를 printk buffer에도 출력한다. `kernel.dump_on_oops[=MODE]`는 Oops 발생 시 ftrace를 dump한다. MODE가 1이거나 생략되면 모든 CPU의 trace buffer를, MODE가 2이면 Oops를 일으킨 CPU의 buffer만 dump한다.

`kernel.traceoff_on_warning`은 `WARN_ON()` 발생 시 추적을 멈춘다. `kernel.fgraph_max_depth`는 function graph tracer의 최대 깊이를 정하며, `kernel.fgraph_filters`와 `kernel.fgraph_notraces`는 각각 추적할 함수와 제외할 함수 filter를 쉼표 목록으로 추가한다.

전역 옵션
Option동작
kernel.tp_printktrace event를 printk buffer에도 출력
kernel.dump_on_oops[=MODE]Oops 시 모든 CPU 또는 해당 CPU trace buffer dump
kernel.traceoff_on_warningWARN_ON()에서 tracing 중지
kernel.fgraph_max_depthfunction graph 최대 호출 깊이
kernel.fgraph_filters추적할 함수 filter 추가
kernel.fgraph_notraces추적하지 않을 함수 filter 추가

부팅 초기에 legacy 명령줄 경로로 적용되는 ftrace 설정이다.

Ftrace Global Options
---------------------

Ftrace global options have "kernel." prefix in boot config, which means
these options are passed as a part of kernel legacy command line.

kernel.tp_printk
   Output trace-event data on printk buffer too.

kernel.dump_on_oops [= MODE]
   Dump ftrace on Oops. If MODE = 1 or omitted, dump trace buffer
   on all CPUs. If MODE = 2, dump a buffer on a CPU which kicks Oops.

kernel.traceoff_on_warning
   Stop tracing if WARN_ON() occurs.

kernel.fgraph_max_depth = MAX_DEPTH
   Set MAX_DEPTH to maximum depth of fgraph tracer.

kernel.fgraph_filters = FILTER[, FILTER2...]
   Add fgraph tracing function filters.

kernel.fgraph_notraces = FILTER[, FILTER2...]
   Add fgraph non-tracing function filters.

ftrace 인스턴스별 옵션

56-93

인스턴스별 옵션은 전역 ftrace node를 포함해 각 trace instance에 적용한다. 경로 형식은 `ftrace.[instance.INSTANCE.]...`이며 `instance.INSTANCE`를 생략하면 전역 node를 뜻한다.

`options`는 ftrace 옵션 목록을 켜고, `tracing_on`은 부팅 시간 추적 시작 시 인스턴스 추적을 켜거나 끈다. 꺼 둔 추적은 event trigger의 `traceon` action으로 나중에 시작할 수 있다. `trace_clock`, `buffer_size`, `alloc_snapshot`, `cpumask`는 clock, KB·MB 단위 buffer, snapshot buffer, 추적 CPU mask를 정한다.

`events`는 wildcard를 허용하는 부팅 시 event 목록을 켠다. `tracer`는 현재 tracer를 지정하며 예로 `function`을 사용할 수 있다. `ftrace.filters`와 `ftrace.notraces`는 각각 함수 추적 포함 규칙과 제외 규칙의 배열을 받는다.

인스턴스별 옵션
하위 키설정
options지정한 ftrace 옵션 활성화
tracing_on부팅 추적 시작 시 해당 instance 켜기·끄기
trace_clocktrace_clock 선택
buffer_sizeKB 또는 MB 단위 buffer 크기
alloc_snapshotsnapshot buffer 할당
cpumask추적할 CPU mask
eventswildcard 가능한 event 목록 활성화
tracer현재 tracer 선택
ftrace.filters / notraces함수 포함 / 제외 규칙 배열

각 trace instance의 실행·저장·선택 범위를 구성한다.

인스턴스 주소 지정
ftrace.optionsGlobal ftrace node
ftrace.instance.foo.optionsInstance foo
tracing_on = 0Later traceon trigger

같은 옵션 구조를 전역 node와 이름 있는 instance에 적용한다.

Ftrace Per-instance Options
---------------------------

These options can be used for each instance including global ftrace node.

ftrace.[instance.INSTANCE.]options = OPT1[, OPT2[...]]
   Enable given ftrace options.

ftrace.[instance.INSTANCE.]tracing_on = 0|1
   Enable/Disable tracing on this instance when starting boot-time tracing.
   (you can enable it by the "traceon" event trigger action)

ftrace.[instance.INSTANCE.]trace_clock = CLOCK
   Set given CLOCK to ftrace's trace_clock.

ftrace.[instance.INSTANCE.]buffer_size = SIZE
   Configure ftrace buffer size to SIZE. You can use "KB" or "MB"
   for that SIZE.

ftrace.[instance.INSTANCE.]alloc_snapshot
   Allocate snapshot buffer.

ftrace.[instance.INSTANCE.]cpumask = CPUMASK
   Set CPUMASK as trace cpu-mask.

ftrace.[instance.INSTANCE.]events = EVENT[, EVENT2[...]]
   Enable given events on boot. You can use a wild card in EVENT.

ftrace.[instance.INSTANCE.]tracer = TRACER
   Set TRACER to current tracer on boot. (e.g. function)

ftrace.[instance.INSTANCE.]ftrace.filters
   This will take an array of tracing function filter rules.

ftrace.[instance.INSTANCE.]ftrace.notraces
   This will take an array of NON-tracing function filter rules.

event별 enable·filter·action과 동적 event

94-127

event별 옵션은 `ftrace.[instance.INSTANCE.]event` 아래에 둔다. `GROUP.EVENT.enable`은 한 event, `GROUP.enable`은 group 전체, `event.enable`은 모든 event의 추적을 켠다.

`GROUP.EVENT.filter`는 해당 event의 filter 규칙을 설정하고 `GROUP.EVENT.actions`는 하나 이상의 action을 설정한다. `event.kprobes.EVENT.probes`는 같은 인수 형식을 가진 하나 이상의 probe로 새 kprobe event를 정의하며 group 이름이 `kprobes`인 event에서만 사용할 수 있다.

`event.synthetic.EVENT.fields`는 `type varname` 형식의 field 목록으로 새 synthetic event를 정의한다. kprobe와 synthetic event 정의는 instance node 아래에 작성할 수 있지만 다른 instance에서도 보이므로 event 이름 충돌을 피해야 한다.

event별 옵션
경로동작
event.GROUP.EVENT.enable단일 event 활성화
event.GROUP.enablegroup의 모든 event 활성화
event.enable모든 event 활성화
event.GROUP.EVENT.filterevent filter 규칙
event.GROUP.EVENT.actionsevent action 목록
event.kprobes.EVENT.probeskprobe event 정의
event.synthetic.EVENT.fieldssynthetic event field 정의

활성화 범위와 동적 event 정의를 구분한다.

동적 event 가시성
Define under instance fookprobe / synthetic event
Event visible from other instancesShared event name
Duplicate nameConflict risk

정의 위치는 instance 아래일 수 있지만 이름 공간은 instance에 갇히지 않는다.

Ftrace Per-Event Options
------------------------

These options are setting per-event options.

ftrace.[instance.INSTANCE.]event.GROUP.EVENT.enable
   Enable GROUP:EVENT tracing.

ftrace.[instance.INSTANCE.]event.GROUP.enable
   Enable all event tracing within GROUP.

ftrace.[instance.INSTANCE.]event.enable
   Enable all event tracing.

ftrace.[instance.INSTANCE.]event.GROUP.EVENT.filter = FILTER
   Set FILTER rule to the GROUP:EVENT.

ftrace.[instance.INSTANCE.]event.GROUP.EVENT.actions = ACTION[, ACTION2[...]]
   Set ACTIONs to the GROUP:EVENT.

ftrace.[instance.INSTANCE.]event.kprobes.EVENT.probes = PROBE[, PROBE2[...]]
   Defines new kprobe event based on PROBEs. It is able to define
   multiple probes on one event, but those must have same type of
   arguments. This option is available only for the event which
   group name is "kprobes".

ftrace.[instance.INSTANCE.]event.synthetic.EVENT.fields = FIELD[, FIELD2[...]]
   Defines new synthetic event with FIELDs. Each field should be
   "type varname".

Note that kprobe and synthetic event definitions can be written under
instance node, but those are also visible from other instances. So please
take care for event name conflict.

히스토그램 키·값·정렬·변수와 제어

128-159

event action 문자열로 histogram 전체를 쓰면 너무 길어지므로 event의 `hist` 하위에 트리형 옵션을 제공한다. 각 매개변수의 자세한 의미는 `Documentation/trace/histogram.rst`를 참조한다.

`hist.[N.]keys`는 필수 key 목록이다. 여러 histogram을 둘 때 `N`은 숫자 문자열이며 하나뿐이면 생략할 수 있다. `values`, `sort`, `size`, `name`은 각각 값 목록, 정렬 옵션, entry 수, histogram 이름을 지정한다.

`var.VARIABLE = EXPR`은 식으로 새 변수를 정의한다. `pause`, `continue`, `clear` 중 하나를 제어 매개변수로 설정할 수 있다.

기본 histogram 하위 키
Subkey의미
keys필수 histogram key
values집계 value
sort정렬 옵션
size최대 entry 수
namehistogram 이름
var.VARIABLEEXPR로 변수 정의
pause / continue / clearhistogram 제어

집계 구조와 실행 상태를 설정한다.

Ftrace Histogram Options
------------------------

Since it is too long to write a histogram action as a string for per-event
action option, there are tree-style options under per-event 'hist' subkey
for the histogram actions. For the detail of the each parameter,
please read the event histogram document (Documentation/trace/histogram.rst)

ftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.[N.]keys = KEY1[, KEY2[...]]
  Set histogram key parameters. (Mandatory)
  The 'N' is a digit string for the multiple histogram. You can omit it
  if there is one histogram on the event.

ftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.[N.]values = VAL1[, VAL2[...]]
  Set histogram value parameters.

ftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.[N.]sort = SORT1[, SORT2[...]]
  Set histogram sort parameter options.

ftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.[N.]size = NR_ENTRIES
  Set histogram size (number of entries).

ftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.[N.]name = NAME
  Set histogram name.

ftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.[N.]var.VARIABLE = EXPR
  Define a new VARIABLE by EXPR expression.

ftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.[N.]<pause|continue|clear>
  Set histogram control parameter. You can set one of them.

ftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.[N.]onmatch.[M.]event = GROUP.EVENT

onmatch·onmax·onchange handler와 filter

160-191

`onmatch.[M.]event`는 일치시킬 `GROUP.EVENT`를 지정한다. 여러 handler를 둘 때 `M`은 숫자 문자열이고 하나뿐이면 생략할 수 있다. `onmatch.[M].trace`는 일치 시 실행할 synthetic event와 인수를 지정하며 `onmatch.event`를 설정했다면 필수다.

`onmax.[M].var`와 `onchange.[M].var`는 각각 최대값 또는 값 변경을 감시할 변수를 지정한다. 두 handler의 `save`는 저장할 인수 목록이고 `snapshot`은 snapshot action이다. `onmax.var`나 `onchange.var`를 설정했다면 `save`와 `snapshot` 중 하나가 필수다.

`hist.filter = FILTER_EXPR`는 histogram filter 식을 설정하며 식 앞에 `if`를 쓰지 않는다. event의 `actions` 옵션에도 histogram action이 있으면 이 트리형 `hist` 옵션과 충돌할 수 있다.

histogram handler
Handler필수 연결
onmatch.event일치시킬 GROUP.EVENT
onmatch.tracesynthetic EVENT와 인수, onmatch.event 사용 시 필수
onmax.var최대값을 감시할 변수
onchange.var변화를 감시할 변수
savehandler에서 저장할 인수
snapshothandler에서 snapshot 생성
filter`if` 없는 FILTER_EXPR

event 일치·최대값·변화 시점에 실행할 동작이다.

handler 필수 조건
onmatch.event setonmatch.trace required
onmax.var setsave OR snapshot required
onchange.var setsave OR snapshot required

변수 handler와 action의 유효 조합이다.

  Set histogram 'onmatch' handler matching event parameter.
  The 'M' is a digit string for the multiple 'onmatch' handler. You can omit it
  if there is one 'onmatch' handler on this histogram.

ftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.[N.]onmatch.[M.]trace = EVENT[, ARG1[...]]
  Set histogram 'trace' action for 'onmatch'.
  EVENT must be a synthetic event name, and ARG1... are parameters
  for that event. Mandatory if 'onmatch.event' option is set.

ftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.[N.]onmax.[M.]var = VAR
  Set histogram 'onmax' handler variable parameter.

ftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.[N.]onchange.[M.]var = VAR
  Set histogram 'onchange' handler variable parameter.

ftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.[N.]<onmax|onchange>.[M.]save = ARG1[, ARG2[...]]
  Set histogram 'save' action parameters for 'onmax' or 'onchange' handler.
  This option or below 'snapshot' option is mandatory if 'onmax.var' or
  'onchange.var' option is set.

ftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.[N.]<onmax|onchange>.[M.]snapshot
  Set histogram 'snapshot' action for 'onmax' or 'onchange' handler.
  This option or above 'save' option is mandatory if 'onmax.var' or
  'onchange.var' option is set.

ftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.filter = FILTER_EXPR
  Set histogram filter expression. You don't need 'if' in the FILTER_EXPR.

Note that this 'hist' option can conflict with the per-event 'actions'
option if the 'actions' option has a histogram action.

추적 활성화 시점

192-205

`ftrace`로 시작하는 모든 boot-time tracing 옵션은 `core_initcall` 끝에서 활성화된다. 따라서 `postcore_initcall`부터 발생하는 event를 추적할 수 있다. 대부분의 subsystem과 아키텍처 의존 driver는 그 뒤의 `arch_initcall` 또는 `subsys_initcall`에서 초기화되므로 boot-time tracing으로 관찰할 수 있다.

`core_initcall`보다 앞선 event가 필요하면 `kernel`로 시작하는 옵션을 사용한다. 일부는 initcall 처리보다 먼저 켜지며 `kernel.ftrace=function`과 `kernel.trace_event`가 그 예다.

부팅 단계별 활성화
kernel.* optionsBefore initcall processing
core_initcall endEnable ftrace.* options
postcore_initcallTrace events
arch_initcall / subsys_initcallTrace drivers and subsystems

접두어가 추적을 시작할 수 있는 가장 이른 시점에 영향을 준다.

When to Start
=============

All boot-time tracing options starting with ``ftrace`` will be enabled at the
end of core_initcall. This means you can trace the events from postcore_initcall.
Most of the subsystems and architecture dependent drivers will be initialized
after that (arch_initcall or subsys_initcall). Thus, you can trace those with
boot-time tracing.
If you want to trace events before core_initcall, you can use the options
starting with ``kernel``. Some of them will be enabled earlier than the initcall
processing (for example, ``kernel.ftrace=function`` and ``kernel.trace_event``
will start before the initcall.)

filter·kprobe·synthetic event와 initcall 지연

206-244

첫 예제는 event마다 filter와 action을 추가하고 kprobe event, synthetic event, histogram을 함께 정의한다. `task.task_newtask`는 `pid < 128`인 event만 활성화한다. `kprobes.vfs_read`는 `vfs_read $arg1 $arg2` probe를 만들고 `common_pid < 200` filter를 적용한다.

`synthetic.initcall_latency`는 `unsigned long func`와 `u64 lat` field를 가지며 `func.sym`, `lat`를 key로, `lat`를 value와 sort 기준으로 쓰는 histogram을 둔다.

`initcall_start` histogram은 `func`를 key로 시작 timestamp를 microsecond 단위 변수 `ts0`에 저장한다. `initcall_finish`는 현재 timestamp에서 `$ts0`를 빼 `lat`를 계산하고, start event와 일치시키는 `onmatch` handler에서 `initcall_latency` synthetic event에 `func`와 `$lat`를 전달한다.

initcall 지연 합성
initcall_startts0 = common_timestamp.usecs
initcall_finishlat = timestamp - $ts0
onmatch initcall_starttrace initcall_latency(func, $lat)
synthetic.initcall_latencyHistogram by func.sym and lat

시작·종료 event를 histogram 변수로 결합해 synthetic event를 만든다.

첫 예제 구성
Node설정
task.task_newtaskpid < 128 filter 후 enable
kprobes.vfs_readvfs_read probe, common_pid < 200
synthetic.initcall_latencyfunc·lat field와 histogram
initcall_start.histfunc key와 ts0 변수
initcall_finish.histlat 계산과 onmatch trace

각 bootconfig node가 맡는 역할이다.

Examples
========

For example, to add filter and actions for each event, define kprobe
events, and synthetic events with histogram, write a boot config like
below::

  ftrace.event {
        task.task_newtask {
                filter = "pid < 128"
                enable
        }
        kprobes.vfs_read {
                probes = "vfs_read $arg1 $arg2"
                filter = "common_pid < 200"
                enable
        }
        synthetic.initcall_latency {
                fields = "unsigned long func", "u64 lat"
                hist {
                        keys = func.sym, lat
                        values = lat
                        sort = lat
                }
        }
        initcall.initcall_start.hist {
                keys = func
                var.ts0 = common_timestamp.usecs
        }
        initcall.initcall_finish.hist {
                keys = func
                var.lat = common_timestamp.usecs - $ts0
                onmatch {
                        event = initcall.initcall_start
                        trace = initcall_latency, func, $lat
                }
        }
  }

목적별 다중 trace instance

245-263

Boot-time tracing은 여러 tracer를 서로 다른 목적으로 동시에 실행하는 `instance` node를 지원한다. 예제의 `foo`와 `bar`는 모두 `function` tracer를 사용하지만 함수 filter를 분리한다.

`foo`는 `user_*`로 시작하는 함수만, `bar`는 `kernel_*`로 시작하는 함수만 추적한다. instance node는 event node도 받을 수 있으므로 각 instance가 event tracing을 독립적으로 맞춤 설정할 수 있다.

다중 instance
InstanceTracerFilter
foofunctionuser_*
barfunctionkernel_*

같은 tracer에 서로 다른 함수 선택 규칙을 적용한다.

instance 격리
ftrace.instance.foouser_* functions
ftrace.instance.barkernel_* functions
Per-instance event nodesCustom event tracing

목적별 buffer와 filter를 분리해 동시에 추적한다.

Also, boot-time tracing supports "instance" node, which allows us to run
several tracers for different purpose at once. For example, one tracer
is for tracing functions starting with "user\_", and others tracing
"kernel\_" functions, you can write boot config as below::

  ftrace.instance {
        foo {
                tracer = "function"
                ftrace.filters = "user_*"
        }
        bar {
                tracer = "function"
                ftrace.filters = "kernel_*"
        }
  }

The instance node also accepts event nodes so that each instance
can customize its event tracing.

kprobe action으로 함수 그래프 구간 제한

264-283

trigger action과 kprobe를 결합하면 특정 함수가 실행되는 동안에만 function graph를 추적할 수 있다. 예제는 `tracing_on = 0`으로 시작하고 tracer를 `function_graph`로 설정한다.

`start_event`는 `pci_proc_init` 진입 kprobe에서 `traceon` action을 실행한다. `end_event`는 `pci_proc_init%return` 반환 probe에서 `traceoff` action을 실행한다. 결과적으로 `pci_proc_init()` 내부에서 호출되는 모든 함수만 기록한다.

pci_proc_init 함수 그래프 창
Boot with tracing_on = 0No function graph records
pci_proc_init entrystart_event: traceon
Calls inside pci_proc_initfunction_graph tracing
pci_proc_init returnend_event: traceoff

진입과 반환 kprobe가 tracing_on 상태를 경계 짓는다.

trigger event
EventProbeAction
start_eventpci_proc_inittraceon
end_eventpci_proc_init%returntraceoff

두 probe가 추적 구간의 시작과 끝을 담당한다.

With the trigger action and kprobes, you can trace function-graph while
a function is called. For example, this will trace all function calls in
the pci_proc_init()::

  ftrace {
        tracing_on = 0
        tracer = function_graph
        event.kprobes {
                start_event {
                        probes = "pci_proc_init"
                        actions = "traceon"
                }
                end_event {
                        probes = "pci_proc_init%return"
                        actions = "traceoff"
                }
        }
  }

기존 ftrace 커널 매개변수의 bootconfig 표현

284-301

Boot-time tracing은 기존 ftrace 커널 매개변수도 bootconfig에서 지원한다. 원래 명령줄의 `trace_options=sym-addr`, `trace_event=initcall:*`, `tp_printk`, `trace_buf_size=1M`, `ftrace=function`, `ftrace_filter="vfs*"`를 `kernel` node 아래의 같은 이름 key로 옮길 수 있다.

이 매개변수들은 트리형 `ftrace` 접두어가 아니라 `kernel` 접두어로 시작한다는 점이 핵심이다.

커널 매개변수 변환
Kernel command lineBootconfig
trace_options=sym-addrkernel.trace_options = sym-addr
trace_event=initcall:*kernel.trace_event = "initcall:*"
tp_printkkernel.tp_printk
trace_buf_size=1Mkernel.trace_buf_size = 1M
ftrace=functionkernel.ftrace = function
ftrace_filter="vfs*"kernel.ftrace_filter = "vfs*"

legacy command line 항목과 bootconfig key의 대응이다.

legacy 옵션 이동
Legacy ftrace kernel parameterskernel { ... }
kernel prefixEarly boot parameter handling

명령줄 기능은 값은 유지하고 `kernel` node 아래 구조로 표현한다.

This boot-time tracing also supports ftrace kernel parameters via boot
config.
For example, following kernel parameters::

 trace_options=sym-addr trace_event=initcall:* tp_printk trace_buf_size=1M ftrace=function ftrace_filter="vfs*"

This can be written in boot config like below::

  kernel {
        trace_options = sym-addr
        trace_event = "initcall:*"
        tp_printk
        trace_buf_size = 1M
        ftrace = function
        ftrace_filter = "vfs*"
  }

Note that parameters start with "kernel" prefix instead of "ftrace".