[PATCH RFC 05/10] perf,tools: record counter statistics during sampling

From: kan . liang
Date: Tue Sep 22 2015 - 17:32:10 EST


From: Kan Liang <kan.liang@xxxxxxxxx>

Reading at the start and the end of sampling, and save the counter
statistics value to PERF_RECORD_COUNTER_READ.

Signed-off-by: Kan Liang <kan.liang@xxxxxxxxx>
---
tools/perf/builtin-record.c | 36 ++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 142eeb3..cc8fd08 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -398,6 +398,40 @@ static struct perf_event_header finished_round_event = {
.type = PERF_RECORD_FINISHED_ROUND,
};

+static void process_counter_read_event(struct record *rec, int id,
+ struct perf_evsel *pos,
+ struct perf_counts_values *count)
+{
+ union perf_event ev;
+
+ memset(&ev, 0, sizeof(ev));
+ ev.counter_read.header.type = PERF_RECORD_COUNTER_READ;
+ ev.counter_read.header.size = sizeof(ev.counter_read);
+ ev.counter_read.cpu = pos->cpus->map[id];
+ ev.counter_read.idx = pos->idx;
+ memcpy(ev.counter_read.values, count, 3 * sizeof(u64));
+
+ record__write(rec, &ev, sizeof(ev.counter_read));
+}
+
+static void perf_read_counter(struct record *rec)
+{
+ struct perf_evlist *evlist = rec->evlist;
+ struct perf_counts_values count;
+ struct perf_evsel *pos;
+ int cpu;
+
+ evlist__for_each(evlist, pos) {
+ if (!pos->counter_read)
+ continue;
+
+ for (cpu = 0; cpu < cpu_map__nr(pos->cpus); cpu++) {
+ if (!perf_evsel__read(pos, cpu, 0, &count))
+ process_counter_read_event(rec, cpu, pos, &count);
+ }
+ }
+}
+
static int record__mmap_read_all(struct record *rec)
{
u64 bytes_written = rec->bytes_written;
@@ -644,6 +678,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
perf_evlist__enable(rec->evlist);
}

+ perf_read_counter(rec);
auxtrace_snapshot_enabled = 1;
for (;;) {
int hits = rec->samples;
@@ -688,6 +723,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
*/
if (done && !disabled && !target__none(&opts->target)) {
auxtrace_snapshot_enabled = 0;
+ perf_read_counter(rec);
perf_evlist__disable(rec->evlist);
disabled = true;
}
--
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/