Linux-Kernel
/sys/kernel/debug/tracing/trace 會在幾秒鐘後自行覆蓋。我怎樣才能在沒有重複的情況下收集它?
在 Linux (Ubuntu 18) 中設置
function_graph
跟踪器時,儲存在 /sys/kernel/debug/tracing/trace 中的跟踪僅儲存幾秒鐘,然後再覆蓋自身。由於期間可能是可變的,例如,我不能保存它
cat /sys/kernel/debug/tracing/trace >> total_trace
因為它可能會產生在後處理過程中不可接受的重複。更糟糕的是,它可能會失去一些資訊。
有沒有辦法我可以打開文件並將所有新傳入的資訊通過管道傳輸到另一個文件?
謝謝
來自ftrace 文件:
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. This file will not disable tracing while being read
或使用
trace-cmd(1)
,具體trace-cmd-show
。從它的人:-p Instead of displaying the contents of the "trace" file, use the "trace_pipe" file. The difference between the two is that the "trace" file is static. That is, if tracing is stopped, the "trace" file will show the same contents each time. The "trace_pipe" file is a consuming read, where a read of the file will consume the output of what was read and it will not read the same thing a second time even if tracing is stopped. This file als will block. If no data is available, trace-cmd show will stop and wait for data to appear.
另請參閱此答案以了解如何更改跟踪文件的大小和行為。