diff options
author | Namhyung Kim <namhyung.kim@lge.com> | 2012-04-26 01:15:18 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-05-02 14:22:08 -0400 |
commit | 4bd0f2d2c0cf14de9c84c2fe689120c6b0f667c8 (patch) | |
tree | d663fdacac1c3d0dd2c75f939fddbe63d2aa86ba /tools/perf/util/usage.c | |
parent | fe9d18a71d2018f8021fd2bd2aaf5137954ef839 (diff) |
perf tools: Introduce perf_target__validate() helper
The perf_target__validate function is used to check given PID/TID/UID/CPU
target options and warn if some combination is impossible. Also this can
make some arguments of parse_target_uid() function useless as it is checked
before the call via our new helper.
Signed-off-by: Namhyung Kim <namhyung.kim@lge.com>
Reviewed-by: David Ahern <dsahern@gmail.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1335417327-11796-5-git-send-email-namhyung.kim@lge.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/usage.c')
-rw-r--r-- | tools/perf/util/usage.c | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/tools/perf/util/usage.c b/tools/perf/util/usage.c index 52bb07c6442a..0a1a885a5914 100644 --- a/tools/perf/util/usage.c +++ b/tools/perf/util/usage.c | |||
@@ -83,7 +83,7 @@ void warning(const char *warn, ...) | |||
83 | va_end(params); | 83 | va_end(params); |
84 | } | 84 | } |
85 | 85 | ||
86 | uid_t parse_target_uid(const char *str, const char *tid, const char *pid) | 86 | uid_t parse_target_uid(const char *str) |
87 | { | 87 | { |
88 | struct passwd pwd, *result; | 88 | struct passwd pwd, *result; |
89 | char buf[1024]; | 89 | char buf[1024]; |
@@ -91,13 +91,6 @@ uid_t parse_target_uid(const char *str, const char *tid, const char *pid) | |||
91 | if (str == NULL) | 91 | if (str == NULL) |
92 | return UINT_MAX; | 92 | return UINT_MAX; |
93 | 93 | ||
94 | /* UID and PID are mutually exclusive */ | ||
95 | if (tid || pid) { | ||
96 | ui__warning("PID/TID switch overriding UID\n"); | ||
97 | sleep(1); | ||
98 | return UINT_MAX; | ||
99 | } | ||
100 | |||
101 | getpwnam_r(str, &pwd, buf, sizeof(buf), &result); | 94 | getpwnam_r(str, &pwd, buf, sizeof(buf), &result); |
102 | 95 | ||
103 | if (result == NULL) { | 96 | if (result == NULL) { |
@@ -120,3 +113,23 @@ uid_t parse_target_uid(const char *str, const char *tid, const char *pid) | |||
120 | 113 | ||
121 | return result->pw_uid; | 114 | return result->pw_uid; |
122 | } | 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 | } | ||