From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Yang Jihong <yangjihong@bytedance.com>
Cc: peterz@infradead.org, mingo@redhat.com, namhyung@kernel.org,
mark.rutland@arm.com, alexander.shishkin@linux.intel.com,
jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com,
kan.liang@linux.intel.com, james.clark@arm.com,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [RFC 00/12] perf record: Add event action support
Date: Thu, 28 Nov 2024 17:14:53 -0300 [thread overview]
Message-ID: <Z0jPPRA8JXSrwyaC@x1> (raw)
In-Reply-To: <20241128133553.823722-1-yangjihong@bytedance.com>
On Thu, Nov 28, 2024 at 09:35:41PM +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.
'perf record' is centered on saving data to disk without processing
events, while it has sideband events for some needs, like processing BPF
related events (PERF_RECORD_BPF_EVENT to catch PERF_BPF_EVENT_PROG_LOAD
and UNLOAD), doing things in a "live" way as your patchkit does seems
more appropriate to do in 'perf trace' :-)
I'll take a look at the rest of the patch series.
- Arnaldo
> This patchset uses bpf prog to attach to tracepoint event, and save sample
> to bpf perf_event ringbuffer in handler. perf-tool read the data and run actions.
>
> Currently only one call is supported, that is, print(),
> and some commonly used builtin variables are also supported.
>
> For example:
>
> # perf record -e sched:sched_switch --action 'print("[%03d][%llu]comm=%s, pid=%d, tid=%d\n", cpu, time, comm, pid, tid)' true
> [003][795464100275136]comm=perf, pid=141580, tid=141580
> [003][795464100278234]comm=swapper/3, pid=0, tid=0
> [003][795464100288984]comm=perf, pid=141580, tid=141580
> [003][795464100457865]comm=swapper/3, pid=0, tid=0
> [003][795464100485547]comm=perf, pid=141580, tid=141580
> [003][795464100491398]comm=kworker/u36:1, pid=139834, tid=139834
> [003][795464100493647]comm=perf, pid=141580, tid=141580
> [003][795464100494967]comm=kworker/u36:1, pid=139834, tid=139834
> [003][795464100498146]comm=perf, pid=141580, tid=141580
> ...
>
> # perf record -e cycles --action 'print("test\n");' true
> bpf record action only supports specifying for tracepoint tracer
>
> # perf record -e sched:sched_switch --action 'print("[%llu]comm=%s, cpu=%d, pid=%d, tid=%d\n", time, comm, cpu, pid)' true
> print() arguments number for format string mismatch: 5 expected, 4 provided
> parse action option failed
>
> Usage: perf record [<options>] [<command>]
> or: perf record [<options>] -- <command> [<options>]
>
> --action <action>
> event action
>
> # perf record -e sched:sched_switch --action 'print("test\n");' true
> test
> test
> test
> test
> test
> test
> test
> test
> test
> test
> ...
>
> This patchset implements simple features and can be extended as needed.
>
> TODO LIST:
> 1. Support common operations such as logical operations and bit operations
> 2. Support other calls such as dumpstack(), count()
> 3. Support specify actions for kprobe events
> 4. For builds that disable bpf_skel, support real-time parsing of perf record mmap ringbuffer data (similar to perf top)
> 5. Link libllvm to support dynamic generation of bpf progs
>
> Yang Jihong (12):
> perf record: Add event action support
> perf event action: Add parsing const expr support
> perf event action: Add parsing const integer expr support
> perf event action: Add parsing const string expr support
> perf event action: Add parsing call expr support
> perf event action: Add parsing print() call expr support
> perf event action: Add parsing builtin expr support
> perf event action: Add parsing builtin cpu expr support
> perf event action: Add parsing builtin pid expr support
> perf event action: Add parsing builtin tid expr support
> perf event action: Add parsing builtin comm expr support
> perf event action: Add parsing builtin time expr support
>
> tools/perf/Documentation/perf-record.txt | 8 +
> tools/perf/Makefile.perf | 1 +
> tools/perf/builtin-record.c | 31 +
> tools/perf/util/Build | 18 +
> tools/perf/util/bpf_skel/bpf_record_action.h | 24 +
> tools/perf/util/bpf_skel/record_action.bpf.c | 151 ++++
> tools/perf/util/parse-action.c | 729 +++++++++++++++++++
> tools/perf/util/parse-action.h | 98 +++
> tools/perf/util/parse-action.l | 190 +++++
> tools/perf/util/parse-action.y | 156 ++++
> tools/perf/util/record_action.c | 380 ++++++++++
> tools/perf/util/record_action.h | 30 +
> 12 files changed, 1816 insertions(+)
> create mode 100644 tools/perf/util/bpf_skel/bpf_record_action.h
> create mode 100644 tools/perf/util/bpf_skel/record_action.bpf.c
> 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
>
> --
> 2.25.1
next prev parent reply other threads:[~2024-11-28 20:14 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-28 13:35 [RFC 00/12] perf record: Add event action support Yang Jihong
2024-11-28 13:35 ` [RFC 01/12] " Yang Jihong
2024-11-28 20:19 ` Arnaldo Carvalho de Melo
2024-12-04 8:24 ` [External] " Yang Jihong
2024-11-28 13:35 ` [RFC 02/12] perf event action: Add parsing const expr support Yang Jihong
2024-11-28 20:23 ` Arnaldo Carvalho de Melo
2024-12-04 8:29 ` [External] " Yang Jihong
2024-11-28 13:35 ` [RFC 03/12] perf event action: Add parsing const integer " Yang Jihong
2024-11-28 20:25 ` Arnaldo Carvalho de Melo
2024-12-04 8:32 ` [External] " Yang Jihong
2024-11-28 13:35 ` [RFC 04/12] perf event action: Add parsing const string " Yang Jihong
2024-11-28 13:35 ` [RFC 05/12] perf event action: Add parsing call " Yang Jihong
2024-11-28 13:35 ` [RFC 06/12] perf event action: Add parsing print() " Yang Jihong
2024-11-28 13:35 ` [RFC 07/12] perf event action: Add parsing builtin " Yang Jihong
2024-11-28 13:35 ` [RFC 08/12] perf event action: Add parsing builtin cpu " Yang Jihong
2024-11-28 13:35 ` [RFC 09/12] perf event action: Add parsing builtin pid " Yang Jihong
2024-11-28 13:35 ` [RFC 10/12] perf event action: Add parsing builtin tid " Yang Jihong
2024-11-28 13:35 ` [RFC 11/12] perf event action: Add parsing builtin comm " Yang Jihong
2024-11-28 13:35 ` [RFC 12/12] perf event action: Add parsing builtin time " Yang Jihong
2024-11-28 13:53 ` [RFC 00/12] perf record: Add event action support Adrian Hunter
2024-12-04 8:07 ` [External] " Yang Jihong
2024-11-28 20:14 ` Arnaldo Carvalho de Melo [this message]
2024-12-02 21:46 ` Namhyung Kim
2024-12-04 8:35 ` [External] " Yang Jihong
2024-12-04 19:54 ` Ian Rogers
2024-12-05 14:01 ` Yang Jihong
2024-12-04 8:21 ` Yang Jihong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Z0jPPRA8JXSrwyaC@x1 \
--to=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=irogers@google.com \
--cc=james.clark@arm.com \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=yangjihong@bytedance.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).