diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-10-06 14:43:20 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-10-06 15:33:22 -0400 |
commit | 9d2f8e22fc965bcdd5561d000d234fe2d23657ba (patch) | |
tree | b0f328b99b87e904c3222ab815e8599e0fe7c29e /tools/perf/util/thread.c | |
parent | 0c1fe6b2f30fa275d939071293b6e28771283f6d (diff) |
perf machine: Introduce find_thread method
There are cases where we want just to find a thread if it exists
already, so provide a method for that.
While doing that start moving 'machine' methods to a separate file.
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-8wpzqs9kfupng6xq8hx6lnxa@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/thread.c')
-rw-r--r-- | tools/perf/util/thread.c | 41 |
1 files changed, 1 insertions, 40 deletions
diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c index fb4b7ea6752f..fe3bb1ec1887 100644 --- a/tools/perf/util/thread.c +++ b/tools/perf/util/thread.c | |||
@@ -7,7 +7,7 @@ | |||
7 | #include "util.h" | 7 | #include "util.h" |
8 | #include "debug.h" | 8 | #include "debug.h" |
9 | 9 | ||
10 | static struct thread *thread__new(pid_t pid) | 10 | struct thread *thread__new(pid_t pid) |
11 | { | 11 | { |
12 | struct thread *self = zalloc(sizeof(*self)); | 12 | struct thread *self = zalloc(sizeof(*self)); |
13 | 13 | ||
@@ -61,45 +61,6 @@ static size_t thread__fprintf(struct thread *self, FILE *fp) | |||
61 | map_groups__fprintf(&self->mg, verbose, fp); | 61 | map_groups__fprintf(&self->mg, verbose, fp); |
62 | } | 62 | } |
63 | 63 | ||
64 | struct thread *machine__findnew_thread(struct machine *self, pid_t pid) | ||
65 | { | ||
66 | struct rb_node **p = &self->threads.rb_node; | ||
67 | struct rb_node *parent = NULL; | ||
68 | struct thread *th; | ||
69 | |||
70 | /* | ||
71 | * Font-end cache - PID lookups come in blocks, | ||
72 | * so most of the time we dont have to look up | ||
73 | * the full rbtree: | ||
74 | */ | ||
75 | if (self->last_match && self->last_match->pid == pid) | ||
76 | return self->last_match; | ||
77 | |||
78 | while (*p != NULL) { | ||
79 | parent = *p; | ||
80 | th = rb_entry(parent, struct thread, rb_node); | ||
81 | |||
82 | if (th->pid == pid) { | ||
83 | self->last_match = th; | ||
84 | return th; | ||
85 | } | ||
86 | |||
87 | if (pid < th->pid) | ||
88 | p = &(*p)->rb_left; | ||
89 | else | ||
90 | p = &(*p)->rb_right; | ||
91 | } | ||
92 | |||
93 | th = thread__new(pid); | ||
94 | if (th != NULL) { | ||
95 | rb_link_node(&th->rb_node, parent, p); | ||
96 | rb_insert_color(&th->rb_node, &self->threads); | ||
97 | self->last_match = th; | ||
98 | } | ||
99 | |||
100 | return th; | ||
101 | } | ||
102 | |||
103 | void thread__insert_map(struct thread *self, struct map *map) | 64 | void thread__insert_map(struct thread *self, struct map *map) |
104 | { | 65 | { |
105 | map_groups__fixup_overlappings(&self->mg, map, verbose, stderr); | 66 | map_groups__fixup_overlappings(&self->mg, map, verbose, stderr); |