diff options
Diffstat (limited to 'tools/perf/util/thread.c')
| -rw-r--r-- | tools/perf/util/thread.c | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c index 74e79d26b421..dcdb87a5d0a1 100644 --- a/tools/perf/util/thread.c +++ b/tools/perf/util/thread.c | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | #include "thread-stack.h" | 7 | #include "thread-stack.h" |
| 8 | #include "util.h" | 8 | #include "util.h" |
| 9 | #include "debug.h" | 9 | #include "debug.h" |
| 10 | #include "namespaces.h" | ||
| 10 | #include "comm.h" | 11 | #include "comm.h" |
| 11 | #include "unwind.h" | 12 | #include "unwind.h" |
| 12 | 13 | ||
| @@ -40,6 +41,7 @@ struct thread *thread__new(pid_t pid, pid_t tid) | |||
| 40 | thread->tid = tid; | 41 | thread->tid = tid; |
| 41 | thread->ppid = -1; | 42 | thread->ppid = -1; |
| 42 | thread->cpu = -1; | 43 | thread->cpu = -1; |
| 44 | INIT_LIST_HEAD(&thread->namespaces_list); | ||
| 43 | INIT_LIST_HEAD(&thread->comm_list); | 45 | INIT_LIST_HEAD(&thread->comm_list); |
| 44 | 46 | ||
| 45 | comm_str = malloc(32); | 47 | comm_str = malloc(32); |
| @@ -66,7 +68,8 @@ err_thread: | |||
| 66 | 68 | ||
| 67 | void thread__delete(struct thread *thread) | 69 | void thread__delete(struct thread *thread) |
| 68 | { | 70 | { |
| 69 | struct comm *comm, *tmp; | 71 | struct namespaces *namespaces, *tmp_namespaces; |
| 72 | struct comm *comm, *tmp_comm; | ||
| 70 | 73 | ||
| 71 | BUG_ON(!RB_EMPTY_NODE(&thread->rb_node)); | 74 | BUG_ON(!RB_EMPTY_NODE(&thread->rb_node)); |
| 72 | 75 | ||
| @@ -76,7 +79,12 @@ void thread__delete(struct thread *thread) | |||
| 76 | map_groups__put(thread->mg); | 79 | map_groups__put(thread->mg); |
| 77 | thread->mg = NULL; | 80 | thread->mg = NULL; |
| 78 | } | 81 | } |
| 79 | list_for_each_entry_safe(comm, tmp, &thread->comm_list, list) { | 82 | list_for_each_entry_safe(namespaces, tmp_namespaces, |
| 83 | &thread->namespaces_list, list) { | ||
| 84 | list_del(&namespaces->list); | ||
| 85 | namespaces__free(namespaces); | ||
| 86 | } | ||
| 87 | list_for_each_entry_safe(comm, tmp_comm, &thread->comm_list, list) { | ||
| 80 | list_del(&comm->list); | 88 | list_del(&comm->list); |
| 81 | comm__free(comm); | 89 | comm__free(comm); |
| 82 | } | 90 | } |
| @@ -104,6 +112,38 @@ void thread__put(struct thread *thread) | |||
| 104 | } | 112 | } |
| 105 | } | 113 | } |
| 106 | 114 | ||
| 115 | struct namespaces *thread__namespaces(const struct thread *thread) | ||
| 116 | { | ||
| 117 | if (list_empty(&thread->namespaces_list)) | ||
| 118 | return NULL; | ||
| 119 | |||
| 120 | return list_first_entry(&thread->namespaces_list, struct namespaces, list); | ||
| 121 | } | ||
| 122 | |||
| 123 | int thread__set_namespaces(struct thread *thread, u64 timestamp, | ||
| 124 | struct namespaces_event *event) | ||
| 125 | { | ||
| 126 | struct namespaces *new, *curr = thread__namespaces(thread); | ||
| 127 | |||
| 128 | new = namespaces__new(event); | ||
| 129 | if (!new) | ||
| 130 | return -ENOMEM; | ||
| 131 | |||
| 132 | list_add(&new->list, &thread->namespaces_list); | ||
| 133 | |||
| 134 | if (timestamp && curr) { | ||
| 135 | /* | ||
| 136 | * setns syscall must have changed few or all the namespaces | ||
| 137 | * of this thread. Update end time for the namespaces | ||
| 138 | * previously used. | ||
| 139 | */ | ||
| 140 | curr = list_next_entry(new, list); | ||
| 141 | curr->end_time = timestamp; | ||
| 142 | } | ||
| 143 | |||
| 144 | return 0; | ||
| 145 | } | ||
| 146 | |||
| 107 | struct comm *thread__comm(const struct thread *thread) | 147 | struct comm *thread__comm(const struct thread *thread) |
| 108 | { | 148 | { |
| 109 | if (list_empty(&thread->comm_list)) | 149 | if (list_empty(&thread->comm_list)) |
