2020-09-01 09:41:46

by Adrian Hunter

[permalink] [raw]
Subject: [PATCH V2 0/6] perf tools: Enable AUX area tracing snapshots using a FIFO

Hi

Here are V2 patches to enable AUX area tracing snapshots using a FIFO.
Presently SIGUSR2 can be used but the advantage of the FIFO is that access
is governed by access to the FIFO. Refer to the example in patch 5.

The first 4 patches are preparation, including patch 4 which enhances the
--control option to accept file names.

Patch 5 adds snapshot control command.

The final patch updates Intel PT documentation.


Changes in V2:
Use fifo: prefix in --control option


Adrian Hunter (6):
perf tools: Consolidate --control option parsing into one function
perf tools: Handle read errors from ctl_fd
perf tools: Use AsciiDoc formatting for --control option documentation
perf tools: Add FIFO file names as alternative options to --control
perf record: Add 'snapshot' control command
perf intel-pt: Document snapshot control command

tools/perf/Documentation/perf-intel-pt.txt | 23 ++++++-
tools/perf/Documentation/perf-record.txt | 56 ++++++++---------
tools/perf/Documentation/perf-stat.txt | 48 ++++++++-------
tools/perf/builtin-record.c | 74 +++++++++++++----------
tools/perf/builtin-stat.c | 35 +++++------
tools/perf/util/evlist.c | 96 +++++++++++++++++++++++++++---
tools/perf/util/evlist.h | 6 +-
tools/perf/util/record.h | 1 +
tools/perf/util/stat.h | 1 +
9 files changed, 227 insertions(+), 113 deletions(-)


Regards
Adrian


2020-09-01 09:42:07

by Adrian Hunter

[permalink] [raw]
Subject: [PATCH V2 3/6] perf tools: Use AsciiDoc formatting for --control option documentation

The --control option does not display well in man pages unless AsciiDoc
formatting is used.

Signed-off-by: Adrian Hunter <[email protected]>
---
tools/perf/Documentation/perf-record.txt | 46 ++++++++++++------------
tools/perf/Documentation/perf-stat.txt | 46 ++++++++++++------------
2 files changed, 46 insertions(+), 46 deletions(-)

diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt
index 3f72d8e261f3..07c4734f1c7a 100644
--- a/tools/perf/Documentation/perf-record.txt
+++ b/tools/perf/Documentation/perf-record.txt
@@ -627,43 +627,43 @@ option. The -e option and this one can be mixed and matched. Events
can be grouped using the {} notation.
endif::HAVE_LIBPFM[]

---control fd:ctl-fd[,ack-fd]
+--control=fd:ctl-fd[,ack-fd]::
Listen on ctl-fd descriptor for command to control measurement ('enable': enable events,
'disable': disable events). 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 controlling process. Example of bash shell script to enable and
disable events during measurements:

-#!/bin/bash
+ #!/bin/bash

-ctl_dir=/tmp/
+ ctl_dir=/tmp/

-ctl_fifo=${ctl_dir}perf_ctl.fifo
-test -p ${ctl_fifo} && unlink ${ctl_fifo}
-mkfifo ${ctl_fifo}
-exec {ctl_fd}<>${ctl_fifo}
+ ctl_fifo=${ctl_dir}perf_ctl.fifo
+ test -p ${ctl_fifo} && unlink ${ctl_fifo}
+ mkfifo ${ctl_fifo}
+ exec {ctl_fd}<>${ctl_fifo}

-ctl_ack_fifo=${ctl_dir}perf_ctl_ack.fifo
-test -p ${ctl_ack_fifo} && unlink ${ctl_ack_fifo}
-mkfifo ${ctl_ack_fifo}
-exec {ctl_fd_ack}<>${ctl_ack_fifo}
+ ctl_ack_fifo=${ctl_dir}perf_ctl_ack.fifo
+ test -p ${ctl_ack_fifo} && unlink ${ctl_ack_fifo}
+ mkfifo ${ctl_ack_fifo}
+ exec {ctl_fd_ack}<>${ctl_ack_fifo}

-perf record -D -1 -e cpu-cycles -a \
- --control fd:${ctl_fd},${ctl_fd_ack} \
- -- sleep 30 &
-perf_pid=$!
+ perf record -D -1 -e cpu-cycles -a \
+ --control fd:${ctl_fd},${ctl_fd_ack} \
+ -- sleep 30 &
+ perf_pid=$!

-sleep 5 && echo 'enable' >&${ctl_fd} && read -u ${ctl_fd_ack} e1 && echo "enabled(${e1})"
-sleep 10 && echo 'disable' >&${ctl_fd} && read -u ${ctl_fd_ack} d1 && echo "disabled(${d1})"
+ sleep 5 && echo 'enable' >&${ctl_fd} && read -u ${ctl_fd_ack} e1 && echo "enabled(${e1})"
+ sleep 10 && echo 'disable' >&${ctl_fd} && read -u ${ctl_fd_ack} d1 && echo "disabled(${d1})"

-exec {ctl_fd_ack}>&-
-unlink ${ctl_ack_fifo}
+ exec {ctl_fd_ack}>&-
+ unlink ${ctl_ack_fifo}

-exec {ctl_fd}>&-
-unlink ${ctl_fifo}
+ exec {ctl_fd}>&-
+ unlink ${ctl_fifo}

-wait -n ${perf_pid}
-exit $?
+ wait -n ${perf_pid}
+ exit $?


SEE ALSO
diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentation/perf-stat.txt
index c9bfefc051fb..7fb7368cc2d9 100644
--- a/tools/perf/Documentation/perf-stat.txt
+++ b/tools/perf/Documentation/perf-stat.txt
@@ -176,43 +176,43 @@ with it. --append may be used here. Examples:
3>results perf stat --log-fd 3 -- $cmd
3>>results perf stat --log-fd 3 --append -- $cmd

---control fd:ctl-fd[,ack-fd]
+--control=fd:ctl-fd[,ack-fd]::
Listen on ctl-fd descriptor for command to control measurement ('enable': enable events,
'disable': disable events). 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 controlling process. Example of bash shell script to enable and
disable events during measurements:

-#!/bin/bash
+ #!/bin/bash

-ctl_dir=/tmp/
+ ctl_dir=/tmp/

-ctl_fifo=${ctl_dir}perf_ctl.fifo
-test -p ${ctl_fifo} && unlink ${ctl_fifo}
-mkfifo ${ctl_fifo}
-exec {ctl_fd}<>${ctl_fifo}
+ ctl_fifo=${ctl_dir}perf_ctl.fifo
+ test -p ${ctl_fifo} && unlink ${ctl_fifo}
+ mkfifo ${ctl_fifo}
+ exec {ctl_fd}<>${ctl_fifo}

-ctl_ack_fifo=${ctl_dir}perf_ctl_ack.fifo
-test -p ${ctl_ack_fifo} && unlink ${ctl_ack_fifo}
-mkfifo ${ctl_ack_fifo}
-exec {ctl_fd_ack}<>${ctl_ack_fifo}
+ ctl_ack_fifo=${ctl_dir}perf_ctl_ack.fifo
+ test -p ${ctl_ack_fifo} && unlink ${ctl_ack_fifo}
+ mkfifo ${ctl_ack_fifo}
+ exec {ctl_fd_ack}<>${ctl_ack_fifo}

-perf stat -D -1 -e cpu-cycles -a -I 1000 \
- --control fd:${ctl_fd},${ctl_fd_ack} \
- -- sleep 30 &
-perf_pid=$!
+ perf stat -D -1 -e cpu-cycles -a -I 1000 \
+ --control fd:${ctl_fd},${ctl_fd_ack} \
+ -- sleep 30 &
+ perf_pid=$!

-sleep 5 && echo 'enable' >&${ctl_fd} && read -u ${ctl_fd_ack} e1 && echo "enabled(${e1})"
-sleep 10 && echo 'disable' >&${ctl_fd} && read -u ${ctl_fd_ack} d1 && echo "disabled(${d1})"
+ sleep 5 && echo 'enable' >&${ctl_fd} && read -u ${ctl_fd_ack} e1 && echo "enabled(${e1})"
+ sleep 10 && echo 'disable' >&${ctl_fd} && read -u ${ctl_fd_ack} d1 && echo "disabled(${d1})"

-exec {ctl_fd_ack}>&-
-unlink ${ctl_ack_fifo}
+ exec {ctl_fd_ack}>&-
+ unlink ${ctl_ack_fifo}

-exec {ctl_fd}>&-
-unlink ${ctl_fifo}
+ exec {ctl_fd}>&-
+ unlink ${ctl_fifo}

-wait -n ${perf_pid}
-exit $?
+ wait -n ${perf_pid}
+ exit $?


--pre::
--
2.17.1

2020-09-01 09:42:28

by Adrian Hunter

[permalink] [raw]
Subject: [PATCH V2 2/6] perf tools: Handle read errors from ctl_fd

Handle read errors from ctl_fd such as EINTR, EAGAIN and EWOULDBLOCK.

Signed-off-by: Adrian Hunter <[email protected]>
---
tools/perf/util/evlist.c | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 62e3f87547ce..47d1045a19af 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -1802,6 +1802,7 @@ static int evlist__ctlfd_recv(struct evlist *evlist, enum evlist_ctl_cmd *cmd,
char c;
size_t bytes_read = 0;

+ *cmd = EVLIST_CTL_CMD_UNSUPPORTED;
memset(cmd_data, 0, data_size);
data_size--;

@@ -1813,17 +1814,22 @@ static int evlist__ctlfd_recv(struct evlist *evlist, enum evlist_ctl_cmd *cmd,
cmd_data[bytes_read++] = c;
if (bytes_read == data_size)
break;
- } else {
- if (err == -1)
+ continue;
+ } else if (err == -1) {
+ if (errno == EINTR)
+ continue;
+ if (errno == EAGAIN || errno == EWOULDBLOCK)
+ err = 0;
+ else
pr_err("Failed to read from ctlfd %d: %m\n", evlist->ctl_fd.fd);
- break;
}
+ break;
} while (1);

pr_debug("Message from ctl_fd: \"%s%s\"\n", cmd_data,
bytes_read == data_size ? "" : c == '\n' ? "\\n" : "\\0");

- if (err > 0) {
+ if (bytes_read > 0) {
if (!strncmp(cmd_data, EVLIST_CTL_CMD_ENABLE_TAG,
(sizeof(EVLIST_CTL_CMD_ENABLE_TAG)-1))) {
*cmd = EVLIST_CTL_CMD_ENABLE;
@@ -1833,7 +1839,7 @@ static int evlist__ctlfd_recv(struct evlist *evlist, enum evlist_ctl_cmd *cmd,
}
}

- return err;
+ return bytes_read ? (int)bytes_read : err;
}

static int evlist__ctlfd_ack(struct evlist *evlist)
--
2.17.1

2020-09-02 16:13:10

by Alexey Budankov

[permalink] [raw]
Subject: Re: [PATCH V2 2/6] perf tools: Handle read errors from ctl_fd


On 01.09.2020 12:37, Adrian Hunter wrote:
> Handle read errors from ctl_fd such as EINTR, EAGAIN and EWOULDBLOCK.
>
> Signed-off-by: Adrian Hunter <[email protected]>
> ---
> tools/perf/util/evlist.c | 16 +++++++++++-----
> 1 file changed, 11 insertions(+), 5 deletions(-)

Acked-by: Alexei Budankov <[email protected]>

Regards,
Alexei

2020-09-02 16:14:47

by Alexey Budankov

[permalink] [raw]
Subject: Re: [PATCH V2 3/6] perf tools: Use AsciiDoc formatting for --control option documentation


On 01.09.2020 12:37, Adrian Hunter wrote:
> The --control option does not display well in man pages unless AsciiDoc
> formatting is used.
>
> Signed-off-by: Adrian Hunter <[email protected]>
> ---
> tools/perf/Documentation/perf-record.txt | 46 ++++++++++++------------
> tools/perf/Documentation/perf-stat.txt | 46 ++++++++++++------------
> 2 files changed, 46 insertions(+), 46 deletions(-)

Thanks Adrian for all the formating corrections.

Acked-by: Alexei Budankov <[email protected]>

Regards,
Alexei

2020-09-03 20:18:44

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: Re: [PATCH V2 2/6] perf tools: Handle read errors from ctl_fd

Em Wed, Sep 02, 2020 at 07:11:14PM +0300, Alexey Budankov escreveu:
>
> On 01.09.2020 12:37, Adrian Hunter wrote:
> > Handle read errors from ctl_fd such as EINTR, EAGAIN and EWOULDBLOCK.
> >
> > Signed-off-by: Adrian Hunter <[email protected]>
> > ---
> > tools/perf/util/evlist.c | 16 +++++++++++-----
> > 1 file changed, 11 insertions(+), 5 deletions(-)
>
> Acked-by: Alexei Budankov <[email protected]>

Thanks, applied.

- Arnaldo

2020-09-03 20:19:59

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: Re: [PATCH V2 3/6] perf tools: Use AsciiDoc formatting for --control option documentation

Em Wed, Sep 02, 2020 at 07:12:43PM +0300, Alexey Budankov escreveu:
>
> On 01.09.2020 12:37, Adrian Hunter wrote:
> > The --control option does not display well in man pages unless AsciiDoc
> > formatting is used.
> >
> > Signed-off-by: Adrian Hunter <[email protected]>
> > ---
> > tools/perf/Documentation/perf-record.txt | 46 ++++++++++++------------
> > tools/perf/Documentation/perf-stat.txt | 46 ++++++++++++------------
> > 2 files changed, 46 insertions(+), 46 deletions(-)
>
> Thanks Adrian for all the formating corrections.
>
> Acked-by: Alexei Budankov <[email protected]>

Thanks, applied.

- Arnaldo