lkml.org 
[lkml]   [2015]   [Sep]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH RFC 05/10] perf,tools: record counter statistics during sampling
Date
From: Kan Liang <kan.liang@intel.com>

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@intel.com>
---
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


\
 
 \ /
  Last update: 2015-09-22 23:41    [W:0.181 / U:0.232 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site