On Thu, Nov 28, 2024 at 09:35:42PM +0800, 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.
Based on this requirement, add the --action option to the event to
specify the behavior when the event occurs.
Signed-off-by: Yang Jihong <yangjihong@xxxxxxxxxxxxx>
---
tools/perf/Documentation/perf-record.txt | 8 +
tools/perf/builtin-record.c | 31 +++
tools/perf/util/Build | 18 ++
tools/perf/util/parse-action.c | 230 +++++++++++++++++++++++
tools/perf/util/parse-action.h | 75 ++++++++
tools/perf/util/parse-action.l | 40 ++++
tools/perf/util/parse-action.y | 82 ++++++++
tools/perf/util/record_action.c | 15 ++
tools/perf/util/record_action.h | 24 +++
9 files changed, 523 insertions(+)
create mode 100644 tools/perf/util/parse-action.c
create mode 100644 tools/perf/util/parse-action.h
create mode 100644 tools/perf/util/parse-action.l
create mode 100644 tools/perf/util/parse-action.y
create mode 100644 tools/perf/util/record_action.c
create mode 100644 tools/perf/util/record_action.h
diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt
index 242223240a08..d0d9e0f69f3d 100644
--- a/tools/perf/Documentation/perf-record.txt
+++ b/tools/perf/Documentation/perf-record.txt
@@ -833,6 +833,14 @@ filtered through the mask provided by -C option.
Prepare BPF filter to be used by regular users. The action should be
either "pin" or "unpin". The filter can be used after it's pinned.
+--action=<action>::
+ Actions are the programs that run when the sampling event is triggered.
+ The action is a list of expressions separated by semicolons (;).
+ The sample data is saved by bpf prog attached by the event.
+ The call currently supported is print(); some commonly used built-in special
+ variables are also supported
+ For example:
+ # perf record -e sched:sched_switch --action 'print("[%llu]comm=%s, cpu=%d, pid=%d, tid=%d\n", time, comm, cpu, pid, tid)' true
But at this point in the series this isn't available, right?
I.e. when testing this specific patch I can't follow what the
documentation above says and expect anything, right? It will just fail?