linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>, Namhyung Kim <namhyung@kernel.org>,
	Clark Williams <williams@redhat.com>,
	linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
	Adrian Hunter <adrian.hunter@intel.com>,
	Jiri Olsa <jolsa@redhat.com>,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 53/53] perf auxtrace: Add timestamp to auxtrace errors
Date: Wed,  6 Feb 2019 15:49:03 -0300	[thread overview]
Message-ID: <20190206184903.24054-54-acme@kernel.org> (raw)
In-Reply-To: <20190206184903.24054-1-acme@kernel.org>

From: Adrian Hunter <adrian.hunter@intel.com>

The timestamp can use useful to find part of a trace that has an error
without outputting all of the trace e.g. using the itrace 's' option to
skip initial number of events.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Link: http://lkml.kernel.org/r/20190206103947.15750-6-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/auxtrace.c    | 22 ++++++++++++++++++++--
 tools/perf/util/auxtrace.h    |  2 +-
 tools/perf/util/event.h       |  3 ++-
 tools/perf/util/intel-bts.c   |  4 ++--
 tools/perf/util/intel-pt.c    | 23 ++++++++++++++++-------
 tools/perf/util/s390-cpumsf.c |  7 ++++---
 tools/perf/util/session.c     |  3 +++
 7 files changed, 48 insertions(+), 16 deletions(-)

diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
index ad186d3255d1..267e54df511b 100644
--- a/tools/perf/util/auxtrace.c
+++ b/tools/perf/util/auxtrace.c
@@ -27,6 +27,7 @@
 #include <linux/bitops.h>
 #include <linux/log2.h>
 #include <linux/string.h>
+#include <linux/time64.h>
 
 #include <sys/param.h>
 #include <stdlib.h>
@@ -858,7 +859,7 @@ void auxtrace_buffer__free(struct auxtrace_buffer *buffer)
 
 void auxtrace_synth_error(struct auxtrace_error_event *auxtrace_error, int type,
 			  int code, int cpu, pid_t pid, pid_t tid, u64 ip,
-			  const char *msg)
+			  const char *msg, u64 timestamp)
 {
 	size_t size;
 
@@ -870,7 +871,9 @@ void auxtrace_synth_error(struct auxtrace_error_event *auxtrace_error, int type,
 	auxtrace_error->cpu = cpu;
 	auxtrace_error->pid = pid;
 	auxtrace_error->tid = tid;
+	auxtrace_error->fmt = 1;
 	auxtrace_error->ip = ip;
+	auxtrace_error->time = timestamp;
 	strlcpy(auxtrace_error->msg, msg, MAX_AUXTRACE_ERROR_MSG);
 
 	size = (void *)auxtrace_error->msg - (void *)auxtrace_error +
@@ -1160,12 +1163,27 @@ static const char *auxtrace_error_name(int type)
 size_t perf_event__fprintf_auxtrace_error(union perf_event *event, FILE *fp)
 {
 	struct auxtrace_error_event *e = &event->auxtrace_error;
+	unsigned long long nsecs = e->time;
+	const char *msg = e->msg;
 	int ret;
 
 	ret = fprintf(fp, " %s error type %u",
 		      auxtrace_error_name(e->type), e->type);
+
+	if (e->fmt && nsecs) {
+		unsigned long secs = nsecs / NSEC_PER_SEC;
+
+		nsecs -= secs * NSEC_PER_SEC;
+		ret += fprintf(fp, " time %lu.%09llu", secs, nsecs);
+	} else {
+		ret += fprintf(fp, " time 0");
+	}
+
+	if (!e->fmt)
+		msg = (const char *)&e->time;
+
 	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);
+		       e->cpu, e->pid, e->tid, e->ip, e->code, msg);
 	return ret;
 }
 
diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h
index fac32482db61..c69bcd9a3091 100644
--- a/tools/perf/util/auxtrace.h
+++ b/tools/perf/util/auxtrace.h
@@ -519,7 +519,7 @@ void auxtrace_index__free(struct list_head *head);
 
 void auxtrace_synth_error(struct auxtrace_error_event *auxtrace_error, int type,
 			  int code, int cpu, pid_t pid, pid_t tid, u64 ip,
-			  const char *msg);
+			  const char *msg, u64 timestamp);
 
 int perf_event__synthesize_auxtrace_info(struct auxtrace_record *itr,
 					 struct perf_tool *tool,
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
index feba1aa819b4..36ae7e92dab1 100644
--- a/tools/perf/util/event.h
+++ b/tools/perf/util/event.h
@@ -532,8 +532,9 @@ struct auxtrace_error_event {
 	u32 cpu;
 	u32 pid;
 	u32 tid;
-	u32 reserved__; /* For alignment */
+	u32 fmt;
 	u64 ip;
+	u64 time;
 	char msg[MAX_AUXTRACE_ERROR_MSG];
 };
 
diff --git a/tools/perf/util/intel-bts.c b/tools/perf/util/intel-bts.c
index f99ac0cbe3ff..0c0180c67574 100644
--- a/tools/perf/util/intel-bts.c
+++ b/tools/perf/util/intel-bts.c
@@ -144,7 +144,7 @@ static int intel_bts_lost(struct intel_bts *bts, struct perf_sample *sample)
 
 	auxtrace_synth_error(&event.auxtrace_error, PERF_AUXTRACE_ERROR_ITRACE,
 			     INTEL_BTS_ERR_LOST, sample->cpu, sample->pid,
-			     sample->tid, 0, "Lost trace data");
+			     sample->tid, 0, "Lost trace data", sample->time);
 
 	err = perf_session__deliver_synth_event(bts->session, &event, NULL);
 	if (err)
@@ -374,7 +374,7 @@ static int intel_bts_synth_error(struct intel_bts *bts, int cpu, pid_t pid,
 
 	auxtrace_synth_error(&event.auxtrace_error, PERF_AUXTRACE_ERROR_ITRACE,
 			     INTEL_BTS_ERR_NOINSN, cpu, pid, tid, ip,
-			     "Failed to get instruction");
+			     "Failed to get instruction", 0);
 
 	err = perf_session__deliver_synth_event(bts->session, &event, NULL);
 	if (err)
diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
index 2e72373ec6df..3b497bab4324 100644
--- a/tools/perf/util/intel-pt.c
+++ b/tools/perf/util/intel-pt.c
@@ -1411,7 +1411,7 @@ static int intel_pt_synth_pwrx_sample(struct intel_pt_queue *ptq)
 }
 
 static int intel_pt_synth_error(struct intel_pt *pt, int code, int cpu,
-				pid_t pid, pid_t tid, u64 ip)
+				pid_t pid, pid_t tid, u64 ip, u64 timestamp)
 {
 	union perf_event event;
 	char msg[MAX_AUXTRACE_ERROR_MSG];
@@ -1420,7 +1420,7 @@ static int intel_pt_synth_error(struct intel_pt *pt, int code, int cpu,
 	intel_pt__strerror(code, msg, MAX_AUXTRACE_ERROR_MSG);
 
 	auxtrace_synth_error(&event.auxtrace_error, PERF_AUXTRACE_ERROR_ITRACE,
-			     code, cpu, pid, tid, ip, msg);
+			     code, cpu, pid, tid, ip, msg, timestamp);
 
 	err = perf_session__deliver_synth_event(pt->session, &event, NULL);
 	if (err)
@@ -1430,6 +1430,18 @@ static int intel_pt_synth_error(struct intel_pt *pt, int code, int cpu,
 	return err;
 }
 
+static int intel_ptq_synth_error(struct intel_pt_queue *ptq,
+				 const struct intel_pt_state *state)
+{
+	struct intel_pt *pt = ptq->pt;
+	u64 tm = ptq->timestamp;
+
+	tm = pt->timeless_decoding ? 0 : tsc_to_perf_time(tm, &pt->tc);
+
+	return intel_pt_synth_error(pt, state->err, ptq->cpu, ptq->pid,
+				    ptq->tid, state->from_ip, tm);
+}
+
 static int intel_pt_next_tid(struct intel_pt *pt, struct intel_pt_queue *ptq)
 {
 	struct auxtrace_queue *queue;
@@ -1676,10 +1688,7 @@ static int intel_pt_run_decoder(struct intel_pt_queue *ptq, u64 *timestamp)
 				intel_pt_next_tid(pt, ptq);
 			}
 			if (pt->synth_opts.errors) {
-				err = intel_pt_synth_error(pt, state->err,
-							   ptq->cpu, ptq->pid,
-							   ptq->tid,
-							   state->from_ip);
+				err = intel_ptq_synth_error(ptq, state);
 				if (err)
 					return err;
 			}
@@ -1804,7 +1813,7 @@ static int intel_pt_process_timeless_queues(struct intel_pt *pt, pid_t tid,
 static int intel_pt_lost(struct intel_pt *pt, struct perf_sample *sample)
 {
 	return intel_pt_synth_error(pt, INTEL_PT_ERR_LOST, sample->cpu,
-				    sample->pid, sample->tid, 0);
+				    sample->pid, sample->tid, 0, sample->time);
 }
 
 static struct intel_pt_queue *intel_pt_cpu_to_ptq(struct intel_pt *pt, int cpu)
diff --git a/tools/perf/util/s390-cpumsf.c b/tools/perf/util/s390-cpumsf.c
index 835249c77f56..d9525d220db1 100644
--- a/tools/perf/util/s390-cpumsf.c
+++ b/tools/perf/util/s390-cpumsf.c
@@ -819,7 +819,7 @@ static int s390_cpumsf_process_queues(struct s390_cpumsf *sf, u64 timestamp)
 }
 
 static int s390_cpumsf_synth_error(struct s390_cpumsf *sf, int code, int cpu,
-				   pid_t pid, pid_t tid, u64 ip)
+				   pid_t pid, pid_t tid, u64 ip, u64 timestamp)
 {
 	char msg[MAX_AUXTRACE_ERROR_MSG];
 	union perf_event event;
@@ -827,7 +827,7 @@ static int s390_cpumsf_synth_error(struct s390_cpumsf *sf, int code, int cpu,
 
 	strncpy(msg, "Lost Auxiliary Trace Buffer", sizeof(msg) - 1);
 	auxtrace_synth_error(&event.auxtrace_error, PERF_AUXTRACE_ERROR_ITRACE,
-			     code, cpu, pid, tid, ip, msg);
+			     code, cpu, pid, tid, ip, msg, timestamp);
 
 	err = perf_session__deliver_synth_event(sf->session, &event, NULL);
 	if (err)
@@ -839,7 +839,8 @@ static int s390_cpumsf_synth_error(struct s390_cpumsf *sf, int code, int cpu,
 static int s390_cpumsf_lost(struct s390_cpumsf *sf, struct perf_sample *sample)
 {
 	return s390_cpumsf_synth_error(sf, 1, sample->cpu,
-				       sample->pid, sample->tid, 0);
+				       sample->pid, sample->tid, 0,
+				       sample->time);
 }
 
 static int
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 2012396abb7c..18fb9c8cbf9c 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -703,7 +703,10 @@ static void perf_event__auxtrace_error_swap(union perf_event *event,
 	event->auxtrace_error.cpu  = bswap_32(event->auxtrace_error.cpu);
 	event->auxtrace_error.pid  = bswap_32(event->auxtrace_error.pid);
 	event->auxtrace_error.tid  = bswap_32(event->auxtrace_error.tid);
+	event->auxtrace_error.fmt  = bswap_32(event->auxtrace_error.fmt);
 	event->auxtrace_error.ip   = bswap_64(event->auxtrace_error.ip);
+	if (event->auxtrace_error.fmt)
+		event->auxtrace_error.time = bswap_64(event->auxtrace_error.time);
 }
 
 static void perf_event__thread_map_swap(union perf_event *event,
-- 
2.20.1

  parent reply	other threads:[~2019-02-06 18:49 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-06 18:48 [GIT PULL 00/53] perf/core improvements and fixes Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 01/53] perf powerpc: Add missing headers to skip-callchain-idx.c Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 02/53] perf arm pmu: Add missing linux/string.h header Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 03/53] perf srccode: Move struct definition from map.h to srccode.h Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 04/53] perf callchain: Uninline callchain_cursor_reset() to remove map.h dependency Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 05/53] perf symbols: Introduce map_symbol.h Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 06/53] pref tools: Add missing map.h includes Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 07/53] perf map: Move structs and prototypes for map groups to a separate header Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 08/53] perf tests: Add missing headers so far obtained indirectly Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 09/53] perf hist: Remove symbol.h from hist.h, just fwd decls are needed Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 10/53] perf tools: Add missing include for symbols.h Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 11/53] perf evsel: No need to include symbol.h in evsel.h, symbol_conf.h is enough Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 12/53] perf thread: Don't include symbol.h, " Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 13/53] perf tools: Add missing include <callchain.h> in various places Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 14/53] perf hist: Remove the needless callchain.h include from hist.h Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 15/53] perf tests pmu: Add missing headers Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 16/53] perf pmu: Remove needless evsel.h include, only needs one fwd decl Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 17/53] perf kvm stat: Replace kvm-stat.h includes with forward declarations Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 18/53] perf powerpc kvm-stat: Add missing evlist.h header Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 19/53] perf bpf-loader: Remove unecessary includes from bpf-loader.h Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 20/53] perf/aux: Make perf_event accessible to setup_aux() Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 21/53] coresight: perf: Add "sinks" group to PMU directory Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 22/53] coresight: Use event attributes for sink selection Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 23/53] perf pmu: Move EVENT_SOURCE_DEVICE_PATH to PMU header file Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 24/53] perf arm cs-etm: Use event attributes to send sink information to kernel Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 25/53] perf coresight: Remove set_drv_config() API Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 26/53] perf pmu: Remove set_drv_config API Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 27/53] perf record: Allocate affinity masks Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 28/53] perf record: Bind the AIO user space buffers to nodes Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 29/53] perf tools: Add fallback versions for CPU_{OR,EQUAL}() Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 30/53] perf record: Apply affinity masks when reading mmap buffers Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 31/53] perf clang: Do not use 'return std::move(something)' Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 32/53] perf hists: Add argument to hists__resort_cb_t callback Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 33/53] perf evsel: Add output_resort_cb method Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 34/53] perf report: Move symbol annotation to the resort phase Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 35/53] perf tools: Add documentation for BPF event selection Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 36/53] perf cs-etm: Add last instruction information in packet Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 37/53] perf cs-etm: Set sample flags for instruction range packet Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 38/53] perf cs-etm: Set sample flags for trace discontinuity Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 39/53] perf cs-etm: Add exception number in exception packet Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 40/53] perf cs-etm: Change tuple from traceID-CPU# to traceID-metadata Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 41/53] perf cs-etm: Add traceID in packet Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 42/53] perf cs-etm: Set sample flags for exception packet Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 43/53] perf cs-etm: Set sample flags for exception return packet Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 44/53] perf vendor events intel: Fix Load_Miss_Real_Latency on CLX Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 45/53] perf tools: Fix split_kallsyms_for_kcore() for trampoline symbols Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 46/53] perf thread-stack: Tidy thread_stack__push_cp() usage Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 47/53] perf thread-stack: Tidy thread_stack__no_call_return() by adding more local variables Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 48/53] perf thread-stack: Represent jmps to the start of a different symbol Arnaldo Carvalho de Melo
2019-02-06 18:48 ` [PATCH 49/53] perf auxtrace: Define auxtrace record alignment Arnaldo Carvalho de Melo
2019-02-06 18:49 ` [PATCH 50/53] perf intel-pt: Fix overlap calculation for padding Arnaldo Carvalho de Melo
2019-02-06 18:49 ` [PATCH 51/53] perf intel-pt: Fix CYC timestamp calculation after OVF Arnaldo Carvalho de Melo
2019-02-06 18:49 ` [PATCH 52/53] perf intel-pt: Packet splitting can happen only on 32-bit Arnaldo Carvalho de Melo
2019-02-06 18:49 ` Arnaldo Carvalho de Melo [this message]
2019-02-09 12:17 ` [GIT PULL 00/53] perf/core improvements and fixes Ingo Molnar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190206184903.24054-54-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=adrian.hunter@intel.com \
    --cc=jolsa@kernel.org \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=williams@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).