From: Jiri Olsa <jolsa@kernel.org>
To: Arnaldo Carvalho de Melo <acme@kernel.org>,
Steven Rostedt <rostedt@goodmis.org>,
Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: lkml <linux-kernel@vger.kernel.org>,
Ingo Molnar <mingo@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Thomas Gleixner <tglx@linutronix.de>,
"Luis Claudio R. Goncalves" <lclaudio@uudg.org>,
ldv@altlinux.org, esyr@redhat.com,
Frederic Weisbecker <fweisbec@gmail.com>
Subject: [PATCH 8/8] perf trace: Add ordered processing for --block option
Date: Wed, 5 Dec 2018 17:05:09 +0100 [thread overview]
Message-ID: <20181205160509.1168-9-jolsa@kernel.org> (raw)
In-Reply-To: <20181205160509.1168-1-jolsa@kernel.org>
Adding support to sort the trace events if --block option is set.
In this mode we don't loose events, and we are potentionally slow
by definition, because the traced process could be blocked.
In this case it makes sense to sort events and provide the precise
outcome of ordered events.
Link: http://lkml.kernel.org/n/tip-me69opepwec6tjtpy2cxrrzd@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
tools/perf/builtin-trace.c | 59 +++++++++++++++++++++++++++++++-
tools/perf/util/ordered-events.c | 11 ++++++
tools/perf/util/ordered-events.h | 1 +
3 files changed, 70 insertions(+), 1 deletion(-)
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index b4b1dafe882a..d650d8cd421b 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -127,6 +127,11 @@ struct trace {
bool force;
bool vfs_getname;
int trace_pgfaults;
+
+ struct {
+ struct ordered_events data;
+ u64 last;
+ } oe;
};
struct tp_field {
@@ -2656,6 +2661,43 @@ static int deliver_event(struct trace *trace, union perf_event *event)
return 0;
}
+
+static int flush_ordered_events(struct trace *trace)
+{
+ u64 first = ordered_events__first_time(&trace->oe.data);
+ u64 flush = trace->oe.last - NSEC_PER_SEC;
+
+ /* Is there some thing to flush.. */
+ if (first && first < flush)
+ return ordered_events__flush_time(&trace->oe.data, flush);
+
+ return 0;
+}
+
+static int deliver_ordered_event(struct trace *trace, union perf_event *event)
+{
+ struct perf_evlist *evlist = trace->evlist;
+ int err;
+
+ err = perf_evlist__parse_sample_timestamp(evlist, event, &trace->oe.last);
+ if (err && err != -1)
+ return err;
+
+ err = ordered_events__queue(&trace->oe.data, event, trace->oe.last, 0);
+ if (err)
+ return err;
+
+ return flush_ordered_events(trace);
+}
+
+static int ordered_events__deliver_event(struct ordered_events *oe,
+ struct ordered_event *event)
+{
+ struct trace *trace = container_of(oe, struct trace, oe.data);
+
+ return deliver_event(trace, event->event);
+}
+
static int trace__run(struct trace *trace, int argc, const char **argv)
{
struct perf_evlist *evlist = trace->evlist;
@@ -2823,7 +2865,13 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
while ((event = perf_mmap__read_event(md)) != NULL) {
++trace->nr_events;
- deliver_event(trace, event);
+ if (trace->opts.block) {
+ err = deliver_ordered_event(trace, event);
+ if (err)
+ goto out_disable;
+ } else {
+ deliver_event(trace, event);
+ }
perf_mmap__consume(md);
@@ -2846,6 +2894,9 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
draining = true;
goto again;
+ } else {
+ if (trace->opts.block && flush_ordered_events(trace))
+ goto out_disable;
}
} else {
goto again;
@@ -2856,6 +2907,9 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
perf_evlist__disable(evlist);
+ if (trace->opts.block)
+ ordered_events__flush(&trace->oe.data, OE_FLUSH__FINAL);
+
if (!err) {
if (trace->summary)
trace__fprintf_thread_summary(trace, trace->output);
@@ -3520,6 +3574,9 @@ int cmd_trace(int argc, const char **argv)
pr_err("ERROR: Can't use --block on non task targets\n");
goto out;
}
+
+ ordered_events__init(&trace.oe.data, ordered_events__deliver_event, &trace);
+ ordered_events__set_copy_on_queue(&trace.oe.data, true);
}
evsel = bpf__setup_output_event(trace.evlist, "__augmented_syscalls__");
diff --git a/tools/perf/util/ordered-events.c b/tools/perf/util/ordered-events.c
index b5c6a854379f..6bd9f50ac83e 100644
--- a/tools/perf/util/ordered-events.c
+++ b/tools/perf/util/ordered-events.c
@@ -343,6 +343,17 @@ int ordered_events__flush_time(struct ordered_events *oe, u64 time)
return __ordered_events__flush(oe, OE_FLUSH__TIME, time);
}
+u64 ordered_events__first_time(struct ordered_events *oe)
+{
+ struct ordered_event *event;
+
+ if (list_empty(&oe->events))
+ return 0;
+
+ event = list_first_entry(&oe->events, struct ordered_event, list);
+ return event->timestamp;
+}
+
void ordered_events__init(struct ordered_events *oe, ordered_events__deliver_t deliver,
void *data)
{
diff --git a/tools/perf/util/ordered-events.h b/tools/perf/util/ordered-events.h
index 6ef81e5be052..4f75f1d2f9db 100644
--- a/tools/perf/util/ordered-events.h
+++ b/tools/perf/util/ordered-events.h
@@ -61,6 +61,7 @@ void ordered_events__init(struct ordered_events *oe, ordered_events__deliver_t d
void *data);
void ordered_events__free(struct ordered_events *oe);
void ordered_events__reinit(struct ordered_events *oe);
+u64 ordered_events__first_time(struct ordered_events *oe);
static inline
void ordered_events__set_alloc_size(struct ordered_events *oe, u64 size)
--
2.17.2
next prev parent reply other threads:[~2018-12-05 16:05 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-05 16:05 [RFC 1/8] perf: Block perf calls for system call tracepoints Jiri Olsa
2018-12-05 16:05 ` [PATCH 1/8] perf: Allow to block process in syscall tracepoints Jiri Olsa
2018-12-05 17:35 ` Steven Rostedt
2018-12-05 17:56 ` Jiri Olsa
2018-12-06 8:09 ` Peter Zijlstra
2018-12-06 10:30 ` Jiri Olsa
2018-12-06 8:10 ` Peter Zijlstra
2018-12-06 8:24 ` Jiri Olsa
2018-12-06 10:31 ` Peter Zijlstra
2018-12-06 8:34 ` Peter Zijlstra
2018-12-06 10:31 ` Jiri Olsa
2018-12-06 18:19 ` Steven Rostedt
2018-12-07 8:44 ` Jiri Olsa
2018-12-07 8:58 ` Peter Zijlstra
2018-12-07 13:41 ` Steven Rostedt
2018-12-07 15:11 ` Peter Zijlstra
2018-12-07 15:49 ` Arnaldo Carvalho de Melo
2018-12-08 10:41 ` Peter Zijlstra
2018-12-08 17:34 ` Steven Rostedt
2018-12-07 20:14 ` Steven Rostedt
2018-12-08 10:44 ` Peter Zijlstra
2018-12-08 17:38 ` Steven Rostedt
2018-12-10 10:18 ` Peter Zijlstra
2018-12-13 0:39 ` Dmitry V. Levin
2018-12-13 1:26 ` Steven Rostedt
2018-12-13 1:49 ` Dmitry V. Levin
2018-12-13 10:01 ` Peter Zijlstra
2018-12-13 10:05 ` Peter Zijlstra
2018-12-13 10:08 ` Peter Zijlstra
2018-12-13 11:29 ` Jiri Olsa
2018-12-06 8:17 ` Peter Zijlstra
2018-12-06 10:27 ` Jiri Olsa
2018-12-05 16:05 ` [PATCH 2/8] perf tools: Sync uapi perf_event.h Jiri Olsa
2018-12-05 16:05 ` [PATCH 3/8] perf record: Add --block option Jiri Olsa
2018-12-05 16:05 ` [PATCH 4/8] perf trace: " Jiri Olsa
2018-12-05 16:05 ` [PATCH 5/8] perf tools: Add block term support for tracepoints Jiri Olsa
2018-12-05 16:05 ` [PATCH 6/8] perf tools: Add ordered_events__flush_time interface Jiri Olsa
2018-12-14 21:00 ` [tip:perf/core] perf ordered_events: " tip-bot for Jiri Olsa
2018-12-18 14:27 ` tip-bot for Jiri Olsa
2018-12-05 16:05 ` [PATCH 7/8] perf trace: Move event delivery to deliver_event function Jiri Olsa
2018-12-14 21:01 ` [tip:perf/core] perf trace: Move event delivery to a new deliver_event() function tip-bot for Jiri Olsa
2018-12-18 14:28 ` tip-bot for Jiri Olsa
2018-12-05 16:05 ` Jiri Olsa [this message]
2018-12-14 21:02 ` [tip:perf/core] perf trace: Add ordered processing tip-bot for Jiri Olsa
2018-12-18 14:29 ` tip-bot for Jiri Olsa
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=20181205160509.1168-9-jolsa@kernel.org \
--to=jolsa@kernel.org \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=esyr@redhat.com \
--cc=fweisbec@gmail.com \
--cc=lclaudio@uudg.org \
--cc=ldv@altlinux.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
/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