aboutsummaryrefslogtreecommitdiffstats
path: root/tools/lib/traceevent
diff options
context:
space:
mode:
authorNamhyung Kim <namhyung@kernel.org>2014-03-18 21:22:53 -0400
committerJiri Olsa <jolsa@redhat.com>2014-04-14 06:55:00 -0400
commit3388cc3eb848154d0f2a0cd01542201d0d0fdad7 (patch)
tree2b8f0e84d8e69f75618507da2a1356a8433aa9d4 /tools/lib/traceevent
parent5e09714b0e877d5d062530aae4061074d864243f (diff)
tools lib traceevent: Print event name when show warning if possible
It's sometimes useful to know where the parse failure was occurred. Add do_warning_event() macro to see the failing event. It now shows the messages like below: $ perf test 5 5: parse events tests : Warning: [kvmmmu:kvm_mmu_get_page] bad op token { Warning: [kvmmmu:kvm_mmu_sync_page] bad op token { Warning: [kvmmmu:kvm_mmu_unsync_page] bad op token { Warning: [kvmmmu:kvm_mmu_prepare_zap_page] bad op token { Warning: [kvmmmu:fast_page_fault] function is_writable_pte not defined Warning: [xen:xen_mmu_ptep_modify_prot_commit] function sizeof not defined Warning: [xen:xen_mmu_ptep_modify_prot_start] function sizeof not defined Warning: [xen:xen_mmu_set_pgd] function sizeof not defined Warning: [xen:xen_mmu_set_pud] function sizeof not defined Warning: [xen:xen_mmu_set_pmd] function sizeof not defined ... 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: Jiri Olsa <jolsa@redhat.com> Cc: Namhyung Kim <namhyung.kim@lge.com> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Ramkumar Ramachandra <artagnon@gmail.com> Cc: Steven Rostedt <rostedt@goodmis.org> Link: http://lkml.kernel.org/r/1395192174-26273-1-git-send-email-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Diffstat (limited to 'tools/lib/traceevent')
-rw-r--r--tools/lib/traceevent/event-parse.c103
1 files changed, 62 insertions, 41 deletions
diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
index 1587ea392ad6..33803c0b94d6 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/lib/traceevent/event-parse.c
@@ -50,6 +50,18 @@ static int show_warning = 1;
50 warning(fmt, ##__VA_ARGS__); \ 50 warning(fmt, ##__VA_ARGS__); \
51 } while (0) 51 } while (0)
52 52
53#define do_warning_event(event, fmt, ...) \
54 do { \
55 if (!show_warning) \
56 continue; \
57 \
58 if (event) \
59 warning("[%s:%s] " fmt, event->system, \
60 event->name, ##__VA_ARGS__); \
61 else \
62 warning(fmt, ##__VA_ARGS__); \
63 } while (0)
64
53static void init_input_buf(const char *buf, unsigned long long size) 65static void init_input_buf(const char *buf, unsigned long long size)
54{ 66{
55 input_buf = buf; 67 input_buf = buf;
@@ -1355,7 +1367,7 @@ static int event_read_fields(struct event_format *event, struct format_field **f
1355 } 1367 }
1356 1368
1357 if (!field->type) { 1369 if (!field->type) {
1358 do_warning("%s: no type found", __func__); 1370 do_warning_event(event, "%s: no type found", __func__);
1359 goto fail; 1371 goto fail;
1360 } 1372 }
1361 field->name = last_token; 1373 field->name = last_token;
@@ -1402,7 +1414,7 @@ static int event_read_fields(struct event_format *event, struct format_field **f
1402 free_token(token); 1414 free_token(token);
1403 type = read_token(&token); 1415 type = read_token(&token);
1404 if (type == EVENT_NONE) { 1416 if (type == EVENT_NONE) {
1405 do_warning("failed to find token"); 1417 do_warning_event(event, "failed to find token");
1406 goto fail; 1418 goto fail;
1407 } 1419 }
1408 } 1420 }
@@ -1636,7 +1648,7 @@ process_cond(struct event_format *event, struct print_arg *top, char **tok)
1636 right = alloc_arg(); 1648 right = alloc_arg();
1637 1649
1638 if (!arg || !left || !right) { 1650 if (!arg || !left || !right) {
1639 do_warning("%s: not enough memory!", __func__); 1651 do_warning_event(event, "%s: not enough memory!", __func__);
1640 /* arg will be freed at out_free */ 1652 /* arg will be freed at out_free */
1641 free_arg(left); 1653 free_arg(left);
1642 free_arg(right); 1654 free_arg(right);
@@ -1686,7 +1698,7 @@ process_array(struct event_format *event, struct print_arg *top, char **tok)
1686 1698
1687 arg = alloc_arg(); 1699 arg = alloc_arg();
1688 if (!arg) { 1700 if (!arg) {
1689 do_warning("%s: not enough memory!", __func__); 1701 do_warning_event(event, "%s: not enough memory!", __func__);
1690 /* '*tok' is set to top->op.op. No need to free. */ 1702 /* '*tok' is set to top->op.op. No need to free. */
1691 *tok = NULL; 1703 *tok = NULL;
1692 return EVENT_ERROR; 1704 return EVENT_ERROR;
@@ -1792,7 +1804,7 @@ process_op(struct event_format *event, struct print_arg *arg, char **tok)
1792 if (arg->type == PRINT_OP && !arg->op.left) { 1804 if (arg->type == PRINT_OP && !arg->op.left) {
1793 /* handle single op */ 1805 /* handle single op */
1794 if (token[1]) { 1806 if (token[1]) {
1795 do_warning("bad op token %s", token); 1807 do_warning_event(event, "bad op token %s", token);
1796 goto out_free; 1808 goto out_free;
1797 } 1809 }
1798 switch (token[0]) { 1810 switch (token[0]) {
@@ -1802,7 +1814,7 @@ process_op(struct event_format *event, struct print_arg *arg, char **tok)
1802 case '-': 1814 case '-':
1803 break; 1815 break;
1804 default: 1816 default:
1805 do_warning("bad op token %s", token); 1817 do_warning_event(event, "bad op token %s", token);
1806 goto out_free; 1818 goto out_free;
1807 1819
1808 } 1820 }
@@ -1888,7 +1900,7 @@ process_op(struct event_format *event, struct print_arg *arg, char **tok)
1888 char *new_atom; 1900 char *new_atom;
1889 1901
1890 if (left->type != PRINT_ATOM) { 1902 if (left->type != PRINT_ATOM) {
1891 do_warning("bad pointer type"); 1903 do_warning_event(event, "bad pointer type");
1892 goto out_free; 1904 goto out_free;
1893 } 1905 }
1894 new_atom = realloc(left->atom.atom, 1906 new_atom = realloc(left->atom.atom,
@@ -1930,7 +1942,7 @@ process_op(struct event_format *event, struct print_arg *arg, char **tok)
1930 type = process_array(event, arg, tok); 1942 type = process_array(event, arg, tok);
1931 1943
1932 } else { 1944 } else {
1933 do_warning("unknown op '%s'", token); 1945 do_warning_event(event, "unknown op '%s'", token);
1934 event->flags |= EVENT_FL_FAILED; 1946 event->flags |= EVENT_FL_FAILED;
1935 /* the arg is now the left side */ 1947 /* the arg is now the left side */
1936 goto out_free; 1948 goto out_free;
@@ -1951,7 +1963,7 @@ process_op(struct event_format *event, struct print_arg *arg, char **tok)
1951 return type; 1963 return type;
1952 1964
1953out_warn_free: 1965out_warn_free:
1954 do_warning("%s: not enough memory!", __func__); 1966 do_warning_event(event, "%s: not enough memory!", __func__);
1955out_free: 1967out_free:
1956 free_token(token); 1968 free_token(token);
1957 *tok = NULL; 1969 *tok = NULL;
@@ -2385,7 +2397,7 @@ process_flags(struct event_format *event, struct print_arg *arg, char **tok)
2385 2397
2386 field = alloc_arg(); 2398 field = alloc_arg();
2387 if (!field) { 2399 if (!field) {
2388 do_warning("%s: not enough memory!", __func__); 2400 do_warning_event(event, "%s: not enough memory!", __func__);
2389 goto out_free; 2401 goto out_free;
2390 } 2402 }
2391 2403
@@ -2438,7 +2450,7 @@ process_symbols(struct event_format *event, struct print_arg *arg, char **tok)
2438 2450
2439 field = alloc_arg(); 2451 field = alloc_arg();
2440 if (!field) { 2452 if (!field) {
2441 do_warning("%s: not enough memory!", __func__); 2453 do_warning_event(event, "%s: not enough memory!", __func__);
2442 goto out_free; 2454 goto out_free;
2443 } 2455 }
2444 2456
@@ -2477,7 +2489,7 @@ process_hex(struct event_format *event, struct print_arg *arg, char **tok)
2477 2489
2478 field = alloc_arg(); 2490 field = alloc_arg();
2479 if (!field) { 2491 if (!field) {
2480 do_warning("%s: not enough memory!", __func__); 2492 do_warning_event(event, "%s: not enough memory!", __func__);
2481 goto out_free; 2493 goto out_free;
2482 } 2494 }
2483 2495
@@ -2492,7 +2504,7 @@ process_hex(struct event_format *event, struct print_arg *arg, char **tok)
2492 2504
2493 field = alloc_arg(); 2505 field = alloc_arg();
2494 if (!field) { 2506 if (!field) {
2495 do_warning("%s: not enough memory!", __func__); 2507 do_warning_event(event, "%s: not enough memory!", __func__);
2496 *tok = NULL; 2508 *tok = NULL;
2497 return EVENT_ERROR; 2509 return EVENT_ERROR;
2498 } 2510 }
@@ -2555,7 +2567,7 @@ process_dynamic_array(struct event_format *event, struct print_arg *arg, char **
2555 free_token(token); 2567 free_token(token);
2556 arg = alloc_arg(); 2568 arg = alloc_arg();
2557 if (!arg) { 2569 if (!arg) {
2558 do_warning("%s: not enough memory!", __func__); 2570 do_warning_event(event, "%s: not enough memory!", __func__);
2559 *tok = NULL; 2571 *tok = NULL;
2560 return EVENT_ERROR; 2572 return EVENT_ERROR;
2561 } 2573 }
@@ -2614,13 +2626,14 @@ process_paren(struct event_format *event, struct print_arg *arg, char **tok)
2614 2626
2615 /* prevous must be an atom */ 2627 /* prevous must be an atom */
2616 if (arg->type != PRINT_ATOM) { 2628 if (arg->type != PRINT_ATOM) {
2617 do_warning("previous needed to be PRINT_ATOM"); 2629 do_warning_event(event, "previous needed to be PRINT_ATOM");
2618 goto out_free; 2630 goto out_free;
2619 } 2631 }
2620 2632
2621 item_arg = alloc_arg(); 2633 item_arg = alloc_arg();
2622 if (!item_arg) { 2634 if (!item_arg) {
2623 do_warning("%s: not enough memory!", __func__); 2635 do_warning_event(event, "%s: not enough memory!",
2636 __func__);
2624 goto out_free; 2637 goto out_free;
2625 } 2638 }
2626 2639
@@ -2721,7 +2734,8 @@ process_func_handler(struct event_format *event, struct pevent_function_handler
2721 for (i = 0; i < func->nr_args; i++) { 2734 for (i = 0; i < func->nr_args; i++) {
2722 farg = alloc_arg(); 2735 farg = alloc_arg();
2723 if (!farg) { 2736 if (!farg) {
2724 do_warning("%s: not enough memory!", __func__); 2737 do_warning_event(event, "%s: not enough memory!",
2738 __func__);
2725 return EVENT_ERROR; 2739 return EVENT_ERROR;
2726 } 2740 }
2727 2741
@@ -2792,7 +2806,7 @@ process_function(struct event_format *event, struct print_arg *arg,
2792 return process_func_handler(event, func, arg, tok); 2806 return process_func_handler(event, func, arg, tok);
2793 } 2807 }
2794 2808
2795 do_warning("function %s not defined", token); 2809 do_warning_event(event, "function %s not defined", token);
2796 free_token(token); 2810 free_token(token);
2797 return EVENT_ERROR; 2811 return EVENT_ERROR;
2798} 2812}
@@ -2878,7 +2892,7 @@ process_arg_token(struct event_format *event, struct print_arg *arg,
2878 2892
2879 case EVENT_ERROR ... EVENT_NEWLINE: 2893 case EVENT_ERROR ... EVENT_NEWLINE:
2880 default: 2894 default:
2881 do_warning("unexpected type %d", type); 2895 do_warning_event(event, "unexpected type %d", type);
2882 return EVENT_ERROR; 2896 return EVENT_ERROR;
2883 } 2897 }
2884 *tok = token; 2898 *tok = token;
@@ -2901,7 +2915,8 @@ static int event_read_print_args(struct event_format *event, struct print_arg **
2901 2915
2902 arg = alloc_arg(); 2916 arg = alloc_arg();
2903 if (!arg) { 2917 if (!arg) {
2904 do_warning("%s: not enough memory!", __func__); 2918 do_warning_event(event, "%s: not enough memory!",
2919 __func__);
2905 return -1; 2920 return -1;
2906 } 2921 }
2907 2922
@@ -3481,11 +3496,12 @@ eval_num_arg(void *data, int size, struct event_format *event, struct print_arg
3481 return val; 3496 return val;
3482 3497
3483out_warning_op: 3498out_warning_op:
3484 do_warning("%s: unknown op '%s'", __func__, arg->op.op); 3499 do_warning_event(event, "%s: unknown op '%s'", __func__, arg->op.op);
3485 return 0; 3500 return 0;
3486 3501
3487out_warning_field: 3502out_warning_field:
3488 do_warning("%s: field %s not found", __func__, arg->field.name); 3503 do_warning_event(event, "%s: field %s not found",
3504 __func__, arg->field.name);
3489 return 0; 3505 return 0;
3490} 3506}
3491 3507
@@ -3591,7 +3607,8 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
3591 } 3607 }
3592 str = malloc(len + 1); 3608 str = malloc(len + 1);
3593 if (!str) { 3609 if (!str) {
3594 do_warning("%s: not enough memory!", __func__); 3610 do_warning_event(event, "%s: not enough memory!",
3611 __func__);
3595 return; 3612 return;
3596 } 3613 }
3597 memcpy(str, data + field->offset, len); 3614 memcpy(str, data + field->offset, len);
@@ -3697,7 +3714,8 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
3697 return; 3714 return;
3698 3715
3699out_warning_field: 3716out_warning_field:
3700 do_warning("%s: field %s not found", __func__, arg->field.name); 3717 do_warning_event(event, "%s: field %s not found",
3718 __func__, arg->field.name);
3701} 3719}
3702 3720
3703static unsigned long long 3721static unsigned long long
@@ -3742,14 +3760,16 @@ process_defined_func(struct trace_seq *s, void *data, int size,
3742 trace_seq_terminate(&str); 3760 trace_seq_terminate(&str);
3743 string = malloc(sizeof(*string)); 3761 string = malloc(sizeof(*string));
3744 if (!string) { 3762 if (!string) {
3745 do_warning("%s(%d): malloc str", __func__, __LINE__); 3763 do_warning_event(event, "%s(%d): malloc str",
3764 __func__, __LINE__);
3746 goto out_free; 3765 goto out_free;
3747 } 3766 }
3748 string->next = strings; 3767 string->next = strings;
3749 string->str = strdup(str.buffer); 3768 string->str = strdup(str.buffer);
3750 if (!string->str) { 3769 if (!string->str) {
3751 free(string); 3770 free(string);
3752 do_warning("%s(%d): malloc str", __func__, __LINE__); 3771 do_warning_event(event, "%s(%d): malloc str",
3772 __func__, __LINE__);
3753 goto out_free; 3773 goto out_free;
3754 } 3774 }
3755 args[i] = (uintptr_t)string->str; 3775 args[i] = (uintptr_t)string->str;
@@ -3761,7 +3781,7 @@ process_defined_func(struct trace_seq *s, void *data, int size,
3761 * Something went totally wrong, this is not 3781 * Something went totally wrong, this is not
3762 * an input error, something in this code broke. 3782 * an input error, something in this code broke.
3763 */ 3783 */
3764 do_warning("Unexpected end of arguments\n"); 3784 do_warning_event(event, "Unexpected end of arguments\n");
3765 goto out_free; 3785 goto out_free;
3766 } 3786 }
3767 farg = farg->next; 3787 farg = farg->next;
@@ -3811,12 +3831,12 @@ static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struc
3811 if (!field) { 3831 if (!field) {
3812 field = pevent_find_field(event, "buf"); 3832 field = pevent_find_field(event, "buf");
3813 if (!field) { 3833 if (!field) {
3814 do_warning("can't find buffer field for binary printk"); 3834 do_warning_event(event, "can't find buffer field for binary printk");
3815 return NULL; 3835 return NULL;
3816 } 3836 }
3817 ip_field = pevent_find_field(event, "ip"); 3837 ip_field = pevent_find_field(event, "ip");
3818 if (!ip_field) { 3838 if (!ip_field) {
3819 do_warning("can't find ip field for binary printk"); 3839 do_warning_event(event, "can't find ip field for binary printk");
3820 return NULL; 3840 return NULL;
3821 } 3841 }
3822 pevent->bprint_buf_field = field; 3842 pevent->bprint_buf_field = field;
@@ -3830,7 +3850,8 @@ static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struc
3830 */ 3850 */
3831 args = alloc_arg(); 3851 args = alloc_arg();
3832 if (!args) { 3852 if (!args) {
3833 do_warning("%s(%d): not enough memory!", __func__, __LINE__); 3853 do_warning_event(event, "%s(%d): not enough memory!",
3854 __func__, __LINE__);
3834 return NULL; 3855 return NULL;
3835 } 3856 }
3836 arg = args; 3857 arg = args;
@@ -3896,7 +3917,7 @@ static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struc
3896 bptr += vsize; 3917 bptr += vsize;
3897 arg = alloc_arg(); 3918 arg = alloc_arg();
3898 if (!arg) { 3919 if (!arg) {
3899 do_warning("%s(%d): not enough memory!", 3920 do_warning_event(event, "%s(%d): not enough memory!",
3900 __func__, __LINE__); 3921 __func__, __LINE__);
3901 goto out_free; 3922 goto out_free;
3902 } 3923 }
@@ -3919,7 +3940,7 @@ static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struc
3919 case 's': 3940 case 's':
3920 arg = alloc_arg(); 3941 arg = alloc_arg();
3921 if (!arg) { 3942 if (!arg) {
3922 do_warning("%s(%d): not enough memory!", 3943 do_warning_event(event, "%s(%d): not enough memory!",
3923 __func__, __LINE__); 3944 __func__, __LINE__);
3924 goto out_free; 3945 goto out_free;
3925 } 3946 }
@@ -3959,7 +3980,7 @@ get_bprint_format(void *data, int size __maybe_unused,
3959 if (!field) { 3980 if (!field) {
3960 field = pevent_find_field(event, "fmt"); 3981 field = pevent_find_field(event, "fmt");
3961 if (!field) { 3982 if (!field) {
3962 do_warning("can't find format field for binary printk"); 3983 do_warning_event(event, "can't find format field for binary printk");
3963 return NULL; 3984 return NULL;
3964 } 3985 }
3965 pevent->bprint_fmt_field = field; 3986 pevent->bprint_fmt_field = field;
@@ -4003,8 +4024,8 @@ static void print_mac_arg(struct trace_seq *s, int mac, void *data, int size,
4003 arg->field.field = 4024 arg->field.field =
4004 pevent_find_any_field(event, arg->field.name); 4025 pevent_find_any_field(event, arg->field.name);
4005 if (!arg->field.field) { 4026 if (!arg->field.field) {
4006 do_warning("%s: field %s not found", 4027 do_warning_event(event, "%s: field %s not found",
4007 __func__, arg->field.name); 4028 __func__, arg->field.name);
4008 return; 4029 return;
4009 } 4030 }
4010 } 4031 }
@@ -4176,7 +4197,7 @@ static void pretty_print(struct trace_seq *s, void *data, int size, struct event
4176 case '*': 4197 case '*':
4177 /* The argument is the length. */ 4198 /* The argument is the length. */
4178 if (!arg) { 4199 if (!arg) {
4179 do_warning("no argument match"); 4200 do_warning_event(event, "no argument match");
4180 event->flags |= EVENT_FL_FAILED; 4201 event->flags |= EVENT_FL_FAILED;
4181 goto out_failed; 4202 goto out_failed;
4182 } 4203 }
@@ -4213,7 +4234,7 @@ static void pretty_print(struct trace_seq *s, void *data, int size, struct event
4213 case 'X': 4234 case 'X':
4214 case 'u': 4235 case 'u':
4215 if (!arg) { 4236 if (!arg) {
4216 do_warning("no argument match"); 4237 do_warning_event(event, "no argument match");
4217 event->flags |= EVENT_FL_FAILED; 4238 event->flags |= EVENT_FL_FAILED;
4218 goto out_failed; 4239 goto out_failed;
4219 } 4240 }
@@ -4223,7 +4244,7 @@ static void pretty_print(struct trace_seq *s, void *data, int size, struct event
4223 4244
4224 /* should never happen */ 4245 /* should never happen */
4225 if (len > 31) { 4246 if (len > 31) {
4226 do_warning("bad format!"); 4247 do_warning_event(event, "bad format!");
4227 event->flags |= EVENT_FL_FAILED; 4248 event->flags |= EVENT_FL_FAILED;
4228 len = 31; 4249 len = 31;
4229 } 4250 }
@@ -4290,13 +4311,13 @@ static void pretty_print(struct trace_seq *s, void *data, int size, struct event
4290 trace_seq_printf(s, format, (long long)val); 4311 trace_seq_printf(s, format, (long long)val);
4291 break; 4312 break;
4292 default: 4313 default:
4293 do_warning("bad count (%d)", ls); 4314 do_warning_event(event, "bad count (%d)", ls);
4294 event->flags |= EVENT_FL_FAILED; 4315 event->flags |= EVENT_FL_FAILED;
4295 } 4316 }
4296 break; 4317 break;
4297 case 's': 4318 case 's':
4298 if (!arg) { 4319 if (!arg) {
4299 do_warning("no matching argument"); 4320 do_warning_event(event, "no matching argument");
4300 event->flags |= EVENT_FL_FAILED; 4321 event->flags |= EVENT_FL_FAILED;
4301 goto out_failed; 4322 goto out_failed;
4302 } 4323 }
@@ -4306,7 +4327,7 @@ static void pretty_print(struct trace_seq *s, void *data, int size, struct event
4306 4327
4307 /* should never happen */ 4328 /* should never happen */
4308 if (len > 31) { 4329 if (len > 31) {
4309 do_warning("bad format!"); 4330 do_warning_event(event, "bad format!");
4310 event->flags |= EVENT_FL_FAILED; 4331 event->flags |= EVENT_FL_FAILED;
4311 len = 31; 4332 len = 31;
4312 } 4333 }