Logging the kernel Ftrace point selectively for particular arguments

285 Views Asked by At

I want to measure performance of some kernel functions using Ftrace but I want to measure it selectively for particular value of argument. This is because the same/other programs calling the same function (but with different argument) pollute my Ftrace output logs. Also, I don't want to set PID filter as it would not solve my issue (I'm running multiple parallel kernel threads, and same program can also call that function with different arguments) What's the best possible way of doing it without affecting the measurements? Is there any Ftrace functionality (or possibly customizing the trace points) that I'm missing?

1

There are 1 best solutions below

0
On

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.