perf session: Move the global threads list to perf_session

So that we can process two perf.data files.

We still need to add a O_MMAP mode for perf_session so that we
can do all the mmap stuff in it.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1260741029-4430-5-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index b13f426..0f7a4da 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -20,8 +20,9 @@
 
 #include "perf.h"
 
-#include "util/symbol.h"
 #include "util/color.h"
+#include "util/session.h"
+#include "util/symbol.h"
 #include "util/thread.h"
 #include "util/util.h"
 #include <linux/rbtree.h>
@@ -926,7 +927,8 @@
 	return 0;
 }
 
-static void event__process_sample(const event_t *self, int counter)
+static void event__process_sample(const event_t *self,
+				 struct perf_session *session, int counter)
 {
 	u64 ip = self->ip.ip;
 	struct sym_entry *syme;
@@ -946,7 +948,7 @@
 		return;
 	}
 
-	if (event__preprocess_sample(self, &al, symbol_filter) < 0 ||
+	if (event__preprocess_sample(self, session, &al, symbol_filter) < 0 ||
 	    al.sym == NULL)
 		return;
 
@@ -1053,7 +1055,7 @@
 		}
 
 		if (event->header.type == PERF_RECORD_SAMPLE)
-			event__process_sample(event, md->counter);
+			event__process_sample(event, self, md->counter);
 		else
 			event__process(event, self);
 		old += size;
@@ -1157,10 +1159,13 @@
 	int i, counter;
 	int ret;
 	/*
-	 * XXX perf_session__new should allow passing a O_MMAP, so that all this
-	 * mmap reading, etc is encapsulated in it.
+	 * FIXME: perf_session__new should allow passing a O_MMAP, so that all this
+	 * mmap reading, etc is encapsulated in it. Use O_WRONLY for now.
 	 */
-	struct perf_session *session = NULL;
+	struct perf_session *session = perf_session__new(NULL, O_WRONLY, false);
+
+	if (session == NULL)
+		return -ENOMEM;
 
 	if (target_pid != -1)
 		event__synthesize_thread(target_pid, event__process, session);