perf tools: Move event__parse_sample to evsel.c
To avoid linking more stuff in the python binding I'm working on, future csets will make the sample type be taken from the evsel itself, but for that we need to first have one file per cpu and per sample_type, not a single perf.data file. Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: Mike Galbraith <efault@gmx.de> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Cc: Tom Zanussi <tzanussi@gmail.com> LKML-Reference: <new-submission> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
@@ -355,3 +355,121 @@ out_unmap:
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int event__parse_id_sample(const event_t *event, u64 type,
|
||||
struct sample_data *sample)
|
||||
{
|
||||
const u64 *array = event->sample.array;
|
||||
|
||||
array += ((event->header.size -
|
||||
sizeof(event->header)) / sizeof(u64)) - 1;
|
||||
|
||||
if (type & PERF_SAMPLE_CPU) {
|
||||
u32 *p = (u32 *)array;
|
||||
sample->cpu = *p;
|
||||
array--;
|
||||
}
|
||||
|
||||
if (type & PERF_SAMPLE_STREAM_ID) {
|
||||
sample->stream_id = *array;
|
||||
array--;
|
||||
}
|
||||
|
||||
if (type & PERF_SAMPLE_ID) {
|
||||
sample->id = *array;
|
||||
array--;
|
||||
}
|
||||
|
||||
if (type & PERF_SAMPLE_TIME) {
|
||||
sample->time = *array;
|
||||
array--;
|
||||
}
|
||||
|
||||
if (type & PERF_SAMPLE_TID) {
|
||||
u32 *p = (u32 *)array;
|
||||
sample->pid = p[0];
|
||||
sample->tid = p[1];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int event__parse_sample(const event_t *event, u64 type, bool sample_id_all,
|
||||
struct sample_data *data)
|
||||
{
|
||||
const u64 *array;
|
||||
|
||||
data->cpu = data->pid = data->tid = -1;
|
||||
data->stream_id = data->id = data->time = -1ULL;
|
||||
|
||||
if (event->header.type != PERF_RECORD_SAMPLE) {
|
||||
if (!sample_id_all)
|
||||
return 0;
|
||||
return event__parse_id_sample(event, type, data);
|
||||
}
|
||||
|
||||
array = event->sample.array;
|
||||
|
||||
if (type & PERF_SAMPLE_IP) {
|
||||
data->ip = event->ip.ip;
|
||||
array++;
|
||||
}
|
||||
|
||||
if (type & PERF_SAMPLE_TID) {
|
||||
u32 *p = (u32 *)array;
|
||||
data->pid = p[0];
|
||||
data->tid = p[1];
|
||||
array++;
|
||||
}
|
||||
|
||||
if (type & PERF_SAMPLE_TIME) {
|
||||
data->time = *array;
|
||||
array++;
|
||||
}
|
||||
|
||||
if (type & PERF_SAMPLE_ADDR) {
|
||||
data->addr = *array;
|
||||
array++;
|
||||
}
|
||||
|
||||
data->id = -1ULL;
|
||||
if (type & PERF_SAMPLE_ID) {
|
||||
data->id = *array;
|
||||
array++;
|
||||
}
|
||||
|
||||
if (type & PERF_SAMPLE_STREAM_ID) {
|
||||
data->stream_id = *array;
|
||||
array++;
|
||||
}
|
||||
|
||||
if (type & PERF_SAMPLE_CPU) {
|
||||
u32 *p = (u32 *)array;
|
||||
data->cpu = *p;
|
||||
array++;
|
||||
}
|
||||
|
||||
if (type & PERF_SAMPLE_PERIOD) {
|
||||
data->period = *array;
|
||||
array++;
|
||||
}
|
||||
|
||||
if (type & PERF_SAMPLE_READ) {
|
||||
fprintf(stderr, "PERF_SAMPLE_READ is unsuported for now\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (type & PERF_SAMPLE_CALLCHAIN) {
|
||||
data->callchain = (struct ip_callchain *)array;
|
||||
array += 1 + data->callchain->nr;
|
||||
}
|
||||
|
||||
if (type & PERF_SAMPLE_RAW) {
|
||||
u32 *p = (u32 *)array;
|
||||
data->raw_size = *p;
|
||||
p++;
|
||||
data->raw_data = p;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user