aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/evsel.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2011-01-21 10:46:41 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2011-01-24 10:17:56 -0500
commitd0dd74e853a0a6f37e8061d6d50be41c7034c54c (patch)
tree1292a98711611cbc4595785ed17605f20a90800c /tools/perf/util/evsel.c
parentfd78260b5376173faeb17127bd63b3c99a8e8bfb (diff)
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>
Diffstat (limited to 'tools/perf/util/evsel.c')
-rw-r--r--tools/perf/util/evsel.c118
1 files changed, 118 insertions, 0 deletions
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 9a6d94299ab8..a85ae12845ea 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -355,3 +355,121 @@ out_unmap:
355 } 355 }
356 return -1; 356 return -1;
357} 357}
358
359static int event__parse_id_sample(const event_t *event, u64 type,
360 struct sample_data *sample)
361{
362 const u64 *array = event->sample.array;
363
364 array += ((event->header.size -
365 sizeof(event->header)) / sizeof(u64)) - 1;
366
367 if (type & PERF_SAMPLE_CPU) {
368 u32 *p = (u32 *)array;
369 sample->cpu = *p;
370 array--;
371 }
372
373 if (type & PERF_SAMPLE_STREAM_ID) {
374 sample->stream_id = *array;
375 array--;
376 }
377
378 if (type & PERF_SAMPLE_ID) {
379 sample->id = *array;
380 array--;
381 }
382
383 if (type & PERF_SAMPLE_TIME) {
384 sample->time = *array;
385 array--;
386 }
387
388 if (type & PERF_SAMPLE_TID) {
389 u32 *p = (u32 *)array;
390 sample->pid = p[0];
391 sample->tid = p[1];
392 }
393
394 return 0;
395}
396
397int event__parse_sample(const event_t *event, u64 type, bool sample_id_all,
398 struct sample_data *data)
399{
400 const u64 *array;
401
402 data->cpu = data->pid = data->tid = -1;
403 data->stream_id = data->id = data->time = -1ULL;
404
405 if (event->header.type != PERF_RECORD_SAMPLE) {
406 if (!sample_id_all)
407 return 0;
408 return event__parse_id_sample(event, type, data);
409 }
410
411 array = event->sample.array;
412
413 if (type & PERF_SAMPLE_IP) {
414 data->ip = event->ip.ip;
415 array++;
416 }
417
418 if (type & PERF_SAMPLE_TID) {
419 u32 *p = (u32 *)array;
420 data->pid = p[0];
421 data->tid = p[1];
422 array++;
423 }
424
425 if (type & PERF_SAMPLE_TIME) {
426 data->time = *array;
427 array++;
428 }
429
430 if (type & PERF_SAMPLE_ADDR) {
431 data->addr = *array;
432 array++;
433 }
434
435 data->id = -1ULL;
436 if (type & PERF_SAMPLE_ID) {
437 data->id = *array;
438 array++;
439 }
440
441 if (type & PERF_SAMPLE_STREAM_ID) {
442 data->stream_id = *array;
443 array++;
444 }
445
446 if (type & PERF_SAMPLE_CPU) {
447 u32 *p = (u32 *)array;
448 data->cpu = *p;
449 array++;
450 }
451
452 if (type & PERF_SAMPLE_PERIOD) {
453 data->period = *array;
454 array++;
455 }
456
457 if (type & PERF_SAMPLE_READ) {
458 fprintf(stderr, "PERF_SAMPLE_READ is unsuported for now\n");
459 return -1;
460 }
461
462 if (type & PERF_SAMPLE_CALLCHAIN) {
463 data->callchain = (struct ip_callchain *)array;
464 array += 1 + data->callchain->nr;
465 }
466
467 if (type & PERF_SAMPLE_RAW) {
468 u32 *p = (u32 *)array;
469 data->raw_size = *p;
470 p++;
471 data->raw_data = p;
472 }
473
474 return 0;
475}