diff options
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/perf/Makefile | 2 | ||||
| -rw-r--r-- | tools/perf/builtin-record.c | 1 | ||||
| -rw-r--r-- | tools/perf/builtin-stat.c | 1 | ||||
| -rw-r--r-- | tools/perf/builtin-test.c | 2 | ||||
| -rw-r--r-- | tools/perf/builtin-top.c | 1 | ||||
| -rw-r--r-- | tools/perf/util/evsel.c | 2 | ||||
| -rw-r--r-- | tools/perf/util/thread.c | 55 | ||||
| -rw-r--r-- | tools/perf/util/thread.h | 14 | ||||
| -rw-r--r-- | tools/perf/util/thread_map.c | 64 | ||||
| -rw-r--r-- | tools/perf/util/thread_map.h | 15 |
10 files changed, 86 insertions, 71 deletions
diff --git a/tools/perf/Makefile b/tools/perf/Makefile index f20bc6f85611..638e8e146bb9 100644 --- a/tools/perf/Makefile +++ b/tools/perf/Makefile | |||
| @@ -426,6 +426,7 @@ LIB_H += util/values.h | |||
| 426 | LIB_H += util/sort.h | 426 | LIB_H += util/sort.h |
| 427 | LIB_H += util/hist.h | 427 | LIB_H += util/hist.h |
| 428 | LIB_H += util/thread.h | 428 | LIB_H += util/thread.h |
| 429 | LIB_H += util/thread_map.h | ||
| 429 | LIB_H += util/trace-event.h | 430 | LIB_H += util/trace-event.h |
| 430 | LIB_H += util/probe-finder.h | 431 | LIB_H += util/probe-finder.h |
| 431 | LIB_H += util/probe-event.h | 432 | LIB_H += util/probe-event.h |
| @@ -471,6 +472,7 @@ LIB_OBJS += $(OUTPUT)util/map.o | |||
| 471 | LIB_OBJS += $(OUTPUT)util/pstack.o | 472 | LIB_OBJS += $(OUTPUT)util/pstack.o |
| 472 | LIB_OBJS += $(OUTPUT)util/session.o | 473 | LIB_OBJS += $(OUTPUT)util/session.o |
| 473 | LIB_OBJS += $(OUTPUT)util/thread.o | 474 | LIB_OBJS += $(OUTPUT)util/thread.o |
| 475 | LIB_OBJS += $(OUTPUT)util/thread_map.o | ||
| 474 | LIB_OBJS += $(OUTPUT)util/trace-event-parse.o | 476 | LIB_OBJS += $(OUTPUT)util/trace-event-parse.o |
| 475 | LIB_OBJS += $(OUTPUT)util/trace-event-read.o | 477 | LIB_OBJS += $(OUTPUT)util/trace-event-read.o |
| 476 | LIB_OBJS += $(OUTPUT)util/trace-event-info.o | 478 | LIB_OBJS += $(OUTPUT)util/trace-event-info.o |
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 1346d4230bc0..d7886307f6f4 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c | |||
| @@ -24,6 +24,7 @@ | |||
| 24 | #include "util/session.h" | 24 | #include "util/session.h" |
| 25 | #include "util/symbol.h" | 25 | #include "util/symbol.h" |
| 26 | #include "util/cpumap.h" | 26 | #include "util/cpumap.h" |
| 27 | #include "util/thread_map.h" | ||
| 27 | 28 | ||
| 28 | #include <unistd.h> | 29 | #include <unistd.h> |
| 29 | #include <sched.h> | 30 | #include <sched.h> |
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index e2a2d02c5c43..8906adfdbd8e 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c | |||
| @@ -49,6 +49,7 @@ | |||
| 49 | #include "util/header.h" | 49 | #include "util/header.h" |
| 50 | #include "util/cpumap.h" | 50 | #include "util/cpumap.h" |
| 51 | #include "util/thread.h" | 51 | #include "util/thread.h" |
| 52 | #include "util/thread_map.h" | ||
| 52 | 53 | ||
| 53 | #include <sys/prctl.h> | 54 | #include <sys/prctl.h> |
| 54 | #include <math.h> | 55 | #include <math.h> |
diff --git a/tools/perf/builtin-test.c b/tools/perf/builtin-test.c index 4fd34537c01d..dc91ee06a37c 100644 --- a/tools/perf/builtin-test.c +++ b/tools/perf/builtin-test.c | |||
| @@ -12,7 +12,7 @@ | |||
| 12 | #include "util/parse-events.h" | 12 | #include "util/parse-events.h" |
| 13 | #include "util/session.h" | 13 | #include "util/session.h" |
| 14 | #include "util/symbol.h" | 14 | #include "util/symbol.h" |
| 15 | #include "util/thread.h" | 15 | #include "util/thread_map.h" |
| 16 | 16 | ||
| 17 | static long page_size; | 17 | static long page_size; |
| 18 | 18 | ||
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index 31fbaf38d9c1..d0b16d905405 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c | |||
| @@ -26,6 +26,7 @@ | |||
| 26 | #include "util/session.h" | 26 | #include "util/session.h" |
| 27 | #include "util/symbol.h" | 27 | #include "util/symbol.h" |
| 28 | #include "util/thread.h" | 28 | #include "util/thread.h" |
| 29 | #include "util/thread_map.h" | ||
| 29 | #include "util/util.h" | 30 | #include "util/util.h" |
| 30 | #include <linux/rbtree.h> | 31 | #include <linux/rbtree.h> |
| 31 | #include "util/parse-options.h" | 32 | #include "util/parse-options.h" |
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index ee490356c817..9a6d94299ab8 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | #include "../perf.h" | 3 | #include "../perf.h" |
| 4 | #include "util.h" | 4 | #include "util.h" |
| 5 | #include "cpumap.h" | 5 | #include "cpumap.h" |
| 6 | #include "thread.h" | 6 | #include "thread_map.h" |
| 7 | 7 | ||
| 8 | #include <unistd.h> | 8 | #include <unistd.h> |
| 9 | #include <sys/mman.h> | 9 | #include <sys/mman.h> |
diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c index 00f4eade2e3e..d5d3b22250f3 100644 --- a/tools/perf/util/thread.c +++ b/tools/perf/util/thread.c | |||
| @@ -7,61 +7,6 @@ | |||
| 7 | #include "util.h" | 7 | #include "util.h" |
| 8 | #include "debug.h" | 8 | #include "debug.h" |
| 9 | 9 | ||
| 10 | /* Skip "." and ".." directories */ | ||
| 11 | static int filter(const struct dirent *dir) | ||
| 12 | { | ||
| 13 | if (dir->d_name[0] == '.') | ||
| 14 | return 0; | ||
| 15 | else | ||
| 16 | return 1; | ||
| 17 | } | ||
| 18 | |||
| 19 | struct thread_map *thread_map__new_by_pid(pid_t pid) | ||
| 20 | { | ||
| 21 | struct thread_map *threads; | ||
| 22 | char name[256]; | ||
| 23 | int items; | ||
| 24 | struct dirent **namelist = NULL; | ||
| 25 | int i; | ||
| 26 | |||
| 27 | sprintf(name, "/proc/%d/task", pid); | ||
| 28 | items = scandir(name, &namelist, filter, NULL); | ||
| 29 | if (items <= 0) | ||
| 30 | return NULL; | ||
| 31 | |||
| 32 | threads = malloc(sizeof(*threads) + sizeof(pid_t) * items); | ||
| 33 | if (threads != NULL) { | ||
| 34 | for (i = 0; i < items; i++) | ||
| 35 | threads->map[i] = atoi(namelist[i]->d_name); | ||
| 36 | threads->nr = items; | ||
| 37 | } | ||
| 38 | |||
| 39 | for (i=0; i<items; i++) | ||
| 40 | free(namelist[i]); | ||
| 41 | free(namelist); | ||
| 42 | |||
| 43 | return threads; | ||
| 44 | } | ||
| 45 | |||
| 46 | struct thread_map *thread_map__new_by_tid(pid_t tid) | ||
| 47 | { | ||
| 48 | struct thread_map *threads = malloc(sizeof(*threads) + sizeof(pid_t)); | ||
| 49 | |||
| 50 | if (threads != NULL) { | ||
| 51 | threads->map[0] = tid; | ||
| 52 | threads->nr = 1; | ||
| 53 | } | ||
| 54 | |||
| 55 | return threads; | ||
| 56 | } | ||
| 57 | |||
| 58 | struct thread_map *thread_map__new(pid_t pid, pid_t tid) | ||
| 59 | { | ||
| 60 | if (pid != -1) | ||
| 61 | return thread_map__new_by_pid(pid); | ||
| 62 | return thread_map__new_by_tid(tid); | ||
| 63 | } | ||
| 64 | |||
| 65 | static struct thread *thread__new(pid_t pid) | 10 | static struct thread *thread__new(pid_t pid) |
| 66 | { | 11 | { |
| 67 | struct thread *self = zalloc(sizeof(*self)); | 12 | struct thread *self = zalloc(sizeof(*self)); |
diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h index d7574101054a..e5f2401c1b5e 100644 --- a/tools/perf/util/thread.h +++ b/tools/perf/util/thread.h | |||
| @@ -18,24 +18,10 @@ struct thread { | |||
| 18 | int comm_len; | 18 | int comm_len; |
| 19 | }; | 19 | }; |
| 20 | 20 | ||
| 21 | struct thread_map { | ||
| 22 | int nr; | ||
| 23 | int map[]; | ||
| 24 | }; | ||
| 25 | |||
| 26 | struct perf_session; | 21 | struct perf_session; |
| 27 | 22 | ||
| 28 | void thread__delete(struct thread *self); | 23 | void thread__delete(struct thread *self); |
| 29 | 24 | ||
| 30 | struct thread_map *thread_map__new_by_pid(pid_t pid); | ||
| 31 | struct thread_map *thread_map__new_by_tid(pid_t tid); | ||
| 32 | struct thread_map *thread_map__new(pid_t pid, pid_t tid); | ||
| 33 | |||
| 34 | static inline void thread_map__delete(struct thread_map *threads) | ||
| 35 | { | ||
| 36 | free(threads); | ||
| 37 | } | ||
| 38 | |||
| 39 | int thread__set_comm(struct thread *self, const char *comm); | 25 | int thread__set_comm(struct thread *self, const char *comm); |
| 40 | int thread__comm_len(struct thread *self); | 26 | int thread__comm_len(struct thread *self); |
| 41 | struct thread *perf_session__findnew(struct perf_session *self, pid_t pid); | 27 | struct thread *perf_session__findnew(struct perf_session *self, pid_t pid); |
diff --git a/tools/perf/util/thread_map.c b/tools/perf/util/thread_map.c new file mode 100644 index 000000000000..a5df131b77c3 --- /dev/null +++ b/tools/perf/util/thread_map.c | |||
| @@ -0,0 +1,64 @@ | |||
| 1 | #include <dirent.h> | ||
| 2 | #include <stdlib.h> | ||
| 3 | #include <stdio.h> | ||
| 4 | #include "thread_map.h" | ||
| 5 | |||
| 6 | /* Skip "." and ".." directories */ | ||
| 7 | static int filter(const struct dirent *dir) | ||
| 8 | { | ||
| 9 | if (dir->d_name[0] == '.') | ||
| 10 | return 0; | ||
| 11 | else | ||
| 12 | return 1; | ||
| 13 | } | ||
| 14 | |||
| 15 | struct thread_map *thread_map__new_by_pid(pid_t pid) | ||
| 16 | { | ||
| 17 | struct thread_map *threads; | ||
| 18 | char name[256]; | ||
| 19 | int items; | ||
| 20 | struct dirent **namelist = NULL; | ||
| 21 | int i; | ||
| 22 | |||
| 23 | sprintf(name, "/proc/%d/task", pid); | ||
| 24 | items = scandir(name, &namelist, filter, NULL); | ||
| 25 | if (items <= 0) | ||
| 26 | return NULL; | ||
| 27 | |||
| 28 | threads = malloc(sizeof(*threads) + sizeof(pid_t) * items); | ||
| 29 | if (threads != NULL) { | ||
| 30 | for (i = 0; i < items; i++) | ||
| 31 | threads->map[i] = atoi(namelist[i]->d_name); | ||
| 32 | threads->nr = items; | ||
| 33 | } | ||
| 34 | |||
| 35 | for (i=0; i<items; i++) | ||
| 36 | free(namelist[i]); | ||
| 37 | free(namelist); | ||
| 38 | |||
| 39 | return threads; | ||
| 40 | } | ||
| 41 | |||
| 42 | struct thread_map *thread_map__new_by_tid(pid_t tid) | ||
| 43 | { | ||
| 44 | struct thread_map *threads = malloc(sizeof(*threads) + sizeof(pid_t)); | ||
| 45 | |||
| 46 | if (threads != NULL) { | ||
| 47 | threads->map[0] = tid; | ||
| 48 | threads->nr = 1; | ||
| 49 | } | ||
| 50 | |||
| 51 | return threads; | ||
| 52 | } | ||
| 53 | |||
| 54 | struct thread_map *thread_map__new(pid_t pid, pid_t tid) | ||
| 55 | { | ||
| 56 | if (pid != -1) | ||
| 57 | return thread_map__new_by_pid(pid); | ||
| 58 | return thread_map__new_by_tid(tid); | ||
| 59 | } | ||
| 60 | |||
| 61 | void thread_map__delete(struct thread_map *threads) | ||
| 62 | { | ||
| 63 | free(threads); | ||
| 64 | } | ||
diff --git a/tools/perf/util/thread_map.h b/tools/perf/util/thread_map.h new file mode 100644 index 000000000000..3cb907311409 --- /dev/null +++ b/tools/perf/util/thread_map.h | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | #ifndef __PERF_THREAD_MAP_H | ||
| 2 | #define __PERF_THREAD_MAP_H | ||
| 3 | |||
| 4 | #include <sys/types.h> | ||
| 5 | |||
| 6 | struct thread_map { | ||
| 7 | int nr; | ||
| 8 | int map[]; | ||
| 9 | }; | ||
| 10 | |||
| 11 | struct thread_map *thread_map__new_by_pid(pid_t pid); | ||
| 12 | struct thread_map *thread_map__new_by_tid(pid_t tid); | ||
| 13 | struct thread_map *thread_map__new(pid_t pid, pid_t tid); | ||
| 14 | void thread_map__delete(struct thread_map *threads); | ||
| 15 | #endif /* __PERF_THREAD_MAP_H */ | ||
