Commit 3461b65d authored by Adrian Hunter's avatar Adrian Hunter Committed by Arnaldo Carvalho de Melo
Browse files

perf tools: Add machine_pid and vcpu to perf_sample



When parsing a sample with a sample ID, copy machine_pid and vcpu from
perf_sample_id to perf_sample.

Note, machine_pid will be zero when unused, so only a non-zero value
represents a guest machine. vcpu should be ignored if machine_pid is zero.

Note also, machine_pid is used with events that have come from injecting a
guest perf.data file, however guest events recorded on the host (i.e. using
perf kvm) have the (QEMU) hypervisor process pid to identify them - refer
machines__find_for_cpumode().

Signed-off-by: default avatarAdrian Hunter <adrian.hunter@intel.com>
Acked-by: default avatarIan Rogers <irogers@google.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: kvm@vger.kernel.org
Link: https://lore.kernel.org/r/20220711093218.10967-14-adrian.hunter@intel.com


Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 797efbc5
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -148,6 +148,8 @@ struct perf_sample {
	u64 code_page_size;
	u64 cgroup;
	u32 flags;
	u32 machine_pid;
	u32 vcpu;
	u16 insn_len;
	u8  cpumode;
	u16 misc;
+13 −1
Original line number Diff line number Diff line
@@ -1507,10 +1507,22 @@ int evlist__start_workload(struct evlist *evlist)
int evlist__parse_sample(struct evlist *evlist, union perf_event *event, struct perf_sample *sample)
{
	struct evsel *evsel = evlist__event2evsel(evlist, event);
	int ret;

	if (!evsel)
		return -EFAULT;
	return evsel__parse_sample(evsel, event, sample);
	ret = evsel__parse_sample(evsel, event, sample);
	if (ret)
		return ret;
	if (perf_guest && sample->id) {
		struct perf_sample_id *sid = evlist__id2sid(evlist, sample->id);

		if (sid) {
			sample->machine_pid = sid->machine_pid;
			sample->vcpu = sid->vcpu.cpu;
		}
	}
	return 0;
}

int evlist__parse_sample_timestamp(struct evlist *evlist, union perf_event *event, u64 *timestamp)
+1 −0
Original line number Diff line number Diff line
@@ -2365,6 +2365,7 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event,
	data->misc    = event->header.misc;
	data->id = -1ULL;
	data->data_src = PERF_MEM_DATA_SRC_NONE;
	data->vcpu = -1;

	if (event->header.type != PERF_RECORD_SAMPLE) {
		if (!evsel->core.attr.sample_id_all)