linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@redhat.com>
To: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Alexandre Montplaisir <alexmonthy@voxpopuli.im>,
	linux-kernel@vger.kernel.org,
	Dominique Toupin <dominique.toupin@ericsson.com>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	Tom Zanussi <tzanussi@gmail.com>,
	Jeremie Galarneau <jgalar@efficios.com>,
	David Ahern <dsahern@gmail.com>,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	Trace Compass Developer Discussions 
	<tracecompass-dev@eclipse.org>,
	matthew.khouzam@ericsson.com, andreas@linutronix.de
Subject: Re: Support for Perf CTF traces now in master (was Re: FW: [RFC 0/5] perf tools: Add perf data CTF conversion)
Date: Fri, 28 Nov 2014 12:26:50 +0100	[thread overview]
Message-ID: <20141128112650.GD27703@krava.brq.redhat.com> (raw)
In-Reply-To: <20141126173721.GA6829@linutronix.de>

On Wed, Nov 26, 2014 at 06:37:21PM +0100, Sebastian Andrzej Siewior wrote:
> * Alexandre Montplaisir | 2014-11-12 17:14:45 [-0500]:

SNIP

> 
> >This was based on the most recent file format I was aware of, we will
> >update it accordingly if required.
> >
> >Testing welcome!
> 
> I pushed the perf changes I mentioned to 
> 
>   git://git.breakpoint.cc/bigeasy/linux.git ctf_convert_7
> 

from perf data convert point of view (and libbabeltrace).. ;-)

I tried to convert big perf.data (2GB) and my laptop got stuck
for few minutes.. the reason is that perf allocated too much memory

I needed to add occasional bt_ctf_stream_flush into the
processing (patch attached)

What I do now is checking if we processed given amount of events
for the stream and once the value is crossed I flush it.

My question is if there's a way to find out the allocated memory
for the stream?  It'd be nicer to setup maximum allocation size
rather than the number of events.

thanks,
jirka



diff --git a/tools/perf/util/data-bt.c b/tools/perf/util/data-bt.c
index c5720e13d8f1..981e8ff2c32a 100644
--- a/tools/perf/util/data-bt.c
+++ b/tools/perf/util/data-bt.c
@@ -39,10 +39,15 @@ struct evsel_priv {
 
 #define MAX_CPUS	4096
 
+struct ctf_stream {
+	struct bt_ctf_stream *stream;
+	u64 count;
+};
+
 struct ctf_writer {
 	/* writer primitives */
 	struct bt_ctf_writer		*writer;
-	struct bt_ctf_stream		*stream[MAX_CPUS];
+	struct ctf_stream		*stream[MAX_CPUS];
 	struct bt_ctf_stream_class	*stream_class;
 	struct bt_ctf_clock		*clock;
 	u32				last_cpu;
@@ -377,6 +382,73 @@ static int add_generic_values(struct ctf_writer *cw,
 	return 0;
 }
 
+#define STREAM_FLUSH_COUNT 1000
+
+static bool is_flush_needed(struct ctf_stream *cstream)
+{
+	return cstream && (cstream->count >= STREAM_FLUSH_COUNT);
+}
+
+static int flush_stream(struct ctf_writer *cw, int cpu)
+{
+	struct ctf_stream *cstream = cw->stream[cpu];
+	int err = 0;
+
+	if (cstream) {
+		err = bt_ctf_stream_flush(cstream->stream);
+		if (err)
+			pr_err("CTF stream %d flush failed\n", cpu);
+
+		cstream->count = 0;
+	}
+
+	return err;
+}
+
+static int create_stream(struct ctf_writer *cw, int cpu)
+{
+	struct ctf_stream *cstream;
+	struct bt_ctf_field *pkt_ctx;
+	struct bt_ctf_field *cpu_field;
+	struct bt_ctf_stream *stream;
+	u32 i = cpu;
+	int ret;
+
+	cstream = zalloc(sizeof(*cstream));
+	if (!cstream) {
+		pr_err("Failed to allocate ctf stream\n");
+		return -1;
+	}
+
+	stream = bt_ctf_writer_create_stream(cw->writer, cw->stream_class);
+	if (!stream)
+		return -1;
+
+	pkt_ctx = bt_ctf_stream_get_packet_context(stream);
+	if (!pkt_ctx) {
+		pr_err("Failed to obtain packet context\n");
+		return -1;
+	}
+
+	cpu_field = bt_ctf_field_structure_get_field(pkt_ctx, "cpu_id");
+	bt_ctf_field_put(pkt_ctx);
+	if (!cpu_field) {
+		pr_err("Failed to obtain cpu field\n");
+		return -1;
+	}
+
+	ret = bt_ctf_field_unsigned_integer_set_value(cpu_field, i);
+	if (ret) {
+		pr_err("Failed to update CPU number\n");
+		return -1;
+	}
+	bt_ctf_field_put(cpu_field);
+
+	cstream->stream = stream;
+	cw->stream[i] = cstream;
+	return 0;
+}
+
 static int process_sample_event(struct perf_tool *tool,
 				union perf_event *_event __maybe_unused,
 				struct perf_sample *sample,
@@ -431,40 +503,14 @@ static int process_sample_event(struct perf_tool *tool,
 		cpu = 0;
 	}
 
-	if (!cw->stream[cpu]) {
-		struct bt_ctf_field *pkt_ctx;
-		struct bt_ctf_field *cpu_field;
-		struct bt_ctf_stream *stream;
-		u32 i = sample->cpu;
-
-		stream = bt_ctf_writer_create_stream(cw->writer, cw->stream_class);
-		if (!stream)
-			return -1;
-
-		pkt_ctx = bt_ctf_stream_get_packet_context(stream);
-		if (!pkt_ctx) {
-			pr_err("Failed to obtain packet context\n");
-			return -1;
-		}
-
-		cpu_field = bt_ctf_field_structure_get_field(pkt_ctx, "cpu_id");
-		bt_ctf_field_put(pkt_ctx);
-		if (!cpu_field) {
-			pr_err("Failed to obtain cpu field\n");
-			return -1;
-		}
+	if (!cw->stream[cpu] && create_stream(cw, cpu))
+		return -1;
 
-		ret = bt_ctf_field_unsigned_integer_set_value(cpu_field, i);
-		if (ret) {
-			pr_err("Failed to update CPU number\n");
-			return -1;
-		}
-		bt_ctf_field_put(cpu_field);
+	if (is_flush_needed(cw->stream[cpu]))
+		flush_stream(cw, cpu);
 
-		cw->stream[i] = stream;
-	}
-
-	bt_ctf_stream_append_event(cw->stream[cpu], event);
+	cw->stream[cpu]->count++;
+	bt_ctf_stream_append_event(cw->stream[cpu]->stream, event);
 	bt_ctf_event_put(event);
 	return 0;
 }
@@ -745,8 +791,12 @@ static void ctf_writer__cleanup(struct ctf_writer *cw)
 	ctf_writer__cleanup_data(cw);
 
 	bt_ctf_clock_put(cw->clock);
-	for (i = 0; i < MAX_CPUS; i++)
-		bt_ctf_stream_put(cw->stream[i]);
+	for (i = 0; i < MAX_CPUS; i++) {
+		if (cw->stream[i]) {
+			bt_ctf_stream_put(cw->stream[i]->stream);
+			free(cw->stream[i]);
+		}
+	}
 	bt_ctf_stream_class_put(cw->stream_class);
 	bt_ctf_writer_put(cw->writer);
 
@@ -862,6 +912,9 @@ int bt_convert__perf2ctf(const char *input, const char *path)
 	if (!session)
 		goto free_writer;
 
+	ordered_events__set_alloc_size(&session->ordered_events,
+				       100*1024*1024);
+
 	/* CTF writer env/clock setup  */
 	if (ctf_writer__setup_env(cw, session))
 		goto free_session;
@@ -872,15 +925,10 @@ int bt_convert__perf2ctf(const char *input, const char *path)
 
 	err = perf_session__process_events(session, &c.tool);
 	if (!err) {
-		int i;
+		int cpu;
 
-		for (i = 0; i < MAX_CPUS; i++) {
-			if (cw->stream[i]) {
-				err = bt_ctf_stream_flush(cw->stream[i]);
-				if (err)
-					pr_err("CTF stream %d flush failed\n", i);
-			}
-		}
+		for (cpu = 0; cpu < MAX_CPUS; cpu++)
+			flush_stream(cw, cpu);
 	}
 
 	fprintf(stderr,

  parent reply	other threads:[~2014-11-28 11:27 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <53F38C74.4030300@voxpopuli.im>
2014-08-20  9:28 ` FW: [RFC 0/5] perf tools: Add perf data CTF conversion Jiri Olsa
2014-08-20 19:14   ` Alexandre Montplaisir
2014-08-21 16:58     ` Jiri Olsa
2014-08-21 20:03       ` Alexandre Montplaisir
2014-08-22 16:46         ` Jiri Olsa
2014-11-03 17:58     ` Sebastian Andrzej Siewior
2014-11-04  1:20       ` Alexandre Montplaisir
2014-11-05 12:50         ` Sebastian Andrzej Siewior
2014-11-05 17:21           ` Mathieu Desnoyers
2014-11-06  4:53             ` Alexandre Montplaisir
2014-11-13 19:24             ` Sebastian Andrzej Siewior
2014-11-14 15:51               ` Mathieu Desnoyers
2014-11-06  3:25           ` FW: " Alexandre Montplaisir
2014-11-10  1:31             ` Alexandre Montplaisir
2014-11-12 22:14               ` Support for Perf CTF traces now in master (was Re: FW: [RFC 0/5] perf tools: Add perf data CTF conversion) Alexandre Montplaisir
2014-11-26 17:37                 ` Sebastian Andrzej Siewior
2014-11-27  4:27                   ` Alexandre Montplaisir
2014-11-29  9:35                     ` [tracecompass-dev] " Jerome CORRENOZ
2014-11-28 11:26                   ` Jiri Olsa [this message]
2014-12-01 17:28                     ` Jérémie Galarneau
2014-12-01 20:44                       ` Jiri Olsa
2014-11-27 15:43                 ` Jiri Olsa
2014-11-27 16:20                   ` Sebastian Andrzej Siewior
2014-11-27 18:31                   ` Alexandre Montplaisir
2014-11-28  9:32                     ` Jiri Olsa
2014-11-13 19:24             ` FW: [RFC 0/5] perf tools: Add perf data CTF conversion Sebastian Andrzej Siewior
2014-11-14 11:50               ` 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=20141128112650.GD27703@krava.brq.redhat.com \
    --to=jolsa@redhat.com \
    --cc=acme@redhat.com \
    --cc=alexmonthy@voxpopuli.im \
    --cc=andreas@linutronix.de \
    --cc=bigeasy@linutronix.de \
    --cc=dominique.toupin@ericsson.com \
    --cc=dsahern@gmail.com \
    --cc=jgalar@efficios.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=matthew.khouzam@ericsson.com \
    --cc=tracecompass-dev@eclipse.org \
    --cc=tzanussi@gmail.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).