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(-)
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
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(-)
diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt
index 34cf651ee237..05a85da0f7c5 100644
--- a/tools/perf/Documentation/perf-record.txt
+++ b/tools/perf/Documentation/perf-record.txt
@@ -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
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index fd3911650612..7302e7527d40 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -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;
}
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 8cc24967bc27..3c6712ed5af7 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -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:
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 05363a7247c4..c71c7e035641 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -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;
--
2.26.2
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) ]
#
Signed-off-by: Jiri Olsa <[email protected]>
---
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(+)
diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt
index 5cf103f28eb0..539230955dbc 100644
--- a/tools/perf/Documentation/perf-record.txt
+++ b/tools/perf/Documentation/perf-record.txt
@@ -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.
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 389be92c5a65..9aa051c3c722 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -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:
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 02fbf0dc8119..5681cbabbec5 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -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;
}
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 9e890b482220..c6de70cefbae 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -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:
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index e79c64d81d21..6f45c3630355 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -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);
--
2.26.2
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.
Signed-off-by: Jiri Olsa <[email protected]>
---
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(-)
diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt
index 05a85da0f7c5..5cf103f28eb0 100644
--- a/tools/perf/Documentation/perf-record.txt
+++ b/tools/perf/Documentation/perf-record.txt
@@ -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
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 7302e7527d40..389be92c5a65 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -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;
}
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 3c6712ed5af7..02fbf0dc8119 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -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;
}
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index c71c7e035641..9e890b482220 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -24,6 +24,7 @@
#include "bpf-event.h"
#include "util/string2.h"
#include "util/perf_api_probe.h"
+#include "util/evsel_fprintf.h"
#include <signal.h>
#include <unistd.h>
#include <sched.h>
@@ -1936,6 +1937,9 @@ static int evlist__ctlfd_recv(struct evlist *evlist, enum evlist_ctl_cmd *cmd,
(sizeof(EVLIST_CTL_CMD_SNAPSHOT_TAG)-1))) {
*cmd = EVLIST_CTL_CMD_SNAPSHOT;
pr_debug("is snapshot\n");
+ } else if (!strncmp(cmd_data, EVLIST_CTL_CMD_EVLIST_TAG,
+ (sizeof(EVLIST_CTL_CMD_EVLIST_TAG)-1))) {
+ *cmd = EVLIST_CTL_CMD_EVLIST;
}
}
@@ -2015,6 +2019,40 @@ static int evlist__ctlfd_enable(struct evlist *evlist, char *cmd_data, bool enab
return 0;
}
+static int evlist__ctlfd_list(struct evlist *evlist, char *cmd_data)
+{
+ struct perf_attr_details details = { .verbose = false, };
+ struct evsel *evsel;
+ char *arg;
+ int err;
+
+ err = get_cmd_arg(cmd_data,
+ sizeof(EVLIST_CTL_CMD_EVLIST_TAG) - 1,
+ &arg);
+ if (err < 0) {
+ pr_info("failed: wrong command\n");
+ return -1;
+ }
+
+ if (err) {
+ if (!strcmp(arg, "-v")) {
+ details.verbose = true;
+ } else if (!strcmp(arg, "-g")) {
+ details.event_group = true;
+ } else if (!strcmp(arg, "-F")) {
+ details.freq = true;
+ } else {
+ pr_info("failed: wrong command\n");
+ return -1;
+ }
+ }
+
+ evlist__for_each_entry(evlist, evsel)
+ evsel__fprintf(evsel, &details, stderr);
+
+ return 0;
+}
+
int evlist__ctlfd_process(struct evlist *evlist, enum evlist_ctl_cmd *cmd)
{
int err = 0;
@@ -2035,6 +2073,9 @@ int evlist__ctlfd_process(struct evlist *evlist, enum evlist_ctl_cmd *cmd)
err = evlist__ctlfd_enable(evlist, cmd_data,
*cmd == EVLIST_CTL_CMD_ENABLE);
break;
+ case EVLIST_CTL_CMD_EVLIST:
+ err = evlist__ctlfd_list(evlist, cmd_data);
+ 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..e79c64d81d21 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -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);
diff --git a/tools/perf/util/evsel_fprintf.c b/tools/perf/util/evsel_fprintf.c
index fb498a723a00..bfedd7b23521 100644
--- a/tools/perf/util/evsel_fprintf.c
+++ b/tools/perf/util/evsel_fprintf.c
@@ -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 */
diff --git a/tools/perf/util/python-ext-sources b/tools/perf/util/python-ext-sources
index a9d9c142eb7c..71b753523fac 100644
--- a/tools/perf/util/python-ext-sources
+++ b/tools/perf/util/python-ext-sources
@@ -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
diff --git a/tools/perf/util/setup.py b/tools/perf/util/setup.py
index c5e3e9a68162..483f05004e68 100644
--- a/tools/perf/util/setup.py
+++ b/tools/perf/util/setup.py
@@ -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' ]
--
2.26.2
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
Signed-off-by: Jiri Olsa <[email protected]>
---
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(+)
diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt
index 539230955dbc..aa2da60ff12b 100644
--- a/tools/perf/Documentation/perf-record.txt
+++ b/tools/perf/Documentation/perf-record.txt
@@ -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.
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 9aa051c3c722..3de81453ff8a 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -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;
}
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 5681cbabbec5..d5d08ffae31b 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -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;
}
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index c6de70cefbae..61b2408821e5 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -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:
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index 6f45c3630355..7c2521cb6b09 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -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);
--
2.26.2
On Sun, Dec 27, 2020 at 12:20:34AM +0100, Jiri Olsa wrote:
> 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
any reviews?
thanks,
jirka
>
> 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(-)
>
Hi Jiri,
On Thu, Jan 7, 2021 at 9:12 PM Jiri Olsa <[email protected]> wrote:
>
> On Sun, Dec 27, 2020 at 12:20:34AM +0100, Jiri Olsa wrote:
> > 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
>
> any reviews?
Acked-by: Namhyung Kim <[email protected]>
Thanks,
Namhyung
On Tue, Jan 19, 2021 at 11:16:37AM -0300, Arnaldo Carvalho de Melo wrote:
SNIP
> > 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.
ok, I'll make patch for that
>
> 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?
>
> 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...
ok, I'll check the note
thanks,
jirka
Em Sun, Dec 27, 2020 at 12:20:34AM +0100, Jiri Olsa escreveu:
> 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
Thanks, applied.
- Arnaldo
>
> ---
> 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(-)
>
--
- Arnaldo
Em Sun, Dec 27, 2020 at 12:20:35AM +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>'
>
> 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
'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
> 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(-)
>
> diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt
> index 34cf651ee237..05a85da0f7c5 100644
> --- a/tools/perf/Documentation/perf-record.txt
> +++ b/tools/perf/Documentation/perf-record.txt
> @@ -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
> diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
> index fd3911650612..7302e7527d40 100644
> --- a/tools/perf/builtin-record.c
> +++ b/tools/perf/builtin-record.c
> @@ -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;
> }
> diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
> index 8cc24967bc27..3c6712ed5af7 100644
> --- a/tools/perf/builtin-stat.c
> +++ b/tools/perf/builtin-stat.c
> @@ -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:
> diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
> index 05363a7247c4..c71c7e035641 100644
> --- a/tools/perf/util/evlist.c
> +++ b/tools/perf/util/evlist.c
> @@ -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;
> --
> 2.26.2
>
--
- Arnaldo