Adding new control events to enable/disable specific event.
The interface string for control file are:
'enable-<EVENT NAME>'
'disable-<EVENT NAME>'
when received the command, perf will scan the current evlist
for <EVENT NAME> and if found it's enabled/disabled.
Example session:
terminal 1:
# mkfifo control ack perf.pipe
# perf record --control=fifo:control,ack -D -1 --no-buffering -e 'sched:*' -o - > perf.pipe
Events disabled
terminal 2:
# cat perf.pipe | ./perf --no-pager script -i -
terminal 3:
# echo enable-sched:sched_process_fork > control
terminal 1:
# mkfifo control ack perf.pipe
# perf record --control=fifo:control,ack -D -1 --no-buffering -e 'sched:*' -o - > perf.pipe
...
event sched:sched_process_fork enabled
terminal 2:
# cat perf.pipe | ./perf --no-pager script -i -
bash 33349 [034] 149587.674295: sched:sched_process_fork: comm=bash pid=33349 child_comm=bash child_pid=34056
bash 33349 [034] 149588.239521: sched:sched_process_fork: comm=bash pid=33349 child_comm=bash child_pid=34057
terminal 3:
# echo enable-sched:sched_wakeup_new > control
terminal 1:
# mkfifo control ack perf.pipe
# perf record --control=fifo:control,ack -D -1 --no-buffering -e 'sched:*' -o - > perf.pipe
...
event sched:sched_wakeup_new enabled
terminal 2:
# cat perf.pipe | ./perf --no-pager script -i -
...
bash 33349 [034] 149632.228023: sched:sched_process_fork: comm=bash pid=33349 child_comm=bash child_pid=34059
bash 33349 [034] 149632.228050: sched:sched_wakeup_new: bash:34059 [120] success=1 CPU:036
bash 33349 [034] 149633.950005: sched:sched_process_fork: comm=bash pid=33349 child_comm=bash child_pid=34060
bash 33349 [034] 149633.950030: sched:sched_wakeup_new: bash:34060 [120] success=1 CPU:036
Acked-by: Namhyung Kim <[email protected]>
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/perf/builtin-record.c | 2 ++
tools/perf/builtin-stat.c | 2 ++
tools/perf/util/evlist.c | 30 +++++++++++++++++++++++++++++-
tools/perf/util/evlist.h | 4 ++++
4 files changed, 37 insertions(+), 1 deletion(-)
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index d832c108a1ca..582b8fba012c 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -1949,6 +1949,8 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
break;
case EVLIST_CTL_CMD_ACK:
case EVLIST_CTL_CMD_UNSUPPORTED:
+ case EVLIST_CTL_CMD_ENABLE_EVSEL:
+ case EVLIST_CTL_CMD_DISABLE_EVSEL:
default:
break;
}
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 89c32692f40c..6a21fb665008 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -590,6 +590,8 @@ static void process_evlist(struct evlist *evlist, unsigned int interval)
case EVLIST_CTL_CMD_SNAPSHOT:
case EVLIST_CTL_CMD_ACK:
case EVLIST_CTL_CMD_UNSUPPORTED:
+ case EVLIST_CTL_CMD_ENABLE_EVSEL:
+ case EVLIST_CTL_CMD_DISABLE_EVSEL:
default:
break;
}
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 70aff26612a9..729c98d10628 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -1915,7 +1915,13 @@ static int evlist__ctlfd_recv(struct evlist *evlist, enum evlist_ctl_cmd *cmd,
bytes_read == data_size ? "" : c == '\n' ? "\\n" : "\\0");
if (bytes_read > 0) {
- if (!strncmp(cmd_data, EVLIST_CTL_CMD_ENABLE_TAG,
+ if (!strncmp(cmd_data, EVLIST_CTL_CMD_ENABLE_EVSEL_TAG,
+ (sizeof(EVLIST_CTL_CMD_ENABLE_EVSEL_TAG)-1))) {
+ *cmd = EVLIST_CTL_CMD_ENABLE_EVSEL;
+ } else if (!strncmp(cmd_data, EVLIST_CTL_CMD_DISABLE_EVSEL_TAG,
+ (sizeof(EVLIST_CTL_CMD_DISABLE_EVSEL_TAG)-1))) {
+ *cmd = EVLIST_CTL_CMD_DISABLE_EVSEL;
+ } else if (!strncmp(cmd_data, EVLIST_CTL_CMD_ENABLE_TAG,
(sizeof(EVLIST_CTL_CMD_ENABLE_TAG)-1))) {
*cmd = EVLIST_CTL_CMD_ENABLE;
} else if (!strncmp(cmd_data, EVLIST_CTL_CMD_DISABLE_TAG,
@@ -1952,6 +1958,8 @@ int evlist__ctlfd_process(struct evlist *evlist, enum evlist_ctl_cmd *cmd)
char cmd_data[EVLIST_CTL_CMD_MAX_LEN];
int ctlfd_pos = evlist->ctl_fd.pos;
struct pollfd *entries = evlist->core.pollfd.entries;
+ struct evsel *evsel;
+ char *evsel_name;
if (!evlist__ctlfd_initialized(evlist) || !entries[ctlfd_pos].revents)
return 0;
@@ -1967,6 +1975,26 @@ int evlist__ctlfd_process(struct evlist *evlist, enum evlist_ctl_cmd *cmd)
case EVLIST_CTL_CMD_DISABLE:
evlist__disable(evlist);
break;
+ case EVLIST_CTL_CMD_ENABLE_EVSEL:
+ evsel_name = cmd_data + sizeof(EVLIST_CTL_CMD_ENABLE_EVSEL_TAG) - 1;
+ evsel = evlist__find_evsel_by_str(evlist, evsel_name);
+ if (evsel) {
+ evlist__enable_evsel(evlist, evsel_name);
+ pr_info("event %s enabled\n", evsel->name);
+ } else {
+ pr_info("failed: can't find '%s' event\n", evsel_name);
+ }
+ break;
+ case EVLIST_CTL_CMD_DISABLE_EVSEL:
+ evsel_name = cmd_data + sizeof(EVLIST_CTL_CMD_DISABLE_EVSEL_TAG) - 1;
+ evsel = evlist__find_evsel_by_str(evlist, evsel_name);
+ if (evsel) {
+ evlist__disable_evsel(evlist, evsel_name);
+ pr_info("event %s disabled\n", evsel->name);
+ } else {
+ pr_info("failed: can't find '%s' event\n", evsel_name);
+ }
+ break;
case EVLIST_CTL_CMD_SNAPSHOT:
break;
case EVLIST_CTL_CMD_ACK:
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index 1aae75895dea..e4e8ff8831a3 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -330,6 +330,8 @@ struct evsel *evlist__reset_weak_group(struct evlist *evlist, struct evsel *evse
#define EVLIST_CTL_CMD_DISABLE_TAG "disable"
#define EVLIST_CTL_CMD_ACK_TAG "ack\n"
#define EVLIST_CTL_CMD_SNAPSHOT_TAG "snapshot"
+#define EVLIST_CTL_CMD_ENABLE_EVSEL_TAG "enable-"
+#define EVLIST_CTL_CMD_DISABLE_EVSEL_TAG "disable-"
#define EVLIST_CTL_CMD_MAX_LEN 64
@@ -337,6 +339,8 @@ enum evlist_ctl_cmd {
EVLIST_CTL_CMD_UNSUPPORTED = 0,
EVLIST_CTL_CMD_ENABLE,
EVLIST_CTL_CMD_DISABLE,
+ EVLIST_CTL_CMD_ENABLE_EVSEL,
+ EVLIST_CTL_CMD_DISABLE_EVSEL,
EVLIST_CTL_CMD_ACK,
EVLIST_CTL_CMD_SNAPSHOT,
};
--
2.26.2
Em Thu, Dec 10, 2020 at 09:43:29PM +0100, Jiri Olsa escreveu:
> Adding new control events to enable/disable specific event.
> The interface string for control file are:
>
> 'enable-<EVENT NAME>'
> 'disable-<EVENT NAME>'
Wwy do we have "enable-" as the "tag" for this?
Also is it possible to use "enable sched:*" and have that match what is
in the evlist and enable (or disable, if using "disable sched:*") what
matches?
This second suggestion can be done on top of this, i.e. as an
enhancement, but mixing up the command (enable, disable) with its
arguments looks strange.
- Arnaldo
> when received the command, perf will scan the current evlist
> for <EVENT NAME> and if found it's enabled/disabled.
>
> Example session:
>
> terminal 1:
> # mkfifo control ack perf.pipe
> # perf record --control=fifo:control,ack -D -1 --no-buffering -e 'sched:*' -o - > perf.pipe
> Events disabled
>
> terminal 2:
> # cat perf.pipe | ./perf --no-pager script -i -
>
> terminal 3:
> # echo enable-sched:sched_process_fork > control
>
> terminal 1:
> # mkfifo control ack perf.pipe
> # perf record --control=fifo:control,ack -D -1 --no-buffering -e 'sched:*' -o - > perf.pipe
> ...
> event sched:sched_process_fork enabled
>
> terminal 2:
> # cat perf.pipe | ./perf --no-pager script -i -
> bash 33349 [034] 149587.674295: sched:sched_process_fork: comm=bash pid=33349 child_comm=bash child_pid=34056
> bash 33349 [034] 149588.239521: sched:sched_process_fork: comm=bash pid=33349 child_comm=bash child_pid=34057
>
> terminal 3:
> # echo enable-sched:sched_wakeup_new > control
>
> terminal 1:
> # mkfifo control ack perf.pipe
> # perf record --control=fifo:control,ack -D -1 --no-buffering -e 'sched:*' -o - > perf.pipe
> ...
> event sched:sched_wakeup_new enabled
>
> terminal 2:
> # cat perf.pipe | ./perf --no-pager script -i -
> ...
> bash 33349 [034] 149632.228023: sched:sched_process_fork: comm=bash pid=33349 child_comm=bash child_pid=34059
> bash 33349 [034] 149632.228050: sched:sched_wakeup_new: bash:34059 [120] success=1 CPU:036
> bash 33349 [034] 149633.950005: sched:sched_process_fork: comm=bash pid=33349 child_comm=bash child_pid=34060
> bash 33349 [034] 149633.950030: sched:sched_wakeup_new: bash:34060 [120] success=1 CPU:036
>
> Acked-by: Namhyung Kim <[email protected]>
> Signed-off-by: Jiri Olsa <[email protected]>
> ---
> tools/perf/builtin-record.c | 2 ++
> tools/perf/builtin-stat.c | 2 ++
> tools/perf/util/evlist.c | 30 +++++++++++++++++++++++++++++-
> tools/perf/util/evlist.h | 4 ++++
> 4 files changed, 37 insertions(+), 1 deletion(-)
>
> diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
> index d832c108a1ca..582b8fba012c 100644
> --- a/tools/perf/builtin-record.c
> +++ b/tools/perf/builtin-record.c
> @@ -1949,6 +1949,8 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
> break;
> case EVLIST_CTL_CMD_ACK:
> case EVLIST_CTL_CMD_UNSUPPORTED:
> + case EVLIST_CTL_CMD_ENABLE_EVSEL:
> + case EVLIST_CTL_CMD_DISABLE_EVSEL:
> default:
> break;
> }
> diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
> index 89c32692f40c..6a21fb665008 100644
> --- a/tools/perf/builtin-stat.c
> +++ b/tools/perf/builtin-stat.c
> @@ -590,6 +590,8 @@ static void process_evlist(struct evlist *evlist, unsigned int interval)
> case EVLIST_CTL_CMD_SNAPSHOT:
> case EVLIST_CTL_CMD_ACK:
> case EVLIST_CTL_CMD_UNSUPPORTED:
> + case EVLIST_CTL_CMD_ENABLE_EVSEL:
> + case EVLIST_CTL_CMD_DISABLE_EVSEL:
> default:
> break;
> }
> diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
> index 70aff26612a9..729c98d10628 100644
> --- a/tools/perf/util/evlist.c
> +++ b/tools/perf/util/evlist.c
> @@ -1915,7 +1915,13 @@ static int evlist__ctlfd_recv(struct evlist *evlist, enum evlist_ctl_cmd *cmd,
> bytes_read == data_size ? "" : c == '\n' ? "\\n" : "\\0");
>
> if (bytes_read > 0) {
> - if (!strncmp(cmd_data, EVLIST_CTL_CMD_ENABLE_TAG,
> + if (!strncmp(cmd_data, EVLIST_CTL_CMD_ENABLE_EVSEL_TAG,
> + (sizeof(EVLIST_CTL_CMD_ENABLE_EVSEL_TAG)-1))) {
> + *cmd = EVLIST_CTL_CMD_ENABLE_EVSEL;
> + } else if (!strncmp(cmd_data, EVLIST_CTL_CMD_DISABLE_EVSEL_TAG,
> + (sizeof(EVLIST_CTL_CMD_DISABLE_EVSEL_TAG)-1))) {
> + *cmd = EVLIST_CTL_CMD_DISABLE_EVSEL;
> + } else if (!strncmp(cmd_data, EVLIST_CTL_CMD_ENABLE_TAG,
> (sizeof(EVLIST_CTL_CMD_ENABLE_TAG)-1))) {
> *cmd = EVLIST_CTL_CMD_ENABLE;
> } else if (!strncmp(cmd_data, EVLIST_CTL_CMD_DISABLE_TAG,
> @@ -1952,6 +1958,8 @@ int evlist__ctlfd_process(struct evlist *evlist, enum evlist_ctl_cmd *cmd)
> char cmd_data[EVLIST_CTL_CMD_MAX_LEN];
> int ctlfd_pos = evlist->ctl_fd.pos;
> struct pollfd *entries = evlist->core.pollfd.entries;
> + struct evsel *evsel;
> + char *evsel_name;
>
> if (!evlist__ctlfd_initialized(evlist) || !entries[ctlfd_pos].revents)
> return 0;
> @@ -1967,6 +1975,26 @@ int evlist__ctlfd_process(struct evlist *evlist, enum evlist_ctl_cmd *cmd)
> case EVLIST_CTL_CMD_DISABLE:
> evlist__disable(evlist);
> break;
> + case EVLIST_CTL_CMD_ENABLE_EVSEL:
> + evsel_name = cmd_data + sizeof(EVLIST_CTL_CMD_ENABLE_EVSEL_TAG) - 1;
> + evsel = evlist__find_evsel_by_str(evlist, evsel_name);
> + if (evsel) {
> + evlist__enable_evsel(evlist, evsel_name);
> + pr_info("event %s enabled\n", evsel->name);
> + } else {
> + pr_info("failed: can't find '%s' event\n", evsel_name);
> + }
> + break;
> + case EVLIST_CTL_CMD_DISABLE_EVSEL:
> + evsel_name = cmd_data + sizeof(EVLIST_CTL_CMD_DISABLE_EVSEL_TAG) - 1;
> + evsel = evlist__find_evsel_by_str(evlist, evsel_name);
> + if (evsel) {
> + evlist__disable_evsel(evlist, evsel_name);
> + pr_info("event %s disabled\n", evsel->name);
> + } else {
> + pr_info("failed: can't find '%s' event\n", evsel_name);
> + }
> + break;
> case EVLIST_CTL_CMD_SNAPSHOT:
> break;
> case EVLIST_CTL_CMD_ACK:
> diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
> index 1aae75895dea..e4e8ff8831a3 100644
> --- a/tools/perf/util/evlist.h
> +++ b/tools/perf/util/evlist.h
> @@ -330,6 +330,8 @@ struct evsel *evlist__reset_weak_group(struct evlist *evlist, struct evsel *evse
> #define EVLIST_CTL_CMD_DISABLE_TAG "disable"
> #define EVLIST_CTL_CMD_ACK_TAG "ack\n"
> #define EVLIST_CTL_CMD_SNAPSHOT_TAG "snapshot"
> +#define EVLIST_CTL_CMD_ENABLE_EVSEL_TAG "enable-"
> +#define EVLIST_CTL_CMD_DISABLE_EVSEL_TAG "disable-"
>
> #define EVLIST_CTL_CMD_MAX_LEN 64
>
> @@ -337,6 +339,8 @@ enum evlist_ctl_cmd {
> EVLIST_CTL_CMD_UNSUPPORTED = 0,
> EVLIST_CTL_CMD_ENABLE,
> EVLIST_CTL_CMD_DISABLE,
> + EVLIST_CTL_CMD_ENABLE_EVSEL,
> + EVLIST_CTL_CMD_DISABLE_EVSEL,
> EVLIST_CTL_CMD_ACK,
> EVLIST_CTL_CMD_SNAPSHOT,
> };
> --
> 2.26.2
>
--
- Arnaldo
On Tue, Dec 15, 2020 at 12:14:13PM -0300, Arnaldo Carvalho de Melo wrote:
> Em Thu, Dec 10, 2020 at 09:43:29PM +0100, Jiri Olsa escreveu:
> > Adding new control events to enable/disable specific event.
> > The interface string for control file are:
> >
> > 'enable-<EVENT NAME>'
> > 'disable-<EVENT NAME>'
>
> Wwy do we have "enable-" as the "tag" for this?
the whole 'enable-' is prefix for command that enables specific event
following '-' starts the event name
>
> Also is it possible to use "enable sched:*" and have that match what is
> in the evlist and enable (or disable, if using "disable sched:*") what
> matches?
yep, that should be possible to add
>
> This second suggestion can be done on top of this, i.e. as an
> enhancement, but mixing up the command (enable, disable) with its
> arguments looks strange.
the '-' determines that there's event name following,
pure 'enable' switches on everything
jirka
Em Tue, Dec 15, 2020 at 04:24:20PM +0100, Jiri Olsa escreveu:
> On Tue, Dec 15, 2020 at 12:14:13PM -0300, Arnaldo Carvalho de Melo wrote:
> > Em Thu, Dec 10, 2020 at 09:43:29PM +0100, Jiri Olsa escreveu:
> > > Adding new control events to enable/disable specific event.
> > > The interface string for control file are:
> > >
> > > 'enable-<EVENT NAME>'
> > > 'disable-<EVENT NAME>'
> >
> > Wwy do we have "enable-" as the "tag" for this?
>
> the whole 'enable-' is prefix for command that enables specific event
> following '-' starts the event name
>
> >
> > Also is it possible to use "enable sched:*" and have that match what is
> > in the evlist and enable (or disable, if using "disable sched:*") what
> > matches?
>
> yep, that should be possible to add
>
> >
> > This second suggestion can be done on top of this, i.e. as an
> > enhancement, but mixing up the command (enable, disable) with its
> > arguments looks strange.
>
> the '-' determines that there's event name following,
> pure 'enable' switches on everything
I see it, but why not use the more natural ' ' space to separate the
command from its arguments? Just like in a bash command line, say?
I.e. why not:
enable
to enable everything, and:
enable sched:sched_switch
To enable just the "sched:sched_switch" event?
- Arnaldo
On Tue, Dec 15, 2020 at 01:03:32PM -0300, Arnaldo Carvalho de Melo wrote:
> Em Tue, Dec 15, 2020 at 04:24:20PM +0100, Jiri Olsa escreveu:
> > On Tue, Dec 15, 2020 at 12:14:13PM -0300, Arnaldo Carvalho de Melo wrote:
> > > Em Thu, Dec 10, 2020 at 09:43:29PM +0100, Jiri Olsa escreveu:
> > > > Adding new control events to enable/disable specific event.
> > > > The interface string for control file are:
> > > >
> > > > 'enable-<EVENT NAME>'
> > > > 'disable-<EVENT NAME>'
> > >
> > > Wwy do we have "enable-" as the "tag" for this?
> >
> > the whole 'enable-' is prefix for command that enables specific event
> > following '-' starts the event name
> >
> > >
> > > Also is it possible to use "enable sched:*" and have that match what is
> > > in the evlist and enable (or disable, if using "disable sched:*") what
> > > matches?
> >
> > yep, that should be possible to add
> >
> > >
> > > This second suggestion can be done on top of this, i.e. as an
> > > enhancement, but mixing up the command (enable, disable) with its
> > > arguments looks strange.
> >
> > the '-' determines that there's event name following,
> > pure 'enable' switches on everything
>
> I see it, but why not use the more natural ' ' space to separate the
> command from its arguments? Just like in a bash command line, say?
>
> I.e. why not:
>
> enable
>
> to enable everything, and:
>
> enable sched:sched_switch
>
> To enable just the "sched:sched_switch" event?
right, that's we discussed in the other patch thread,
I'll make the change
thanks,
jirka
Em Tue, Dec 15, 2020 at 05:18:38PM +0100, Jiri Olsa escreveu:
> On Tue, Dec 15, 2020 at 01:03:32PM -0300, Arnaldo Carvalho de Melo wrote:
> > I see it, but why not use the more natural ' ' space to separate the
> > command from its arguments? Just like in a bash command line, say?
> > I.e. why not:
> > enable
> > to enable everything, and:
> > enable sched:sched_switch
> > To enable just the "sched:sched_switch" event?
> right, that's we discussed in the other patch thread,
> I'll make the change
This is a new way to control perf, its important that we try to reuse
the same concepts as in the pre-existing forms of interaction, so as to
reduce the learning curve for using this control mode.
I.e. this 'enable' should be as equivalent to the -e argument as
possible, for what makes sense for a pre-existing, already configured
event.
For _adding_ new ones, that we probably will want next, then its even
more important to reuse the same -e parser :-)
Thanks!
- Arnaldo