diff options
author | Namhyung Kim <namhyung.kim@lge.com> | 2012-05-07 01:09:02 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-05-07 16:30:21 -0400 |
commit | 16ad2ffb822cd28e2330284a60fdfec8bb90bbb0 (patch) | |
tree | 4455824202a98540493d75dc5333f77cb42b59ba /tools | |
parent | dfe78adaaca90417ece98edbd3eb1c9661334406 (diff) |
perf tools: Introduce perf_target__strerror()
The perf_target__strerror() sets @buf to a string that describes the
(perf_target-specific) error condition that is passed via @errnum.
This is similar to strerror_r() and does same thing if @errnum has a
standard errno value.
Signed-off-by: Namhyung Kim <namhyung.kim@lge.com>
Suggested-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
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/1336367344-28071-6-git-send-email-namhyung.kim@lge.com
[ committer note: No need to use PERF_ERRNO_TARGET__SUCCESS, use shorter idiom ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf/builtin-record.c | 18 | ||||
-rw-r--r-- | tools/perf/builtin-top.c | 19 | ||||
-rw-r--r-- | tools/perf/util/debug.c | 1 | ||||
-rw-r--r-- | tools/perf/util/target.c | 51 | ||||
-rw-r--r-- | tools/perf/util/target.h | 3 |
5 files changed, 87 insertions, 5 deletions
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index d26a279796d9..c8bf6ea000da 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c | |||
@@ -831,6 +831,7 @@ int cmd_record(int argc, const char **argv, const char *prefix __used) | |||
831 | struct perf_evsel *pos; | 831 | struct perf_evsel *pos; |
832 | struct perf_evlist *evsel_list; | 832 | struct perf_evlist *evsel_list; |
833 | struct perf_record *rec = &record; | 833 | struct perf_record *rec = &record; |
834 | char errbuf[BUFSIZ]; | ||
834 | 835 | ||
835 | perf_header__set_cmdline(argc, argv); | 836 | perf_header__set_cmdline(argc, argv); |
836 | 837 | ||
@@ -884,11 +885,24 @@ int cmd_record(int argc, const char **argv, const char *prefix __used) | |||
884 | goto out_symbol_exit; | 885 | goto out_symbol_exit; |
885 | } | 886 | } |
886 | 887 | ||
887 | perf_target__validate(&rec->opts.target); | 888 | err = perf_target__validate(&rec->opts.target); |
889 | if (err) { | ||
890 | perf_target__strerror(&rec->opts.target, err, errbuf, BUFSIZ); | ||
891 | ui__warning("%s", errbuf); | ||
892 | } | ||
893 | |||
894 | err = perf_target__parse_uid(&rec->opts.target); | ||
895 | if (err) { | ||
896 | int saved_errno = errno; | ||
888 | 897 | ||
889 | if (perf_target__parse_uid(&rec->opts.target) < 0) | 898 | perf_target__strerror(&rec->opts.target, err, errbuf, BUFSIZ); |
899 | ui__warning("%s", errbuf); | ||
900 | |||
901 | err = -saved_errno; | ||
890 | goto out_free_fd; | 902 | goto out_free_fd; |
903 | } | ||
891 | 904 | ||
905 | err = -ENOMEM; | ||
892 | if (perf_evlist__create_maps(evsel_list, &rec->opts.target) < 0) | 906 | if (perf_evlist__create_maps(evsel_list, &rec->opts.target) < 0) |
893 | usage_with_options(record_usage, record_options); | 907 | usage_with_options(record_usage, record_options); |
894 | 908 | ||
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index c9137ba580d9..7ba0f03c0132 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c | |||
@@ -1150,7 +1150,8 @@ static const char * const top_usage[] = { | |||
1150 | int cmd_top(int argc, const char **argv, const char *prefix __used) | 1150 | int cmd_top(int argc, const char **argv, const char *prefix __used) |
1151 | { | 1151 | { |
1152 | struct perf_evsel *pos; | 1152 | struct perf_evsel *pos; |
1153 | int status = -ENOMEM; | 1153 | int status; |
1154 | char errbuf[BUFSIZ]; | ||
1154 | struct perf_top top = { | 1155 | struct perf_top top = { |
1155 | .count_filter = 5, | 1156 | .count_filter = 5, |
1156 | .delay_secs = 2, | 1157 | .delay_secs = 2, |
@@ -1252,10 +1253,22 @@ int cmd_top(int argc, const char **argv, const char *prefix __used) | |||
1252 | 1253 | ||
1253 | setup_browser(false); | 1254 | setup_browser(false); |
1254 | 1255 | ||
1255 | perf_target__validate(&top.target); | 1256 | status = perf_target__validate(&top.target); |
1257 | if (status) { | ||
1258 | perf_target__strerror(&top.target, status, errbuf, BUFSIZ); | ||
1259 | ui__warning("%s", errbuf); | ||
1260 | } | ||
1261 | |||
1262 | status = perf_target__parse_uid(&top.target); | ||
1263 | if (status) { | ||
1264 | int saved_errno = errno; | ||
1256 | 1265 | ||
1257 | if (perf_target__parse_uid(&top.target) < 0) | 1266 | perf_target__strerror(&top.target, status, errbuf, BUFSIZ); |
1267 | ui__warning("%s", errbuf); | ||
1268 | |||
1269 | status = -saved_errno; | ||
1258 | goto out_delete_evlist; | 1270 | goto out_delete_evlist; |
1271 | } | ||
1259 | 1272 | ||
1260 | if (top.target.tid == 0 && top.target.pid == 0 && | 1273 | if (top.target.tid == 0 && top.target.pid == 0 && |
1261 | top.target.uid_str == NULL) | 1274 | top.target.uid_str == NULL) |
diff --git a/tools/perf/util/debug.c b/tools/perf/util/debug.c index 26817daa2961..efb1fce259a4 100644 --- a/tools/perf/util/debug.c +++ b/tools/perf/util/debug.c | |||
@@ -11,6 +11,7 @@ | |||
11 | #include "event.h" | 11 | #include "event.h" |
12 | #include "debug.h" | 12 | #include "debug.h" |
13 | #include "util.h" | 13 | #include "util.h" |
14 | #include "target.h" | ||
14 | 15 | ||
15 | int verbose; | 16 | int verbose; |
16 | bool dump_trace = false, quiet = false; | 17 | bool dump_trace = false, quiet = false; |
diff --git a/tools/perf/util/target.c b/tools/perf/util/target.c index 02a6bedb69a3..1064d5b148ad 100644 --- a/tools/perf/util/target.c +++ b/tools/perf/util/target.c | |||
@@ -10,6 +10,7 @@ | |||
10 | #include "debug.h" | 10 | #include "debug.h" |
11 | 11 | ||
12 | #include <pwd.h> | 12 | #include <pwd.h> |
13 | #include <string.h> | ||
13 | 14 | ||
14 | 15 | ||
15 | enum perf_target_errno perf_target__validate(struct perf_target *target) | 16 | enum perf_target_errno perf_target__validate(struct perf_target *target) |
@@ -89,3 +90,53 @@ enum perf_target_errno perf_target__parse_uid(struct perf_target *target) | |||
89 | target->uid = result->pw_uid; | 90 | target->uid = result->pw_uid; |
90 | return PERF_ERRNO_TARGET__SUCCESS; | 91 | return PERF_ERRNO_TARGET__SUCCESS; |
91 | } | 92 | } |
93 | |||
94 | /* | ||
95 | * This must have a same ordering as the enum perf_target_errno. | ||
96 | */ | ||
97 | static const char *perf_target__error_str[] = { | ||
98 | "PID/TID switch overriding CPU", | ||
99 | "PID/TID switch overriding UID", | ||
100 | "UID switch overriding CPU", | ||
101 | "PID/TID switch overriding SYSTEM", | ||
102 | "UID switch overriding SYSTEM", | ||
103 | "Invalid User: %s", | ||
104 | "Problems obtaining information for user %s", | ||
105 | }; | ||
106 | |||
107 | int perf_target__strerror(struct perf_target *target, int errnum, | ||
108 | char *buf, size_t buflen) | ||
109 | { | ||
110 | int idx; | ||
111 | const char *msg; | ||
112 | |||
113 | if (errnum >= 0) { | ||
114 | strerror_r(errnum, buf, buflen); | ||
115 | return 0; | ||
116 | } | ||
117 | |||
118 | if (errnum < __PERF_ERRNO_TARGET__START || | ||
119 | errnum >= __PERF_ERRNO_TARGET__END) | ||
120 | return -1; | ||
121 | |||
122 | idx = errnum - __PERF_ERRNO_TARGET__START; | ||
123 | msg = perf_target__error_str[idx]; | ||
124 | |||
125 | switch (errnum) { | ||
126 | case PERF_ERRNO_TARGET__PID_OVERRIDE_CPU | ||
127 | ... PERF_ERRNO_TARGET__UID_OVERRIDE_SYSTEM: | ||
128 | snprintf(buf, buflen, "%s", msg); | ||
129 | break; | ||
130 | |||
131 | case PERF_ERRNO_TARGET__INVALID_UID: | ||
132 | case PERF_ERRNO_TARGET__USER_NOT_FOUND: | ||
133 | snprintf(buf, buflen, msg, target->uid_str); | ||
134 | break; | ||
135 | |||
136 | default: | ||
137 | /* cannot reach here */ | ||
138 | break; | ||
139 | } | ||
140 | |||
141 | return 0; | ||
142 | } | ||
diff --git a/tools/perf/util/target.h b/tools/perf/util/target.h index d4aabdaba42a..6fcd01c440a9 100644 --- a/tools/perf/util/target.h +++ b/tools/perf/util/target.h | |||
@@ -43,4 +43,7 @@ enum perf_target_errno { | |||
43 | enum perf_target_errno perf_target__validate(struct perf_target *target); | 43 | enum perf_target_errno perf_target__validate(struct perf_target *target); |
44 | enum perf_target_errno perf_target__parse_uid(struct perf_target *target); | 44 | enum perf_target_errno perf_target__parse_uid(struct perf_target *target); |
45 | 45 | ||
46 | int perf_target__strerror(struct perf_target *target, int errnum, char *buf, | ||
47 | size_t buflen); | ||
48 | |||
46 | #endif /* _PERF_TARGET_H */ | 49 | #endif /* _PERF_TARGET_H */ |