diff options
author | Namhyung Kim <namhyung.kim@lge.com> | 2012-08-22 03:00:30 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-08-22 15:03:39 -0400 |
commit | 2f197b9d7eeaa723a80243610956fe4a17e7b5a4 (patch) | |
tree | b5f8181066874ece8cff95a5a0e8b18857cb5de7 /tools/lib | |
parent | bffddffde7f9bd093909235a25dbb806fe639dde (diff) |
tools lib traceevent: Introduce pevent_strerror
The pevent_strerror() sets @buf to a string that describes the
(libtraceevent-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.
To sync error string with its code, define PEVENT_ERRORS with _PE()
macro and use it as suggested by Steven.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/r/1345618831-9148-4-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/lib')
-rw-r--r-- | tools/lib/traceevent/event-parse.c | 43 | ||||
-rw-r--r-- | tools/lib/traceevent/event-parse.h | 20 |
2 files changed, 57 insertions, 6 deletions
diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c index a46cae701db7..1373e4cf109e 100644 --- a/tools/lib/traceevent/event-parse.c +++ b/tools/lib/traceevent/event-parse.c | |||
@@ -4795,6 +4795,49 @@ enum pevent_errno pevent_parse_event(struct pevent *pevent, const char *buf, | |||
4795 | return ret; | 4795 | return ret; |
4796 | } | 4796 | } |
4797 | 4797 | ||
4798 | #undef _PE | ||
4799 | #define _PE(code, str) str | ||
4800 | static const char * const pevent_error_str[] = { | ||
4801 | PEVENT_ERRORS | ||
4802 | }; | ||
4803 | #undef _PE | ||
4804 | |||
4805 | int pevent_strerror(struct pevent *pevent, enum pevent_errno errnum, | ||
4806 | char *buf, size_t buflen) | ||
4807 | { | ||
4808 | int idx; | ||
4809 | const char *msg; | ||
4810 | |||
4811 | if (errnum >= 0) { | ||
4812 | strerror_r(errnum, buf, buflen); | ||
4813 | return 0; | ||
4814 | } | ||
4815 | |||
4816 | if (errnum <= __PEVENT_ERRNO__START || | ||
4817 | errnum >= __PEVENT_ERRNO__END) | ||
4818 | return -1; | ||
4819 | |||
4820 | idx = errnum - __PEVENT_ERRNO__START; | ||
4821 | msg = pevent_error_str[idx]; | ||
4822 | |||
4823 | switch (errnum) { | ||
4824 | case PEVENT_ERRNO__MEM_ALLOC_FAILED: | ||
4825 | case PEVENT_ERRNO__PARSE_EVENT_FAILED: | ||
4826 | case PEVENT_ERRNO__READ_ID_FAILED: | ||
4827 | case PEVENT_ERRNO__READ_FORMAT_FAILED: | ||
4828 | case PEVENT_ERRNO__READ_PRINT_FAILED: | ||
4829 | case PEVENT_ERRNO__OLD_FTRACE_ARG_FAILED: | ||
4830 | snprintf(buf, buflen, "%s", msg); | ||
4831 | break; | ||
4832 | |||
4833 | default: | ||
4834 | /* cannot reach here */ | ||
4835 | break; | ||
4836 | } | ||
4837 | |||
4838 | return 0; | ||
4839 | } | ||
4840 | |||
4798 | int get_field_val(struct trace_seq *s, struct format_field *field, | 4841 | int get_field_val(struct trace_seq *s, struct format_field *field, |
4799 | const char *name, struct pevent_record *record, | 4842 | const char *name, struct pevent_record *record, |
4800 | unsigned long long *val, int err) | 4843 | unsigned long long *val, int err) |
diff --git a/tools/lib/traceevent/event-parse.h b/tools/lib/traceevent/event-parse.h index 3c48229a7bce..527df038a25f 100644 --- a/tools/lib/traceevent/event-parse.h +++ b/tools/lib/traceevent/event-parse.h | |||
@@ -345,6 +345,16 @@ enum pevent_flag { | |||
345 | PEVENT_NSEC_OUTPUT = 1, /* output in NSECS */ | 345 | PEVENT_NSEC_OUTPUT = 1, /* output in NSECS */ |
346 | }; | 346 | }; |
347 | 347 | ||
348 | #define PEVENT_ERRORS \ | ||
349 | _PE(MEM_ALLOC_FAILED, "failed to allocate memory"), \ | ||
350 | _PE(PARSE_EVENT_FAILED, "failed to parse event"), \ | ||
351 | _PE(READ_ID_FAILED, "failed to read event id"), \ | ||
352 | _PE(READ_FORMAT_FAILED, "failed to read event format"), \ | ||
353 | _PE(READ_PRINT_FAILED, "failed to read event print fmt"), \ | ||
354 | _PE(OLD_FTRACE_ARG_FAILED,"failed to allocate field name for ftrace") | ||
355 | |||
356 | #undef _PE | ||
357 | #define _PE(__code, __str) PEVENT_ERRNO__ ## __code | ||
348 | enum pevent_errno { | 358 | enum pevent_errno { |
349 | PEVENT_ERRNO__SUCCESS = 0, | 359 | PEVENT_ERRNO__SUCCESS = 0, |
350 | 360 | ||
@@ -357,15 +367,11 @@ enum pevent_errno { | |||
357 | */ | 367 | */ |
358 | __PEVENT_ERRNO__START = -100000, | 368 | __PEVENT_ERRNO__START = -100000, |
359 | 369 | ||
360 | PEVENT_ERRNO__MEM_ALLOC_FAILED = __PEVENT_ERRNO__START, | 370 | PEVENT_ERRORS, |
361 | PEVENT_ERRNO__PARSE_EVENT_FAILED, | ||
362 | PEVENT_ERRNO__READ_ID_FAILED, | ||
363 | PEVENT_ERRNO__READ_FORMAT_FAILED, | ||
364 | PEVENT_ERRNO__READ_PRINT_FAILED, | ||
365 | PEVENT_ERRNO__OLD_FTRACE_ARG_FAILED, | ||
366 | 371 | ||
367 | __PEVENT_ERRNO__END, | 372 | __PEVENT_ERRNO__END, |
368 | }; | 373 | }; |
374 | #undef _PE | ||
369 | 375 | ||
370 | struct cmdline; | 376 | struct cmdline; |
371 | struct cmdline_list; | 377 | struct cmdline_list; |
@@ -583,6 +589,8 @@ int pevent_data_pid(struct pevent *pevent, struct pevent_record *rec); | |||
583 | const char *pevent_data_comm_from_pid(struct pevent *pevent, int pid); | 589 | const char *pevent_data_comm_from_pid(struct pevent *pevent, int pid); |
584 | void pevent_event_info(struct trace_seq *s, struct event_format *event, | 590 | void pevent_event_info(struct trace_seq *s, struct event_format *event, |
585 | struct pevent_record *record); | 591 | struct pevent_record *record); |
592 | int pevent_strerror(struct pevent *pevent, enum pevent_errno errnum, | ||
593 | char *buf, size_t buflen); | ||
586 | 594 | ||
587 | struct event_format **pevent_list_events(struct pevent *pevent, enum event_sort_type); | 595 | struct event_format **pevent_list_events(struct pevent *pevent, enum event_sort_type); |
588 | struct format_field **pevent_event_common_fields(struct event_format *event); | 596 | struct format_field **pevent_event_common_fields(struct event_format *event); |