Skip to content

Commit c45c86e

Browse files
WangNan0acmel
authored andcommitted
perf record: Extract synthesize code to record__synthesize()
Create record__synthesize(). It can be used to create tracking events for each perf.data after perf supporting splitting into multiple outputs. Signed-off-by: He Kuang <[email protected]> Cc: Alexei Starovoitov <[email protected]> Cc: He Kuang <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Li Zefan <[email protected]> Cc: Masami Hiramatsu <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Zefan Li <[email protected]> Cc: [email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Wang Nan <[email protected]> Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent d8871ea commit c45c86e

File tree

1 file changed

+70
-55
lines changed

1 file changed

+70
-55
lines changed

tools/perf/builtin-record.c

Lines changed: 70 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,74 @@ static void workload_exec_failed_signal(int signo __maybe_unused,
486486

487487
static void snapshot_sig_handler(int sig);
488488

489+
static int record__synthesize(struct record *rec)
490+
{
491+
struct perf_session *session = rec->session;
492+
struct machine *machine = &session->machines.host;
493+
struct perf_data_file *file = &rec->file;
494+
struct record_opts *opts = &rec->opts;
495+
struct perf_tool *tool = &rec->tool;
496+
int fd = perf_data_file__fd(file);
497+
int err = 0;
498+
499+
if (file->is_pipe) {
500+
err = perf_event__synthesize_attrs(tool, session,
501+
process_synthesized_event);
502+
if (err < 0) {
503+
pr_err("Couldn't synthesize attrs.\n");
504+
goto out;
505+
}
506+
507+
if (have_tracepoints(&rec->evlist->entries)) {
508+
/*
509+
* FIXME err <= 0 here actually means that
510+
* there were no tracepoints so its not really
511+
* an error, just that we don't need to
512+
* synthesize anything. We really have to
513+
* return this more properly and also
514+
* propagate errors that now are calling die()
515+
*/
516+
err = perf_event__synthesize_tracing_data(tool, fd, rec->evlist,
517+
process_synthesized_event);
518+
if (err <= 0) {
519+
pr_err("Couldn't record tracing data.\n");
520+
goto out;
521+
}
522+
rec->bytes_written += err;
523+
}
524+
}
525+
526+
if (rec->opts.full_auxtrace) {
527+
err = perf_event__synthesize_auxtrace_info(rec->itr, tool,
528+
session, process_synthesized_event);
529+
if (err)
530+
goto out;
531+
}
532+
533+
err = perf_event__synthesize_kernel_mmap(tool, process_synthesized_event,
534+
machine);
535+
WARN_ONCE(err < 0, "Couldn't record kernel reference relocation symbol\n"
536+
"Symbol resolution may be skewed if relocation was used (e.g. kexec).\n"
537+
"Check /proc/kallsyms permission or run as root.\n");
538+
539+
err = perf_event__synthesize_modules(tool, process_synthesized_event,
540+
machine);
541+
WARN_ONCE(err < 0, "Couldn't record kernel module information.\n"
542+
"Symbol resolution may be skewed if relocation was used (e.g. kexec).\n"
543+
"Check /proc/modules permission or run as root.\n");
544+
545+
if (perf_guest) {
546+
machines__process_guests(&session->machines,
547+
perf_event__synthesize_guest_os, tool);
548+
}
549+
550+
err = __machine__synthesize_threads(machine, tool, &opts->target, rec->evlist->threads,
551+
process_synthesized_event, opts->sample_address,
552+
opts->proc_map_timeout);
553+
out:
554+
return err;
555+
}
556+
489557
static int __cmd_record(struct record *rec, int argc, const char **argv)
490558
{
491559
int err;
@@ -580,61 +648,8 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
580648

581649
machine = &session->machines.host;
582650

583-
if (file->is_pipe) {
584-
err = perf_event__synthesize_attrs(tool, session,
585-
process_synthesized_event);
586-
if (err < 0) {
587-
pr_err("Couldn't synthesize attrs.\n");
588-
goto out_child;
589-
}
590-
591-
if (have_tracepoints(&rec->evlist->entries)) {
592-
/*
593-
* FIXME err <= 0 here actually means that
594-
* there were no tracepoints so its not really
595-
* an error, just that we don't need to
596-
* synthesize anything. We really have to
597-
* return this more properly and also
598-
* propagate errors that now are calling die()
599-
*/
600-
err = perf_event__synthesize_tracing_data(tool, fd, rec->evlist,
601-
process_synthesized_event);
602-
if (err <= 0) {
603-
pr_err("Couldn't record tracing data.\n");
604-
goto out_child;
605-
}
606-
rec->bytes_written += err;
607-
}
608-
}
609-
610-
if (rec->opts.full_auxtrace) {
611-
err = perf_event__synthesize_auxtrace_info(rec->itr, tool,
612-
session, process_synthesized_event);
613-
if (err)
614-
goto out_delete_session;
615-
}
616-
617-
err = perf_event__synthesize_kernel_mmap(tool, process_synthesized_event,
618-
machine);
619-
WARN_ONCE(err < 0, "Couldn't record kernel reference relocation symbol\n"
620-
"Symbol resolution may be skewed if relocation was used (e.g. kexec).\n"
621-
"Check /proc/kallsyms permission or run as root.\n");
622-
623-
err = perf_event__synthesize_modules(tool, process_synthesized_event,
624-
machine);
625-
WARN_ONCE(err < 0, "Couldn't record kernel module information.\n"
626-
"Symbol resolution may be skewed if relocation was used (e.g. kexec).\n"
627-
"Check /proc/modules permission or run as root.\n");
628-
629-
if (perf_guest) {
630-
machines__process_guests(&session->machines,
631-
perf_event__synthesize_guest_os, tool);
632-
}
633-
634-
err = __machine__synthesize_threads(machine, tool, &opts->target, rec->evlist->threads,
635-
process_synthesized_event, opts->sample_address,
636-
opts->proc_map_timeout);
637-
if (err != 0)
651+
err = record__synthesize(rec);
652+
if (err < 0)
638653
goto out_child;
639654

640655
if (rec->realtime_prio) {

0 commit comments

Comments
 (0)