diff options
Diffstat (limited to 'tools/perf/util')
-rw-r--r-- | tools/perf/util/thread.c | 32 | ||||
-rw-r--r-- | tools/perf/util/thread.h | 1 |
2 files changed, 33 insertions, 0 deletions
diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c index fa968312ee7d..ea6506234d57 100644 --- a/tools/perf/util/thread.c +++ b/tools/perf/util/thread.c | |||
@@ -7,6 +7,37 @@ | |||
7 | #include "util.h" | 7 | #include "util.h" |
8 | #include "debug.h" | 8 | #include "debug.h" |
9 | 9 | ||
10 | int find_all_tid(int pid, pid_t ** all_tid) | ||
11 | { | ||
12 | char name[256]; | ||
13 | int items; | ||
14 | struct dirent **namelist = NULL; | ||
15 | int ret = 0; | ||
16 | int i; | ||
17 | |||
18 | sprintf(name, "/proc/%d/task", pid); | ||
19 | items = scandir(name, &namelist, NULL, NULL); | ||
20 | if (items <= 0) | ||
21 | return -ENOENT; | ||
22 | *all_tid = malloc(sizeof(pid_t) * items); | ||
23 | if (!*all_tid) { | ||
24 | ret = -ENOMEM; | ||
25 | goto failure; | ||
26 | } | ||
27 | |||
28 | for (i = 0; i < items; i++) | ||
29 | (*all_tid)[i] = atoi(namelist[i]->d_name); | ||
30 | |||
31 | ret = items; | ||
32 | |||
33 | failure: | ||
34 | for (i=0; i<items; i++) | ||
35 | free(namelist[i]); | ||
36 | free(namelist); | ||
37 | |||
38 | return ret; | ||
39 | } | ||
40 | |||
10 | void map_groups__init(struct map_groups *self) | 41 | void map_groups__init(struct map_groups *self) |
11 | { | 42 | { |
12 | int i; | 43 | int i; |
@@ -348,3 +379,4 @@ struct symbol *map_groups__find_symbol(struct map_groups *self, | |||
348 | 379 | ||
349 | return NULL; | 380 | return NULL; |
350 | } | 381 | } |
382 | |||
diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h index dcf70303e58e..a81426a891bf 100644 --- a/tools/perf/util/thread.h +++ b/tools/perf/util/thread.h | |||
@@ -23,6 +23,7 @@ struct thread { | |||
23 | int comm_len; | 23 | int comm_len; |
24 | }; | 24 | }; |
25 | 25 | ||
26 | int find_all_tid(int pid, pid_t ** all_tid); | ||
26 | void map_groups__init(struct map_groups *self); | 27 | void map_groups__init(struct map_groups *self); |
27 | int thread__set_comm(struct thread *self, const char *comm); | 28 | int thread__set_comm(struct thread *self, const char *comm); |
28 | int thread__comm_len(struct thread *self); | 29 | int thread__comm_len(struct thread *self); |