[PATCH V3 10/22] perf itrace: Add helpers for Instruction Tracing errors

From: Adrian Hunter
Date: Fri Dec 12 2014 - 08:57:40 EST


Add functions to synthesize, count and print
Instruction Tracing error events.

Signed-off-by: Adrian Hunter <adrian.hunter@xxxxxxxxx>
---
tools/perf/util/itrace.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++
tools/perf/util/itrace.h | 16 ++++++++++++++
2 files changed, 71 insertions(+)

diff --git a/tools/perf/util/itrace.c b/tools/perf/util/itrace.c
index 0d3ff21..a6d38f5 100644
--- a/tools/perf/util/itrace.c
+++ b/tools/perf/util/itrace.c
@@ -22,6 +22,7 @@
#include <linux/types.h>

#include <stdlib.h>
+#include <stdio.h>
#include <string.h>
#include <errno.h>

@@ -33,6 +34,7 @@
#include "itrace.h"

#include "event.h"
+#include "session.h"
#include "debug.h"
#include "parse-options.h"

@@ -158,6 +160,28 @@ itrace_record__init(struct perf_evlist *evlist __maybe_unused, int *err)
return NULL;
}

+void itrace_synth_error(struct itrace_error_event *itrace_error, int type,
+ int code, int cpu, pid_t pid, pid_t tid, u64 ip,
+ const char *msg)
+{
+ size_t size;
+
+ memset(itrace_error, 0, sizeof(struct itrace_error_event));
+
+ itrace_error->header.type = PERF_RECORD_ITRACE_ERROR;
+ itrace_error->type = type;
+ itrace_error->code = code;
+ itrace_error->cpu = cpu;
+ itrace_error->pid = pid;
+ itrace_error->tid = tid;
+ itrace_error->ip = ip;
+ strlcpy(itrace_error->msg, msg, MAX_ITRACE_ERROR_MSG);
+
+ size = (void *)itrace_error->msg - (void *)itrace_error +
+ strlen(itrace_error->msg) + 1;
+ itrace_error->header.size = PERF_ALIGN(size, sizeof(u64));
+}
+
int perf_event__synthesize_itrace_info(struct itrace_record *itr,
struct perf_tool *tool,
struct perf_session *session,
@@ -337,6 +361,37 @@ out_err:
return -EINVAL;
}

+size_t perf_event__fprintf_itrace_error(union perf_event *event, FILE *fp)
+{
+ struct itrace_error_event *e = &event->itrace_error;
+ int ret;
+
+ ret = fprintf(fp, " Instruction trace error type %u", e->type);
+ ret += fprintf(fp, " cpu %d pid %d tid %d ip %#"PRIx64" code %u: %s\n",
+ e->cpu, e->pid, e->tid, e->ip, e->code, e->msg);
+ return ret;
+}
+
+int perf_event__process_itrace_error(struct perf_tool *tool __maybe_unused,
+ union perf_event *event,
+ struct perf_session *session)
+{
+ if (session->itrace)
+ session->itrace->error_count += 1;
+
+ perf_event__fprintf_itrace_error(event, stdout);
+ return 0;
+}
+
+int perf_event__count_itrace_error(struct perf_tool *tool __maybe_unused,
+ union perf_event *event __maybe_unused,
+ struct perf_session *session)
+{
+ if (session->itrace)
+ session->itrace->error_count += 1;
+ return 0;
+}
+
int itrace_mmap__read(struct itrace_mmap *mm, struct itrace_record *itr,
struct perf_tool *tool, process_itrace_t fn)
{
diff --git a/tools/perf/util/itrace.h b/tools/perf/util/itrace.h
index 5abb85a..54b8607 100644
--- a/tools/perf/util/itrace.h
+++ b/tools/perf/util/itrace.h
@@ -33,6 +33,10 @@ struct option;
struct record_opts;
struct itrace_info_event;

+enum itrace_error_type {
+ PERF_ITRACE_DECODER_ERROR = 1,
+};
+
enum itrace_period_type {
PERF_ITRACE_PERIOD_INSTRUCTIONS,
PERF_ITRACE_PERIOD_TICKS,
@@ -202,6 +206,10 @@ int itrace_record__info_fill(struct itrace_record *itr,
void itrace_record__free(struct itrace_record *itr);
u64 itrace_record__reference(struct itrace_record *itr);

+void itrace_synth_error(struct itrace_error_event *itrace_error, int type,
+ int code, int cpu, pid_t pid, pid_t tid, u64 ip,
+ const char *msg);
+
int perf_event__synthesize_itrace_info(struct itrace_record *itr,
struct perf_tool *tool,
struct perf_session *session,
@@ -210,10 +218,18 @@ int perf_event__synthesize_itrace(struct perf_tool *tool,
perf_event__handler_t process,
size_t size, u64 offset, u64 ref, int idx,
u32 tid, u32 cpu);
+int perf_event__process_itrace_error(struct perf_tool *tool,
+ union perf_event *event,
+ struct perf_session *session);
+int perf_event__count_itrace_error(struct perf_tool *tool __maybe_unused,
+ union perf_event *event __maybe_unused,
+ struct perf_session *session);
int itrace_parse_synth_opts(const struct option *opt, const char *str,
int unset);
void itrace_synth_opts__set_default(struct itrace_synth_opts *synth_opts);

+size_t perf_event__fprintf_itrace_error(union perf_event *event, FILE *fp);
+
static inline int itrace__process_event(struct perf_session *session,
union perf_event *event,
struct perf_sample *sample,
--
1.9.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/