From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753105AbbCGVJN (ORCPT ); Sat, 7 Mar 2015 16:09:13 -0500 Received: from mga11.intel.com ([192.55.52.93]:28546 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753031AbbCGVJB (ORCPT ); Sat, 7 Mar 2015 16:09:01 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.11,359,1422950400"; d="scan'208";a="688543892" From: Adrian Hunter To: Peter Zijlstra , Arnaldo Carvalho de Melo Cc: linux-kernel@vger.kernel.org, David Ahern , Frederic Weisbecker , Jiri Olsa , Namhyung Kim , Paul Mackerras , Stephane Eranian , Alexander Shishkin Subject: [PATCH V5 10/25] perf itrace: Add helpers for Instruction Tracing errors Date: Sat, 7 Mar 2015 23:06:19 +0200 Message-Id: <1425762394-29799-11-git-send-email-adrian.hunter@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1425762394-29799-1-git-send-email-adrian.hunter@intel.com> References: <1425762394-29799-1-git-send-email-adrian.hunter@intel.com> Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add functions to synthesize, count and print Instruction Tracing error events. Signed-off-by: Adrian Hunter --- 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 #include +#include #include #include @@ -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