[PATCH 3/8] perf record: Add --block option

From: Jiri Olsa
Date: Wed Dec 05 2018 - 11:05:53 EST


Adding --block option to allow record command set block
bool in struct perf_event_attr for event, like:

# perf record -e raw_syscalls:sys_enter --block ls
# perf record -e raw_syscalls:sys_enter --block -p ...

It's allowed only for syscall tracepoint events
attached to process.

Link: http://lkml.kernel.org/n/tip-ocz7zwwkkx11v0mkxrtcddih@xxxxxxxxxxxxxx
Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx>
---
tools/perf/builtin-record.c | 9 +++++++++
tools/perf/perf.h | 1 +
tools/perf/util/evsel.c | 3 +++
3 files changed, 13 insertions(+)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 4736dc96c4ca..79c8d2f94f86 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -1937,6 +1937,8 @@ static struct option __record_options[] = {
"append timestamp to output filename"),
OPT_BOOLEAN(0, "timestamp-boundary", &record.timestamp_boundary,
"Record timestamp boundary (time of first/last samples)"),
+ OPT_BOOLEAN(0, "block", &record.opts.block,
+ "Request blocked tracing (for syscall tracepoints)"),
OPT_STRING_OPTARG_SET(0, "switch-output", &record.switch_output.str,
&record.switch_output.set, "signal,size,time",
"Switch output when receive SIGUSR2 or cross size,time threshold",
@@ -2116,6 +2118,13 @@ int cmd_record(int argc, const char **argv)
goto out;
}

+ if (rec->opts.block &&
+ !target__has_task(&rec->opts.target) &&
+ !target__none(&rec->opts.target)) {
+ pr_err("Can't use --block on non task targets\n");
+ goto out;
+ }
+
/* Enable ignoring missing threads when -u/-p option is defined. */
rec->opts.ignore_missing_thread = rec->opts.target.uid != UINT_MAX || rec->opts.target.pid;

diff --git a/tools/perf/perf.h b/tools/perf/perf.h
index 4d40baa45a5f..7884701247b8 100644
--- a/tools/perf/perf.h
+++ b/tools/perf/perf.h
@@ -66,6 +66,7 @@ struct record_opts {
bool ignore_missing_thread;
bool strict_freq;
bool sample_id;
+ bool block;
unsigned int freq;
unsigned int mmap_pages;
unsigned int auxtrace_mmap_pages;
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index dbc0466db368..e4943e8f811b 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -1045,6 +1045,9 @@ void perf_evsel__config(struct perf_evsel *evsel, struct record_opts *opts,
if (opts->sample_transaction)
perf_evsel__set_sample_bit(evsel, TRANSACTION);

+ if (opts->block)
+ attr->block = true;
+
if (opts->running_time) {
evsel->attr.read_format |=
PERF_FORMAT_TOTAL_TIME_ENABLED |
--
2.17.2