Implement --switch-output-event
Arnaldo Carvalho de Melo
maintainerRFC PATCH v2 1/1 Implement --switch-output-event
Hi guys,
Please consider reviewing, this addresses comments by Jiri in
the V1.
Again, the example provided is too simple, using 'perf probe' to
put probes in specific places in some workload to then get any other event close to the time the trigger hits comes to mind as well, using the signal was just to reuse the pre-existing logic and keep the patchkit small.
One other thing that occurred to me while testing is that this
can be combined with 'perf report/perf script' --switch-off option:
$ perf report -h --switch-off
Usage: perf report [<options>]
--switch-off <event>
Stop considering events after the ocurrence of this event
$
To remove from consideration the events that end up being
recorded in the ring buffer after the --switch-output-event but gets in the ring buffer because we process the --switch-output-event asynchronously.
Its available at:
git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git perf/switch-output-event
Best regards,
- Arnaldo
Arnaldo Carvalho de Melo (8):
perf record: Move sb_evlist to 'struct record'
perf top: Move sb_evlist to 'struct perf_top'
perf bpf: Decouple creating the evlist from adding the SB event perf parse-events: Add parse_events_option() variant that creates evlist perf evlist: Allow reusing the side band thread for more purposes
libsubcmd: Introduce OPT_CALLBACK_SET()
perf record: Introduce --switch-output-event
perf record: Move side band evlist setup to separate routine
tools/lib/subcmd/parse-options.h | 2 + tools/perf/Documentation/perf-record.txt | 13 ++++ tools/perf/builtin-record.c | 75 ++++++++++++++++++++---- tools/perf/builtin-top.c | 20 +++++-- tools/perf/util/bpf-event.c | 3 +- tools/perf/util/bpf-event.h | 7 +-- tools/perf/util/evlist.c | 39 +++++++----- tools/perf/util/evlist.h | 3 +- tools/perf/util/parse-events.c | 23 ++++++++ tools/perf/util/parse-events.h | 1 + tools/perf/util/top.h | 2 +- 11 files changed, 151 insertions(+), 37 deletions(-)
Signature · 1 line
2.21.1
Arnaldo Carvalho de Melo
maintainerPATCH 1/8 perf record: Move sb_evlist to 'struct record'
From: Arnaldo Carvalho de Melo <[email protected]>
Where state related to a 'perf record' session is grouped.
--- tools/perf/builtin-record.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
tools/perf/builtin-record.c +4 -4
@@ -86,6 +86,7 @@ struct record {struct auxtrace_record *itr;struct evlist *evlist;struct perf_session *session; +struct evlist *sb_evlist;int realtime_prio;bool no_buildid;bool no_buildid_set;
@@ -1446,7 +1447,6 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)struct perf_data *data = &rec->data;struct perf_session *session;bool disabled = false, draining = false; -struct evlist *sb_evlist =NULL ;int fd;float ratio =0 ;
@@ -1581,9 +1581,9 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) }if (!opts->no_bpf_event) -bpf_event__add_sb_event (&sb_evlist, &session->header.env); +bpf_event__add_sb_event (&rec->sb_evlist, &session->header.env); -if (perf_evlist__start_sb_thread (sb_evlist, &rec->opts.target)) { +if (perf_evlist__start_sb_thread (rec->sb_evlist, &rec->opts.target)) {pr_debug ("Couldn't start the BPF side band thread:\nBPF programs starting from now on won't be annotatable\n" ); opts->no_bpf_event = true; }
@@ -1857,7 +1857,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)perf_session__delete (session);if (!opts->no_bpf_event) -perf_evlist__stop_sb_thread (sb_evlist); +perf_evlist__stop_sb_thread (rec->sb_evlist);return status; }
Signature · 1 line
2.21.1
[tip: perf/core] perf record: Move sb_evlist to 'struct record'
The following commit has been merged into the perf/core branch of tip:
The following commit has been merged into the perf/core branch of tip:
Commit-ID: bc477d7983e345262757568ec27be0395dc2fe73 Gitweb: https://git.kernel.org/tip/bc477d7983e345262757568ec27be0395dc2fe73 Author: Arnaldo Carvalho de Melo <[email protected]> AuthorDate: Fri, 24 Apr 2020 10:24:04 -03:00 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitterDate: Tue, 05 May 2020 16:35:28 -03:00
perf record: Move sb_evlist to 'struct record'
Where state related to a 'perf record' session is grouped.
--- tools/perf/builtin-record.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
tools/perf/builtin-record.c +4 -4
@@ -87,6 +87,7 @@ struct record {struct auxtrace_record *itr;struct evlist *evlist;struct perf_session *session; +struct evlist *sb_evlist;int realtime_prio;bool no_buildid;bool no_buildid_set;
@@ -1447,7 +1448,6 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)struct perf_data *data = &rec->data;struct perf_session *session;bool disabled = false, draining = false; -struct evlist *sb_evlist =NULL ;int fd;float ratio =0 ;
@@ -1582,9 +1582,9 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) }if (!opts->no_bpf_event) -bpf_event__add_sb_event (&sb_evlist, &session->header.env); +bpf_event__add_sb_event (&rec->sb_evlist, &session->header.env); -if (perf_evlist__start_sb_thread (sb_evlist, &rec->opts.target)) { +if (perf_evlist__start_sb_thread (rec->sb_evlist, &rec->opts.target)) {pr_debug ("Couldn't start the BPF side band thread:\nBPF programs starting from now on won't be annotatable\n" ); opts->no_bpf_event = true; }
@@ -1858,7 +1858,7 @@ out_delete_session:perf_session__delete (session);if (!opts->no_bpf_event) -perf_evlist__stop_sb_thread (sb_evlist); +perf_evlist__stop_sb_thread (rec->sb_evlist);return status; }
Arnaldo Carvalho de Melo
maintainerPATCH 2/8 perf top: Move sb_evlist to 'struct perf_top'
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
Where state related to a 'perf top' session is grouped.
--- tools/perf/builtin-top.c | 7 +++---- tools/perf/util/top.h | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-)
tools/perf/builtin-top.c +3 -4
@@ -1580,7 +1580,6 @@ int cmd_top(int argc, const char **argv)OPTS_EVSWITCH (&top.evswitch),OPT_END () }; -struct evlist *sb_evlist =NULL ;const char *const top_usage[] = {"perf top [<options>]" , NULL
@@ -1744,9 +1743,9 @@ int cmd_top(int argc, const char **argv) }if (!top.record_opts.no_bpf_event) -bpf_event__add_sb_event (&sb_evlist, &perf_env); +bpf_event__add_sb_event (&top.sb_evlist, &perf_env); -if (perf_evlist__start_sb_thread (sb_evlist, target)) { +if (perf_evlist__start_sb_thread (top.sb_evlist, target)) {pr_debug ("Couldn't start the BPF side band thread:\nBPF programs starting from now on won't be annotatable\n" ); opts->no_bpf_event = true; }
@@ -1754,7 +1753,7 @@ int cmd_top(int argc, const char **argv) status =__cmd_top (&top);if (!opts->no_bpf_event) -perf_evlist__stop_sb_thread (sb_evlist); +perf_evlist__stop_sb_thread (top.sb_evlist); out_delete_evlist:evlist__delete (top.evlist);
tools/perf/util/top.h +1 -1
@@ -18,7 +18,7 @@ struct perf_session;struct perf_top {struct perf_tool tool; -struct evlist *evlist; +struct evlist *evlist, *sb_evlist;struct record_opts record_opts;struct annotation_options annotation_opts;struct evswitch evswitch;
Signature · 1 line
2.21.1
[tip: perf/core] perf top: Move sb_evlist to 'struct perf_top'
The following commit has been merged into the perf/core branch of tip:
The following commit has been merged into the perf/core branch of tip:
Commit-ID: ca6c9c8b107f9788662117587cd24bbb19cea94d Gitweb: https://git.kernel.org/tip/ca6c9c8b107f9788662117587cd24bbb19cea94d Author: Arnaldo Carvalho de Melo <[email protected]> AuthorDate: Fri, 24 Apr 2020 10:40:54 -03:00 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitterDate: Tue, 05 May 2020 16:35:29 -03:00
perf top: Move sb_evlist to 'struct perf_top'
Where state related to a 'perf top' session is grouped.
--- tools/perf/builtin-top.c | 7 +++---- tools/perf/util/top.h | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-)
tools/perf/builtin-top.c +3 -4
@@ -1580,7 +1580,6 @@ int cmd_top(int argc, const char **argv)OPTS_EVSWITCH (&top.evswitch),OPT_END () }; -struct evlist *sb_evlist =NULL ;const char *const top_usage[] = {"perf top [<options>]" , NULL
@@ -1744,9 +1743,9 @@ int cmd_top(int argc, const char **argv) }if (!top.record_opts.no_bpf_event) -bpf_event__add_sb_event (&sb_evlist, &perf_env); +bpf_event__add_sb_event (&top.sb_evlist, &perf_env); -if (perf_evlist__start_sb_thread (sb_evlist, target)) { +if (perf_evlist__start_sb_thread (top.sb_evlist, target)) {pr_debug ("Couldn't start the BPF side band thread:\nBPF programs starting from now on won't be annotatable\n" ); opts->no_bpf_event = true; }
@@ -1754,7 +1753,7 @@ int cmd_top(int argc, const char **argv) status =__cmd_top (&top);if (!opts->no_bpf_event) -perf_evlist__stop_sb_thread (sb_evlist); +perf_evlist__stop_sb_thread (top.sb_evlist); out_delete_evlist:evlist__delete (top.evlist);
tools/perf/util/top.h +1 -1
@@ -18,7 +18,7 @@ struct perf_session;struct perf_top {struct perf_tool tool; -struct evlist *evlist; +struct evlist *evlist, *sb_evlist;struct record_opts record_opts;struct annotation_options annotation_opts;struct evswitch evswitch;
Arnaldo Carvalho de Melo
maintainerPATCH 3/8 perf bpf: Decouple creating the evlist from adding the SB event
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
Renaming bpf_event__add_sb_event() to evlist__add_sb_event() and requiring that the evlist be allocated beforehand.
This will allow using the same side band thread and evlist to be used for multiple purposes in addition to react to PERF_RECORD_BPF_EVENT soon after they are generated.
--- tools/perf/builtin-record.c | 17 ++++++++++++++--- tools/perf/builtin-top.c | 15 +++++++++++++-- tools/perf/util/bpf-event.c | 3 +-- tools/perf/util/bpf-event.h | 7 +++---- tools/perf/util/evlist.c | 17 +++-------------- tools/perf/util/evlist.h | 2 +- 6 files changed, 35 insertions(+), 26 deletions(-)
tools/perf/builtin-record.c +14 -3
@@ -1572,16 +1572,27 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) goto out_child; } + err =-1 ;if (!rec->no_buildid && !perf_header__has_feat (&session->header,HEADER_BUILD_ID )) {pr_err ("Couldn't generate buildids. " "Use --no-buildid to profile anyway.\n" ); - err =-1 ; goto out_child; } -if (!opts->no_bpf_event) -bpf_event__add_sb_event (&rec->sb_evlist, &session->header.env); +if (!opts->no_bpf_event) { + rec->sb_evlist =evlist__new (); + +if (rec->sb_evlist ==NULL ) { +pr_err ("Couldn't create side band evlist.\n." ); + goto out_child; + } + +if (evlist__add_bpf_sb_event (rec->sb_evlist, &session->header.env)) { +pr_err ("Couldn't ask for PERF_RECORD_BPF_EVENT side band events.\n." ); + goto out_child; + } + }if (perf_evlist__start_sb_thread (rec->sb_evlist, &rec->opts.target)) {pr_debug ("Couldn't start the BPF side band thread:\nBPF programs starting from now on won't be annotatable\n" );
tools/perf/builtin-top.c +13 -2
@@ -1742,8 +1742,19 @@ int cmd_top(int argc, const char **argv) goto out_delete_evlist; } -if (!top.record_opts.no_bpf_event) -bpf_event__add_sb_event (&top.sb_evlist, &perf_env); +if (!top.record_opts.no_bpf_event) { + top.sb_evlist =evlist__new (); + +if (top.sb_evlist ==NULL ) { +pr_err ("Couldn't create side band evlist.\n." ); + goto out_delete_evlist; + } + +if (evlist__add_bpf_sb_event (top.sb_evlist, &perf_env)) { +pr_err ("Couldn't ask for PERF_RECORD_BPF_EVENT side band events.\n." ); + goto out_delete_evlist; + } + }if (perf_evlist__start_sb_thread (top.sb_evlist, target)) {pr_debug ("Couldn't start the BPF side band thread:\nBPF programs starting from now on won't be annotatable\n" );
tools/perf/util/bpf-event.c +1 -2
@@ -509,8 +509,7 @@ static int bpf_event__sb_cb(union perf_event *event, void *data)return 0 ; } -int bpf_event__add_sb_event (struct evlist **evlist, -struct perf_env *env) +int evlist__add_bpf_sb_event (struct evlist *evlist,struct perf_env *env) {struct perf_event_attr attr = { .type =PERF_TYPE_SOFTWARE ,
tools/perf/util/bpf-event.h +3 -4
@@ -33,8 +33,7 @@ struct btf_node {#ifdef HAVE_LIBBPF_SUPPORT int machine__process_bpf (struct machine *machine,union perf_event *event,struct perf_sample *sample); -int bpf_event__add_sb_event (struct evlist **evlist, -struct perf_env *env); +int evlist__add_bpf_sb_event (struct evlist *evlist,struct perf_env *env);void bpf_event__print_bpf_prog_info (struct bpf_prog_info *info,struct perf_env *env,FILE *fp);
@@ -46,8 +45,8 @@ static inline int machine__process_bpf(struct machine *machine __maybe_unused,return 0 ; } -static inline int bpf_event__add_sb_event (struct evlist **evlist__maybe_unused , -struct perf_env *env__maybe_unused ) +static inline int evlist__add_bpf_sb_event (struct evlist *evlist__maybe_unused , +struct perf_env *env__maybe_unused ) {return 0 ; }
tools/perf/util/evlist.c +3 -14
@@ -1704,38 +1704,27 @@ struct evsel *perf_evlist__reset_weak_group(struct evlist *evsel_list,return leader; } -int perf_evlist__add_sb_event (struct evlist **evlist, +int perf_evlist__add_sb_event (struct evlist *evlist,struct perf_event_attr *attr,perf_evsel__sb_cb_t cb,void *data) {struct evsel *evsel; -bool new_evlist = (*evlist) ==NULL ; - -if (*evlist ==NULL ) - *evlist =evlist__new (); -if (*evlist ==NULL ) -return -1 ;if (!attr->sample_id_all) {pr_warning ("enabling sample_id_all for all side band events\n" ); attr->sample_id_all =1 ; } - evsel =perf_evsel__new_idx (attr, (*evlist)->core.nr_entries); + evsel =perf_evsel__new_idx (attr, evlist->core.nr_entries);if (!evsel) goto out_err; evsel->side_band.cb = cb; evsel->side_band.data = data; -evlist__add (*evlist, evsel); +evlist__add (evlist, evsel);return 0 ; - out_err: -if (new_evlist) { -evlist__delete (*evlist); - *evlist =NULL ; - }return -1 ; }
tools/perf/util/evlist.h +1 -1
@@ -107,7 +107,7 @@ int __perf_evlist__add_default_attrs(struct evlist *evlist,int perf_evlist__add_dummy (struct evlist *evlist); -int perf_evlist__add_sb_event (struct evlist **evlist, +int perf_evlist__add_sb_event (struct evlist *evlist,struct perf_event_attr *attr,perf_evsel__sb_cb_t cb,void *data);
Signature · 1 line
2.21.1
Re: [PATCH 3/8] perf bpf: Decouple creating the evlist from adding the SB event
On Wed, Apr 29, 2020 at 10:11:01AM -0300, Arnaldo Carvalho de Melo wrote:
SNIP
Quoted 13 lines
tools/perf/util/evlist.c +1
-7-int perf_evlist__add_sb_event (struct evlist **evlist, +int perf_evlist__add_sb_event (struct evlist *evlist,struct perf_event_attr *attr,perf_evsel__sb_cb_t cb,void *data) {struct evsel *evsel; -bool new_evlist = (*evlist) ==NULL ; - -if (*evlist ==NULL ) - *evlist =evlist__new (); -if (*evlist ==NULL ) -return -1 ;
tools/perf/util/evlist.c struct evsel *perf_evlist__reset_weak_group(struct evlist *evsel_list, · line 1721
Quoted 10 lines
tools/perf/util/evlist.c +1
-1if (!attr->sample_id_all) {pr_warning ("enabling sample_id_all for all side band events\n" ); attr->sample_id_all =1 ; } - evsel =perf_evsel__new_idx (attr, (*evlist)->core.nr_entries); + evsel =perf_evsel__new_idx (attr, evlist->core.nr_entries);if (!evsel) goto out_err;
we can return -1 right here
jirka
Quoted 31 lines
tools/perf/util/evlist.c +1
-6evsel->side_band.cb = cb; evsel->side_band.data = data; -evlist__add (*evlist, evsel); +evlist__add (evlist, evsel);return 0 ; - out_err: -if (new_evlist) { -evlist__delete (*evlist); - *evlist =NULL ; - }return -1 ; }tools/perf/util/evlist.h +1
-1@@ -107,7 +107,7 @@ int __perf_evlist__add_default_attrs(struct evlist *evlist,int perf_evlist__add_dummy (struct evlist *evlist); -int perf_evlist__add_sb_event (struct evlist **evlist, +int perf_evlist__add_sb_event (struct evlist *evlist,struct perf_event_attr *attr,perf_evsel__sb_cb_t cb,void *data);Signature · 1 line
2.21.1
Re: [PATCH 3/8] perf bpf: Decouple creating the evlist from adding the SB event
Em Thu, Apr 30, 2020 at 11:04:23AM +0200, Jiri Olsa escreveu:
Quoted 23 lines · Arnaldo Carvalho de Melo
SNIP
Quoted 19 lines
tools/perf/util/evlist.c +1
-7-int perf_evlist__add_sb_event (struct evlist **evlist, +int perf_evlist__add_sb_event (struct evlist *evlist,struct perf_event_attr *attr,perf_evsel__sb_cb_t cb,void *data) {struct evsel *evsel; -bool new_evlist = (*evlist) ==NULL ; - -if (*evlist ==NULL ) - *evlist =evlist__new (); -if (*evlist ==NULL ) -return -1 ;if (!attr->sample_id_all) {pr_warning ("enabling sample_id_all for all side band events\n" ); attr->sample_id_all =1 ; }
Quoted 6 lines
tools/perf/util/evlist.c struct evsel *perf_evlist__reset_weak_group(struct evlist *evsel_list, · line 1721
Quoted 4 lines
tools/perf/util/evlist.c +1
-1- evsel =perf_evsel__new_idx (attr, (*evlist)->core.nr_entries); + evsel =perf_evsel__new_idx (attr, evlist->core.nr_entries);if (!evsel) goto out_err;we can return -1 right here
Yeah, I was just trying to keep the patch minimal, I'll remove the out_err label and the goto to it and call return directly,
Thanks,
- Arnaldo
Quoted 34 lines
jirka
Quoted 31 lines
tools/perf/util/evlist.c +1
-6evsel->side_band.cb = cb; evsel->side_band.data = data; -evlist__add (*evlist, evsel); +evlist__add (evlist, evsel);return 0 ; - out_err: -if (new_evlist) { -evlist__delete (*evlist); - *evlist =NULL ; - }return -1 ; }tools/perf/util/evlist.h +1
-1@@ -107,7 +107,7 @@ int __perf_evlist__add_default_attrs(struct evlist *evlist,int perf_evlist__add_dummy (struct evlist *evlist); -int perf_evlist__add_sb_event (struct evlist **evlist, +int perf_evlist__add_sb_event (struct evlist *evlist,struct perf_event_attr *attr,perf_evsel__sb_cb_t cb,void *data);Signature · 1 line
2.21.1
Signature · 1 line
- Arnaldo
[tip: perf/core] perf bpf: Decouple creating the evlist from adding the SB event
In reply to Arnaldo Carvalho de MeloThe following commit has been merged into the perf/core branch of tip:
The following commit has been merged into the perf/core branch of tip:
Commit-ID: b38d85ef49cf6af9d1deaaf01daf0986d47e6c7a Gitweb: https://git.kernel.org/tip/b38d85ef49cf6af9d1deaaf01daf0986d47e6c7a Author: Arnaldo Carvalho de Melo <[email protected]> AuthorDate: Fri, 24 Apr 2020 12:24:51 -03:00 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitterDate: Tue, 05 May 2020 16:35:29 -03:00
perf bpf: Decouple creating the evlist from adding the SB event
Renaming bpf_event__add_sb_event() to evlist__add_sb_event() and requiring that the evlist be allocated beforehand.
This will allow using the same side band thread and evlist to be used for multiple purposes in addition to react to PERF_RECORD_BPF_EVENT soon after they are generated.
--- tools/perf/builtin-record.c | 17 ++++++++++++++--- tools/perf/builtin-top.c | 15 +++++++++++++-- tools/perf/util/bpf-event.c | 3 +-- tools/perf/util/bpf-event.h | 7 +++---- tools/perf/util/evlist.c | 21 ++++----------------- tools/perf/util/evlist.h | 2 +- 6 files changed, 36 insertions(+), 29 deletions(-)
tools/perf/builtin-record.c +14 -3
@@ -1573,16 +1573,27 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) goto out_child; } + err =-1 ;if (!rec->no_buildid && !perf_header__has_feat (&session->header,HEADER_BUILD_ID )) {pr_err ("Couldn't generate buildids. " "Use --no-buildid to profile anyway.\n" ); - err =-1 ; goto out_child; } -if (!opts->no_bpf_event) -bpf_event__add_sb_event (&rec->sb_evlist, &session->header.env); +if (!opts->no_bpf_event) { + rec->sb_evlist =evlist__new (); + +if (rec->sb_evlist ==NULL ) { +pr_err ("Couldn't create side band evlist.\n." ); + goto out_child; + } + +if (evlist__add_bpf_sb_event (rec->sb_evlist, &session->header.env)) { +pr_err ("Couldn't ask for PERF_RECORD_BPF_EVENT side band events.\n." ); + goto out_child; + } + }if (perf_evlist__start_sb_thread (rec->sb_evlist, &rec->opts.target)) {pr_debug ("Couldn't start the BPF side band thread:\nBPF programs starting from now on won't be annotatable\n" );
tools/perf/builtin-top.c +13 -2
@@ -1742,8 +1742,19 @@ int cmd_top(int argc, const char **argv) goto out_delete_evlist; } -if (!top.record_opts.no_bpf_event) -bpf_event__add_sb_event (&top.sb_evlist, &perf_env); +if (!top.record_opts.no_bpf_event) { + top.sb_evlist =evlist__new (); + +if (top.sb_evlist ==NULL ) { +pr_err ("Couldn't create side band evlist.\n." ); + goto out_delete_evlist; + } + +if (evlist__add_bpf_sb_event (top.sb_evlist, &perf_env)) { +pr_err ("Couldn't ask for PERF_RECORD_BPF_EVENT side band events.\n." ); + goto out_delete_evlist; + } + }if (perf_evlist__start_sb_thread (top.sb_evlist, target)) {pr_debug ("Couldn't start the BPF side band thread:\nBPF programs starting from now on won't be annotatable\n" );
tools/perf/util/bpf-event.c +1 -2
@@ -509,8 +509,7 @@ static int bpf_event__sb_cb(union perf_event *event, void *data)return 0 ; } -int bpf_event__add_sb_event (struct evlist **evlist, -struct perf_env *env) +int evlist__add_bpf_sb_event (struct evlist *evlist,struct perf_env *env) {struct perf_event_attr attr = { .type =PERF_TYPE_SOFTWARE ,
tools/perf/util/bpf-event.h +3 -4
@@ -33,8 +33,7 @@ struct btf_node {#ifdef HAVE_LIBBPF_SUPPORT int machine__process_bpf (struct machine *machine,union perf_event *event,struct perf_sample *sample); -int bpf_event__add_sb_event (struct evlist **evlist, -struct perf_env *env); +int evlist__add_bpf_sb_event (struct evlist *evlist,struct perf_env *env);void bpf_event__print_bpf_prog_info (struct bpf_prog_info *info,struct perf_env *env,FILE *fp);
@@ -46,8 +45,8 @@ static inline int machine__process_bpf(struct machine *machine __maybe_unused,return 0 ; } -static inline int bpf_event__add_sb_event (struct evlist **evlist__maybe_unused , -struct perf_env *env__maybe_unused ) +static inline int evlist__add_bpf_sb_event (struct evlist *evlist__maybe_unused , +struct perf_env *env__maybe_unused ) {return 0 ; }
tools/perf/util/evlist.c +4 -17
@@ -1705,39 +1705,26 @@ struct evsel *perf_evlist__reset_weak_group(struct evlist *evsel_list,return leader; } -int perf_evlist__add_sb_event (struct evlist **evlist, +int perf_evlist__add_sb_event (struct evlist *evlist,struct perf_event_attr *attr,perf_evsel__sb_cb_t cb,void *data) {struct evsel *evsel; -bool new_evlist = (*evlist) ==NULL ; - -if (*evlist ==NULL ) - *evlist =evlist__new (); -if (*evlist ==NULL ) -return -1 ;if (!attr->sample_id_all) {pr_warning ("enabling sample_id_all for all side band events\n" ); attr->sample_id_all =1 ; } - evsel =perf_evsel__new_idx (attr, (*evlist)->core.nr_entries); + evsel =perf_evsel__new_idx (attr, evlist->core.nr_entries);if (!evsel) - goto out_err; +return -1 ; evsel->side_band.cb = cb; evsel->side_band.data = data; -evlist__add (*evlist, evsel); +evlist__add (evlist, evsel);return 0 ; - -out_err: -if (new_evlist) { -evlist__delete (*evlist); - *evlist =NULL ; - } -return -1 ; }static void *perf_evlist__poll_thread (void *arg)
tools/perf/util/evlist.h +1 -1
@@ -107,7 +107,7 @@ int __perf_evlist__add_default_attrs(struct evlist *evlist,int perf_evlist__add_dummy (struct evlist *evlist); -int perf_evlist__add_sb_event (struct evlist **evlist, +int perf_evlist__add_sb_event (struct evlist *evlist,struct perf_event_attr *attr,perf_evsel__sb_cb_t cb,void *data);
Arnaldo Carvalho de Melo
maintainerPATCH 4/8 perf parse-events: Add parse_events_option() variant that creates evlist
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
For the upcoming --switch-output-event option we want to create the side band event, populate it with the specified events and then, if it is present multiple times, go on adding to it, then, if the BPF tracking is required, use the first event to set its attr.bpf_event to get those PERF_RECORD_BPF_EVENT metadata events too.
--- tools/perf/util/parse-events.c | 23 +++++++++++++++++++++++ tools/perf/util/parse-events.h | 1 + 2 files changed, 24 insertions(+)
tools/perf/util/parse-events.c +23 -0
@@ -2190,6 +2190,29 @@ int parse_events_option(const struct option *opt, const char *str,return ret; } +int parse_events_option_new_evlist (const struct option *opt,const char *str,int unset) +{ +struct evlist **evlistp = opt->value; +int ret; + +if (*evlistp ==NULL ) { + *evlistp =evlist__new (); + +if (*evlistp ==NULL ) { +fprintf (stderr,"Not enough memory to create evlist\n" ); +return -1 ; + } + } + + ret =parse_events_option (opt, str, unset); +if (ret) { +evlist__delete (*evlistp); + *evlistp =NULL ; + } + +return ret; +} + static int foreach_evsel_in_last_glob(struct evlist *evlist, int (*func)(struct evsel *evsel,
tools/perf/util/parse-events.h +1 -0
@@ -31,6 +31,7 @@ bool have_tracepoints(struct list_head *evlist);const char *event_type (int type);int parse_events_option (const struct option *opt,const char *str,int unset); +int parse_events_option_new_evlist (const struct option *opt,const char *str,int unset);int parse_events (struct evlist *evlist,const char *str,struct parse_events_error *error);int parse_events_terms (struct list_head *terms,const char *str);
Signature · 1 line
2.21.1
[tip: perf/core] perf parse-events: Add parse_events_option() variant that creates evlist
The following commit has been merged into the perf/core branch of tip:
The following commit has been merged into the perf/core branch of tip:
Commit-ID: d0abbc3ce695437fe83446aef44b2f5ef65a80b9 Gitweb: https://git.kernel.org/tip/d0abbc3ce695437fe83446aef44b2f5ef65a80b9 Author: Arnaldo Carvalho de Melo <[email protected]> AuthorDate: Mon, 27 Apr 2020 13:58:11 -03:00 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitterDate: Tue, 05 May 2020 16:35:29 -03:00
perf parse-events: Add parse_events_option() variant that creates evlist
For the upcoming --switch-output-event option we want to create the side band event, populate it with the specified events and then, if it is present multiple times, go on adding to it, then, if the BPF tracking is required, use the first event to set its attr.bpf_event to get those PERF_RECORD_BPF_EVENT metadata events too.
--- tools/perf/util/parse-events.c | 23 +++++++++++++++++++++++ tools/perf/util/parse-events.h | 1 + 2 files changed, 24 insertions(+)
tools/perf/util/parse-events.c +23 -0
@@ -2190,6 +2190,29 @@ int parse_events_option(const struct option *opt, const char *str,return ret; } +int parse_events_option_new_evlist (const struct option *opt,const char *str,int unset) +{ +struct evlist **evlistp = opt->value; +int ret; + +if (*evlistp ==NULL ) { + *evlistp =evlist__new (); + +if (*evlistp ==NULL ) { +fprintf (stderr,"Not enough memory to create evlist\n" ); +return -1 ; + } + } + + ret =parse_events_option (opt, str, unset); +if (ret) { +evlist__delete (*evlistp); + *evlistp =NULL ; + } + +return ret; +} + static int foreach_evsel_in_last_glob(struct evlist *evlist, int (*func)(struct evsel *evsel,
tools/perf/util/parse-events.h +1 -0
@@ -31,6 +31,7 @@ bool have_tracepoints(struct list_head *evlist);const char *event_type (int type);int parse_events_option (const struct option *opt,const char *str,int unset); +int parse_events_option_new_evlist (const struct option *opt,const char *str,int unset);int parse_events (struct evlist *evlist,const char *str,struct parse_events_error *error);int parse_events_terms (struct list_head *terms,const char *str);
Arnaldo Carvalho de Melo
maintainerPATCH 5/8 perf evlist: Allow reusing the side band thread for more purposes
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
I.e. so far we had just one event in that side band thread, a dummy one with attr.bpf_event set, so that 'perf record' can go ahead and ask the kernel for further information about BPF programs being loaded.
Allow for more than one event to be there, so that we can use it as well for the upcoming --switch-output-event feature.
--- tools/perf/util/evlist.c | 22 ++++++++++++++++++++++ tools/perf/util/evlist.h | 1 + 2 files changed, 23 insertions(+)
tools/perf/util/evlist.c +22 -0
@@ -1777,6 +1777,19 @@ static void *perf_evlist__poll_thread(void *arg)return NULL ; } +void evlist__set_cb (struct evlist *evlist,perf_evsel__sb_cb_t cb,void *data) +{ +struct evsel *evsel; + +evlist__for_each_entry (evlist, evsel) { + evsel->core.attr.sample_id_all =1 ; + evsel->core.attr.watermark =1 ; + evsel->core.attr.wakeup_watermark =1 ; + evsel->side_band.cb = cb; + evsel->side_band.data = data; + } +} +int perf_evlist__start_sb_thread (struct evlist *evlist,struct target *target) {
@@ -1788,6 +1801,15 @@ int perf_evlist__start_sb_thread(struct evlist *evlist,if (perf_evlist__create_maps (evlist, target)) goto out_delete_evlist; +if (evlist->core.nr_entries >1 ) { +bool can_sample_identifier =perf_can_sample_identifier (); + +evlist__for_each_entry (evlist, counter) +perf_evsel__set_sample_id (counter, can_sample_identifier); + +perf_evlist__set_id_pos (evlist); + } +evlist__for_each_entry (evlist, counter) {if (evsel__open (counter, evlist->core.cpus, evlist->core.threads) <0 )
tools/perf/util/evlist.h +1 -0
@@ -111,6 +111,7 @@ int perf_evlist__add_sb_event(struct evlist *evlist,struct perf_event_attr *attr, perf_evsel__sb_cb_t cb, void *data); +void evlist__set_cb (struct evlist *evlist,perf_evsel__sb_cb_t cb,void *data);int perf_evlist__start_sb_thread (struct evlist *evlist,struct target *target);void perf_evlist__stop_sb_thread (struct evlist *evlist);
Signature · 1 line
2.21.1
Re: [PATCH 5/8] perf evlist: Allow reusing the side band thread for more purposes
Quoted 45 lines · Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo <[email protected]>
I.e. so far we had just one event in that side band thread, a dummy one with attr.bpf_event set, so that 'perf record' can go ahead and ask the kernel for further information about BPF programs being loaded.
Allow for more than one event to be there, so that we can use it as well for the upcoming --switch-output-event feature.
Cc Adrian Hunter <[email protected]>Cc Jiri Olsa <[email protected]>Cc Namhyung Kim <[email protected]>Cc Song Liu <[email protected]>Signed-off-by Arnaldo Carvalho de Melo <[email protected]>--- tools/perf/util/evlist.c | 22 ++++++++++++++++++++++ tools/perf/util/evlist.h | 1 + 2 files changed, 23 insertions(+)tools/perf/util/evlist.c +13
-0@@ -1777,6 +1777,19 @@ static void *perf_evlist__poll_thread(void *arg)return NULL ; } +void evlist__set_cb (struct evlist *evlist,perf_evsel__sb_cb_t cb,void *data) +{ +struct evsel *evsel; + +evlist__for_each_entry (evlist, evsel) { + evsel->core.attr.sample_id_all =1 ; + evsel->core.attr.watermark =1 ; + evsel->core.attr.wakeup_watermark =1 ; + evsel->side_band.cb = cb; + evsel->side_band.data = data; + } +} +int perf_evlist__start_sb_thread (struct evlist *evlist,struct target *target) {
tools/perf/util/evlist.c int perf_evlist__start_sb_thread(struct evlist *evlist, · line 1805
Quoted 5 lines
tools/perf/util/evlist.c +2
-0@@ -1788,6 +1801,15 @@ int perf_evlist__start_sb_thread(struct evlist *evlist,if (perf_evlist__create_maps (evlist, target)) goto out_delete_evlist; +if (evlist->core.nr_entries >1 ) { +bool can_sample_identifier =perf_can_sample_identifier ();
I just found this breaks python, because perf_can_sample_identifier is defined in util/record.c
19: 'import perf' in python :
--- start ---
test child forked, pid 1808205
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: python/perf.so: undefined symbol: perf_can_sample_identifier test child finished with -1
---- end ----
'import perf' in python: FAILED!
jirka
Re: [PATCH 5/8] perf evlist: Allow reusing the side band thread for more purposes
Quoted 53 lines · Jiri Olsa
Quoted 3 lines · Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo <[email protected]>
I.e. so far we had just one event in that side band thread, a dummy
one
Quoted 1 line
with attr.bpf_event set, so that 'perf record' can go ahead and ask
the
Quoted 10 lines
kernel for further information about BPF programs being loaded.
Allow for more than one event to be there, so that we can use it as well for the upcoming --switch-output-event feature.
Cc: Adrian Hunter <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Song Liu <[email protected]>
Link:http://lore.kernel.org/lkml/[email protected]
tools/perf/util/evlist.c static void *perf_evlist__poll_thread(void
Quoted 11 lines
Signed-off-by Arnaldo Carvalho de Melo <[email protected]>--- tools/perf/util/evlist.c | 22 ++++++++++++++++++++++ tools/perf/util/evlist.h | 1 + 2 files changed, 23 insertions(+)tools/perf/util/evlist.c +0
-0@@ -1777,6 +1777,19 @@ static void *perf_evlist__poll_thread(void*arg)
tools/perf/util/evlist.c static void *perf_evlist__poll_thread(void *arg)
Quoted 4 lines
tools/perf/util/evlist.c +1
-0return NULL ; } +void evlist__set_cb(struct evlist *evlist, perf_evsel__sb_cb_t cb,void *data)
tools/perf/util/evlist.c int perf_evlist__start_sb_thread(struct evlist
Quoted 16 lines
tools/perf/util/evlist.c +12
-0+{ +struct evsel *evsel; + +evlist__for_each_entry (evlist, evsel) { + evsel->core.attr.sample_id_all =1 ; + evsel->core.attr.watermark =1 ; + evsel->core.attr.wakeup_watermark =1 ; + evsel->side_band.cb = cb; + evsel->side_band.data = data; + } +} +int perf_evlist__start_sb_thread (struct evlist *evlist,struct target *target) {@@ -1788,6 +1801,15 @@ int perf_evlist__start_sb_thread(struct evlist*evlist,
Quoted 8 lines
tools/perf/util/evlist.c int perf_evlist__start_sb_thread(struct evlist *evlist, · line 1805
Quoted 5 lines
tools/perf/util/evlist.c +2
-0if (perf_evlist__create_maps (evlist, target)) goto out_delete_evlist; +if (evlist->core.nr_entries >1 ) { +bool can_sample_identifier =perf_can_sample_identifier ();I just found this breaks python, because
perf_can_sample_identifieris defined inutil/record.c
Yeah, I noticed it too, will fix
Quoted 13 lines
19: 'import perf' in python : --- start --- test child forked, pid 1808205 Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: python/perf.so: undefined symbol:
perf_can_sample_identifier
test child finished with -1
---- end ----
'import perf' in python: FAILED!jirka
Signature · 1 line
Sent from my Android device with K-9 Mail. Please excuse my brevity.
[tip: perf/core] perf evlist: Allow reusing the side band thread for more purposes
In reply to Arnaldo Carvalho de MeloThe following commit has been merged into the perf/core branch of tip:
The following commit has been merged into the perf/core branch of tip:
Commit-ID: 976be84504b8285d43dc890b02ceff432cd0dd4b Gitweb: https://git.kernel.org/tip/976be84504b8285d43dc890b02ceff432cd0dd4b Author: Arnaldo Carvalho de Melo <[email protected]> AuthorDate: Mon, 27 Apr 2020 17:54:27 -03:00 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitterDate: Tue, 05 May 2020 16:35:29 -03:00
perf evlist: Allow reusing the side band thread for more purposes
I.e. so far we had just one event in that side band thread, a dummy one with attr.bpf_event set, so that 'perf record' can go ahead and ask the kernel for further information about BPF programs being loaded.
Allow for more than one event to be there, so that we can use it as well for the upcoming --switch-output-event feature.
--- tools/perf/util/evlist.h | 1 + tools/perf/util/sideband_evlist.c | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+)
tools/perf/util/evlist.h +1 -0
@@ -111,6 +111,7 @@ int perf_evlist__add_sb_event(struct evlist *evlist,struct perf_event_attr *attr, perf_evsel__sb_cb_t cb, void *data); +void evlist__set_cb (struct evlist *evlist,perf_evsel__sb_cb_t cb,void *data);int perf_evlist__start_sb_thread (struct evlist *evlist,struct target *target);void perf_evlist__stop_sb_thread (struct evlist *evlist);
tools/perf/util/sideband_evlist.c +23 -0
@@ -4,6 +4,7 @@#include "util/evlist.h" #include "util/evsel.h" #include "util/mmap.h" +#include "util/perf_api_probe.h" #include <perf/mmap.h> #include <linux/perf_event.h> #include <limits.h>
@@ -80,6 +81,19 @@ static void *perf_evlist__poll_thread(void *arg)return NULL ; } +void evlist__set_cb (struct evlist *evlist,perf_evsel__sb_cb_t cb,void *data) +{ +struct evsel *evsel; + +evlist__for_each_entry (evlist, evsel) { + evsel->core.attr.sample_id_all =1 ; + evsel->core.attr.watermark =1 ; + evsel->core.attr.wakeup_watermark =1 ; + evsel->side_band.cb = cb; + evsel->side_band.data = data; + } +} +int perf_evlist__start_sb_thread (struct evlist *evlist,struct target *target) {struct evsel *counter;
@@ -90,6 +104,15 @@ int perf_evlist__start_sb_thread(struct evlist *evlist, struct target *target)if (perf_evlist__create_maps (evlist, target)) goto out_delete_evlist; +if (evlist->core.nr_entries >1 ) { +bool can_sample_identifier =perf_can_sample_identifier (); + +evlist__for_each_entry (evlist, counter) +perf_evsel__set_sample_id (counter, can_sample_identifier); + +perf_evlist__set_id_pos (evlist); + } +evlist__for_each_entry (evlist, counter) {if (evsel__open (counter, evlist->core.cpus, evlist->core.threads) <0 ) goto out_delete_evlist;
Arnaldo Carvalho de Melo
maintainerPATCH 6/8 libsubcmd: Introduce OPT_CALLBACK_SET()
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
To register that an option was set, like with the upcoming 'perf record --switch-output-option' one.
--- tools/lib/subcmd/parse-options.h | 2 ++ 1 file changed, 2 insertions(+)
tools/lib/subcmd/parse-options.h +2 -0
@@ -151,6 +151,8 @@ struct option { { .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), .value = (v), .argh = "time", .help = (h), .callback = parse_opt_approxidate_cb }#define OPT_CALLBACK (s, l, v, a, h, f) \ { .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), .value = (v), .argh = (a), .help = (h), .callback = (f) } +#define OPT_CALLBACK_SET (s, l, v, os, a, h, f) \ + { .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), .value = (v), .argh = (a), .help = (h), .callback = (f), .set = check_vtype(os, bool *)}#define OPT_CALLBACK_NOOPT (s, l, v, a, h, f) \ { .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), .value = (v), .argh = (a), .help = (h), .callback = (f), .flags = PARSE_OPT_NOARG }#define OPT_CALLBACK_DEFAULT (s, l, v, a, h, f, d) \
Signature · 1 line
2.21.1
[tip: perf/core] libsubcmd: Introduce OPT_CALLBACK_SET()
The following commit has been merged into the perf/core branch of tip:
The following commit has been merged into the perf/core branch of tip:
Commit-ID: 636eb4d001b18922b149f59a9f924a5907d20d39 Gitweb: https://git.kernel.org/tip/636eb4d001b18922b149f59a9f924a5907d20d39 Author: Arnaldo Carvalho de Melo <[email protected]> AuthorDate: Tue, 28 Apr 2020 09:16:25 -03:00 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitterDate: Tue, 05 May 2020 16:35:29 -03:00
libsubcmd: Introduce OPT_CALLBACK_SET()
To register that an option was set, like with the upcoming 'perf record --switch-output-option' one.
--- tools/lib/subcmd/parse-options.h | 2 ++ 1 file changed, 2 insertions(+)
tools/lib/subcmd/parse-options.h +2 -0
@@ -151,6 +151,8 @@ struct option { { .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), .value = (v), .argh = "time", .help = (h), .callback = parse_opt_approxidate_cb }#define OPT_CALLBACK (s, l, v, a, h, f) \ { .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), .value = (v), .argh = (a), .help = (h), .callback = (f) } +#define OPT_CALLBACK_SET (s, l, v, os, a, h, f) \ + { .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), .value = (v), .argh = (a), .help = (h), .callback = (f), .set = check_vtype(os, bool *)}#define OPT_CALLBACK_NOOPT (s, l, v, a, h, f) \ { .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), .value = (v), .argh = (a), .help = (h), .callback = (f), .flags = PARSE_OPT_NOARG }#define OPT_CALLBACK_DEFAULT (s, l, v, a, h, f, d) \
Arnaldo Carvalho de Melo
maintainerPATCH 7/8 perf record: Introduce --switch-output-event
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
Now we can use it with --overwrite to have a flight recorder mode that gets snapshot requests from arbitrary events that are processed in the side band thread together with the PERF_RECORD_BPF_EVENT processing.
Example:
To collect scheduler events until a recvmmsg syscall happens, system wide:
[root@five a]# rm -f perf.data.2020042717*
[root@five a]# perf record --overwrite -e sched:*switch,syscalls:*recvmmsg --switch-output-event syscalls:sys_enter_recvmmsg [ perf record: dump data: Woken up 1 times ]
[ perf record: Dump perf.data.2020042717585458 ]
[ perf record: dump data: Woken up 1 times ]
[ perf record: Dump perf.data.2020042717590235 ]
[ perf record: dump data: Woken up 1 times ]
[ perf record: Dump perf.data.2020042717590398 ]
^C[ perf record: Woken up 1 times to write data ]
[ perf record: Dump perf.data.2020042717590511 ]
[ perf record: Captured and wrote 7.244 MB perf.data.<timestamp> ]
So in the above case we had 3 snapshots, the fourth was forced by control+C:
[root@five a]# ls -la
total 20440
drwxr-xr-x. 2 root root 4096 Apr 27 17:59 .
dr-xr-x---. 12 root root 4096 Apr 27 17:46 ..
-rw-------. 1 root root 3936125 Apr 27 17:58 perf.data.2020042717585458 -rw-------. 1 root root 5074869 Apr 27 17:59 perf.data.2020042717590235 -rw-------. 1 root root 4291037 Apr 27 17:59 perf.data.2020042717590398 -rw-------. 1 root root 7617037 Apr 27 17:59 perf.data.2020042717590511
[root@five a]#
One can make this more precise by adding the switch output event to the main -e events list, as since this is done asynchronously, a few events after the signal event will appear in the snapshots, as can be seen with:
[root@five a]# rm -f perf.data.20200427175*
[root@five a]# perf record --overwrite -e sched:*switch,syscalls:*recvmmsg --switch-output-event syscalls:sys_enter_recvmmsg [ perf record: dump data: Woken up 1 times ]
[ perf record: Dump perf.data.2020042718024203 ]
[ perf record: dump data: Woken up 1 times ]
[ perf record: Dump perf.data.2020042718024301 ]
[ perf record: dump data: Woken up 1 times ]
[ perf record: Dump perf.data.2020042718024484 ]
^C[ perf record: Woken up 1 times to write data ]
[ perf record: Dump perf.data.2020042718024562 ]
[ perf record: Captured and wrote 7.337 MB perf.data.<timestamp> ]
[root@five a]# perf script -i perf.data.2020042718024203 | tail -15
PacerThread 148586 [005] 122.830729: sched:sched_switch: prev_comm=PacerThread prev_pid=148586...
swapper 0 [000] 122.833588: sched:sched_switch: prev_comm=swapper/0 prev_pid=...
NetworkManager 1251 [000] 122.833619: syscalls:sys_enter_recvmmsg: fd: 0x0000001c, mmsg: 0x7ffe83054a1...
swapper 0 [002] 122.833624: sched:sched_switch: prev_comm=swapper/2 prev_pid=...
swapper 0 [003] 122.833624: sched:sched_switch: prev_comm=swapper/3 prev_pid=...
NetworkManager 1251 [000] 122.833626: syscalls:sys_exit_recvmmsg: 0x1
kworker/3:3-eve 158946 [003] 122.833628: sched:sched_switch: prev_comm=kworker/3:3 prev_pid=15894...
swapper 0 [004] 122.833641: sched:sched_switch: prev_comm=swapper/4 prev_pid=...
NetworkManager 1251 [000] 122.833642: sched:sched_switch: prev_comm=NetworkManage...
perf 228273 [002] 122.833645: sched:sched_switch: prev_comm=perf prev_pid=22827...
swapper 0 [011] 122.833646: sched:sched_switch: prev_comm=swapper/1...
swapper 0 [002] 122.833648: sched:sched_switch: prev_comm=swapper/...
kworker/0:2-eve 207387 [000] 122.833648: sched:sched_switch: prev_comm=kworker/0:2 prev_pid=20738...
kworker/2:3-eve 232038 [002] 122.833652: sched:sched_switch: prev_comm=kworker/2:3 prev_pid=23203...
perf 235825 [003] 122.833653: sched:sched_switch: prev_comm=perf prev_pid=23582...[root@five a]#
--- tools/perf/Documentation/perf-record.txt | 13 ++++++++ tools/perf/builtin-record.c | 41 +++++++++++++++++++++--- 2 files changed, 50 insertions(+), 4 deletions(-)
tools/perf/Documentation/perf-record.txt +13 -0
@@ -556,6 +556,19 @@ overhead. You can still switch them on with: --switch-output --no-no-buildid --no-no-buildid-cache +--switch-output-event:: +Events that will cause the switch of the perf.data file, auto-selecting +--switch-output=signal, the results are similar as internally the side band +thread will also send a SIGUSR2 to the main one. + +Uses the same syntax as --event, it will just not be recorded, serving only to +switch the perf.data file as soon as the --switch-output event is processed by +a separate sideband thread. + +This sideband thread is also used to other purposes, like processing the +PERF_RECORD_BPF_EVENT records as they happen, asking the kernel for extra BPF +information, etc. + --switch-max-files=N:: When rotating perf.data with --switch-output, only keep N files.
tools/perf/builtin-record.c +37 -4
78 lines not on this page · raw message
Signature · 1 line
2.21.1
Ian Rogers
reviewerRe: [PATCH 7/8] perf record: Introduce --switch-output-event
Quoted 89 lines · Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo <[email protected]>
Now we can use it with --overwrite to have a flight recorder mode that gets snapshot requests from arbitrary events that are processed in the side band thread together with the
PERF_RECORD_BPF_EVENTprocessing.Example:
To collect scheduler events until a recvmmsg syscall happens, system wide:
[root@five a]# rm -f perf.data.2020042717*
[root@five a]# perf record --overwrite -e sched:*switch,syscalls:*recvmmsg --switch-output-event syscalls:sys_enter_recvmmsg [ perf record: dump data: Woken up 1 times ]
[ perf record: Dump perf.data.2020042717585458 ]
[ perf record: dump data: Woken up 1 times ]
[ perf record: Dump perf.data.2020042717590235 ]
[ perf record: dump data: Woken up 1 times ]
[ perf record: Dump perf.data.2020042717590398 ]
^C[ perf record: Woken up 1 times to write data ]
[ perf record: Dump perf.data.2020042717590511 ]
[ perf record: Captured and wrote 7.244 MB perf.data.<timestamp> ]So in the above case we had 3 snapshots, the fourth was forced by control+C:
[root@five a]# ls -la
total 20440
drwxr-xr-x. 2 root root 4096 Apr 27 17:59 .
dr-xr-x---. 12 root root 4096 Apr 27 17:46 ..-rw-------. 1 root root 3936125 Apr 27 17:58 perf.data.2020042717585458 -rw-------. 1 root root 5074869 Apr 27 17:59 perf.data.2020042717590235 -rw-------. 1 root root 4291037 Apr 27 17:59 perf.data.2020042717590398 -rw-------. 1 root root 7617037 Apr 27 17:59 perf.data.2020042717590511[root@five a]#
One can make this more precise by adding the switch output event to the main -e events list, as since this is done asynchronously, a few events after the signal event will appear in the snapshots, as can be seen with:
[root@five a]# rm -f perf.data.20200427175*
[root@five a]# perf record --overwrite -e sched:*switch,syscalls:*recvmmsg --switch-output-event syscalls:sys_enter_recvmmsg [ perf record: dump data: Woken up 1 times ]
[ perf record: Dump perf.data.2020042718024203 ]
[ perf record: dump data: Woken up 1 times ]
[ perf record: Dump perf.data.2020042718024301 ]
[ perf record: dump data: Woken up 1 times ]
[ perf record: Dump perf.data.2020042718024484 ]
^C[ perf record: Woken up 1 times to write data ]
[ perf record: Dump perf.data.2020042718024562 ]
[ perf record: Captured and wrote 7.337 MB perf.data.<timestamp> ]
[root@five a]# perf script -i perf.data.2020042718024203 | tail -15PacerThread 148586 [005] 122.830729: sched:sched_switch: prev_comm=PacerThread prev_pid=148586... swapper 0 [000] 122.833588: sched:sched_switch: prev_comm=swapper/0 prev_pid=... NetworkManager 1251 [000] 122.833619: syscalls:sys_enter_recvmmsg: fd: 0x0000001c, mmsg: 0x7ffe83054a1... swapper 0 [002] 122.833624: sched:sched_switch: prev_comm=swapper/2 prev_pid=... swapper 0 [003] 122.833624: sched:sched_switch: prev_comm=swapper/3 prev_pid=... NetworkManager 1251 [000] 122.833626: syscalls:sys_exit_recvmmsg: 0x1 kworker/3:3-eve 158946 [003] 122.833628: sched:sched_switch: prev_comm=kworker/3:3 prev_pid=15894... swapper 0 [004] 122.833641: sched:sched_switch: prev_comm=swapper/4 prev_pid=... NetworkManager 1251 [000] 122.833642: sched:sched_switch: prev_comm=NetworkManage... perf 228273 [002] 122.833645: sched:sched_switch: prev_comm=perf prev_pid=22827... swapper 0 [011] 122.833646: sched:sched_switch: prev_comm=swapper/1... swapper 0 [002] 122.833648: sched:sched_switch: prev_comm=swapper/... kworker/0:2-eve 207387 [000] 122.833648: sched:sched_switch: prev_comm=kworker/0:2 prev_pid=20738... kworker/2:3-eve 232038 [002] 122.833652: sched:sched_switch: prev_comm=kworker/2:3 prev_pid=23203... perf 235825 [003] 122.833653: sched:sched_switch: prev_comm=perf prev_pid=23582...[root@five a]#
Cc Adrian Hunter <[email protected]>Cc Jiri Olsa <[email protected]>Cc Namhyung Kim <[email protected]>Cc Song Liu <[email protected]>Cc Wang Nan <[email protected]>Signed-off-by Arnaldo Carvalho de Melo <[email protected]>--- tools/perf/Documentation/perf-record.txt | 13 ++++++++ tools/perf/builtin-record.c | 41 +++++++++++++++++++++--- 2 files changed, 50 insertions(+), 4 deletions(-)tools/perf/Documentation/perf-record.txt +0
-0
tools/perf/Documentation/perf-record.txt overhead. You can still switch them on with: · line 562
Quoted 7 lines
tools/perf/Documentation/perf-record.txt +4
-0@@ -556,6 +556,19 @@ overhead. You can still switch them on with: --switch-output --no-no-buildid --no-no-buildid-cache +--switch-output-event:: +Events that will cause the switch of the perf.data file, auto-selecting +--switch-output=signal, the results are similar as internally the side band +thread will also send a SIGUSR2 to the main one.
I found this paragraph a little hard, perhaps:
A list of events that when they occur cause the output perf.data file to be ended and a new one created. The signal event, --switch-output=signal, is auto-selected as SIGUSR2 is used internally by the thread monitoring the events.
Quoted 89 lines
tools/perf/Documentation/perf-record.txt +8
-0+Uses the same syntax as --event, it will just not be recorded, serving only to +switch the perf.data file as soon as the --switch-output event is processed by +a separate sideband thread. + +This sideband thread is also used to other purposes, like processing the +PERF_RECORD_BPF_EVENT records as they happen, asking the kernel for extra BPF +information, etc. + --switch-max-files=N:: When rotating perf.data with --switch-output, only keep N files.tools/perf/builtin-record.c +34
-4@@ -87,7 +87,9 @@ struct record {struct evlist *evlist;struct perf_session *session;struct evlist *sb_evlist; +pthread_t thread_id;int realtime_prio; +bool switch_output_event_set;bool no_buildid;bool no_buildid_set;bool no_buildid_cache;@@ -1436,6 +1438,13 @@ static int record__synthesize(struct record *rec, bool tail)return err; } +static int record__process_signal_event (union perf_event *event__maybe_unused ,void *data) +{ +struct record *rec = data; +pthread_kill (rec->thread_id,SIGUSR2 ); +return 0 ; +} +static int __cmd_record (struct record *rec,int argc,const char **argv) {int err;@@ -1580,12 +1589,24 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) goto out_child; } -if (!opts->no_bpf_event) { - rec->sb_evlist =evlist__new (); +if (rec->sb_evlist !=NULL ) { +/* +* We get here if --switch-output-event populated the +* sb_evlist, so associate a callback that will send a SIGUSR2 +* to the main thread. +*/ +evlist__set_cb (rec->sb_evlist, record__process_signal_event, rec); + rec->thread_id =pthread_self (); + } +if (!opts->no_bpf_event) {if (rec->sb_evlist ==NULL ) { -pr_err ("Couldn't create side band evlist.\n." ); - goto out_child; + rec->sb_evlist =evlist__new (); + +if (rec->sb_evlist ==NULL ) { +pr_err ("Couldn't create side band evlist.\n." ); + goto out_child; + } }if (evlist__add_bpf_sb_event (rec->sb_evlist, &session->header.env)) {@@ -2179,10 +2200,19 @@ static int switch_output_setup(struct record *rec) };unsigned long val; +/* +* If we're using --switch-output-events, then we imply its +* --switch-output=signal, as we'll send a SIGUSR2 from the side band +* thread to its parent. +*/ +if (rec->switch_output_event_set) + goto do_signal; +if (!s->set)return 0 ;if (!strcmp (s->str,"signal" )) { +do_signal: s->signal = true;pr_debug ("switch-output with SIGUSR2 signal\n" ); goto enabled;
tools/perf/builtin-record.c static struct option __record_options[] = { · line 2474
Quoted 5 lines
tools/perf/builtin-record.c +2
-0@@ -2440,6 +2470,9 @@ static struct option __record_options[] = { &record.switch_output.set, "signal or size[BKMG] or time[smhd]", "Switch output when receiving SIGUSR2 (signal) or cross a size or time threshold", "signal"), + OPT_CALLBACK_SET(0, "switch-output-event", &record.sb_evlist, &record.switch_output_event_set, "switch output event", + "switch output event selector. use 'perf list' to list available events",
Perhaps:
"A list of events, see 'perf list', that when they occur cause the end of one perf.data file and the creation of another"
Thanks,
Ian
Quoted 7 lines
tools/perf/builtin-record.c +1
-1+ parse_events_option_new_evlist),OPT_INTEGER (0 ,"switch-max-files" , &record.switch_output.num_files,"Limit number of switch output generated files" ), OPT_BOOLEAN(0, "dry-run", &dry_run, --2.21.1
Re: [PATCH 7/8] perf record: Introduce --switch-output-event
Em Wed, Apr 29, 2020 at 10:25:52AM -0700, Ian Rogers escreveu:
Quoted 94 lines
Quoted 92 lines · Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo <[email protected]>
Now we can use it with --overwrite to have a flight recorder mode that gets snapshot requests from arbitrary events that are processed in the side band thread together with the
PERF_RECORD_BPF_EVENTprocessing.Example:
To collect scheduler events until a recvmmsg syscall happens, system wide:
[root@five a]# rm -f perf.data.2020042717*
[root@five a]# perf record --overwrite -e sched:*switch,syscalls:*recvmmsg --switch-output-event syscalls:sys_enter_recvmmsg [ perf record: dump data: Woken up 1 times ]
[ perf record: Dump perf.data.2020042717585458 ]
[ perf record: dump data: Woken up 1 times ]
[ perf record: Dump perf.data.2020042717590235 ]
[ perf record: dump data: Woken up 1 times ]
[ perf record: Dump perf.data.2020042717590398 ]
^C[ perf record: Woken up 1 times to write data ]
[ perf record: Dump perf.data.2020042717590511 ]
[ perf record: Captured and wrote 7.244 MB perf.data.<timestamp> ]So in the above case we had 3 snapshots, the fourth was forced by control+C:
[root@five a]# ls -la
total 20440
drwxr-xr-x. 2 root root 4096 Apr 27 17:59 .
dr-xr-x---. 12 root root 4096 Apr 27 17:46 ..-rw-------. 1 root root 3936125 Apr 27 17:58 perf.data.2020042717585458 -rw-------. 1 root root 5074869 Apr 27 17:59 perf.data.2020042717590235 -rw-------. 1 root root 4291037 Apr 27 17:59 perf.data.2020042717590398 -rw-------. 1 root root 7617037 Apr 27 17:59 perf.data.2020042717590511[root@five a]#
One can make this more precise by adding the switch output event to the main -e events list, as since this is done asynchronously, a few events after the signal event will appear in the snapshots, as can be seen with:
[root@five a]# rm -f perf.data.20200427175*
[root@five a]# perf record --overwrite -e sched:*switch,syscalls:*recvmmsg --switch-output-event syscalls:sys_enter_recvmmsg [ perf record: dump data: Woken up 1 times ]
[ perf record: Dump perf.data.2020042718024203 ]
[ perf record: dump data: Woken up 1 times ]
[ perf record: Dump perf.data.2020042718024301 ]
[ perf record: dump data: Woken up 1 times ]
[ perf record: Dump perf.data.2020042718024484 ]
^C[ perf record: Woken up 1 times to write data ]
[ perf record: Dump perf.data.2020042718024562 ]
[ perf record: Captured and wrote 7.337 MB perf.data.<timestamp> ]
[root@five a]# perf script -i perf.data.2020042718024203 | tail -15PacerThread 148586 [005] 122.830729: sched:sched_switch: prev_comm=PacerThread prev_pid=148586... swapper 0 [000] 122.833588: sched:sched_switch: prev_comm=swapper/0 prev_pid=... NetworkManager 1251 [000] 122.833619: syscalls:sys_enter_recvmmsg: fd: 0x0000001c, mmsg: 0x7ffe83054a1... swapper 0 [002] 122.833624: sched:sched_switch: prev_comm=swapper/2 prev_pid=... swapper 0 [003] 122.833624: sched:sched_switch: prev_comm=swapper/3 prev_pid=... NetworkManager 1251 [000] 122.833626: syscalls:sys_exit_recvmmsg: 0x1 kworker/3:3-eve 158946 [003] 122.833628: sched:sched_switch: prev_comm=kworker/3:3 prev_pid=15894... swapper 0 [004] 122.833641: sched:sched_switch: prev_comm=swapper/4 prev_pid=... NetworkManager 1251 [000] 122.833642: sched:sched_switch: prev_comm=NetworkManage... perf 228273 [002] 122.833645: sched:sched_switch: prev_comm=perf prev_pid=22827... swapper 0 [011] 122.833646: sched:sched_switch: prev_comm=swapper/1... swapper 0 [002] 122.833648: sched:sched_switch: prev_comm=swapper/... kworker/0:2-eve 207387 [000] 122.833648: sched:sched_switch: prev_comm=kworker/0:2 prev_pid=20738... kworker/2:3-eve 232038 [002] 122.833652: sched:sched_switch: prev_comm=kworker/2:3 prev_pid=23203... perf 235825 [003] 122.833653: sched:sched_switch: prev_comm=perf prev_pid=23582...[root@five a]#
Cc Adrian Hunter <[email protected]>Cc Jiri Olsa <[email protected]>Cc Namhyung Kim <[email protected]>Cc Song Liu <[email protected]>Cc Wang Nan <[email protected]>Signed-off-by Arnaldo Carvalho de Melo <[email protected]>--- tools/perf/Documentation/perf-record.txt | 13 ++++++++ tools/perf/builtin-record.c | 41 +++++++++++++++++++++--- 2 files changed, 50 insertions(+), 4 deletions(-)tools/perf/Documentation/perf-record.txt +0
-0@@ -556,6 +556,19 @@ overhead. You can still switch them on with: --switch-output --no-no-buildid --no-no-buildid-cache
Quoted 10 lines
tools/perf/Documentation/perf-record.txt overhead. You can still switch them on with: · line 562
Quoted 4 lines
tools/perf/Documentation/perf-record.txt +4
-0+--switch-output-event:: +Events that will cause the switch of the perf.data file, auto-selecting +--switch-output=signal, the results are similar as internally the side band +thread will also send a SIGUSR2 to the main one.I found this paragraph a little hard, perhaps:
A list of events that when they occur cause the output perf.data file to be ended and a new one created. The signal event, --switch-output=signal, is auto-selected as SIGUSR2 is used internally by the thread monitoring the events.
Good suggestions (the one above and the one at the end of this message), can you please put those in a formal patch?
Thanks,
- Arnaldo
Quoted 109 lines
Quoted 89 lines
tools/perf/Documentation/perf-record.txt +8
-0+Uses the same syntax as --event, it will just not be recorded, serving only to +switch the perf.data file as soon as the --switch-output event is processed by +a separate sideband thread. + +This sideband thread is also used to other purposes, like processing the +PERF_RECORD_BPF_EVENT records as they happen, asking the kernel for extra BPF +information, etc. + --switch-max-files=N:: When rotating perf.data with --switch-output, only keep N files.tools/perf/builtin-record.c +34
-4@@ -87,7 +87,9 @@ struct record {struct evlist *evlist;struct perf_session *session;struct evlist *sb_evlist; +pthread_t thread_id;int realtime_prio; +bool switch_output_event_set;bool no_buildid;bool no_buildid_set;bool no_buildid_cache;@@ -1436,6 +1438,13 @@ static int record__synthesize(struct record *rec, bool tail)return err; } +static int record__process_signal_event (union perf_event *event__maybe_unused ,void *data) +{ +struct record *rec = data; +pthread_kill (rec->thread_id,SIGUSR2 ); +return 0 ; +} +static int __cmd_record (struct record *rec,int argc,const char **argv) {int err;@@ -1580,12 +1589,24 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) goto out_child; } -if (!opts->no_bpf_event) { - rec->sb_evlist =evlist__new (); +if (rec->sb_evlist !=NULL ) { +/* +* We get here if --switch-output-event populated the +* sb_evlist, so associate a callback that will send a SIGUSR2 +* to the main thread. +*/ +evlist__set_cb (rec->sb_evlist, record__process_signal_event, rec); + rec->thread_id =pthread_self (); + } +if (!opts->no_bpf_event) {if (rec->sb_evlist ==NULL ) { -pr_err ("Couldn't create side band evlist.\n." ); - goto out_child; + rec->sb_evlist =evlist__new (); + +if (rec->sb_evlist ==NULL ) { +pr_err ("Couldn't create side band evlist.\n." ); + goto out_child; + } }if (evlist__add_bpf_sb_event (rec->sb_evlist, &session->header.env)) {@@ -2179,10 +2200,19 @@ static int switch_output_setup(struct record *rec) };unsigned long val; +/* +* If we're using --switch-output-events, then we imply its +* --switch-output=signal, as we'll send a SIGUSR2 from the side band +* thread to its parent. +*/ +if (rec->switch_output_event_set) + goto do_signal; +if (!s->set)return 0 ;if (!strcmp (s->str,"signal" )) { +do_signal: s->signal = true;pr_debug ("switch-output with SIGUSR2 signal\n" ); goto enabled;tools/perf/builtin-record.c static struct option __record_options[] = { · line 2474
Quoted 5 lines
tools/perf/builtin-record.c +2
-0@@ -2440,6 +2470,9 @@ static struct option __record_options[] = { &record.switch_output.set, "signal or size[BKMG] or time[smhd]", "Switch output when receiving SIGUSR2 (signal) or cross a size or time threshold", "signal"), + OPT_CALLBACK_SET(0, "switch-output-event", &record.sb_evlist, &record.switch_output_event_set, "switch output event", + "switch output event selector. use 'perf list' to list available events",Perhaps:
"A list of events, see 'perf list', that when they occur cause the end of one perf.data file and the creation of another"Thanks,
IanQuoted 7 lines
tools/perf/builtin-record.c +1
-1+ parse_events_option_new_evlist),OPT_INTEGER (0 ,"switch-max-files" , &record.switch_output.num_files,"Limit number of switch output generated files" ), OPT_BOOLEAN(0, "dry-run", &dry_run, --2.21.1
[tip: perf/core] perf record: Introduce --switch-output-event
In reply to Arnaldo Carvalho de MeloThe following commit has been merged into the perf/core branch of tip:
The following commit has been merged into the perf/core branch of tip:
Commit-ID: 899e5ffbf246a30986ced9dd48092c408978afc7 Gitweb: https://git.kernel.org/tip/899e5ffbf246a30986ced9dd48092c408978afc7 Author: Arnaldo Carvalho de Melo <[email protected]> AuthorDate: Mon, 27 Apr 2020 17:56:37 -03:00 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitterDate: Tue, 05 May 2020 16:35:29 -03:00
perf record: Introduce --switch-output-event
Now we can use it with --overwrite to have a flight recorder mode that gets snapshot requests from arbitrary events that are processed in the side band thread together with the PERF_RECORD_BPF_EVENT processing.
Example:
To collect scheduler events until a recvmmsg syscall happens, system wide:
[root@five a]# rm -f perf.data.2020042717*
[root@five a]# perf record --overwrite -e sched:*switch,syscalls:*recvmmsg --switch-output-event syscalls:sys_enter_recvmmsg [ perf record: dump data: Woken up 1 times ]
[ perf record: Dump perf.data.2020042717585458 ]
[ perf record: dump data: Woken up 1 times ]
[ perf record: Dump perf.data.2020042717590235 ]
[ perf record: dump data: Woken up 1 times ]
[ perf record: Dump perf.data.2020042717590398 ]
^C[ perf record: Woken up 1 times to write data ]
[ perf record: Dump perf.data.2020042717590511 ]
[ perf record: Captured and wrote 7.244 MB perf.data.<timestamp> ]
So in the above case we had 3 snapshots, the fourth was forced by control+C:
[root@five a]# ls -la
total 20440
drwxr-xr-x. 2 root root 4096 Apr 27 17:59 .
dr-xr-x---. 12 root root 4096 Apr 27 17:46 ..
-rw-------. 1 root root 3936125 Apr 27 17:58 perf.data.2020042717585458 -rw-------. 1 root root 5074869 Apr 27 17:59 perf.data.2020042717590235 -rw-------. 1 root root 4291037 Apr 27 17:59 perf.data.2020042717590398 -rw-------. 1 root root 7617037 Apr 27 17:59 perf.data.2020042717590511
[root@five a]#
One can make this more precise by adding the switch output event to the main -e events list, as since this is done asynchronously, a few events after the signal event will appear in the snapshots, as can be seen with:
[root@five a]# rm -f perf.data.20200427175*
[root@five a]# perf record --overwrite -e sched:*switch,syscalls:*recvmmsg --switch-output-event syscalls:sys_enter_recvmmsg [ perf record: dump data: Woken up 1 times ]
[ perf record: Dump perf.data.2020042718024203 ]
[ perf record: dump data: Woken up 1 times ]
[ perf record: Dump perf.data.2020042718024301 ]
[ perf record: dump data: Woken up 1 times ]
[ perf record: Dump perf.data.2020042718024484 ]
^C[ perf record: Woken up 1 times to write data ]
[ perf record: Dump perf.data.2020042718024562 ]
[ perf record: Captured and wrote 7.337 MB perf.data.<timestamp> ]
[root@five a]# perf script -i perf.data.2020042718024203 | tail -15
PacerThread 148586 [005] 122.830729: sched:sched_switch: prev_comm=PacerThread prev_pid=148586...
swapper 0 [000] 122.833588: sched:sched_switch: prev_comm=swapper/0 prev_pid=...
NetworkManager 1251 [000] 122.833619: syscalls:sys_enter_recvmmsg: fd: 0x0000001c, mmsg: 0x7ffe83054a1...
swapper 0 [002] 122.833624: sched:sched_switch: prev_comm=swapper/2 prev_pid=...
swapper 0 [003] 122.833624: sched:sched_switch: prev_comm=swapper/3 prev_pid=...
NetworkManager 1251 [000] 122.833626: syscalls:sys_exit_recvmmsg: 0x1
kworker/3:3-eve 158946 [003] 122.833628: sched:sched_switch: prev_comm=kworker/3:3 prev_pid=15894...
swapper 0 [004] 122.833641: sched:sched_switch: prev_comm=swapper/4 prev_pid=...
NetworkManager 1251 [000] 122.833642: sched:sched_switch: prev_comm=NetworkManage...
perf 228273 [002] 122.833645: sched:sched_switch: prev_comm=perf prev_pid=22827...
swapper 0 [011] 122.833646: sched:sched_switch: prev_comm=swapper/1...
swapper 0 [002] 122.833648: sched:sched_switch: prev_comm=swapper/...
kworker/0:2-eve 207387 [000] 122.833648: sched:sched_switch: prev_comm=kworker/0:2 prev_pid=20738...
kworker/2:3-eve 232038 [002] 122.833652: sched:sched_switch: prev_comm=kworker/2:3 prev_pid=23203...
perf 235825 [003] 122.833653: sched:sched_switch: prev_comm=perf prev_pid=23582...[root@five a]#
--- tools/perf/Documentation/perf-record.txt | 13 +++++++- tools/perf/builtin-record.c | 41 ++++++++++++++++++++--- 2 files changed, 50 insertions(+), 4 deletions(-)
tools/perf/Documentation/perf-record.txt +13 -0
@@ -556,6 +556,19 @@ overhead. You can still switch them on with: --switch-output --no-no-buildid --no-no-buildid-cache +--switch-output-event:: +Events that will cause the switch of the perf.data file, auto-selecting +--switch-output=signal, the results are similar as internally the side band +thread will also send a SIGUSR2 to the main one. + +Uses the same syntax as --event, it will just not be recorded, serving only to +switch the perf.data file as soon as the --switch-output event is processed by +a separate sideband thread. + +This sideband thread is also used to other purposes, like processing the +PERF_RECORD_BPF_EVENT records as they happen, asking the kernel for extra BPF +information, etc. + --switch-max-files=N:: When rotating perf.data with --switch-output, only keep N files.
tools/perf/builtin-record.c +37 -4
78 lines not on this page · raw message
Arnaldo Carvalho de Melo
maintainerPATCH 8/8 perf record: Move side band evlist setup to separate routine
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
It is quite big by now, move that code to a separate record__setup_sb_evlist() routine.
--- tools/perf/builtin-record.c | 71 +++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 30 deletions(-)
tools/perf/builtin-record.c +41 -30
@@ -1445,6 +1445,44 @@ static int record__process_signal_event(union perf_event *event __maybe_unused,return 0 ; } +static int record__setup_sb_evlist (struct record *rec) +{ +struct record_opts *opts = &rec->opts; + +if (rec->sb_evlist !=NULL ) { +/* +* We get here if --switch-output-event populated the +* sb_evlist, so associate a callback that will send a SIGUSR2 +* to the main thread. +*/ +evlist__set_cb (rec->sb_evlist, record__process_signal_event, rec); + rec->thread_id =pthread_self (); + } + +if (!opts->no_bpf_event) { +if (rec->sb_evlist ==NULL ) { + rec->sb_evlist =evlist__new (); + +if (rec->sb_evlist ==NULL ) { +pr_err ("Couldn't create side band evlist.\n." ); +return -1 ; + } + } + +if (evlist__add_bpf_sb_event (rec->sb_evlist, &rec->session->header.env)) { +pr_err ("Couldn't ask for PERF_RECORD_BPF_EVENT side band events.\n." ); +return -1 ; + } + } + +if (perf_evlist__start_sb_thread (rec->sb_evlist, &rec->opts.target)) { +pr_debug ("Couldn't start the BPF side band thread:\nBPF programs starting from now on won't be annotatable\n" ); + opts->no_bpf_event = true; + } + +return 0 ; +} +static int __cmd_record (struct record *rec,int argc,const char **argv) {int err;
@@ -1589,36 +1627,9 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) goto out_child; } -if (rec->sb_evlist !=NULL ) { -/* -* We get here if --switch-output-event populated the -* sb_evlist, so associate a callback that will send a SIGUSR2 -* to the main thread. -*/ -evlist__set_cb (rec->sb_evlist, record__process_signal_event, rec); - rec->thread_id =pthread_self (); - } - -if (!opts->no_bpf_event) { -if (rec->sb_evlist ==NULL ) { - rec->sb_evlist =evlist__new (); - -if (rec->sb_evlist ==NULL ) { -pr_err ("Couldn't create side band evlist.\n." ); - goto out_child; - } - } - -if (evlist__add_bpf_sb_event (rec->sb_evlist, &session->header.env)) { -pr_err ("Couldn't ask for PERF_RECORD_BPF_EVENT side band events.\n." ); - goto out_child; - } - } - -if (perf_evlist__start_sb_thread (rec->sb_evlist, &rec->opts.target)) { -pr_debug ("Couldn't start the BPF side band thread:\nBPF programs starting from now on won't be annotatable\n" ); - opts->no_bpf_event = true; - } + err =record__setup_sb_evlist (rec); +if (err) + goto out_child; err =record__synthesize (rec, false);if (err <0 )
Signature · 1 line
2.21.1
[tip: perf/core] perf record: Move side band evlist setup to separate routine
The following commit has been merged into the perf/core branch of tip:
The following commit has been merged into the perf/core branch of tip:
Commit-ID: 23cbb41c939a09a4b51eabacdb1f68af210c084d Gitweb: https://git.kernel.org/tip/23cbb41c939a09a4b51eabacdb1f68af210c084d Author: Arnaldo Carvalho de Melo <[email protected]> AuthorDate: Tue, 28 Apr 2020 14:58:29 -03:00 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitterDate: Tue, 05 May 2020 16:35:29 -03:00
perf record: Move side band evlist setup to separate routine
It is quite big by now, move that code to a separate record__setup_sb_evlist() routine.
--- tools/perf/builtin-record.c | 71 ++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 30 deletions(-)
tools/perf/builtin-record.c +41 -30
@@ -1446,6 +1446,44 @@ static int record__process_signal_event(union perf_event *event __maybe_unused,return 0 ; } +static int record__setup_sb_evlist (struct record *rec) +{ +struct record_opts *opts = &rec->opts; + +if (rec->sb_evlist !=NULL ) { +/* +* We get here if --switch-output-event populated the +* sb_evlist, so associate a callback that will send a SIGUSR2 +* to the main thread. +*/ +evlist__set_cb (rec->sb_evlist, record__process_signal_event, rec); + rec->thread_id =pthread_self (); + } + +if (!opts->no_bpf_event) { +if (rec->sb_evlist ==NULL ) { + rec->sb_evlist =evlist__new (); + +if (rec->sb_evlist ==NULL ) { +pr_err ("Couldn't create side band evlist.\n." ); +return -1 ; + } + } + +if (evlist__add_bpf_sb_event (rec->sb_evlist, &rec->session->header.env)) { +pr_err ("Couldn't ask for PERF_RECORD_BPF_EVENT side band events.\n." ); +return -1 ; + } + } + +if (perf_evlist__start_sb_thread (rec->sb_evlist, &rec->opts.target)) { +pr_debug ("Couldn't start the BPF side band thread:\nBPF programs starting from now on won't be annotatable\n" ); + opts->no_bpf_event = true; + } + +return 0 ; +} +static int __cmd_record (struct record *rec,int argc,const char **argv) {int err;
@@ -1590,36 +1628,9 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) goto out_child; } -if (rec->sb_evlist !=NULL ) { -/* -* We get here if --switch-output-event populated the -* sb_evlist, so associate a callback that will send a SIGUSR2 -* to the main thread. -*/ -evlist__set_cb (rec->sb_evlist, record__process_signal_event, rec); - rec->thread_id =pthread_self (); - } - -if (!opts->no_bpf_event) { -if (rec->sb_evlist ==NULL ) { - rec->sb_evlist =evlist__new (); - -if (rec->sb_evlist ==NULL ) { -pr_err ("Couldn't create side band evlist.\n." ); - goto out_child; - } - } - -if (evlist__add_bpf_sb_event (rec->sb_evlist, &session->header.env)) { -pr_err ("Couldn't ask for PERF_RECORD_BPF_EVENT side band events.\n." ); - goto out_child; - } - } - -if (perf_evlist__start_sb_thread (rec->sb_evlist, &rec->opts.target)) { -pr_debug ("Couldn't start the BPF side band thread:\nBPF programs starting from now on won't be annotatable\n" ); - opts->no_bpf_event = true; - } + err =record__setup_sb_evlist (rec); +if (err) + goto out_child; err =record__synthesize (rec, false);if (err <0 )
Quoted 4 lines · Arnaldo Carvalho de Melo
Hi guys,
Please consider reviewing, this addresses comments by Jiri in
the V1.
small nit posted, but overall looks good
jirka
Quoted 59 lines
Again, the example provided is too simple, using 'perf probe' to
put probes in specific places in some workload to then get any other event close to the time the trigger hits comes to mind as well, using the signal was just to reuse the pre-existing logic and keep the patchkit small.One other thing that occurred to me while testing is that this
can be combined with 'perf report/perf script' --switch-off option:$ perf report -h --switch-offUsage: perf report [<options>]
--switch-off <event>
Stop considering events after the ocurrence of this event$
To remove from consideration the events that end up being
recorded in the ring buffer after the --switch-output-event but gets in the ring buffer because we process the --switch-output-event asynchronously.Its available at:
git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.gitperf/switch-output-eventBest regards,
- Arnaldo
Arnaldo Carvalho de Melo (8):
perf record: Movesb_evlistto 'struct record'
perf top: Movesb_evlistto 'structperf_top'
perf bpf: Decouple creating the evlist from adding the SB event perf parse-events: Addparse_events_option()variant that creates evlist perf evlist: Allow reusing the side band thread for more purposes
libsubcmd: IntroduceOPT_CALLBACK_SET()
perf record: Introduce --switch-output-event
perf record: Move side band evlist setup to separate routinetools/lib/subcmd/parse-options.h | 2 + tools/perf/Documentation/perf-record.txt | 13 ++++ tools/perf/builtin-record.c | 75 ++++++++++++++++++++---- tools/perf/builtin-top.c | 20 +++++-- tools/perf/util/bpf-event.c | 3 +- tools/perf/util/bpf-event.h | 7 +-- tools/perf/util/evlist.c | 39 +++++++----- tools/perf/util/evlist.h | 3 +- tools/perf/util/parse-events.c | 23 ++++++++ tools/perf/util/parse-events.h | 1 + tools/perf/util/top.h | 2 +- 11 files changed, 151 insertions(+), 37 deletions(-)Signature · 1 line
2.21.1