[PATCH RFC 04/10] perf,tools: New RECORD type PERF_RECORD_COUNTER_READ

From: kan . liang
Date: Tue Sep 22 2015 - 17:30:53 EST


From: Kan Liang <kan.liang@xxxxxxxxx>

Introduce a new user RECORD type PERF_RECORD_COUNTER_READ to store the
counter statistics result.

Signed-off-by: Kan Liang <kan.liang@xxxxxxxxx>
---
tools/perf/util/event.c | 1 +
tools/perf/util/event.h | 18 ++++++++++++++++++
tools/perf/util/session.c | 16 ++++++++++++++++
tools/perf/util/tool.h | 1 +
4 files changed, 36 insertions(+)

diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index 497157a..608c83a 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -37,6 +37,7 @@ static const char *perf_event__names[] = {
[PERF_RECORD_AUXTRACE_INFO] = "AUXTRACE_INFO",
[PERF_RECORD_AUXTRACE] = "AUXTRACE",
[PERF_RECORD_AUXTRACE_ERROR] = "AUXTRACE_ERROR",
+ [PERF_RECORD_COUNTER_READ] = "COUNTER_READ",
};

const char *perf_event__name(unsigned int id)
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
index f729df5..7f125ce 100644
--- a/tools/perf/util/event.h
+++ b/tools/perf/util/event.h
@@ -226,6 +226,7 @@ enum perf_user_event_type { /* above any possible kernel type */
PERF_RECORD_AUXTRACE_INFO = 70,
PERF_RECORD_AUXTRACE = 71,
PERF_RECORD_AUXTRACE_ERROR = 72,
+ PERF_RECORD_COUNTER_READ = 73,
PERF_RECORD_HEADER_MAX
};

@@ -355,6 +356,22 @@ struct context_switch_event {
u32 next_prev_tid;
};

+struct counter_read_event {
+ struct perf_event_header header;
+
+ int idx;
+ u32 cpu;
+
+ union {
+ struct {
+ u64 val;
+ u64 ena;
+ u64 run;
+ };
+ u64 values[3];
+ };
+};
+
union perf_event {
struct perf_event_header header;
struct mmap_event mmap;
@@ -377,6 +394,7 @@ union perf_event {
struct aux_event aux;
struct itrace_start_event itrace_start;
struct context_switch_event context_switch;
+ struct counter_read_event counter_read;
};

void perf_event__print_totals(void);
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index d1a43a3..4d5c644 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -322,6 +322,8 @@ void perf_tool__fill_defaults(struct perf_tool *tool)
tool->context_switch = perf_event__process_switch;
if (tool->read == NULL)
tool->read = process_event_sample_stub;
+ if (tool->counter_read == NULL)
+ tool->counter_read = process_build_id_stub;
if (tool->throttle == NULL)
tool->throttle = process_event_stub;
if (tool->unthrottle == NULL)
@@ -425,6 +427,17 @@ static void perf_event__task_swap(union perf_event *event, bool sample_id_all)
swap_sample_id_all(event, &event->fork + 1);
}

+static void perf_event__counter_read_swap(union perf_event *event,
+ bool sample_id_all __maybe_unused)
+{
+ event->counter_read.idx = bswap_32(event->counter_read.idx);
+ event->counter_read.cpu = bswap_32(event->counter_read.cpu);
+
+ event->counter_read.val = bswap_64(event->counter_read.val);
+ event->counter_read.ena = bswap_64(event->counter_read.ena);
+ event->counter_read.run = bswap_64(event->counter_read.run);
+}
+
static void perf_event__read_swap(union perf_event *event, bool sample_id_all)
{
event->read.pid = bswap_32(event->read.pid);
@@ -627,6 +640,7 @@ static perf_event__swap_op perf_event__swap_ops[] = {
[PERF_RECORD_EXIT] = perf_event__task_swap,
[PERF_RECORD_LOST] = perf_event__all64_swap,
[PERF_RECORD_READ] = perf_event__read_swap,
+ [PERF_RECORD_COUNTER_READ] = perf_event__counter_read_swap,
[PERF_RECORD_THROTTLE] = perf_event__throttle_swap,
[PERF_RECORD_UNTHROTTLE] = perf_event__throttle_swap,
[PERF_RECORD_SAMPLE] = perf_event__all64_swap,
@@ -1176,6 +1190,8 @@ static s64 perf_session__process_user_event(struct perf_session *session,
case PERF_RECORD_AUXTRACE_ERROR:
perf_session__auxtrace_error_inc(session, event);
return tool->auxtrace_error(tool, event, session);
+ case PERF_RECORD_COUNTER_READ:
+ return tool->counter_read(tool, event, session);
default:
return -EINVAL;
}
diff --git a/tools/perf/util/tool.h b/tools/perf/util/tool.h
index cab8cc2..89477b2 100644
--- a/tools/perf/util/tool.h
+++ b/tools/perf/util/tool.h
@@ -57,6 +57,7 @@ struct perf_tool {
auxtrace_info,
auxtrace_error;
event_op3 auxtrace;
+ event_op2 counter_read;
bool ordered_events;
bool ordering_requires_timestamps;
};
--
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/