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/perf/util | |
| 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/perf/util')
| -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 |
3 files changed, 55 insertions, 0 deletions
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 */ |
