Skip to contentSkip to conversation

perf tools: Allow to enable/disable events via control pipe

PATCH Applied Jiri Olsa 4 participants 10 messages Dec 26, 2020 – Jan 19, 2021 perf events

lore
Share & tools
lore

Jiri Olsa

author reviewer
#0 lore raw

v4 cover perf tools: Allow to enable/disable events via control pipe

hi,
adding support to enable/disable specific events via control file via following commands:

    # echo 'enable sched:sched_process_fork' > control
    # echo 'disabled sched:sched_process_fork' > control

v4 changes:
- some of the patches got merged
- rebased to latest perf/core
- fixed changelogs
- added 'ping' command

v3 changes:
- use ' ' instead of '-' in syntax and add command argument processing [Arnaldo]
- add options to evlist [Arnaldo]
- add man page changes

v2 changes:
- added acks
- change list to evlist [Arnaldo]
- add evlist-verbose command [Arnaldo]
- add '' to enale-/disable- error message

The code is available in here:
git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
perf/control

thanks,
jirka

---
Jiri Olsa (4):
perf tools: Allow to enable/disable events via control file perf tools: Add evlist control command
perf tools: Add stop control command
perf tools: Add ping control command

 tools/perf/Documentation/perf-record.txt |  15 ++++++++++++---
 tools/perf/builtin-record.c              |  13 +++++++------
 tools/perf/builtin-stat.c                |   5 +++--
 tools/perf/util/evlist.c                 | 112 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 tools/perf/util/evlist.h                 |   6 ++++++
 tools/perf/util/evsel_fprintf.c          |   2 ++
 tools/perf/util/python-ext-sources       |   1 +
 tools/perf/util/setup.py                 |   2 +-
 8 files changed, 141 insertions(+), 15 deletions(-)
author reviewer
#1 lore raw

PATCH v4 1/4 perf tools: Allow to enable/disable events via control file

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

terminal 2:

    # cat perf.pipe | perf --no-pager script -i -

terminal 1:
Events disabled

NOTE Above message will show only after read side of the pipe ('>') is started on 'terminal 2'. The 'terminal 1's bash does not execute perf before that, hence the delyaed perf record message.

terminal 3:

    # echo 'enable sched:sched_process_fork' > control

terminal 1:
event sched:sched_process_fork enabled

terminal 2:

    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:
event sched:sched_wakeup_new enabled

terminal 2:

    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
---
 tools/perf/Documentation/perf-record.txt |  8 +--
 tools/perf/builtin-record.c              |  8 +--
 tools/perf/builtin-stat.c                |  2 -
 tools/perf/util/evlist.c                 | 63 ++++++++++++++++++++++--
 4 files changed, 67 insertions(+), 14 deletions(-)
tools/perf/Documentation/perf-record.txt +5 -3
index 34cf651ee237..05a85da0f7c5 100644
@@ -640,9 +640,11 @@ ctl-fifo / ack-fifo are opened and used as ctl-fd / ack-fd as follows.
 Listen on ctl-fd descriptor for command to control measurement.
 
 Available commands:
-  'enable'  : enable events
-  'disable' : disable events
-  'snapshot': AUX area tracing snapshot).
+  'enable'       : enable events
+  'disable'      : disable events
+  'enable name'  : enable event 'name'
+  'disable name' : disable event 'name'
+  'snapshot'     : AUX area tracing snapshot).
 
 Measurements can be started with events disabled using --delay=-1 option. Optionally
 send control command completion ('ack\n') to ack-fd descriptor to synchronize with the
tools/perf/builtin-record.c +2 -6
index fd3911650612..7302e7527d40 100644
@@ -1937,18 +1937,14 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
 
 		if (evlist__ctlfd_process(rec->evlist, &cmd) > 0) {
 			switch (cmd) {
-			case EVLIST_CTL_CMD_ENABLE:
-				pr_info(EVLIST_ENABLED_MSG);
-				break;
-			case EVLIST_CTL_CMD_DISABLE:
-				pr_info(EVLIST_DISABLED_MSG);
-				break;
 			case EVLIST_CTL_CMD_SNAPSHOT:
 				hit_auxtrace_snapshot_trigger(rec);
 				evlist__ctlfd_ack(rec->evlist);
 				break;
 			case EVLIST_CTL_CMD_ACK:
 			case EVLIST_CTL_CMD_UNSUPPORTED:
+			case EVLIST_CTL_CMD_ENABLE:
+			case EVLIST_CTL_CMD_DISABLE:
 			default:
 				break;
 			}
tools/perf/builtin-stat.c +0 -2
index 8cc24967bc27..3c6712ed5af7 100644
@@ -578,14 +578,12 @@ static void process_evlist(struct evlist *evlist, unsigned int interval)
 	if (evlist__ctlfd_process(evlist, &cmd) > 0) {
 		switch (cmd) {
 		case EVLIST_CTL_CMD_ENABLE:
-			pr_info(EVLIST_ENABLED_MSG);
 			if (interval)
 				process_interval();
 			break;
 		case EVLIST_CTL_CMD_DISABLE:
 			if (interval)
 				process_interval();
-			pr_info(EVLIST_DISABLED_MSG);
 			break;
 		case EVLIST_CTL_CMD_SNAPSHOT:
 		case EVLIST_CTL_CMD_ACK:
tools/perf/util/evlist.c +60 -3

76 lines not on this page · raw message

Signature · 1 line
2.26.2
#2 lore raw

Re: [PATCH 1/4] perf tools: Allow to enable/disable events via control file

Em Sun, Dec 27, 2020 at 12:20:35AM +0100, Jiri Olsa escreveu:

Quoted 38 lines

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

terminal 2:

    # cat perf.pipe | perf --no-pager script -i -

terminal 1:
Events disabled

NOTE Above message will show only after read side of the pipe ('>') is started on 'terminal 2'. The 'terminal 1's bash does not execute perf before that, hence the delyaed perf record message.

terminal 3:

    # echo 'enable sched:sched_process_fork' > control

terminal 1:
event sched:sched_process_fork enabled

terminal 2:

    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
Quoted 8 lines

terminal 1:
event sched:sched_wakeup_new enabled

terminal 2:

    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

'disable' doesn't seem to be working:

Terminal 3:

[root@five ~]# echo 'enable sched:sched_process_fork' > control [root@five ~]# echo 'disable sched:sched_process_fork' > control [root@five ~]# echo 'disable' > control
[root@five ~]# echo 'disable sched:sched_process_fork' > control [root@five ~]# echo 'disable sched:sched_process_fork' > control [root@five ~]# echo 'enable sched:sched_process_fork' > control [root@five ~]# echo 'disable sched:sched_process_fork' > control [root@five ~]# echo 'enable sched:sched_process_fork' > control [root@five ~]# echo 'disable sched:sched_process_fork' > control [root@five ~]# echo 'enable' > control
[root@five ~]# echo 'disable' > control
[root@five ~]# echo 'disable' > control
[root@five ~]# echo 'disable' > control
[root@five ~]#

Terminal 1:

[root@five ~]# perf record --control=fifo:control,ack -D -1 --no-buffering -e 'sched:*' > perf.pipe Events disabled
Event sched:sched_process_fork enabled
Event sched:sched_process_fork disabled
Event sched:sched_process_fork enabled
Event sched:sched_process_fork disabled
Events enabled

I tried also with '-o -', made no difference and:

[root@five ~]# perf record --control=fifo:control,ack -D -1 --no-buffering -e 'sched:*' -o - > perf.pipe Events disabled
Event sched:sched_process_fork enabled
Event sched:sched_process_fork disabled
Event sched:sched_process_fork disabled

The second probably should be more clear stating that that event was already disabled.

Probably your example with all the sched tracepoints make 'perf record' just process the stream of events and not look at the commands?

If I try with:

[root@five ~]# perf list sched:sched_process_* 2> /dev/null

List of pre-defined events (to be used in -e):

  sched:sched_process_exec                           [Tracepoint event]
  sched:sched_process_exit                           [Tracepoint event]
  sched:sched_process_fork                           [Tracepoint event]
  sched:sched_process_free                           [Tracepoint event]
  sched:sched_process_wait                           [Tracepoint event]

[root@five ~]#

[root@five ~]# perf record --control=fifo:control,ack -D -1 --no-buffering -e 'sched:sched_process_*' -o - > perf.pipe Events disabled
Events enabled
Events disabled

It works.

So it is a pre-existing problem, I'll continue processing your patches and make a note about this...

- Arnaldo

Quoted 156 lines
---
 tools/perf/Documentation/perf-record.txt |  8 +--
 tools/perf/builtin-record.c              |  8 +--
 tools/perf/builtin-stat.c                |  2 -
 tools/perf/util/evlist.c                 | 63 ++++++++++++++++++++++--
 4 files changed, 67 insertions(+), 14 deletions(-)
tools/perf/Documentation/perf-record.txt +5 -3
index 34cf651ee237..05a85da0f7c5 100644
@@ -640,9 +640,11 @@ ctl-fifo / ack-fifo are opened and used as ctl-fd / ack-fd as follows.
 Listen on ctl-fd descriptor for command to control measurement.
 
 Available commands:
-  'enable'  : enable events
-  'disable' : disable events
-  'snapshot': AUX area tracing snapshot).
+  'enable'       : enable events
+  'disable'      : disable events
+  'enable name'  : enable event 'name'
+  'disable name' : disable event 'name'
+  'snapshot'     : AUX area tracing snapshot).
 
 Measurements can be started with events disabled using --delay=-1 option. Optionally
 send control command completion ('ack\n') to ack-fd descriptor to synchronize with the
tools/perf/builtin-record.c +2 -6
index fd3911650612..7302e7527d40 100644
@@ -1937,18 +1937,14 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
 
 		if (evlist__ctlfd_process(rec->evlist, &cmd) > 0) {
 			switch (cmd) {
-			case EVLIST_CTL_CMD_ENABLE:
-				pr_info(EVLIST_ENABLED_MSG);
-				break;
-			case EVLIST_CTL_CMD_DISABLE:
-				pr_info(EVLIST_DISABLED_MSG);
-				break;
 			case EVLIST_CTL_CMD_SNAPSHOT:
 				hit_auxtrace_snapshot_trigger(rec);
 				evlist__ctlfd_ack(rec->evlist);
 				break;
 			case EVLIST_CTL_CMD_ACK:
 			case EVLIST_CTL_CMD_UNSUPPORTED:
+			case EVLIST_CTL_CMD_ENABLE:
+			case EVLIST_CTL_CMD_DISABLE:
 			default:
 				break;
 			}
tools/perf/builtin-stat.c +0 -2
index 8cc24967bc27..3c6712ed5af7 100644
@@ -578,14 +578,12 @@ static void process_evlist(struct evlist *evlist, unsigned int interval)
 	if (evlist__ctlfd_process(evlist, &cmd) > 0) {
 		switch (cmd) {
 		case EVLIST_CTL_CMD_ENABLE:
-			pr_info(EVLIST_ENABLED_MSG);
 			if (interval)
 				process_interval();
 			break;
 		case EVLIST_CTL_CMD_DISABLE:
 			if (interval)
 				process_interval();
-			pr_info(EVLIST_DISABLED_MSG);
 			break;
 		case EVLIST_CTL_CMD_SNAPSHOT:
 		case EVLIST_CTL_CMD_ACK:
tools/perf/util/evlist.c +60 -3
index 05363a7247c4..c71c7e035641 100644
@@ -1957,6 +1957,64 @@ int evlist__ctlfd_ack(struct evlist *evlist)
 	return err;
 }
 
+static int get_cmd_arg(char *cmd_data, size_t cmd_size, char **arg)
+{
+	char *data = cmd_data + cmd_size;
+
+	/* no argument */
+	if (!*data)
+		return 0;
+
+	/* there's argument */
+	if (*data == ' ') {
+		*arg = data + 1;
+		return 1;
+	}
+
+	/* malformed */
+	return -1;
+}
+
+static int evlist__ctlfd_enable(struct evlist *evlist, char *cmd_data, bool enable)
+{
+	struct evsel *evsel;
+	char *name;
+	int err;
+
+	err = get_cmd_arg(cmd_data,
+			  enable ? sizeof(EVLIST_CTL_CMD_ENABLE_TAG) - 1 :
+				   sizeof(EVLIST_CTL_CMD_DISABLE_TAG) - 1,
+			  &name);
+	if (err < 0) {
+		pr_info("failed: wrong command\n");
+		return -1;
+	}
+
+	if (err) {
+		evsel = evlist__find_evsel_by_str(evlist, name);
+		if (evsel) {
+			if (enable)
+				evlist__enable_evsel(evlist, name);
+			else
+				evlist__disable_evsel(evlist, name);
+			pr_info("Event %s %s\n", evsel->name,
+				enable ? "enabled" : "disabled");
+		} else {
+			pr_info("failed: can't find '%s' event\n", name);
+		}
+	} else {
+		if (enable) {
+			evlist__enable(evlist);
+			pr_info(EVLIST_ENABLED_MSG);
+		} else {
+			evlist__disable(evlist);
+			pr_info(EVLIST_DISABLED_MSG);
+		}
+	}
+
+	return 0;
+}
+
 int evlist__ctlfd_process(struct evlist *evlist, enum evlist_ctl_cmd *cmd)
 {
 	int err = 0;
@@ -1973,10 +2031,9 @@ int evlist__ctlfd_process(struct evlist *evlist, enum evlist_ctl_cmd *cmd)
 		if (err > 0) {
 			switch (*cmd) {
 			case EVLIST_CTL_CMD_ENABLE:
-				evlist__enable(evlist);
-				break;
 			case EVLIST_CTL_CMD_DISABLE:
-				evlist__disable(evlist);
+				err = evlist__ctlfd_enable(evlist, cmd_data,
+							   *cmd == EVLIST_CTL_CMD_ENABLE);
 				break;
 			case EVLIST_CTL_CMD_SNAPSHOT:
 				break;
Signature · 1 line
2.26.2
Signature · 1 line
- Arnaldo
#3 lore raw

Re: [PATCH 1/4] perf tools: Allow to enable/disable events via control file

On Tue, Jan 19, 2021 at 11:16:37AM -0300, Arnaldo Carvalho de Melo wrote:

SNIP

Quoted 37 lines
Quoted 5 lines

terminal 2:

    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

'disable' doesn't seem to be working:

Terminal 3:

[root@five ~]# echo 'enable sched:sched_process_fork' > control [root@five ~]# echo 'disable sched:sched_process_fork' > control [root@five ~]# echo 'disable' > control
[root@five ~]# echo 'disable sched:sched_process_fork' > control [root@five ~]# echo 'disable sched:sched_process_fork' > control [root@five ~]# echo 'enable sched:sched_process_fork' > control [root@five ~]# echo 'disable sched:sched_process_fork' > control [root@five ~]# echo 'enable sched:sched_process_fork' > control [root@five ~]# echo 'disable sched:sched_process_fork' > control [root@five ~]# echo 'enable' > control
[root@five ~]# echo 'disable' > control
[root@five ~]# echo 'disable' > control
[root@five ~]# echo 'disable' > control
[root@five ~]#

Terminal 1:

[root@five ~]# perf record --control=fifo:control,ack -D -1 --no-buffering -e 'sched:*' > perf.pipe Events disabled
Event sched:sched_process_fork enabled
Event sched:sched_process_fork disabled
Event sched:sched_process_fork enabled
Event sched:sched_process_fork disabled
Events enabled

I tried also with '-o -', made no difference and:

Quoted 8 lines

[root@five ~]# perf record --control=fifo:control,ack -D -1 --no-buffering -e 'sched:*' -o - > perf.pipe Events disabled
Event sched:sched_process_fork enabled
Event sched:sched_process_fork disabled
Event sched:sched_process_fork disabled

The second probably should be more clear stating that that event was already disabled.

ok, I'll make patch for that

Quoted 3 lines

Probably your example with all the sched tracepoints make 'perf record' just process the stream of events and not look at the commands?

hum, I'm not sure I understand what's the problem apart from not printing that the event is already disabled some events are not disabed?

Quoted 20 lines

If I try with:

[root@five ~]# perf list sched:sched_process_* 2> /dev/null

List of pre-defined events (to be used in -e):

  sched:sched_process_exec                           [Tracepoint event]
  sched:sched_process_exit                           [Tracepoint event]
  sched:sched_process_fork                           [Tracepoint event]
  sched:sched_process_free                           [Tracepoint event]
  sched:sched_process_wait                           [Tracepoint event]

[root@five ~]#

[root@five ~]# perf record --control=fifo:control,ack -D -1 --no-buffering -e 'sched:sched_process_*' -o - > perf.pipe Events disabled
Events enabled
Events disabled

Quoted 4 lines

It works.

So it is a pre-existing problem, I'll continue processing your patches and make a note about this...

ok, I'll check the note

thanks,
jirka

author reviewer
#4 lore raw

PATCH v4 2/4 perf tools: Add evlist control command

In reply to Jiri Olsa

Adding new evlist control event to display all evlist events. When it is received, perf will scan and print current evlist into perf record terminal.

The interface string for control file is:
evlist [-v|-g|-F]

The syntax follows perf evlist command:

  -F  Show just the sample frequency used for each event.
  -v  Show all fields.
  -g  Show event group information.

Example session:

terminal 1:

    # mkfifo control ack
    # perf record --control=fifo:control,ack -e '{cycles,instructions}'

terminal 2:

    # echo evlist > control

terminal 1:
cycles
instructions
dummy:HG

terminal 2:

    # echo 'evlist -v' > control
  terminal 1:
    cycles: size: 120, { sample_period, sample_freq }: 4000, sample_type:            \
    IP|TID|TIME|ID|CPU|PERIOD, read_format: ID, disabled: 1, inherit: 1, freq: 1,    \
    sample_id_all: 1, exclude_guest: 1
    instructions: size: 120, config: 0x1, { sample_period, sample_freq }: 4000,      \
    sample_type: IP|TID|TIME|ID|CPU|PERIOD, read_format: ID, inherit: 1, freq: 1,    \
    sample_id_all: 1, exclude_guest: 1
    dummy:HG: type: 1, size: 120, config: 0x9, { sample_period, sample_freq }: 4000, \
    sample_type: IP|TID|TIME|ID|CPU|PERIOD, read_format: ID, inherit: 1, mmap: 1,    \
    comm: 1, freq: 1, task: 1, sample_id_all: 1, mmap2: 1, comm_exec: 1, ksymbol: 1, \
     bpf_event: 1

terminal 2:

    # echo 'evlist -g' > control

terminal 1:

    {cycles,instructions}
    dummy:HG

terminal 2:

    # echo 'evlist -F' > control

terminal 1:

    cycles: sample_freq=4000
    instructions: sample_freq=4000
    dummy:HG: sample_freq=4000

This new evlist command is handy to get real event names when wildcards are used.

Adding evsel_fprintf.c object to python/perf.so build, because it's now evlist.c dependency.

Adding PYTHON_PERF define for python/perf.so compilation, so we can use it to compile in only evsel__fprintf from evsel_fprintf.c object.

---
 tools/perf/Documentation/perf-record.txt | 15 ++++++---
 tools/perf/builtin-record.c              |  1 +
 tools/perf/builtin-stat.c                |  1 +
 tools/perf/util/evlist.c                 | 41 ++++++++++++++++++++++++
 tools/perf/util/evlist.h                 |  2 ++
 tools/perf/util/evsel_fprintf.c          |  2 ++
 tools/perf/util/python-ext-sources       |  1 +
 tools/perf/util/setup.py                 |  2 +-
 8 files changed, 59 insertions(+), 6 deletions(-)
tools/perf/Documentation/perf-record.txt +10 -5
index 05a85da0f7c5..5cf103f28eb0 100644
@@ -640,11 +640,16 @@ ctl-fifo / ack-fifo are opened and used as ctl-fd / ack-fd as follows.
 Listen on ctl-fd descriptor for command to control measurement.
 
 Available commands:
-  'enable'       : enable events
-  'disable'      : disable events
-  'enable name'  : enable event 'name'
-  'disable name' : disable event 'name'
-  'snapshot'     : AUX area tracing snapshot).
+  'enable'           : enable events
+  'disable'          : disable events
+  'enable name'      : enable event 'name'
+  'disable name'     : disable event 'name'
+  'snapshot'         : AUX area tracing snapshot).
+
+  'evlist [-v|-g|-F] : display all events
+                       -F  Show just the sample frequency used for each event.
+                       -v  Show all fields.
+                       -g  Show event group information.
 
 Measurements can be started with events disabled using --delay=-1 option. Optionally
 send control command completion ('ack\n') to ack-fd descriptor to synchronize with the
tools/perf/builtin-record.c +1 -0
index 7302e7527d40..389be92c5a65 100644
@@ -1945,6 +1945,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
 			case EVLIST_CTL_CMD_UNSUPPORTED:
 			case EVLIST_CTL_CMD_ENABLE:
 			case EVLIST_CTL_CMD_DISABLE:
+			case EVLIST_CTL_CMD_EVLIST:
 			default:
 				break;
 			}
tools/perf/builtin-stat.c +1 -0
index 3c6712ed5af7..02fbf0dc8119 100644
@@ -588,6 +588,7 @@ 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_EVLIST:
 		default:
 			break;
 		}
tools/perf/util/evlist.c +41 -0

65 lines not on this page · raw message

tools/perf/util/evlist.h +2 -0
index 1aae75895dea..e79c64d81d21 100644
@@ -330,6 +330,7 @@ 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_EVLIST_TAG "evlist"
 
 #define EVLIST_CTL_CMD_MAX_LEN 64
 
@@ -339,6 +340,7 @@ enum evlist_ctl_cmd {
 	EVLIST_CTL_CMD_DISABLE,
 	EVLIST_CTL_CMD_ACK,
 	EVLIST_CTL_CMD_SNAPSHOT,
+	EVLIST_CTL_CMD_EVLIST,
 };
 
 int evlist__parse_control(const char *str, int *ctl_fd, int *ctl_fd_ack, bool *ctl_fd_close);
tools/perf/util/evsel_fprintf.c +2 -0
index fb498a723a00..bfedd7b23521 100644
@@ -100,6 +100,7 @@ int evsel__fprintf(struct evsel *evsel, struct perf_attr_details *details, FILE
 	return ++printed;
 }
 
+#ifndef PYTHON_PERF
 int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment,
 			      unsigned int print_opts, struct callchain_cursor *cursor,
 			      struct strlist *bt_stop_list, FILE *fp)
@@ -239,3 +240,4 @@ int sample__fprintf_sym(struct perf_sample *sample, struct addr_location *al,
 
 	return printed;
 }
+#endif /* PYTHON_PERF */
tools/perf/util/python-ext-sources +1 -0
index a9d9c142eb7c..71b753523fac 100644
@@ -10,6 +10,7 @@ util/python.c
 util/cap.c
 util/evlist.c
 util/evsel.c
+util/evsel_fprintf.c
 util/perf_event_attr_fprintf.c
 util/cpumap.c
 util/memswap.c
tools/perf/util/setup.py +1 -1
index c5e3e9a68162..483f05004e68 100644
@@ -43,7 +43,7 @@ class install_lib(_install_lib):
 
 cflags = getenv('CFLAGS', '').split()
 # switch off several checks (need to be at the end of cflags list)
-cflags += ['-fno-strict-aliasing', '-Wno-write-strings', '-Wno-unused-parameter', '-Wno-redundant-decls' ]
+cflags += ['-fno-strict-aliasing', '-Wno-write-strings', '-Wno-unused-parameter', '-Wno-redundant-decls', '-DPYTHON_PERF' ]
 if not cc_is_clang:
     cflags += ['-Wno-cast-function-type' ]
 
Signature · 1 line
2.26.2
author reviewer
#5 lore raw

PATCH v4 3/4 perf tools: Add stop control command

In reply to Jiri Olsa

Adding control 'stop' command to stop perf record. When it is received, perf will set done = 1.

Example session:

terminal 1:

    # mkfifo control ack
    # perf record --control=fifo:control,ack

terminal 2:

    # echo stop > control

terminal 1:
[ perf record: Woken up 7 times to write data ]
[ perf record: Captured and wrote 3.214 MB perf.data (38280 samples) ] #

---
 tools/perf/Documentation/perf-record.txt | 1 +
 tools/perf/builtin-record.c              | 3 +++
 tools/perf/builtin-stat.c                | 1 +
 tools/perf/util/evlist.c                 | 4 ++++
 tools/perf/util/evlist.h                 | 2 ++
 5 files changed, 11 insertions(+)
tools/perf/Documentation/perf-record.txt +1 -0
index 5cf103f28eb0..539230955dbc 100644
@@ -645,6 +645,7 @@ Available commands:
   'enable name'      : enable event 'name'
   'disable name'     : disable event 'name'
   'snapshot'         : AUX area tracing snapshot).
+  'stop'             : stop perf record
 
   'evlist [-v|-g|-F] : display all events
                        -F  Show just the sample frequency used for each event.
tools/perf/builtin-record.c +3 -0
index 389be92c5a65..9aa051c3c722 100644
@@ -1941,6 +1941,9 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
 				hit_auxtrace_snapshot_trigger(rec);
 				evlist__ctlfd_ack(rec->evlist);
 				break;
+			case EVLIST_CTL_CMD_STOP:
+				done = 1;
+				break;
 			case EVLIST_CTL_CMD_ACK:
 			case EVLIST_CTL_CMD_UNSUPPORTED:
 			case EVLIST_CTL_CMD_ENABLE:
tools/perf/builtin-stat.c +1 -0
index 02fbf0dc8119..5681cbabbec5 100644
@@ -589,6 +589,7 @@ static void process_evlist(struct evlist *evlist, unsigned int interval)
 		case EVLIST_CTL_CMD_ACK:
 		case EVLIST_CTL_CMD_UNSUPPORTED:
 		case EVLIST_CTL_CMD_EVLIST:
+		case EVLIST_CTL_CMD_STOP:
 		default:
 			break;
 		}
tools/perf/util/evlist.c +4 -0
index 9e890b482220..c6de70cefbae 100644
@@ -1940,6 +1940,9 @@ static int evlist__ctlfd_recv(struct evlist *evlist, enum evlist_ctl_cmd *cmd,
 		} else if (!strncmp(cmd_data, EVLIST_CTL_CMD_EVLIST_TAG,
 				    (sizeof(EVLIST_CTL_CMD_EVLIST_TAG)-1))) {
 			*cmd = EVLIST_CTL_CMD_EVLIST;
+		} else if (!strncmp(cmd_data, EVLIST_CTL_CMD_STOP_TAG,
+				    (sizeof(EVLIST_CTL_CMD_STOP_TAG)-1))) {
+			*cmd = EVLIST_CTL_CMD_STOP;
 		}
 	}
 
@@ -2077,6 +2080,7 @@ int evlist__ctlfd_process(struct evlist *evlist, enum evlist_ctl_cmd *cmd)
 				err = evlist__ctlfd_list(evlist, cmd_data);
 				break;
 			case EVLIST_CTL_CMD_SNAPSHOT:
+			case EVLIST_CTL_CMD_STOP:
 				break;
 			case EVLIST_CTL_CMD_ACK:
 			case EVLIST_CTL_CMD_UNSUPPORTED:
tools/perf/util/evlist.h +2 -0
index e79c64d81d21..6f45c3630355 100644
@@ -331,6 +331,7 @@ struct evsel *evlist__reset_weak_group(struct evlist *evlist, struct evsel *evse
 #define EVLIST_CTL_CMD_ACK_TAG     "ack\n"
 #define EVLIST_CTL_CMD_SNAPSHOT_TAG "snapshot"
 #define EVLIST_CTL_CMD_EVLIST_TAG "evlist"
+#define EVLIST_CTL_CMD_STOP_TAG "stop"
 
 #define EVLIST_CTL_CMD_MAX_LEN 64
 
@@ -341,6 +342,7 @@ enum evlist_ctl_cmd {
 	EVLIST_CTL_CMD_ACK,
 	EVLIST_CTL_CMD_SNAPSHOT,
 	EVLIST_CTL_CMD_EVLIST,
+	EVLIST_CTL_CMD_STOP,
 };
 
 int evlist__parse_control(const char *str, int *ctl_fd, int *ctl_fd_ack, bool *ctl_fd_close);
Signature · 1 line
2.26.2
author reviewer
#6 lore raw

PATCH v4 4/4 perf tools: Add ping control command

In reply to Jiri Olsa

Adding control 'ping' command to detect if perf is up and control interface is operational.

It will be used in following daemon patches to synchronize with record session - when control interface is up and running, we know that perf record is monitoring and ready to receive signals.

Example session:

terminal 1:

    # mkfifo control ack
    # perf record --control=fifo:control,ack

terminal 2:

    # echo ping > control
    # cat ack
    ack
---
 tools/perf/Documentation/perf-record.txt | 1 +
 tools/perf/builtin-record.c              | 1 +
 tools/perf/builtin-stat.c                | 1 +
 tools/perf/util/evlist.c                 | 4 ++++
 tools/perf/util/evlist.h                 | 2 ++
 5 files changed, 9 insertions(+)
tools/perf/Documentation/perf-record.txt +1 -0
index 539230955dbc..aa2da60ff12b 100644
@@ -646,6 +646,7 @@ Available commands:
   'disable name'     : disable event 'name'
   'snapshot'         : AUX area tracing snapshot).
   'stop'             : stop perf record
+  'ping'             : ping
 
   'evlist [-v|-g|-F] : display all events
                        -F  Show just the sample frequency used for each event.
tools/perf/builtin-record.c +1 -0
index 9aa051c3c722..3de81453ff8a 100644
@@ -1949,6 +1949,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
 			case EVLIST_CTL_CMD_ENABLE:
 			case EVLIST_CTL_CMD_DISABLE:
 			case EVLIST_CTL_CMD_EVLIST:
+			case EVLIST_CTL_CMD_PING:
 			default:
 				break;
 			}
tools/perf/builtin-stat.c +1 -0
index 5681cbabbec5..d5d08ffae31b 100644
@@ -590,6 +590,7 @@ static void process_evlist(struct evlist *evlist, unsigned int interval)
 		case EVLIST_CTL_CMD_UNSUPPORTED:
 		case EVLIST_CTL_CMD_EVLIST:
 		case EVLIST_CTL_CMD_STOP:
+		case EVLIST_CTL_CMD_PING:
 		default:
 			break;
 		}
tools/perf/util/evlist.c +4 -0
index c6de70cefbae..61b2408821e5 100644
@@ -1943,6 +1943,9 @@ static int evlist__ctlfd_recv(struct evlist *evlist, enum evlist_ctl_cmd *cmd,
 		} else if (!strncmp(cmd_data, EVLIST_CTL_CMD_STOP_TAG,
 				    (sizeof(EVLIST_CTL_CMD_STOP_TAG)-1))) {
 			*cmd = EVLIST_CTL_CMD_STOP;
+		} else if (!strncmp(cmd_data, EVLIST_CTL_CMD_PING_TAG,
+				    (sizeof(EVLIST_CTL_CMD_PING_TAG)-1))) {
+			*cmd = EVLIST_CTL_CMD_PING;
 		}
 	}
 
@@ -2081,6 +2084,7 @@ int evlist__ctlfd_process(struct evlist *evlist, enum evlist_ctl_cmd *cmd)
 				break;
 			case EVLIST_CTL_CMD_SNAPSHOT:
 			case EVLIST_CTL_CMD_STOP:
+			case EVLIST_CTL_CMD_PING:
 				break;
 			case EVLIST_CTL_CMD_ACK:
 			case EVLIST_CTL_CMD_UNSUPPORTED:
tools/perf/util/evlist.h +2 -0
index 6f45c3630355..7c2521cb6b09 100644
@@ -332,6 +332,7 @@ struct evsel *evlist__reset_weak_group(struct evlist *evlist, struct evsel *evse
 #define EVLIST_CTL_CMD_SNAPSHOT_TAG "snapshot"
 #define EVLIST_CTL_CMD_EVLIST_TAG "evlist"
 #define EVLIST_CTL_CMD_STOP_TAG "stop"
+#define EVLIST_CTL_CMD_PING_TAG "ping"
 
 #define EVLIST_CTL_CMD_MAX_LEN 64
 
@@ -343,6 +344,7 @@ enum evlist_ctl_cmd {
 	EVLIST_CTL_CMD_SNAPSHOT,
 	EVLIST_CTL_CMD_EVLIST,
 	EVLIST_CTL_CMD_STOP,
+	EVLIST_CTL_CMD_PING,
 };
 
 int evlist__parse_control(const char *str, int *ctl_fd, int *ctl_fd_ack, bool *ctl_fd_close);
Signature · 1 line
2.26.2
#7 lore raw
In reply to Jiri Olsa
Quoted 4 lines · Jiri Olsa

hi,
adding support to enable/disable specific events via control file via following commands:

Quoted 8 lines
    # echo 'enable sched:sched_process_fork' > control
    # echo 'disabled sched:sched_process_fork' > control

v4 changes:
- some of the patches got merged
- rebased to latest perf/core
- fixed changelogs
- added 'ping' command

any reviews?

thanks,
jirka

Quoted 38 lines

v3 changes:
- use ' ' instead of '-' in syntax and add command argument processing [Arnaldo]
- add options to evlist [Arnaldo]
- add man page changes

v2 changes:
- added acks
- change list to evlist [Arnaldo]
- add evlist-verbose command [Arnaldo]
- add '' to enale-/disable- error message

The code is available in here:
git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
perf/control

thanks,
jirka

---
Jiri Olsa (4):
perf tools: Allow to enable/disable events via control file perf tools: Add evlist control command
perf tools: Add stop control command
perf tools: Add ping control command

 tools/perf/Documentation/perf-record.txt |  15 ++++++++++++---
 tools/perf/builtin-record.c              |  13 +++++++------
 tools/perf/builtin-stat.c                |   5 +++--
 tools/perf/util/evlist.c                 | 112 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 tools/perf/util/evlist.h                 |   6 ++++++
 tools/perf/util/evsel_fprintf.c          |   2 ++
 tools/perf/util/python-ext-sources       |   1 +
 tools/perf/util/setup.py                 |   2 +-
 8 files changed, 141 insertions(+), 15 deletions(-)
maintainer Acked-by
#8 lore raw

Hi Jiri,

Quoted 9 lines · Jiri Olsa
Quoted 7 lines · Jiri Olsa

hi,
adding support to enable/disable specific events via control file via following commands:

    # echo 'enable sched:sched_process_fork' > control
    # echo 'disabled sched:sched_process_fork' > control
Quoted 7 lines
Quoted 5 lines

v4 changes:
- some of the patches got merged
- rebased to latest perf/core
- fixed changelogs
- added 'ping' command

any reviews?

Thanks,
Namhyung

maintainer Applied
#9 lore raw
In reply to Jiri Olsa

Em Sun, Dec 27, 2020 at 12:20:34AM +0100, Jiri Olsa escreveu:

Quoted 25 lines

hi,
adding support to enable/disable specific events via control file via following commands:

    # echo 'enable sched:sched_process_fork' > control
    # echo 'disabled sched:sched_process_fork' > control

v4 changes:
- some of the patches got merged
- rebased to latest perf/core
- fixed changelogs
- added 'ping' command

v3 changes:
- use ' ' instead of '-' in syntax and add command argument processing [Arnaldo]
- add options to evlist [Arnaldo]
- add man page changes

v2 changes:
- added acks
- change list to evlist [Arnaldo]
- add evlist-verbose command [Arnaldo]
- add '' to enale-/disable- error message

Quoted 6 lines

The code is available in here:
git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
perf/control

thanks,
jirka

Thanks, applied.

- Arnaldo

Quoted 18 lines

---
Jiri Olsa (4):
perf tools: Allow to enable/disable events via control file perf tools: Add evlist control command
perf tools: Add stop control command
perf tools: Add ping control command

 tools/perf/Documentation/perf-record.txt |  15 ++++++++++++---
 tools/perf/builtin-record.c              |  13 +++++++------
 tools/perf/builtin-stat.c                |   5 +++--
 tools/perf/util/evlist.c                 | 112 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 tools/perf/util/evlist.h                 |   6 ++++++
 tools/perf/util/evsel_fprintf.c          |   2 ++
 tools/perf/util/python-ext-sources       |   1 +
 tools/perf/util/setup.py                 |   2 +-
 8 files changed, 141 insertions(+), 15 deletions(-)
Signature · 1 line
- Arnaldo