aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/evsel.c
diff options
context:
space:
mode:
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}