Skip to content

Commit

Permalink
perf record: Move side band evlist setup to separate routine
Browse files Browse the repository at this point in the history
It is quite big by now, move that code to a separate
record__setup_sb_evlist() routine.

Suggested-by: Jiri Olsa <[email protected]>
Acked-by: Jiri Olsa <[email protected]>
Cc: Adrian Hunter <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Song Liu <[email protected]>
Link: http://lore.kernel.org/lkml/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
  • Loading branch information
acmel committed May 5, 2020
1 parent 899e5ff commit 23cbb41
Showing 1 changed file with 41 additions and 30 deletions.
71 changes: 41 additions & 30 deletions tools/perf/builtin-record.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 23cbb41

Please sign in to comment.