Re: [External] Re: [RFC 00/12] perf record: Add event action support

Yang Jihong
2024-12-04T08:07:56Z

Hello,

On 11/28/24 21:53, Adrian Hunter wrote:
> On 28/11/24 15:35, Yang Jihong wrote:
>> In perf-record, when an event is triggered, default behavior is to
>> save sample data to perf.data. Sometimes, we may just want to do
>> some lightweight actions, such as printing a log.
>
> Why not just pipe 'perf record' to 'perf script'?
>
> # perf record -e sched:sched_switch | perf script | head
> perf 768231 [000] 2318380.474267: sched:sched_switch: perf:768231 [120] R ==> migration/0:18 [0]
> migration/0 18 [000] 2318380.474294: sched:sched_switch: migration/0:18 [0] S ==> swapper/0:0 [120]
> perf 768231 [001] 2318380.474353: sched:sched_switch: perf:768231 [120] R ==> migration/1:23 [0]
> migration/1 23 [001] 2318380.474382: sched:sched_switch: migration/1:23 [0] S ==> swapper/1:0 [120]
> perf 768231 [002] 2318380.474477: sched:sched_switch: perf:768231 [120] R ==> migration/2:29 [0]
> migration/2 29 [002] 2318380.474503: sched:sched_switch: migration/2:29 [0] S ==> swapper/2:0 [120]
> perf 768231 [003] 2318380.474513: sched:sched_switch: perf:768231 [120] R ==> migration/3:35 [0]
> migration/3 35 [003] 2318380.474523: sched:sched_switch: migration/3:35 [0] S ==> swapper/3:0 [120]
> perf 768231 [004] 2318380.474534: sched:sched_switch: perf:768231 [120] R ==> migration/4:41 [0]
> migration/4 41 [004] 2318380.474541: sched:sched_switch: migration/4:41 [0] S ==> swapper/4:0 [120]

pipe 'perf record' to 'perf script' has limited extensions.
We can use bpf prog to do more (such as saving user-defined data (such
as registers, function parameters), and customizing the format of
user-printed logs).

Now we only implement a simple print() call, and we can support more
calls later.

Thanks,
Yang