Commit 84111b9c authored by Namhyung Kim's avatar Namhyung Kim Committed by Arnaldo Carvalho de Melo

perf tools: Allow controlling synthesizing PERF_RECORD_ metadata events during record

Depending on the use case, it might require some kind of synthesizing
and some not.  Make it controllable to turn off heavy operations like
MMAP for all tasks.

Currently all users are converted to enable all the synthesis by
default.  It'll be updated in the later patch.
Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
Acked-by: default avatarJiri Olsa <jolsa@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: https //lore.kernel.org/r/20210811044658.1313391-1-namhyung@kernel.org
Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 8228e936
...@@ -80,7 +80,7 @@ static int do_run_single_threaded(struct perf_session *session, ...@@ -80,7 +80,7 @@ static int do_run_single_threaded(struct perf_session *session,
NULL, NULL,
target, threads, target, threads,
process_synthesized_event, process_synthesized_event,
data_mmap, true, data_mmap,
nr_threads_synthesize); nr_threads_synthesize);
if (err) if (err)
return err; return err;
...@@ -171,7 +171,7 @@ static int do_run_multi_threaded(struct target *target, ...@@ -171,7 +171,7 @@ static int do_run_multi_threaded(struct target *target,
NULL, NULL,
target, NULL, target, NULL,
process_synthesized_event, process_synthesized_event,
false, true, false,
nr_threads_synthesize); nr_threads_synthesize);
if (err) { if (err) {
perf_session__delete(session); perf_session__delete(session);
......
...@@ -1456,7 +1456,7 @@ static int kvm_events_live(struct perf_kvm_stat *kvm, ...@@ -1456,7 +1456,7 @@ static int kvm_events_live(struct perf_kvm_stat *kvm,
perf_session__set_id_hdr_size(kvm->session); perf_session__set_id_hdr_size(kvm->session);
ordered_events__set_copy_on_queue(&kvm->session->ordered_events, true); ordered_events__set_copy_on_queue(&kvm->session->ordered_events, true);
machine__synthesize_threads(&kvm->session->machines.host, &kvm->opts.target, machine__synthesize_threads(&kvm->session->machines.host, &kvm->opts.target,
kvm->evlist->core.threads, false, 1); kvm->evlist->core.threads, true, false, 1);
err = kvm_live_open_events(kvm); err = kvm_live_open_events(kvm);
if (err) if (err)
goto out; goto out;
......
...@@ -1266,6 +1266,7 @@ static int record__synthesize_workload(struct record *rec, bool tail) ...@@ -1266,6 +1266,7 @@ static int record__synthesize_workload(struct record *rec, bool tail)
err = perf_event__synthesize_thread_map(&rec->tool, thread_map, err = perf_event__synthesize_thread_map(&rec->tool, thread_map,
process_synthesized_event, process_synthesized_event,
&rec->session->machines.host, &rec->session->machines.host,
true,
rec->opts.sample_address); rec->opts.sample_address);
perf_thread_map__put(thread_map); perf_thread_map__put(thread_map);
return err; return err;
...@@ -1480,8 +1481,9 @@ static int record__synthesize(struct record *rec, bool tail) ...@@ -1480,8 +1481,9 @@ static int record__synthesize(struct record *rec, bool tail)
f = process_locked_synthesized_event; f = process_locked_synthesized_event;
} }
err = __machine__synthesize_threads(machine, tool, &opts->target, rec->evlist->core.threads, err = __machine__synthesize_threads(machine, tool, &opts->target,
f, opts->sample_address, rec->evlist->core.threads,
f, true, opts->sample_address,
rec->opts.nr_threads_synthesize); rec->opts.nr_threads_synthesize);
if (rec->opts.nr_threads_synthesize > 1) if (rec->opts.nr_threads_synthesize > 1)
......
...@@ -1271,7 +1271,7 @@ static int __cmd_top(struct perf_top *top) ...@@ -1271,7 +1271,7 @@ static int __cmd_top(struct perf_top *top)
pr_debug("Couldn't synthesize cgroup events.\n"); pr_debug("Couldn't synthesize cgroup events.\n");
machine__synthesize_threads(&top->session->machines.host, &opts->target, machine__synthesize_threads(&top->session->machines.host, &opts->target,
top->evlist->core.threads, false, top->evlist->core.threads, true, false,
top->nr_threads_synthesize); top->nr_threads_synthesize);
if (top->nr_threads_synthesize > 1) if (top->nr_threads_synthesize > 1)
......
...@@ -1628,8 +1628,8 @@ static int trace__symbols_init(struct trace *trace, struct evlist *evlist) ...@@ -1628,8 +1628,8 @@ static int trace__symbols_init(struct trace *trace, struct evlist *evlist)
goto out; goto out;
err = __machine__synthesize_threads(trace->host, &trace->tool, &trace->opts.target, err = __machine__synthesize_threads(trace->host, &trace->tool, &trace->opts.target,
evlist->core.threads, trace__tool_process, false, evlist->core.threads, trace__tool_process,
1); true, false, 1);
out: out:
if (err) if (err)
symbol__exit(); symbol__exit();
......
...@@ -606,7 +606,8 @@ static int do_test_code_reading(bool try_kcore) ...@@ -606,7 +606,8 @@ static int do_test_code_reading(bool try_kcore)
} }
ret = perf_event__synthesize_thread_map(NULL, threads, ret = perf_event__synthesize_thread_map(NULL, threads,
perf_event__process, machine, false); perf_event__process, machine,
true, false);
if (ret < 0) { if (ret < 0) {
pr_debug("perf_event__synthesize_thread_map failed\n"); pr_debug("perf_event__synthesize_thread_map failed\n");
goto out_err; goto out_err;
......
...@@ -135,7 +135,7 @@ static int synth_all(struct machine *machine) ...@@ -135,7 +135,7 @@ static int synth_all(struct machine *machine)
{ {
return perf_event__synthesize_threads(NULL, return perf_event__synthesize_threads(NULL,
perf_event__process, perf_event__process,
machine, 0, 1); machine, 1, 0, 1);
} }
static int synth_process(struct machine *machine) static int synth_process(struct machine *machine)
...@@ -147,7 +147,7 @@ static int synth_process(struct machine *machine) ...@@ -147,7 +147,7 @@ static int synth_process(struct machine *machine)
err = perf_event__synthesize_thread_map(NULL, map, err = perf_event__synthesize_thread_map(NULL, map,
perf_event__process, perf_event__process,
machine, 0); machine, 1, 0);
perf_thread_map__put(map); perf_thread_map__put(map);
return err; return err;
......
...@@ -715,7 +715,8 @@ static int __event__synthesize_thread(union perf_event *comm_event, ...@@ -715,7 +715,8 @@ static int __event__synthesize_thread(union perf_event *comm_event,
union perf_event *fork_event, union perf_event *fork_event,
union perf_event *namespaces_event, union perf_event *namespaces_event,
pid_t pid, int full, perf_event__handler_t process, pid_t pid, int full, perf_event__handler_t process,
struct perf_tool *tool, struct machine *machine, bool mmap_data) struct perf_tool *tool, struct machine *machine,
bool needs_mmap, bool mmap_data)
{ {
char filename[PATH_MAX]; char filename[PATH_MAX];
struct dirent **dirent; struct dirent **dirent;
...@@ -739,7 +740,7 @@ static int __event__synthesize_thread(union perf_event *comm_event, ...@@ -739,7 +740,7 @@ static int __event__synthesize_thread(union perf_event *comm_event,
* send mmap only for thread group leader * send mmap only for thread group leader
* see thread__init_maps() * see thread__init_maps()
*/ */
if (pid == tgid && if (pid == tgid && needs_mmap &&
perf_event__synthesize_mmap_events(tool, mmap_event, pid, tgid, perf_event__synthesize_mmap_events(tool, mmap_event, pid, tgid,
process, machine, mmap_data)) process, machine, mmap_data))
return -1; return -1;
...@@ -786,7 +787,7 @@ static int __event__synthesize_thread(union perf_event *comm_event, ...@@ -786,7 +787,7 @@ static int __event__synthesize_thread(union perf_event *comm_event,
break; break;
rc = 0; rc = 0;
if (_pid == pid && !kernel_thread) { if (_pid == pid && !kernel_thread && needs_mmap) {
/* process the parent's maps too */ /* process the parent's maps too */
rc = perf_event__synthesize_mmap_events(tool, mmap_event, pid, tgid, rc = perf_event__synthesize_mmap_events(tool, mmap_event, pid, tgid,
process, machine, mmap_data); process, machine, mmap_data);
...@@ -806,7 +807,7 @@ int perf_event__synthesize_thread_map(struct perf_tool *tool, ...@@ -806,7 +807,7 @@ int perf_event__synthesize_thread_map(struct perf_tool *tool,
struct perf_thread_map *threads, struct perf_thread_map *threads,
perf_event__handler_t process, perf_event__handler_t process,
struct machine *machine, struct machine *machine,
bool mmap_data) bool needs_mmap, bool mmap_data)
{ {
union perf_event *comm_event, *mmap_event, *fork_event; union perf_event *comm_event, *mmap_event, *fork_event;
union perf_event *namespaces_event; union perf_event *namespaces_event;
...@@ -836,7 +837,7 @@ int perf_event__synthesize_thread_map(struct perf_tool *tool, ...@@ -836,7 +837,7 @@ int perf_event__synthesize_thread_map(struct perf_tool *tool,
fork_event, namespaces_event, fork_event, namespaces_event,
perf_thread_map__pid(threads, thread), 0, perf_thread_map__pid(threads, thread), 0,
process, tool, machine, process, tool, machine,
mmap_data)) { needs_mmap, mmap_data)) {
err = -1; err = -1;
break; break;
} }
...@@ -862,7 +863,7 @@ int perf_event__synthesize_thread_map(struct perf_tool *tool, ...@@ -862,7 +863,7 @@ int perf_event__synthesize_thread_map(struct perf_tool *tool,
fork_event, namespaces_event, fork_event, namespaces_event,
comm_event->comm.pid, 0, comm_event->comm.pid, 0,
process, tool, machine, process, tool, machine,
mmap_data)) { needs_mmap, mmap_data)) {
err = -1; err = -1;
break; break;
} }
...@@ -882,6 +883,7 @@ int perf_event__synthesize_thread_map(struct perf_tool *tool, ...@@ -882,6 +883,7 @@ int perf_event__synthesize_thread_map(struct perf_tool *tool,
static int __perf_event__synthesize_threads(struct perf_tool *tool, static int __perf_event__synthesize_threads(struct perf_tool *tool,
perf_event__handler_t process, perf_event__handler_t process,
struct machine *machine, struct machine *machine,
bool needs_mmap,
bool mmap_data, bool mmap_data,
struct dirent **dirent, struct dirent **dirent,
int start, int start,
...@@ -926,7 +928,7 @@ static int __perf_event__synthesize_threads(struct perf_tool *tool, ...@@ -926,7 +928,7 @@ static int __perf_event__synthesize_threads(struct perf_tool *tool,
*/ */
__event__synthesize_thread(comm_event, mmap_event, fork_event, __event__synthesize_thread(comm_event, mmap_event, fork_event,
namespaces_event, pid, 1, process, namespaces_event, pid, 1, process,
tool, machine, mmap_data); tool, machine, needs_mmap, mmap_data);
} }
err = 0; err = 0;
...@@ -945,6 +947,7 @@ struct synthesize_threads_arg { ...@@ -945,6 +947,7 @@ struct synthesize_threads_arg {
struct perf_tool *tool; struct perf_tool *tool;
perf_event__handler_t process; perf_event__handler_t process;
struct machine *machine; struct machine *machine;
bool needs_mmap;
bool mmap_data; bool mmap_data;
struct dirent **dirent; struct dirent **dirent;
int num; int num;
...@@ -956,7 +959,8 @@ static void *synthesize_threads_worker(void *arg) ...@@ -956,7 +959,8 @@ static void *synthesize_threads_worker(void *arg)
struct synthesize_threads_arg *args = arg; struct synthesize_threads_arg *args = arg;
__perf_event__synthesize_threads(args->tool, args->process, __perf_event__synthesize_threads(args->tool, args->process,
args->machine, args->mmap_data, args->machine,
args->needs_mmap, args->mmap_data,
args->dirent, args->dirent,
args->start, args->num); args->start, args->num);
return NULL; return NULL;
...@@ -965,7 +969,7 @@ static void *synthesize_threads_worker(void *arg) ...@@ -965,7 +969,7 @@ static void *synthesize_threads_worker(void *arg)
int perf_event__synthesize_threads(struct perf_tool *tool, int perf_event__synthesize_threads(struct perf_tool *tool,
perf_event__handler_t process, perf_event__handler_t process,
struct machine *machine, struct machine *machine,
bool mmap_data, bool needs_mmap, bool mmap_data,
unsigned int nr_threads_synthesize) unsigned int nr_threads_synthesize)
{ {
struct synthesize_threads_arg *args = NULL; struct synthesize_threads_arg *args = NULL;
...@@ -994,7 +998,8 @@ int perf_event__synthesize_threads(struct perf_tool *tool, ...@@ -994,7 +998,8 @@ int perf_event__synthesize_threads(struct perf_tool *tool,
if (thread_nr <= 1) { if (thread_nr <= 1) {
err = __perf_event__synthesize_threads(tool, process, err = __perf_event__synthesize_threads(tool, process,
machine, mmap_data, machine,
needs_mmap, mmap_data,
dirent, base, n); dirent, base, n);
goto free_dirent; goto free_dirent;
} }
...@@ -1015,6 +1020,7 @@ int perf_event__synthesize_threads(struct perf_tool *tool, ...@@ -1015,6 +1020,7 @@ int perf_event__synthesize_threads(struct perf_tool *tool,
args[i].tool = tool; args[i].tool = tool;
args[i].process = process; args[i].process = process;
args[i].machine = machine; args[i].machine = machine;
args[i].needs_mmap = needs_mmap;
args[i].mmap_data = mmap_data; args[i].mmap_data = mmap_data;
args[i].dirent = dirent; args[i].dirent = dirent;
} }
...@@ -1775,26 +1781,27 @@ int perf_event__synthesize_id_index(struct perf_tool *tool, perf_event__handler_ ...@@ -1775,26 +1781,27 @@ int perf_event__synthesize_id_index(struct perf_tool *tool, perf_event__handler_
int __machine__synthesize_threads(struct machine *machine, struct perf_tool *tool, int __machine__synthesize_threads(struct machine *machine, struct perf_tool *tool,
struct target *target, struct perf_thread_map *threads, struct target *target, struct perf_thread_map *threads,
perf_event__handler_t process, bool data_mmap, perf_event__handler_t process, bool needs_mmap,
unsigned int nr_threads_synthesize) bool data_mmap, unsigned int nr_threads_synthesize)
{ {
if (target__has_task(target)) if (target__has_task(target))
return perf_event__synthesize_thread_map(tool, threads, process, machine, data_mmap); return perf_event__synthesize_thread_map(tool, threads, process, machine,
needs_mmap, data_mmap);
else if (target__has_cpu(target)) else if (target__has_cpu(target))
return perf_event__synthesize_threads(tool, process, return perf_event__synthesize_threads(tool, process, machine,
machine, data_mmap, needs_mmap, data_mmap,
nr_threads_synthesize); nr_threads_synthesize);
/* command specified */ /* command specified */
return 0; return 0;
} }
int machine__synthesize_threads(struct machine *machine, struct target *target, int machine__synthesize_threads(struct machine *machine, struct target *target,
struct perf_thread_map *threads, bool data_mmap, struct perf_thread_map *threads, bool needs_mmap,
unsigned int nr_threads_synthesize) bool data_mmap, unsigned int nr_threads_synthesize)
{ {
return __machine__synthesize_threads(machine, NULL, target, threads, return __machine__synthesize_threads(machine, NULL, target, threads,
perf_event__process, data_mmap, perf_event__process, needs_mmap,
nr_threads_synthesize); data_mmap, nr_threads_synthesize);
} }
static struct perf_record_event_update *event_update_event__new(size_t size, u64 type, u64 id) static struct perf_record_event_update *event_update_event__new(size_t size, u64 type, u64 id)
......
...@@ -53,8 +53,8 @@ int perf_event__synthesize_stat_events(struct perf_stat_config *config, struct p ...@@ -53,8 +53,8 @@ int perf_event__synthesize_stat_events(struct perf_stat_config *config, struct p
int perf_event__synthesize_stat_round(struct perf_tool *tool, u64 time, u64 type, perf_event__handler_t process, struct machine *machine); int perf_event__synthesize_stat_round(struct perf_tool *tool, u64 time, u64 type, perf_event__handler_t process, struct machine *machine);
int perf_event__synthesize_stat(struct perf_tool *tool, u32 cpu, u32 thread, u64 id, struct perf_counts_values *count, perf_event__handler_t process, struct machine *machine); int perf_event__synthesize_stat(struct perf_tool *tool, u32 cpu, u32 thread, u64 id, struct perf_counts_values *count, perf_event__handler_t process, struct machine *machine);
int perf_event__synthesize_thread_map2(struct perf_tool *tool, struct perf_thread_map *threads, perf_event__handler_t process, struct machine *machine); int perf_event__synthesize_thread_map2(struct perf_tool *tool, struct perf_thread_map *threads, perf_event__handler_t process, struct machine *machine);
int perf_event__synthesize_thread_map(struct perf_tool *tool, struct perf_thread_map *threads, perf_event__handler_t process, struct machine *machine, bool mmap_data); int perf_event__synthesize_thread_map(struct perf_tool *tool, struct perf_thread_map *threads, perf_event__handler_t process, struct machine *machine, bool needs_mmap, bool mmap_data);
int perf_event__synthesize_threads(struct perf_tool *tool, perf_event__handler_t process, struct machine *machine, bool mmap_data, unsigned int nr_threads_synthesize); int perf_event__synthesize_threads(struct perf_tool *tool, perf_event__handler_t process, struct machine *machine, bool needs_mmap, bool mmap_data, unsigned int nr_threads_synthesize);
int perf_event__synthesize_tracing_data(struct perf_tool *tool, int fd, struct evlist *evlist, perf_event__handler_t process); int perf_event__synthesize_tracing_data(struct perf_tool *tool, int fd, struct evlist *evlist, perf_event__handler_t process);
int perf_event__synth_time_conv(const struct perf_event_mmap_page *pc, struct perf_tool *tool, perf_event__handler_t process, struct machine *machine); int perf_event__synth_time_conv(const struct perf_event_mmap_page *pc, struct perf_tool *tool, perf_event__handler_t process, struct machine *machine);
pid_t perf_event__synthesize_comm(struct perf_tool *tool, union perf_event *event, pid_t pid, perf_event__handler_t process, struct machine *machine); pid_t perf_event__synthesize_comm(struct perf_tool *tool, union perf_event *event, pid_t pid, perf_event__handler_t process, struct machine *machine);
...@@ -65,10 +65,10 @@ size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type, ...@@ -65,10 +65,10 @@ size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type,
int __machine__synthesize_threads(struct machine *machine, struct perf_tool *tool, int __machine__synthesize_threads(struct machine *machine, struct perf_tool *tool,
struct target *target, struct perf_thread_map *threads, struct target *target, struct perf_thread_map *threads,
perf_event__handler_t process, bool data_mmap, perf_event__handler_t process, bool needs_mmap, bool data_mmap,
unsigned int nr_threads_synthesize); unsigned int nr_threads_synthesize);
int machine__synthesize_threads(struct machine *machine, struct target *target, int machine__synthesize_threads(struct machine *machine, struct target *target,
struct perf_thread_map *threads, bool data_mmap, struct perf_thread_map *threads, bool needs_mmap, bool data_mmap,
unsigned int nr_threads_synthesize); unsigned int nr_threads_synthesize);
#ifdef HAVE_AUXTRACE_SUPPORT #ifdef HAVE_AUXTRACE_SUPPORT
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment