Skip to contentSkip to conversation

perf session: Move threads to struct machine

tip:perf/core tip-bot for Arnaldo Carvalho de Melo 1 participant 1 message Dec 5, 2011 perf events

lore
Share & tools
lore
#0 lore raw
Commit-ID:  b424eba27160dd19577896d4520b8eebabed919f
Gitweb:     http://git.kernel.org/tip/b424eba27160dd19577896d4520b8eebabed919f
Author:     Arnaldo Carvalho de Melo <[email protected]>
AuthorDate: Wed, 9 Nov 2011 13:24:25 -0200
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 28 Nov 2011 10:35:31 -0200

perf session: Move threads to struct machine

The 'machine' abstraction was introduced with 'perf kvm' where we could have samples for the host and multiple guests, but at the time we ended up keeping the list of all machines threads all in session->host_machine.

Move the threads rb_tree to struct machine to separate the namespaces.

Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/perf/util/build-id.c |    4 +-
 tools/perf/util/map.c      |    4 +++
 tools/perf/util/map.h      |    9 ++++++++
 tools/perf/util/session.c  |   47 +++++++++++++++++++++++++++++++++++++------
 tools/perf/util/session.h  |    3 --
 tools/perf/util/thread.c   |    6 ++--
 6 files changed, 58 insertions(+), 15 deletions(-)
tools/perf/util/build-id.c +2 -2
index a91cd99..f2fe6ec 100644
@@ -48,8 +48,8 @@ static int perf_event__exit_del_thread(union perf_event *event,
 		    event->fork.ppid, event->fork.ptid);
 
 	if (thread) {
-		rb_erase(&thread->rb_node, &session->threads);
-		session->last_match = NULL;
+		rb_erase(&thread->rb_node, &session->host_machine.threads);
+		session->host_machine.last_match = NULL;
 		thread__delete(thread);
 	}
 
tools/perf/util/map.c +4 -0
index 78284b1..316aa0a 100644
@@ -562,6 +562,10 @@ int machine__init(struct machine *self, const char *root_dir, pid_t pid)
 	INIT_LIST_HEAD(&self->user_dsos);
 	INIT_LIST_HEAD(&self->kernel_dsos);
 
+	self->threads = RB_ROOT;
+	INIT_LIST_HEAD(&self->dead_threads);
+	self->last_match = NULL;
+
 	self->kmaps.machine = self;
 	self->pid	    = pid;
 	self->root_dir      = strdup(root_dir);
tools/perf/util/map.h +9 -0
index 890d855..bde6835 100644
@@ -62,6 +62,9 @@ struct machine {
 	struct rb_node	  rb_node;
 	pid_t		  pid;
 	char		  *root_dir;
+	struct rb_root	  threads;
+	struct list_head  dead_threads;
+	struct thread	  *last_match;
 	struct list_head  user_dsos;
 	struct list_head  kernel_dsos;
 	struct map_groups kmaps;
@@ -190,6 +193,12 @@ struct symbol *map_groups__find_symbol_by_name(struct map_groups *mg,
 					       struct map **mapp,
 					       symbol_filter_t filter);
 
+
+struct thread *machine__findnew_thread(struct machine *machine, pid_t pid);
+void machine__remove_thread(struct machine *machine, struct thread *th);
+
+size_t machine__fprintf(struct machine *machine, FILE *fp);
+
 static inline
 struct symbol *machine__find_kernel_symbol(struct machine *self,
 					   enum map_type type, u64 addr,
tools/perf/util/session.c +40 -7

91 lines not on this page · raw message

tools/perf/util/session.h +0 -3
index 6e393c9..76d462d 100644
@@ -30,9 +30,6 @@ struct perf_session {
 	struct perf_header	header;
 	unsigned long		size;
 	unsigned long		mmap_window;
-	struct rb_root		threads;
-	struct list_head	dead_threads;
-	struct thread		*last_match;
 	struct machine		host_machine;
 	struct rb_root		machines;
 	struct perf_evlist	*evlist;
tools/perf/util/thread.c +3 -3
index d5d3b22..fb4b7ea 100644
@@ -61,7 +61,7 @@ static size_t thread__fprintf(struct thread *self, FILE *fp)
 	       map_groups__fprintf(&self->mg, verbose, fp);
 }
 
-struct thread *perf_session__findnew(struct perf_session *self, pid_t pid)
+struct thread *machine__findnew_thread(struct machine *self, pid_t pid)
 {
 	struct rb_node **p = &self->threads.rb_node;
 	struct rb_node *parent = NULL;
@@ -125,12 +125,12 @@ int thread__fork(struct thread *self, struct thread *parent)
 	return 0;
 }
 
-size_t perf_session__fprintf(struct perf_session *self, FILE *fp)
+size_t machine__fprintf(struct machine *machine, FILE *fp)
 {
 	size_t ret = 0;
 	struct rb_node *nd;
 
-	for (nd = rb_first(&self->threads); nd; nd = rb_next(nd)) {
+	for (nd = rb_first(&machine->threads); nd; nd = rb_next(nd)) {
 		struct thread *pos = rb_entry(nd, struct thread, rb_node);
 
 		ret += thread__fprintf(pos, fp);