aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNamhyung Kim <namhyung.kim@lge.com>2012-04-26 01:15:18 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2012-05-02 14:22:08 -0400
commit4bd0f2d2c0cf14de9c84c2fe689120c6b0f667c8 (patch)
treed663fdacac1c3d0dd2c75f939fddbe63d2aa86ba
parentfe9d18a71d2018f8021fd2bd2aaf5137954ef839 (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>
-rw-r--r--tools/perf/builtin-record.c9
-rw-r--r--tools/perf/builtin-stat.c3
-rw-r--r--tools/perf/builtin-top.c15
-rw-r--r--tools/perf/util/usage.c29
-rw-r--r--tools/perf/util/util.h4
5 files changed, 31 insertions, 29 deletions
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 4dcf27057bd2..3596ccab6d3b 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -884,16 +884,13 @@ int cmd_record(int argc, const char **argv, const char *prefix __used)
884 goto out_symbol_exit; 884 goto out_symbol_exit;
885 } 885 }
886 886
887 rec->opts.target.uid = parse_target_uid(rec->opts.target.uid_str, 887 perf_target__validate(&rec->opts.target);
888 rec->opts.target.tid, 888
889 rec->opts.target.pid); 889 rec->opts.target.uid = parse_target_uid(rec->opts.target.uid_str);
890 if (rec->opts.target.uid_str != NULL && 890 if (rec->opts.target.uid_str != NULL &&
891 rec->opts.target.uid == UINT_MAX - 1) 891 rec->opts.target.uid == UINT_MAX - 1)
892 goto out_free_fd; 892 goto out_free_fd;
893 893
894 if (rec->opts.target.pid)
895 rec->opts.target.tid = rec->opts.target.pid;
896
897 if (perf_evlist__create_maps(evsel_list, rec->opts.target.pid, 894 if (perf_evlist__create_maps(evsel_list, rec->opts.target.pid,
898 rec->opts.target.tid, rec->opts.target.uid, 895 rec->opts.target.tid, rec->opts.target.uid,
899 rec->opts.target.cpu_list) < 0) 896 rec->opts.target.cpu_list) < 0)
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 1ca767d906ef..bb7723221c0d 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -1203,8 +1203,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used)
1203 if (add_default_attributes()) 1203 if (add_default_attributes())
1204 goto out; 1204 goto out;
1205 1205
1206 if (target.pid) 1206 perf_target__validate(&target);
1207 target.tid = target.pid;
1208 1207
1209 evsel_list->threads = thread_map__new_str(target.pid, 1208 evsel_list->threads = thread_map__new_str(target.pid,
1210 target.tid, UINT_MAX); 1209 target.tid, UINT_MAX);
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 2c1c207627b4..4f47952eddbd 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -1252,21 +1252,12 @@ int cmd_top(int argc, const char **argv, const char *prefix __used)
1252 1252
1253 setup_browser(false); 1253 setup_browser(false);
1254 1254
1255 top.target.uid = parse_target_uid(top.target.uid_str, top.target.tid, 1255 perf_target__validate(&top.target);
1256 top.target.pid); 1256
1257 top.target.uid = parse_target_uid(top.target.uid_str);
1257 if (top.target.uid_str != NULL && top.target.uid == UINT_MAX - 1) 1258 if (top.target.uid_str != NULL && top.target.uid == UINT_MAX - 1)
1258 goto out_delete_evlist; 1259 goto out_delete_evlist;
1259 1260
1260 /* CPU and PID are mutually exclusive */
1261 if (top.target.tid && top.target.cpu_list) {
1262 printf("WARNING: PID switch overriding CPU\n");
1263 sleep(1);
1264 top.target.cpu_list = NULL;
1265 }
1266
1267 if (top.target.pid)
1268 top.target.tid = top.target.pid;
1269
1270 if (perf_evlist__create_maps(top.evlist, top.target.pid, 1261 if (perf_evlist__create_maps(top.evlist, top.target.pid,
1271 top.target.tid, top.target.uid, 1262 top.target.tid, top.target.uid,
1272 top.target.cpu_list) < 0) 1263 top.target.cpu_list) < 0)
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
86uid_t parse_target_uid(const char *str, const char *tid, const char *pid) 86uid_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
117void 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}
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index 0f99f394d8e0..3f05d6264dab 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -246,10 +246,12 @@ unsigned long convert_unit(unsigned long value, char *unit);
246int readn(int fd, void *buf, size_t size); 246int readn(int fd, void *buf, size_t size);
247 247
248struct perf_event_attr; 248struct perf_event_attr;
249struct perf_target;
249 250
250void event_attr_init(struct perf_event_attr *attr); 251void event_attr_init(struct perf_event_attr *attr);
251 252
252uid_t parse_target_uid(const char *str, const char *tid, const char *pid); 253uid_t parse_target_uid(const char *str);
254void perf_target__validate(struct perf_target *target);
253 255
254#define _STR(x) #x 256#define _STR(x) #x
255#define STR(x) _STR(x) 257#define STR(x) _STR(x)