From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Wang Nan <wangnan0@huawei.com>
Cc: linux-kernel@vger.kernel.org, pi3orama@163.com,
He Kuang <hekuang@huawei.com>,
Arnaldo Carvalho de Melo <acme@redhat.com>,
Jiri Olsa <jolsa@kernel.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
Namhyung Kim <namhyung@kernel.org>, Zefan Li <lizefan@huawei.com>
Subject: Re: [PATCH v8 6/8] perf tools: Enable overwrite settings
Date: Tue, 21 Jun 2016 18:49:40 -0300 [thread overview]
Message-ID: <20160621214940.GG4213@kernel.org> (raw)
In-Reply-To: <1466419645-75551-7-git-send-email-wangnan0@huawei.com>
Em Mon, Jun 20, 2016 at 10:47:23AM +0000, Wang Nan escreveu:
> This patch allows following config terms and option:
>
> Globally setting events to overwrite;
>
> # perf record --overwrite ...
>
> Set specific events to be overwrite or no-overwrite.
>
> # perf record --event cycles/overwrite/ ...
> # perf record --event cycles/no-overwrite/ ...
>
> Add missing config terms and update config term array size because the
> longest string length is changed.
>
> For overwritable events, automatically select attr.write_backward since
> perf requires it to be backward for reading.
>
> Test result:
> # perf record --overwrite -e syscalls:*enter_nanosleep* usleep 1
> [ perf record: Woken up 2 times to write data ]
> [ perf record: Captured and wrote 0.011 MB perf.data (1 samples) ]
> # perf evlist -v
> syscalls:sys_enter_nanosleep: type: 2, size: 112, config: 0x134, { sample_period, sample_freq }: 1, sample_type: IP|TID|TIME|CPU|PERIOD|RAW, disabled: 1, inherit: 1, mmap: 1, comm: 1, enable_on_exec: 1, task: 1, sample_id_all: 1, exclude_guest: 1, mmap2: 1, comm_exec: 1, write_backward: 1
> # Tip: use 'perf evlist --trace-fields' to show fields for tracepoint events
>
> Signed-off-by: Wang Nan <wangnan0@huawei.com>
> Signed-off-by: He Kuang <hekuang@huawei.com>
> Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
> Cc: Jiri Olsa <jolsa@kernel.org>
> Cc: Masami Hiramatsu <mhiramat@kernel.org>
> Cc: Namhyung Kim <namhyung@kernel.org>
> Cc: Zefan Li <lizefan@huawei.com>
> Cc: pi3orama@163.com
> ---
> tools/perf/Documentation/perf-record.txt | 14 ++++++++++++++
> tools/perf/builtin-record.c | 1 +
> tools/perf/perf.h | 1 +
> tools/perf/tests/backward-ring-buffer.c | 15 ++++++---------
> tools/perf/util/evsel.c | 12 ++++++++++++
> tools/perf/util/evsel.h | 2 ++
> tools/perf/util/parse-events.c | 20 ++++++++++++++++++--
> tools/perf/util/parse-events.h | 2 ++
> tools/perf/util/parse-events.l | 2 ++
> 9 files changed, 58 insertions(+), 11 deletions(-)
>
> diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt
> index 8dbee83..f5cb932 100644
> --- a/tools/perf/Documentation/perf-record.txt
> +++ b/tools/perf/Documentation/perf-record.txt
> @@ -360,6 +360,20 @@ particular perf.data snapshot should be kept or not.
>
> Implies --timestamp-filename, --no-buildid and --no-buildid-cache.
>
> +--overwrite::
> +Makes all events use overwritable ring buffer. Event with overwritable ring
> +buffer works like a flight recorder: when buffer gets full, instead of dumping
> +records into output file, kernel overwrites old records silently. Perf dumps
> +data from overwritable ring buffer when switching output (see --switch-output)
> +and before terminate.
What about: (some other alternative paragraphs below)
---------------
Makes all events use an overwritable ring buffer. An overwritable ring
buffer works like a flight recorder: when it gets full, the kernel will
overwrite the oldest records, that thus will never make it to the
perf.data file.
> +
> +Perf behaves like a daemon when '--overwrite' and '--switch-output' are
> +provided. It record and drop events in background, and dumps data when
> +something unusual is detected.
When '--overwrite' and '--switch-output' are used perf records and drops
events until it receives a signal, meaning that something unusual was
detected that warrants taking a snapshot of the most current events,
those fitting in the ring buffer at that moment.
> +
> +'overwrite' attribute can also be set or canceled for specific event using
an
> +config terms like 'cycles/overwrite/' and 'instructions/no-overwrite/'.
in
> +
> SEE ALSO
> --------
> linkperf:perf-stat[1], linkperf:perf-list[1]
> diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
> index 48c0051..bb62882 100644
> --- a/tools/perf/builtin-record.c
> +++ b/tools/perf/builtin-record.c
> @@ -1520,6 +1520,7 @@ struct option __record_options[] = {
> OPT_BOOLEAN_SET('i', "no-inherit", &record.opts.no_inherit,
> &record.opts.no_inherit_set,
> "child tasks do not inherit counters"),
> + OPT_BOOLEAN(0, "overwrite", &record.opts.overwrite, "use overwrite mode"),
> OPT_UINTEGER('F', "freq", &record.opts.user_freq, "profile at this frequency"),
> OPT_CALLBACK('m', "mmap-pages", &record.opts, "pages[,pages]",
> "number of mmap data pages and AUX area tracing mmap pages",
> diff --git a/tools/perf/perf.h b/tools/perf/perf.h
> index cd8f1b1..608b42b 100644
> --- a/tools/perf/perf.h
> +++ b/tools/perf/perf.h
> @@ -59,6 +59,7 @@ struct record_opts {
> bool record_switch_events;
> bool all_kernel;
> bool all_user;
> + bool overwrite;
> unsigned int freq;
> unsigned int mmap_pages;
> unsigned int auxtrace_mmap_pages;
> diff --git a/tools/perf/tests/backward-ring-buffer.c b/tools/perf/tests/backward-ring-buffer.c
> index 76e34c0..bba0b83 100644
> --- a/tools/perf/tests/backward-ring-buffer.c
> +++ b/tools/perf/tests/backward-ring-buffer.c
> @@ -130,27 +130,24 @@ int test__backward_ring_buffer(int subtest __maybe_unused)
> }
>
> bzero(&parse_error, sizeof(parse_error));
> - err = parse_events(evlist, "syscalls:sys_enter_prctl", &parse_error);
> + /*
> + * Set backward bit, ring buffer should be writing from end. Record
> + * it in aux evlist
> + */
> + err = parse_events(evlist, "syscalls:sys_enter_prctl/overwrite/", &parse_error);
> if (err) {
> pr_debug("Failed to parse tracepoint event, try use root\n");
> ret = TEST_SKIP;
> goto out_delete_evlist;
> }
>
> - /*
> - * Set backward bit, ring buffer should be writing from end. Record
> - * it in aux evlist
> - */
> - perf_evlist__last(evlist)->overwrite = true;
> - perf_evlist__last(evlist)->attr.write_backward = 1;
> -
> + /* Don't set backward bit for exit event. Record it in main evlist */
> err = parse_events(evlist, "syscalls:sys_exit_prctl", &parse_error);
> if (err) {
> pr_debug("Failed to parse tracepoint event, try use root\n");
> ret = TEST_SKIP;
> goto out_delete_evlist;
> }
> - /* Don't set backward bit for exit event. Record it in main evlist */
>
> perf_evlist__config(evlist, &opts, NULL);
>
> diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
> index 1d8f2bb..3629520 100644
> --- a/tools/perf/util/evsel.c
> +++ b/tools/perf/util/evsel.c
> @@ -677,11 +677,22 @@ static void apply_config_terms(struct perf_evsel *evsel,
> */
> attr->inherit = term->val.inherit ? 1 : 0;
> break;
> + case PERF_EVSEL__CONFIG_TERM_OVERWRITE:
> + evsel->overwrite = term->val.overwrite ? 1 : 0;
> + break;
> default:
> break;
> }
> }
>
> + /*
> + * Set backward after config term processing because it is
> + * possible to set overwrite globally, without config
> + * terms.
> + */
> + if (evsel->overwrite)
> + attr->write_backward = 1;
> +
> /* User explicitly set per-event callgraph, clear the old setting and reset. */
> if ((callgraph_buf != NULL) || (dump_size > 0) || max_stack) {
> if (max_stack) {
> @@ -758,6 +769,7 @@ void perf_evsel__config(struct perf_evsel *evsel, struct record_opts *opts,
>
> attr->sample_id_all = perf_missing_features.sample_id_all ? 0 : 1;
> attr->inherit = !opts->no_inherit;
> + evsel->overwrite = opts->overwrite;
>
> perf_evsel__set_sample_bit(evsel, IP);
> perf_evsel__set_sample_bit(evsel, TID);
> diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
> index 828ddd1..55ff958 100644
> --- a/tools/perf/util/evsel.h
> +++ b/tools/perf/util/evsel.h
> @@ -45,6 +45,7 @@ enum {
> PERF_EVSEL__CONFIG_TERM_STACK_USER,
> PERF_EVSEL__CONFIG_TERM_INHERIT,
> PERF_EVSEL__CONFIG_TERM_MAX_STACK,
> + PERF_EVSEL__CONFIG_TERM_OVERWRITE,
> PERF_EVSEL__CONFIG_TERM_MAX,
> };
>
> @@ -59,6 +60,7 @@ struct perf_evsel_config_term {
> u64 stack_user;
> int max_stack;
> bool inherit;
> + bool overwrite;
> } val;
> };
>
> diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
> index d15e335..b641f75 100644
> --- a/tools/perf/util/parse-events.c
> +++ b/tools/perf/util/parse-events.c
> @@ -901,6 +901,8 @@ static const char *config_term_names[__PARSE_EVENTS__TERM_TYPE_NR] = {
> [PARSE_EVENTS__TERM_TYPE_NOINHERIT] = "no-inherit",
> [PARSE_EVENTS__TERM_TYPE_INHERIT] = "inherit",
> [PARSE_EVENTS__TERM_TYPE_MAX_STACK] = "max-stack",
> + [PARSE_EVENTS__TERM_TYPE_OVERWRITE] = "overwrite",
> + [PARSE_EVENTS__TERM_TYPE_NOOVERWRITE] = "no-overwrite",
> };
>
> static bool config_term_shrinked;
> @@ -993,6 +995,12 @@ do { \
> case PARSE_EVENTS__TERM_TYPE_NOINHERIT:
> CHECK_TYPE_VAL(NUM);
> break;
> + case PARSE_EVENTS__TERM_TYPE_OVERWRITE:
> + CHECK_TYPE_VAL(NUM);
> + break;
> + case PARSE_EVENTS__TERM_TYPE_NOOVERWRITE:
> + CHECK_TYPE_VAL(NUM);
> + break;
> case PARSE_EVENTS__TERM_TYPE_NAME:
> CHECK_TYPE_VAL(STR);
> break;
> @@ -1045,6 +1053,8 @@ static int config_term_tracepoint(struct perf_event_attr *attr,
> case PARSE_EVENTS__TERM_TYPE_INHERIT:
> case PARSE_EVENTS__TERM_TYPE_NOINHERIT:
> case PARSE_EVENTS__TERM_TYPE_MAX_STACK:
> + case PARSE_EVENTS__TERM_TYPE_OVERWRITE:
> + case PARSE_EVENTS__TERM_TYPE_NOOVERWRITE:
> return config_term_common(attr, term, err);
> default:
> if (err) {
> @@ -1117,6 +1127,12 @@ do { \
> case PARSE_EVENTS__TERM_TYPE_MAX_STACK:
> ADD_CONFIG_TERM(MAX_STACK, max_stack, term->val.num);
> break;
> + case PARSE_EVENTS__TERM_TYPE_OVERWRITE:
> + ADD_CONFIG_TERM(OVERWRITE, overwrite, term->val.num ? 1 : 0);
> + break;
> + case PARSE_EVENTS__TERM_TYPE_NOOVERWRITE:
> + ADD_CONFIG_TERM(OVERWRITE, overwrite, term->val.num ? 0 : 1);
> + break;
> default:
> break;
> }
> @@ -2330,9 +2346,9 @@ static void config_terms_list(char *buf, size_t buf_sz)
> char *parse_events_formats_error_string(char *additional_terms)
> {
> char *str;
> - /* "branch_type" is the longest name */
> + /* "no-overwrite" is the longest name */
> char static_terms[__PARSE_EVENTS__TERM_TYPE_NR *
> - (sizeof("branch_type") - 1)];
> + (sizeof("no-overwrite") - 1)];
>
> config_terms_list(static_terms, sizeof(static_terms));
> /* valid terms */
> diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h
> index 46c05cc..1b04d82 100644
> --- a/tools/perf/util/parse-events.h
> +++ b/tools/perf/util/parse-events.h
> @@ -69,6 +69,8 @@ enum {
> PARSE_EVENTS__TERM_TYPE_NOINHERIT,
> PARSE_EVENTS__TERM_TYPE_INHERIT,
> PARSE_EVENTS__TERM_TYPE_MAX_STACK,
> + PARSE_EVENTS__TERM_TYPE_NOOVERWRITE,
> + PARSE_EVENTS__TERM_TYPE_OVERWRITE,
> __PARSE_EVENTS__TERM_TYPE_NR,
> };
>
> diff --git a/tools/perf/util/parse-events.l b/tools/perf/util/parse-events.l
> index 3c15b33..7a25194 100644
> --- a/tools/perf/util/parse-events.l
> +++ b/tools/perf/util/parse-events.l
> @@ -202,6 +202,8 @@ stack-size { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_STACKSIZE); }
> max-stack { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_MAX_STACK); }
> inherit { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_INHERIT); }
> no-inherit { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_NOINHERIT); }
> +overwrite { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_OVERWRITE); }
> +no-overwrite { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_NOOVERWRITE); }
> , { return ','; }
> "/" { BEGIN(INITIAL); return '/'; }
> {name_minus} { return str(yyscanner, PE_NAME); }
> --
> 1.8.3.4
next prev parent reply other threads:[~2016-06-21 22:00 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-20 10:47 [PATCH v8 0/8] perf tools: Support overwritable ring buffer Wang Nan
2016-06-20 10:47 ` [PATCH v8 1/8] perf tools: Fix write_backwards fallback Wang Nan
2016-06-20 10:47 ` [PATCH v8 2/8] perf evlist: Introduce aux evlist Wang Nan
2016-06-20 20:36 ` Arnaldo Carvalho de Melo
2016-06-21 1:31 ` Wangnan (F)
2016-06-20 10:47 ` [PATCH v8 3/8] perf tests: Add testcase for auxiliary evlist Wang Nan
2016-06-21 21:05 ` Arnaldo Carvalho de Melo
2016-06-22 4:10 ` Wangnan (F)
2016-06-20 10:47 ` [PATCH v8 4/8] perf record: Introduce rec->overwrite_evlist for overwritable events Wang Nan
2016-06-21 21:30 ` Arnaldo Carvalho de Melo
2016-06-20 10:47 ` [PATCH v8 5/8] perf record: Toggle overwrite ring buffer for reading Wang Nan
2016-06-20 10:47 ` [PATCH v8 6/8] perf tools: Enable overwrite settings Wang Nan
2016-06-21 21:49 ` Arnaldo Carvalho de Melo [this message]
2016-06-20 10:47 ` [PATCH v8 7/8] perf tools: Don't warn about out of order event if write_backward is used Wang Nan
2016-06-20 10:47 ` [PATCH v8 8/8] perf tools: Add --tail-synthesize option Wang Nan
-- strict thread matches above, loose matches on Subject: below --
2016-06-15 2:23 [PATCH v7 0/8] perf tools: Support overwritable ring buffer Wang Nan
2016-06-15 2:23 ` [PATCH v7 1/8] perf evlist: Introduce aux evlist Wang Nan
2016-06-15 2:23 ` [PATCH v7 2/8] perf tests: Add testcase for auxiliary evlist Wang Nan
2016-06-15 2:23 ` [PATCH v7 3/8] perf record: Introduce rec->overwrite_evlist for overwritable events Wang Nan
2016-06-15 2:23 ` [PATCH v7 4/8] perf record: Toggle overwrite ring buffer for reading Wang Nan
2016-06-15 2:23 ` [PATCH v7 5/8] perf tools: Enable overwrite settings Wang Nan
2016-06-15 2:23 ` [PATCH v7 6/8] perf tools: Don't warn about out of order event if write_backward is used Wang Nan
2016-06-15 2:23 ` [PATCH v7 7/8] perf tools: Check write_backward during evlist config Wang Nan
2016-06-16 21:47 ` Arnaldo Carvalho de Melo
2016-06-20 4:09 ` Wangnan (F)
2016-06-22 7:43 ` [tip:perf/core] perf evsel: Fix write_backwards fallback tip-bot for Arnaldo Carvalho de Melo
2016-06-15 2:23 ` [PATCH v7 8/8] perf record: Unmap overwrite evlist when event terminate Wang Nan
2016-06-16 20:59 ` Arnaldo Carvalho de Melo
2016-06-20 8:04 ` Wangnan (F)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160621214940.GG4213@kernel.org \
--to=acme@kernel.org \
--cc=acme@redhat.com \
--cc=hekuang@huawei.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lizefan@huawei.com \
--cc=mhiramat@kernel.org \
--cc=namhyung@kernel.org \
--cc=pi3orama@163.com \
--cc=wangnan0@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.