Skip to content

Commit d03f217

Browse files
ahunter6acmel
authored andcommitted
perf tools: Expand perf_event__synthesize_sample()
Expand perf_event__synthesize_sample() to handle all sample format bits. Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Namhyung Kim <namhyung@gmail.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/r/1377591794-30553-10-git-send-email-adrian.hunter@intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 5b95a4a commit d03f217

3 files changed

Lines changed: 97 additions & 3 deletions

File tree

‎tools/perf/builtin-inject.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,9 @@ static int perf_inject__sched_stat(struct perf_tool *tool,
301301
sample_sw.period = sample->period;
302302
sample_sw.time = sample->time;
303303
perf_event__synthesize_sample(event_sw, evsel->attr.sample_type,
304-
&sample_sw, false);
304+
evsel->attr.sample_regs_user,
305+
evsel->attr.read_format, &sample_sw,
306+
false);
305307
build_id__mark_dso_hit(tool, event_sw, &sample_sw, evsel, machine);
306308
return perf_event__repipe(tool, event_sw, &sample_sw, machine);
307309
}

‎tools/perf/util/event.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ int perf_event__preprocess_sample(const union perf_event *self,
230230
const char *perf_event__name(unsigned int id);
231231

232232
int perf_event__synthesize_sample(union perf_event *event, u64 type,
233+
u64 sample_regs_user, u64 read_format,
233234
const struct perf_sample *sample,
234235
bool swapped);
235236

‎tools/perf/util/evsel.c‎

Lines changed: 93 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,7 +1416,6 @@ int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event,
14161416
}
14171417

14181418
if (type & PERF_SAMPLE_REGS_USER) {
1419-
/* First u64 tells us if we have any regs in sample. */
14201419
OVERFLOW_CHECK_u64(array);
14211420
data->user_regs.abi = *array;
14221421
array++;
@@ -1467,11 +1466,12 @@ int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event,
14671466
}
14681467

14691468
int perf_event__synthesize_sample(union perf_event *event, u64 type,
1469+
u64 sample_regs_user, u64 read_format,
14701470
const struct perf_sample *sample,
14711471
bool swapped)
14721472
{
14731473
u64 *array;
1474-
1474+
size_t sz;
14751475
/*
14761476
* used for cross-endian analysis. See git commit 65014ab3
14771477
* for why this goofiness is needed.
@@ -1544,6 +1544,97 @@ int perf_event__synthesize_sample(union perf_event *event, u64 type,
15441544
array++;
15451545
}
15461546

1547+
if (type & PERF_SAMPLE_READ) {
1548+
if (read_format & PERF_FORMAT_GROUP)
1549+
*array = sample->read.group.nr;
1550+
else
1551+
*array = sample->read.one.value;
1552+
array++;
1553+
1554+
if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
1555+
*array = sample->read.time_enabled;
1556+
array++;
1557+
}
1558+
1559+
if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
1560+
*array = sample->read.time_running;
1561+
array++;
1562+
}
1563+
1564+
/* PERF_FORMAT_ID is forced for PERF_SAMPLE_READ */
1565+
if (read_format & PERF_FORMAT_GROUP) {
1566+
sz = sample->read.group.nr *
1567+
sizeof(struct sample_read_value);
1568+
memcpy(array, sample->read.group.values, sz);
1569+
array = (void *)array + sz;
1570+
} else {
1571+
*array = sample->read.one.id;
1572+
array++;
1573+
}
1574+
}
1575+
1576+
if (type & PERF_SAMPLE_CALLCHAIN) {
1577+
sz = (sample->callchain->nr + 1) * sizeof(u64);
1578+
memcpy(array, sample->callchain, sz);
1579+
array = (void *)array + sz;
1580+
}
1581+
1582+
if (type & PERF_SAMPLE_RAW) {
1583+
u.val32[0] = sample->raw_size;
1584+
if (WARN_ONCE(swapped,
1585+
"Endianness of raw data not corrected!\n")) {
1586+
/*
1587+
* Inverse of what is done in perf_evsel__parse_sample
1588+
*/
1589+
u.val32[0] = bswap_32(u.val32[0]);
1590+
u.val32[1] = bswap_32(u.val32[1]);
1591+
u.val64 = bswap_64(u.val64);
1592+
}
1593+
*array = u.val64;
1594+
array = (void *)array + sizeof(u32);
1595+
1596+
memcpy(array, sample->raw_data, sample->raw_size);
1597+
array = (void *)array + sample->raw_size;
1598+
}
1599+
1600+
if (type & PERF_SAMPLE_BRANCH_STACK) {
1601+
sz = sample->branch_stack->nr * sizeof(struct branch_entry);
1602+
sz += sizeof(u64);
1603+
memcpy(array, sample->branch_stack, sz);
1604+
array = (void *)array + sz;
1605+
}
1606+
1607+
if (type & PERF_SAMPLE_REGS_USER) {
1608+
if (sample->user_regs.abi) {
1609+
*array++ = sample->user_regs.abi;
1610+
sz = hweight_long(sample_regs_user) * sizeof(u64);
1611+
memcpy(array, sample->user_regs.regs, sz);
1612+
array = (void *)array + sz;
1613+
} else {
1614+
*array++ = 0;
1615+
}
1616+
}
1617+
1618+
if (type & PERF_SAMPLE_STACK_USER) {
1619+
sz = sample->user_stack.size;
1620+
*array++ = sz;
1621+
if (sz) {
1622+
memcpy(array, sample->user_stack.data, sz);
1623+
array = (void *)array + sz;
1624+
*array++ = sz;
1625+
}
1626+
}
1627+
1628+
if (type & PERF_SAMPLE_WEIGHT) {
1629+
*array = sample->weight;
1630+
array++;
1631+
}
1632+
1633+
if (type & PERF_SAMPLE_DATA_SRC) {
1634+
*array = sample->data_src;
1635+
array++;
1636+
}
1637+
15471638
return 0;
15481639
}
15491640

0 commit comments

Comments
 (0)