10 struct thread *thread__new(pid_t pid, pid_t tid)
12 struct thread *self = zalloc(sizeof(*self));
15 map_groups__init(&self->mg);
19 self->comm = malloc(32);
21 snprintf(self->comm, 32, ":%d", self->tid);
27 void thread__delete(struct thread *self)
29 map_groups__exit(&self->mg);
34 int thread__set_comm(struct thread *self, const char *comm)
40 self->comm = strdup(comm);
41 err = self->comm == NULL ? -ENOMEM : 0;
43 self->comm_set = true;
48 int thread__comm_len(struct thread *self)
50 if (!self->comm_len) {
53 self->comm_len = strlen(self->comm);
56 return self->comm_len;
59 size_t thread__fprintf(struct thread *thread, FILE *fp)
61 return fprintf(fp, "Thread %d %s\n", thread->tid, thread->comm) +
62 map_groups__fprintf(&thread->mg, verbose, fp);
65 void thread__insert_map(struct thread *self, struct map *map)
67 map_groups__fixup_overlappings(&self->mg, map, verbose, stderr);
68 map_groups__insert(&self->mg, map);
71 int thread__fork(struct thread *self, struct thread *parent)
75 if (parent->comm_set) {
78 self->comm = strdup(parent->comm);
81 self->comm_set = true;
84 for (i = 0; i < MAP__NR_TYPES; ++i)
85 if (map_groups__clone(&self->mg, &parent->mg, i) < 0)
88 self->ppid = parent->tid;