10 struct thread
*thread__new(pid_t pid
, pid_t tid
)
12 struct thread
*thread
= zalloc(sizeof(*thread
));
15 map_groups__init(&thread
->mg
);
19 thread
->comm
= malloc(32);
21 snprintf(thread
->comm
, 32, ":%d", thread
->tid
);
27 void thread__delete(struct thread
*thread
)
29 map_groups__exit(&thread
->mg
);
34 int thread__set_comm(struct thread
*thread
, const char *comm
,
35 u64 timestamp __maybe_unused
)
41 thread
->comm
= strdup(comm
);
42 err
= thread
->comm
== NULL
? -ENOMEM
: 0;
44 thread
->comm_set
= true;
49 const char *thread__comm_str(const struct thread
*thread
)
54 int thread__comm_len(struct thread
*thread
)
56 if (!thread
->comm_len
) {
59 thread
->comm_len
= strlen(thread
->comm
);
62 return thread
->comm_len
;
65 size_t thread__fprintf(struct thread
*thread
, FILE *fp
)
67 return fprintf(fp
, "Thread %d %s\n", thread
->tid
, thread__comm_str(thread
)) +
68 map_groups__fprintf(&thread
->mg
, verbose
, fp
);
71 void thread__insert_map(struct thread
*thread
, struct map
*map
)
73 map_groups__fixup_overlappings(&thread
->mg
, map
, verbose
, stderr
);
74 map_groups__insert(&thread
->mg
, map
);
77 int thread__fork(struct thread
*thread
, struct thread
*parent
,
78 u64 timestamp __maybe_unused
)
82 if (parent
->comm_set
) {
85 thread
->comm
= strdup(parent
->comm
);
88 thread
->comm_set
= true;
91 for (i
= 0; i
< MAP__NR_TYPES
; ++i
)
92 if (map_groups__clone(&thread
->mg
, &parent
->mg
, i
) < 0)
95 thread
->ppid
= parent
->tid
;