[PATCH V5 10/25] perf itrace: Add helpers for Instruction Tracing errors

From: Adrian Hunter
Date: Sat Mar 07 2015 - 16:09:17 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 | 43 +++++++++++++++++++++++++++++++++++++++++++
tools/perf/util/itrace.h | 13 +++++++++++++
2 files changed, 56 insertions(+)

diff --git a/tools/perf/util/itrace.c b/tools/perf/util/itrace.c
index 817b7b7..cf5a476 100644
--- a/tools/perf/util/itrace.c
+++ b/tools/perf/util/itrace.c
@@ -24,6 +24,7 @@
#include <linux/log2.h>

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

@@ -35,6 +36,7 @@
#include "itrace.h"

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

@@ -160,6 +162,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,
@@ -339,6 +363,25 @@ 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 __maybe_unused)
+{
+ perf_event__fprintf_itrace_error(event, stdout);
+ 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 5a82326..743fe96 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,
@@ -200,6 +204,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,
@@ -208,10 +216,15 @@ 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 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/