diff options
-rw-r--r-- | tools/perf/Makefile | 2 | ||||
-rw-r--r-- | tools/perf/perf.h | 9 | ||||
-rw-r--r-- | tools/perf/util/evlist.c | 1 | ||||
-rw-r--r-- | tools/perf/util/evsel.c | 1 | ||||
-rw-r--r-- | tools/perf/util/target.c | 45 | ||||
-rw-r--r-- | tools/perf/util/target.h | 18 | ||||
-rw-r--r-- | tools/perf/util/usage.c | 34 | ||||
-rw-r--r-- | tools/perf/util/util.h | 2 |
8 files changed, 68 insertions, 44 deletions
diff --git a/tools/perf/Makefile b/tools/perf/Makefile index e98e14c88532..4122a668952e 100644 --- a/tools/perf/Makefile +++ b/tools/perf/Makefile | |||
@@ -300,6 +300,7 @@ LIB_H += util/cpumap.h | |||
300 | LIB_H += util/top.h | 300 | LIB_H += util/top.h |
301 | LIB_H += $(ARCH_INCLUDE) | 301 | LIB_H += $(ARCH_INCLUDE) |
302 | LIB_H += util/cgroup.h | 302 | LIB_H += util/cgroup.h |
303 | LIB_H += util/target.h | ||
303 | 304 | ||
304 | LIB_OBJS += $(OUTPUT)util/abspath.o | 305 | LIB_OBJS += $(OUTPUT)util/abspath.o |
305 | LIB_OBJS += $(OUTPUT)util/alias.o | 306 | LIB_OBJS += $(OUTPUT)util/alias.o |
@@ -361,6 +362,7 @@ LIB_OBJS += $(OUTPUT)util/util.o | |||
361 | LIB_OBJS += $(OUTPUT)util/xyarray.o | 362 | LIB_OBJS += $(OUTPUT)util/xyarray.o |
362 | LIB_OBJS += $(OUTPUT)util/cpumap.o | 363 | LIB_OBJS += $(OUTPUT)util/cpumap.o |
363 | LIB_OBJS += $(OUTPUT)util/cgroup.o | 364 | LIB_OBJS += $(OUTPUT)util/cgroup.o |
365 | LIB_OBJS += $(OUTPUT)util/target.o | ||
364 | 366 | ||
365 | BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o | 367 | BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o |
366 | 368 | ||
diff --git a/tools/perf/perf.h b/tools/perf/perf.h index 7e226c0e0e31..14f1034f14f9 100644 --- a/tools/perf/perf.h +++ b/tools/perf/perf.h | |||
@@ -207,14 +207,7 @@ extern const char perf_version_string[]; | |||
207 | 207 | ||
208 | void pthread__unblock_sigwinch(void); | 208 | void pthread__unblock_sigwinch(void); |
209 | 209 | ||
210 | struct perf_target { | 210 | #include "util/target.h" |
211 | const char *pid; | ||
212 | const char *tid; | ||
213 | const char *cpu_list; | ||
214 | const char *uid_str; | ||
215 | uid_t uid; | ||
216 | bool system_wide; | ||
217 | }; | ||
218 | 211 | ||
219 | struct perf_record_opts { | 212 | struct perf_record_opts { |
220 | struct perf_target target; | 213 | struct perf_target target; |
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index a43e2c56d1c6..30328623cae6 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c | |||
@@ -11,6 +11,7 @@ | |||
11 | #include <poll.h> | 11 | #include <poll.h> |
12 | #include "cpumap.h" | 12 | #include "cpumap.h" |
13 | #include "thread_map.h" | 13 | #include "thread_map.h" |
14 | #include "target.h" | ||
14 | #include "evlist.h" | 15 | #include "evlist.h" |
15 | #include "evsel.h" | 16 | #include "evsel.h" |
16 | #include <unistd.h> | 17 | #include <unistd.h> |
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index d90598edcf1d..bb785a098ced 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c | |||
@@ -14,6 +14,7 @@ | |||
14 | #include "util.h" | 14 | #include "util.h" |
15 | #include "cpumap.h" | 15 | #include "cpumap.h" |
16 | #include "thread_map.h" | 16 | #include "thread_map.h" |
17 | #include "target.h" | ||
17 | 18 | ||
18 | #define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y)) | 19 | #define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y)) |
19 | #define GROUP_FD(group_fd, cpu) (*(int *)xyarray__entry(group_fd, cpu, 0)) | 20 | #define GROUP_FD(group_fd, cpu) (*(int *)xyarray__entry(group_fd, cpu, 0)) |
diff --git a/tools/perf/util/target.c b/tools/perf/util/target.c new file mode 100644 index 000000000000..3fadf85dd7e3 --- /dev/null +++ b/tools/perf/util/target.c | |||
@@ -0,0 +1,45 @@ | |||
1 | /* | ||
2 | * Helper functions for handling target threads/cpus | ||
3 | * | ||
4 | * Copyright (C) 2012, LG Electronics, Namhyung Kim <namhyung.kim@lge.com> | ||
5 | * | ||
6 | * Released under the GPL v2. | ||
7 | */ | ||
8 | |||
9 | #include "target.h" | ||
10 | #include "debug.h" | ||
11 | |||
12 | |||
13 | void perf_target__validate(struct perf_target *target) | ||
14 | { | ||
15 | if (target->pid) | ||
16 | target->tid = target->pid; | ||
17 | |||
18 | /* CPU and PID are mutually exclusive */ | ||
19 | if (target->tid && target->cpu_list) { | ||
20 | ui__warning("WARNING: PID switch overriding CPU\n"); | ||
21 | sleep(1); | ||
22 | target->cpu_list = NULL; | ||
23 | } | ||
24 | |||
25 | /* UID and PID are mutually exclusive */ | ||
26 | if (target->tid && target->uid_str) { | ||
27 | ui__warning("PID/TID switch overriding UID\n"); | ||
28 | sleep(1); | ||
29 | target->uid_str = NULL; | ||
30 | } | ||
31 | |||
32 | /* UID and CPU are mutually exclusive */ | ||
33 | if (target->uid_str && target->cpu_list) { | ||
34 | ui__warning("UID switch overriding CPU\n"); | ||
35 | sleep(1); | ||
36 | target->cpu_list = NULL; | ||
37 | } | ||
38 | |||
39 | /* PID/UID and SYSTEM are mutually exclusive */ | ||
40 | if ((target->tid || target->uid_str) && target->system_wide) { | ||
41 | ui__warning("PID/TID/UID switch overriding CPU\n"); | ||
42 | sleep(1); | ||
43 | target->system_wide = false; | ||
44 | } | ||
45 | } | ||
diff --git a/tools/perf/util/target.h b/tools/perf/util/target.h new file mode 100644 index 000000000000..218291f921ed --- /dev/null +++ b/tools/perf/util/target.h | |||
@@ -0,0 +1,18 @@ | |||
1 | #ifndef _PERF_TARGET_H | ||
2 | #define _PERF_TARGET_H | ||
3 | |||
4 | #include <stdbool.h> | ||
5 | #include <sys/types.h> | ||
6 | |||
7 | struct perf_target { | ||
8 | const char *pid; | ||
9 | const char *tid; | ||
10 | const char *cpu_list; | ||
11 | const char *uid_str; | ||
12 | uid_t uid; | ||
13 | bool system_wide; | ||
14 | }; | ||
15 | |||
16 | void perf_target__validate(struct perf_target *target); | ||
17 | |||
18 | #endif /* _PERF_TARGET_H */ | ||
diff --git a/tools/perf/util/usage.c b/tools/perf/util/usage.c index 228f0a558872..e851abc22ccc 100644 --- a/tools/perf/util/usage.c +++ b/tools/perf/util/usage.c | |||
@@ -113,37 +113,3 @@ uid_t parse_target_uid(const char *str) | |||
113 | 113 | ||
114 | return result->pw_uid; | 114 | return result->pw_uid; |
115 | } | 115 | } |
116 | |||
117 | void perf_target__validate(struct perf_target *target) | ||
118 | { | ||
119 | if (target->pid) | ||
120 | target->tid = target->pid; | ||
121 | |||
122 | /* CPU and PID are mutually exclusive */ | ||
123 | if (target->tid && target->cpu_list) { | ||
124 | ui__warning("WARNING: PID switch overriding CPU\n"); | ||
125 | sleep(1); | ||
126 | target->cpu_list = NULL; | ||
127 | } | ||
128 | |||
129 | /* UID and PID are mutually exclusive */ | ||
130 | if (target->tid && target->uid_str) { | ||
131 | ui__warning("PID/TID switch overriding UID\n"); | ||
132 | sleep(1); | ||
133 | target->uid_str = NULL; | ||
134 | } | ||
135 | |||
136 | /* UID and CPU are mutually exclusive */ | ||
137 | if (target->uid_str && target->cpu_list) { | ||
138 | ui__warning("UID switch overriding CPU\n"); | ||
139 | sleep(1); | ||
140 | target->cpu_list = NULL; | ||
141 | } | ||
142 | |||
143 | /* PID/UID and SYSTEM are mutually exclusive */ | ||
144 | if ((target->tid || target->uid_str) && target->system_wide) { | ||
145 | ui__warning("PID/TID/UID switch overriding CPU\n"); | ||
146 | sleep(1); | ||
147 | target->system_wide = false; | ||
148 | } | ||
149 | } | ||
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h index 3f05d6264dab..52be74c359d3 100644 --- a/tools/perf/util/util.h +++ b/tools/perf/util/util.h | |||
@@ -246,12 +246,10 @@ unsigned long convert_unit(unsigned long value, char *unit); | |||
246 | int readn(int fd, void *buf, size_t size); | 246 | int readn(int fd, void *buf, size_t size); |
247 | 247 | ||
248 | struct perf_event_attr; | 248 | struct perf_event_attr; |
249 | struct perf_target; | ||
250 | 249 | ||
251 | void event_attr_init(struct perf_event_attr *attr); | 250 | void event_attr_init(struct perf_event_attr *attr); |
252 | 251 | ||
253 | uid_t parse_target_uid(const char *str); | 252 | uid_t parse_target_uid(const char *str); |
254 | void perf_target__validate(struct perf_target *target); | ||
255 | 253 | ||
256 | #define _STR(x) #x | 254 | #define _STR(x) #x |
257 | #define STR(x) _STR(x) | 255 | #define STR(x) _STR(x) |