aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/thread.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/util/thread.c')
-rw-r--r--tools/perf/util/thread.c169
1 files changed, 2 insertions, 167 deletions
diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c
index 9bbe27d75306..1f7ecd47f499 100644
--- a/tools/perf/util/thread.c
+++ b/tools/perf/util/thread.c
@@ -38,15 +38,6 @@ failure:
38 return ret; 38 return ret;
39} 39}
40 40
41void map_groups__init(struct map_groups *self)
42{
43 int i;
44 for (i = 0; i < MAP__NR_TYPES; ++i) {
45 self->maps[i] = RB_ROOT;
46 INIT_LIST_HEAD(&self->removed_maps[i]);
47 }
48}
49
50static struct thread *thread__new(pid_t pid) 41static struct thread *thread__new(pid_t pid)
51{ 42{
52 struct thread *self = zalloc(sizeof(*self)); 43 struct thread *self = zalloc(sizeof(*self));
@@ -62,28 +53,6 @@ static struct thread *thread__new(pid_t pid)
62 return self; 53 return self;
63} 54}
64 55
65static void map_groups__flush(struct map_groups *self)
66{
67 int type;
68
69 for (type = 0; type < MAP__NR_TYPES; type++) {
70 struct rb_root *root = &self->maps[type];
71 struct rb_node *next = rb_first(root);
72
73 while (next) {
74 struct map *pos = rb_entry(next, struct map, rb_node);
75 next = rb_next(&pos->rb_node);
76 rb_erase(&pos->rb_node, root);
77 /*
78 * We may have references to this map, for
79 * instance in some hist_entry instances, so
80 * just move them to a separate list.
81 */
82 list_add_tail(&pos->node, &self->removed_maps[pos->type]);
83 }
84 }
85}
86
87int thread__set_comm(struct thread *self, const char *comm) 56int thread__set_comm(struct thread *self, const char *comm)
88{ 57{
89 int err; 58 int err;
@@ -110,69 +79,10 @@ int thread__comm_len(struct thread *self)
110 return self->comm_len; 79 return self->comm_len;
111} 80}
112 81
113size_t __map_groups__fprintf_maps(struct map_groups *self,
114 enum map_type type, FILE *fp)
115{
116 size_t printed = fprintf(fp, "%s:\n", map_type__name[type]);
117 struct rb_node *nd;
118
119 for (nd = rb_first(&self->maps[type]); nd; nd = rb_next(nd)) {
120 struct map *pos = rb_entry(nd, struct map, rb_node);
121 printed += fprintf(fp, "Map:");
122 printed += map__fprintf(pos, fp);
123 if (verbose > 2) {
124 printed += dso__fprintf(pos->dso, type, fp);
125 printed += fprintf(fp, "--\n");
126 }
127 }
128
129 return printed;
130}
131
132size_t map_groups__fprintf_maps(struct map_groups *self, FILE *fp)
133{
134 size_t printed = 0, i;
135 for (i = 0; i < MAP__NR_TYPES; ++i)
136 printed += __map_groups__fprintf_maps(self, i, fp);
137 return printed;
138}
139
140static size_t __map_groups__fprintf_removed_maps(struct map_groups *self,
141 enum map_type type, FILE *fp)
142{
143 struct map *pos;
144 size_t printed = 0;
145
146 list_for_each_entry(pos, &self->removed_maps[type], node) {
147 printed += fprintf(fp, "Map:");
148 printed += map__fprintf(pos, fp);
149 if (verbose > 1) {
150 printed += dso__fprintf(pos->dso, type, fp);
151 printed += fprintf(fp, "--\n");
152 }
153 }
154 return printed;
155}
156
157static size_t map_groups__fprintf_removed_maps(struct map_groups *self, FILE *fp)
158{
159 size_t printed = 0, i;
160 for (i = 0; i < MAP__NR_TYPES; ++i)
161 printed += __map_groups__fprintf_removed_maps(self, i, fp);
162 return printed;
163}
164
165static size_t map_groups__fprintf(struct map_groups *self, FILE *fp)
166{
167 size_t printed = map_groups__fprintf_maps(self, fp);
168 printed += fprintf(fp, "Removed maps:\n");
169 return printed + map_groups__fprintf_removed_maps(self, fp);
170}
171
172static size_t thread__fprintf(struct thread *self, FILE *fp) 82static size_t thread__fprintf(struct thread *self, FILE *fp)
173{ 83{
174 return fprintf(fp, "Thread %d %s\n", self->pid, self->comm) + 84 return fprintf(fp, "Thread %d %s\n", self->pid, self->comm) +
175 map_groups__fprintf(&self->mg, fp); 85 map_groups__fprintf(&self->mg, verbose, fp);
176} 86}
177 87
178struct thread *perf_session__findnew(struct perf_session *self, pid_t pid) 88struct thread *perf_session__findnew(struct perf_session *self, pid_t pid)
@@ -214,87 +124,12 @@ struct thread *perf_session__findnew(struct perf_session *self, pid_t pid)
214 return th; 124 return th;
215} 125}
216 126
217static int map_groups__fixup_overlappings(struct map_groups *self,
218 struct map *map)
219{
220 struct rb_root *root = &self->maps[map->type];
221 struct rb_node *next = rb_first(root);
222
223 while (next) {
224 struct map *pos = rb_entry(next, struct map, rb_node);
225 next = rb_next(&pos->rb_node);
226
227 if (!map__overlap(pos, map))
228 continue;
229
230 if (verbose >= 2) {
231 fputs("overlapping maps:\n", stderr);
232 map__fprintf(map, stderr);
233 map__fprintf(pos, stderr);
234 }
235
236 rb_erase(&pos->rb_node, root);
237 /*
238 * We may have references to this map, for instance in some
239 * hist_entry instances, so just move them to a separate
240 * list.
241 */
242 list_add_tail(&pos->node, &self->removed_maps[map->type]);
243 /*
244 * Now check if we need to create new maps for areas not
245 * overlapped by the new map:
246 */
247 if (map->start > pos->start) {
248 struct map *before = map__clone(pos);
249
250 if (before == NULL)
251 return -ENOMEM;
252
253 before->end = map->start - 1;
254 map_groups__insert(self, before);
255 if (verbose >= 2)
256 map__fprintf(before, stderr);
257 }
258
259 if (map->end < pos->end) {
260 struct map *after = map__clone(pos);
261
262 if (after == NULL)
263 return -ENOMEM;
264
265 after->start = map->end + 1;
266 map_groups__insert(self, after);
267 if (verbose >= 2)
268 map__fprintf(after, stderr);
269 }
270 }
271
272 return 0;
273}
274
275void thread__insert_map(struct thread *self, struct map *map) 127void thread__insert_map(struct thread *self, struct map *map)
276{ 128{
277 map_groups__fixup_overlappings(&self->mg, map); 129 map_groups__fixup_overlappings(&self->mg, map, verbose, stderr);
278 map_groups__insert(&self->mg, map); 130 map_groups__insert(&self->mg, map);
279} 131}
280 132
281/*
282 * XXX This should not really _copy_ te maps, but refcount them.
283 */
284static int map_groups__clone(struct map_groups *self,
285 struct map_groups *parent, enum map_type type)
286{
287 struct rb_node *nd;
288 for (nd = rb_first(&parent->maps[type]); nd; nd = rb_next(nd)) {
289 struct map *map = rb_entry(nd, struct map, rb_node);
290 struct map *new = map__clone(map);
291 if (new == NULL)
292 return -ENOMEM;
293 map_groups__insert(self, new);
294 }
295 return 0;
296}
297
298int thread__fork(struct thread *self, struct thread *parent) 133int thread__fork(struct thread *self, struct thread *parent)
299{ 134{
300 int i; 135 int i;