【问题标题】:How to set the buffer size for trace_pipe in ftrace?如何在 ftrace 中设置 trace_pipe 的缓冲区大小?
【发布时间】:2017-03-26 16:54:56
【问题描述】:

读取 ftrace 日志基本上有两种主要方法。 要么从 /sys/内核/调试/跟踪/跟踪 或从 /sys/kernel/debug/tracing/trace_pipe

可以使用设置前者的缓冲区大小 /sys/kernel/debug/tracing/buffer_size_kb

是否可以为 trace_pipe 设置缓冲区大小。如果是,如何?

【问题讨论】:

    标签: android linux linux-kernel android-ndk


    【解决方案1】:

    您不需要为 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.
    

    【讨论】:

    • 感谢您的回复,但您可能没有正确理解我的问题。让我再次澄清一下。我的疑问是,如果您在时间戳 t1 开始从 trace_pipe 读取数据,那么它会仅从 t1 时间或从 t1-K 时间(K 某个常数)提供 ftrace 日志。
    • 你所解释的对于trace来说是正确的;但不适用于 trace_pipe。
    【解决方案2】:

    只有一个缓冲区,/sys/kernel/debug/tracing/buffer_size_kb 设置它的大小。

    当您从../trace 读取时,内核会暂停跟踪,冻结缓冲区,然后您读取该缓冲区的副本(包含从(t1 - Kt1)的所有事件。

    当您从../trace_pipe 读取数据时,您会使用缓冲区尾部的数据,并且这些数据会从内核中消失。内核继续跟踪并将数据添加到缓冲区的头部,如果读取器已经消耗了缓冲区中的所有内容,您的阅读器将阻塞等待新数据。

    如果没有消费者(即在你开始读取之前)并且缓冲区已满,内核要么从缓冲区的尾部下降,要么停止在头部插入新数据,具体取决于/sys/kernel/debug/tracing/options/overwrite 的值.因此,如果overwrite 设置为1,您将从t1 - K 开始获取事件,否则您将读取从更早开始的事件(首次启用跟踪时),然后有一个间隙,然后最近的事件开始在t1

    来源:https://www.kernel.org/doc/Documentation/trace/ftrace.txt

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-10
      • 1970-01-01
      • 1970-01-01
      • 2019-07-06
      相关资源
      最近更新 更多