@@ -1465,6 +1465,98 @@ int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event,
1465
1465
return 0 ;
1466
1466
}
1467
1467
1468
+ size_t perf_event__sample_event_size (const struct perf_sample * sample , u64 type ,
1469
+ u64 sample_regs_user , u64 read_format )
1470
+ {
1471
+ size_t sz , result = sizeof (struct sample_event );
1472
+
1473
+ if (type & PERF_SAMPLE_IDENTIFIER )
1474
+ result += sizeof (u64 );
1475
+
1476
+ if (type & PERF_SAMPLE_IP )
1477
+ result += sizeof (u64 );
1478
+
1479
+ if (type & PERF_SAMPLE_TID )
1480
+ result += sizeof (u64 );
1481
+
1482
+ if (type & PERF_SAMPLE_TIME )
1483
+ result += sizeof (u64 );
1484
+
1485
+ if (type & PERF_SAMPLE_ADDR )
1486
+ result += sizeof (u64 );
1487
+
1488
+ if (type & PERF_SAMPLE_ID )
1489
+ result += sizeof (u64 );
1490
+
1491
+ if (type & PERF_SAMPLE_STREAM_ID )
1492
+ result += sizeof (u64 );
1493
+
1494
+ if (type & PERF_SAMPLE_CPU )
1495
+ result += sizeof (u64 );
1496
+
1497
+ if (type & PERF_SAMPLE_PERIOD )
1498
+ result += sizeof (u64 );
1499
+
1500
+ if (type & PERF_SAMPLE_READ ) {
1501
+ result += sizeof (u64 );
1502
+ if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED )
1503
+ result += sizeof (u64 );
1504
+ if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING )
1505
+ result += sizeof (u64 );
1506
+ /* PERF_FORMAT_ID is forced for PERF_SAMPLE_READ */
1507
+ if (read_format & PERF_FORMAT_GROUP ) {
1508
+ sz = sample -> read .group .nr *
1509
+ sizeof (struct sample_read_value );
1510
+ result += sz ;
1511
+ } else {
1512
+ result += sizeof (u64 );
1513
+ }
1514
+ }
1515
+
1516
+ if (type & PERF_SAMPLE_CALLCHAIN ) {
1517
+ sz = (sample -> callchain -> nr + 1 ) * sizeof (u64 );
1518
+ result += sz ;
1519
+ }
1520
+
1521
+ if (type & PERF_SAMPLE_RAW ) {
1522
+ result += sizeof (u32 );
1523
+ result += sample -> raw_size ;
1524
+ }
1525
+
1526
+ if (type & PERF_SAMPLE_BRANCH_STACK ) {
1527
+ sz = sample -> branch_stack -> nr * sizeof (struct branch_entry );
1528
+ sz += sizeof (u64 );
1529
+ result += sz ;
1530
+ }
1531
+
1532
+ if (type & PERF_SAMPLE_REGS_USER ) {
1533
+ if (sample -> user_regs .abi ) {
1534
+ result += sizeof (u64 );
1535
+ sz = hweight_long (sample_regs_user ) * sizeof (u64 );
1536
+ result += sz ;
1537
+ } else {
1538
+ result += sizeof (u64 );
1539
+ }
1540
+ }
1541
+
1542
+ if (type & PERF_SAMPLE_STACK_USER ) {
1543
+ sz = sample -> user_stack .size ;
1544
+ result += sizeof (u64 );
1545
+ if (sz ) {
1546
+ result += sz ;
1547
+ result += sizeof (u64 );
1548
+ }
1549
+ }
1550
+
1551
+ if (type & PERF_SAMPLE_WEIGHT )
1552
+ result += sizeof (u64 );
1553
+
1554
+ if (type & PERF_SAMPLE_DATA_SRC )
1555
+ result += sizeof (u64 );
1556
+
1557
+ return result ;
1558
+ }
1559
+
1468
1560
int perf_event__synthesize_sample (union perf_event * event , u64 type ,
1469
1561
u64 sample_regs_user , u64 read_format ,
1470
1562
const struct perf_sample * sample ,
0 commit comments