Skip to content

Commit 23cbb41

Browse files
committed
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. Suggested-by: Jiri Olsa <jolsa@redhat.com> Acked-by: Jiri Olsa <jolsa@redhat.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Song Liu <songliubraving@fb.com> Link: http://lore.kernel.org/lkml/20200429131106.27974-9-acme@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 899e5ff commit 23cbb41

File tree

1 file changed

+41
-30
lines changed

1 file changed

+41
-30
lines changed

tools/perf/builtin-record.c

+41-30
Original file line numberDiff line numberDiff line change
@@ -1446,6 +1446,44 @@ static int record__process_signal_event(union perf_event *event __maybe_unused,
14461446
return 0;
14471447
}
14481448

1449+
static int record__setup_sb_evlist(struct record *rec)
1450+
{
1451+
struct record_opts *opts = &rec->opts;
1452+
1453+
if (rec->sb_evlist != NULL) {
1454+
/*
1455+
* We get here if --switch-output-event populated the
1456+
* sb_evlist, so associate a callback that will send a SIGUSR2
1457+
* to the main thread.
1458+
*/
1459+
evlist__set_cb(rec->sb_evlist, record__process_signal_event, rec);
1460+
rec->thread_id = pthread_self();
1461+
}
1462+
1463+
if (!opts->no_bpf_event) {
1464+
if (rec->sb_evlist == NULL) {
1465+
rec->sb_evlist = evlist__new();
1466+
1467+
if (rec->sb_evlist == NULL) {
1468+
pr_err("Couldn't create side band evlist.\n.");
1469+
return -1;
1470+
}
1471+
}
1472+
1473+
if (evlist__add_bpf_sb_event(rec->sb_evlist, &rec->session->header.env)) {
1474+
pr_err("Couldn't ask for PERF_RECORD_BPF_EVENT side band events.\n.");
1475+
return -1;
1476+
}
1477+
}
1478+
1479+
if (perf_evlist__start_sb_thread(rec->sb_evlist, &rec->opts.target)) {
1480+
pr_debug("Couldn't start the BPF side band thread:\nBPF programs starting from now on won't be annotatable\n");
1481+
opts->no_bpf_event = true;
1482+
}
1483+
1484+
return 0;
1485+
}
1486+
14491487
static int __cmd_record(struct record *rec, int argc, const char **argv)
14501488
{
14511489
int err;
@@ -1590,36 +1628,9 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
15901628
goto out_child;
15911629
}
15921630

1593-
if (rec->sb_evlist != NULL) {
1594-
/*
1595-
* We get here if --switch-output-event populated the
1596-
* sb_evlist, so associate a callback that will send a SIGUSR2
1597-
* to the main thread.
1598-
*/
1599-
evlist__set_cb(rec->sb_evlist, record__process_signal_event, rec);
1600-
rec->thread_id = pthread_self();
1601-
}
1602-
1603-
if (!opts->no_bpf_event) {
1604-
if (rec->sb_evlist == NULL) {
1605-
rec->sb_evlist = evlist__new();
1606-
1607-
if (rec->sb_evlist == NULL) {
1608-
pr_err("Couldn't create side band evlist.\n.");
1609-
goto out_child;
1610-
}
1611-
}
1612-
1613-
if (evlist__add_bpf_sb_event(rec->sb_evlist, &session->header.env)) {
1614-
pr_err("Couldn't ask for PERF_RECORD_BPF_EVENT side band events.\n.");
1615-
goto out_child;
1616-
}
1617-
}
1618-
1619-
if (perf_evlist__start_sb_thread(rec->sb_evlist, &rec->opts.target)) {
1620-
pr_debug("Couldn't start the BPF side band thread:\nBPF programs starting from now on won't be annotatable\n");
1621-
opts->no_bpf_event = true;
1622-
}
1631+
err = record__setup_sb_evlist(rec);
1632+
if (err)
1633+
goto out_child;
16231634

16241635
err = record__synthesize(rec, false);
16251636
if (err < 0)

0 commit comments

Comments
 (0)