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.c33
1 files changed, 28 insertions, 5 deletions
diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c
index 12c7a253a63c..c41411726c7a 100644
--- a/tools/perf/util/thread.c
+++ b/tools/perf/util/thread.c
@@ -7,6 +7,7 @@
7#include "util.h" 7#include "util.h"
8#include "debug.h" 8#include "debug.h"
9#include "comm.h" 9#include "comm.h"
10#include "unwind.h"
10 11
11int thread__init_map_groups(struct thread *thread, struct machine *machine) 12int thread__init_map_groups(struct thread *thread, struct machine *machine)
12{ 13{
@@ -37,17 +38,21 @@ struct thread *thread__new(pid_t pid, pid_t tid)
37 thread->cpu = -1; 38 thread->cpu = -1;
38 INIT_LIST_HEAD(&thread->comm_list); 39 INIT_LIST_HEAD(&thread->comm_list);
39 40
41 if (unwind__prepare_access(thread) < 0)
42 goto err_thread;
43
40 comm_str = malloc(32); 44 comm_str = malloc(32);
41 if (!comm_str) 45 if (!comm_str)
42 goto err_thread; 46 goto err_thread;
43 47
44 snprintf(comm_str, 32, ":%d", tid); 48 snprintf(comm_str, 32, ":%d", tid);
45 comm = comm__new(comm_str, 0); 49 comm = comm__new(comm_str, 0, false);
46 free(comm_str); 50 free(comm_str);
47 if (!comm) 51 if (!comm)
48 goto err_thread; 52 goto err_thread;
49 53
50 list_add(&comm->list, &thread->comm_list); 54 list_add(&comm->list, &thread->comm_list);
55
51 } 56 }
52 57
53 return thread; 58 return thread;
@@ -69,6 +74,7 @@ void thread__delete(struct thread *thread)
69 list_del(&comm->list); 74 list_del(&comm->list);
70 comm__free(comm); 75 comm__free(comm);
71 } 76 }
77 unwind__finish_access(thread);
72 78
73 free(thread); 79 free(thread);
74} 80}
@@ -81,22 +87,39 @@ struct comm *thread__comm(const struct thread *thread)
81 return list_first_entry(&thread->comm_list, struct comm, list); 87 return list_first_entry(&thread->comm_list, struct comm, list);
82} 88}
83 89
90struct comm *thread__exec_comm(const struct thread *thread)
91{
92 struct comm *comm, *last = NULL;
93
94 list_for_each_entry(comm, &thread->comm_list, list) {
95 if (comm->exec)
96 return comm;
97 last = comm;
98 }
99
100 return last;
101}
102
84/* CHECKME: time should always be 0 if event aren't ordered */ 103/* CHECKME: time should always be 0 if event aren't ordered */
85int thread__set_comm(struct thread *thread, const char *str, u64 timestamp) 104int __thread__set_comm(struct thread *thread, const char *str, u64 timestamp,
105 bool exec)
86{ 106{
87 struct comm *new, *curr = thread__comm(thread); 107 struct comm *new, *curr = thread__comm(thread);
88 int err; 108 int err;
89 109
90 /* Override latest entry if it had no specific time coverage */ 110 /* Override latest entry if it had no specific time coverage */
91 if (!curr->start) { 111 if (!curr->start && !curr->exec) {
92 err = comm__override(curr, str, timestamp); 112 err = comm__override(curr, str, timestamp, exec);
93 if (err) 113 if (err)
94 return err; 114 return err;
95 } else { 115 } else {
96 new = comm__new(str, timestamp); 116 new = comm__new(str, timestamp, exec);
97 if (!new) 117 if (!new)
98 return -ENOMEM; 118 return -ENOMEM;
99 list_add(&new->list, &thread->comm_list); 119 list_add(&new->list, &thread->comm_list);
120
121 if (exec)
122 unwind__flush_access(thread);
100 } 123 }
101 124
102 thread->comm_set = true; 125 thread->comm_set = true;