perf tools: Allow to enable/disable events via control pipe
Jiri Olsa
reviewerv4 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' > controlv4 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(-)
Jiri Olsa
reviewerPATCH 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.pipeterminal 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=34057terminal 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
@@ -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
@@ -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
@@ -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
Jiri Olsa
reviewerPATCH v4 2/4 perf tools: Add evlist control command
In reply to Jiri OlsaAdding 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: 1terminal 2:
# echo 'evlist -g' > control
terminal 1:
{cycles,instructions}
dummy:HGterminal 2:
# echo 'evlist -F' > control
terminal 1:
cycles: sample_freq=4000
instructions: sample_freq=4000
dummy:HG: sample_freq=4000This 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -100,6 +100,7 @@ int evsel__fprintf(struct evsel *evsel, struct perf_attr_details *details, FILEreturn ++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
@@ -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
@@ -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
Jiri Olsa
reviewerPATCH v4 3/4 perf tools: Add stop control command
In reply to Jiri OlsaAdding 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,ackterminal 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
Jiri Olsa
reviewerPATCH v4 4/4 perf tools: Add ping control command
In reply to Jiri OlsaAdding 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,ackterminal 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
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' > controlv4 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 changesv2 changes:
- added acks
- change list to evlist [Arnaldo]
- add evlist-verbose command [Arnaldo]
- add '' to enale-/disable- error messageThe code is available in here:
git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
perf/controlthanks,
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 commandtools/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(-)
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' commandany reviews?
Thanks,
Namhyung
Re: [PATCH 1/4] perf tools: Allow to enable/disable events via control file
In reply to Arnaldo Carvalho de MeloOn 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 enabledI 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 disabledThe 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/nullList 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
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' > controlv4 changes:
- some of the patches got merged
- rebased to latest perf/core
- fixed changelogs
- added 'ping' commandv3 changes:
- use ' ' instead of '-' in syntax and add command argument processing [Arnaldo]
- add options to evlist [Arnaldo]
- add man page changesv2 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/controlthanks,
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 commandtools/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
Arnaldo Carvalho de Melo
maintainerRe: [PATCH 1/4] perf tools: Allow to enable/disable events via control file
In reply to Jiri OlsaEm 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.pipeterminal 2:
# cat perf.pipe | perf --no-pager script -i -terminal 1:
Events disabledNOTE 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' > controlterminal 1:
event sched:sched_process_fork enabledterminal 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=34057terminal 3:
# echo 'enable sched:sched_wakeup_new' > control
Quoted 8 lines
terminal 1:
event sched:sched_wakeup_new enabledterminal 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
Signed-off-by Jiri Olsa <[email protected]>--- 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@@ -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 thetools/perf/builtin-record.c +2
-6@@ -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@@ -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@@ -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