問題描述
有選擇地為特定參數記錄內核 Ftrace 點 (Logging the kernel Ftrace point selectively for particular arguments)
我想使用 Ftrace 測量一些內核函數的性能,但我想針對參數的特定值選擇性地測量它。這是因為調用相同函數(但參數不同)的相同/其他程序污染了我的 Ftrace 輸出日誌。另外,我不想設置 PID 過濾器,因為它不能解決我的問題(我正在運行多個並行內核線程,並且同一個程序也可以使用不同的參數調用該函數)在不影響的情況下最好的方法是什麼測量?我是否缺少任何 Ftrace 功能(或可能自定義跟踪點)?
參考解法
方法 1:
We can use Conditional Tracepoints for this kinds of case. This patch may also be helpful in understanding. One can check this file ‑ samples\trace_events\trace‑events‑sample.h
in linux kernel to see sample examples.
In samples\trace_events\trace‑events‑sample.h
, It became crystal‑clear to me after seeing this macro ‑ TRACE_EVENT_CONDITION()
. Thanks to the author for providing a detailed documentation there.
Moreover, one can use pre‑defined event‑tracepoints or define a new custom event tracepoint in include/trace/events/*.h
and filter the trace logs by adding condition in TRACE_DIR/tracing/events/EVENT/filter
. This kernel documentation link is very helpful to understand this.