基本上有两种主要的方法来读取ftrace日志。从/ sys / kernel / debug / tracing / trace读取或从/ sys / kernel / debug / tracing / trace_pipe读取
可以使用/ sys / kernel / debug / tracing / buffer_size_kb设置前者的缓冲区大小
是否可以为trace_pipe设置缓冲区大小。如果有,怎么样?
您不需要为trace_pipe设置缓冲区大小,因为它会提供实时跟踪,如果没有可用数据则会阻塞。
阅读更多(https://www.kernel.org/doc/Documentation/trace/ftrace.txt):
trace_pipe:
The output is the same as the "trace" file but this
file is meant to be streamed with live tracing.
Reads from this file will block until new data is
retrieved. Unlike the "trace" file, this file is a
consumer. This means reading from this file causes
sequential reads to display more current data. Once
data is read from this file, it is consumed, and
will not be read again with a sequential read. The
"trace" file is static, and if the tracer is not
adding more data, it will display the same
information every time it is read.
只有一个缓冲区,/sys/kernel/debug/tracing/buffer_size_kb
设置它的大小。
当您从../trace
读取时,内核暂停跟踪,冻结缓冲区,并读取该缓冲区的副本(包含从(t1 - K
到t1
)的所有事件。
当您从../trace_pipe
读取时,您使用缓冲区尾端的数据并从内核中消失。内核继续跟踪并向缓冲区的头部添加数据,如果已经消耗了缓冲区中的所有内容,读者将只阻止等待新数据。
如果没有消费者(即,在开始阅读之前)并且缓冲区已满,则内核将从缓冲区的尾部掉落,或者停止在头部插入新数据,具体取决于/sys/kernel/debug/tracing/options/overwrite
的值。因此,如果overwrite
设置为1
,您将开始从t1 - K
获取事件,否则您将从更早开始读取事件(首次启用跟踪时),然后有间隙,然后从t1
开始的最近事件
资料来源:https://www.kernel.org/doc/Documentation/trace/ftrace.txt