tools lib traceevent: Add support for __print_hex()
authorNamhyung Kim <namhyung.kim@lge.com>
Wed, 27 Jun 2012 00:41:41 +0000 (09:41 +0900)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 29 Jun 2012 16:28:12 +0000 (13:28 -0300)
Since the __print_hex() function is used in print fmt now, add
corresponding parser routines. This makes the output of perf script on
the kvm_emulate_insn event not to fail any more.

 before:
      kvm_emulate_insn:     [FAILED TO PARSE] rip=3238197797 ...

 after:
      kvm_emulate_insn:     0:c102fa25:89 10 (prot32)

Signed-off-by: Namhyung Kim <namhyung@kernel.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/1340757701-10711-4-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/lib/traceevent/event-parse.c
tools/lib/traceevent/event-parse.h
tools/perf/util/scripting-engines/trace-event-perl.c
tools/perf/util/scripting-engines/trace-event-python.c

index 63d02be5480f10d0723751ba67d5be3be7d3a5e0..b1abd39923d65ac53389429689e8e22a9247af2e 100644 (file)
@@ -697,6 +697,10 @@ static void free_arg(struct print_arg *arg)
                free_arg(arg->symbol.field);
                free_flag_sym(arg->symbol.symbols);
                break;
+       case PRINT_HEX:
+               free_arg(arg->hex.field);
+               free_arg(arg->hex.size);
+               break;
        case PRINT_TYPE:
                free(arg->typecast.type);
                free_arg(arg->typecast.item);
@@ -2259,6 +2263,45 @@ process_symbols(struct event_format *event, struct print_arg *arg, char **tok)
        return EVENT_ERROR;
 }
 
+static enum event_type
+process_hex(struct event_format *event, struct print_arg *arg, char **tok)
+{
+       struct print_arg *field;
+       enum event_type type;
+       char *token;
+
+       memset(arg, 0, sizeof(*arg));
+       arg->type = PRINT_HEX;
+
+       field = alloc_arg();
+       type = process_arg(event, field, &token);
+
+       if (test_type_token(type, token, EVENT_DELIM, ","))
+               goto out_free;
+
+       arg->hex.field = field;
+
+       free_token(token);
+
+       field = alloc_arg();
+       type = process_arg(event, field, &token);
+
+       if (test_type_token(type, token, EVENT_DELIM, ")"))
+               goto out_free;
+
+       arg->hex.size = field;
+
+       free_token(token);
+       type = read_token_item(tok);
+       return type;
+
+ out_free:
+       free_arg(field);
+       free_token(token);
+       *tok = NULL;
+       return EVENT_ERROR;
+}
+
 static enum event_type
 process_dynamic_array(struct event_format *event, struct print_arg *arg, char **tok)
 {
@@ -2488,6 +2531,10 @@ process_function(struct event_format *event, struct print_arg *arg,
                is_symbolic_field = 1;
                return process_symbols(event, arg, tok);
        }
+       if (strcmp(token, "__print_hex") == 0) {
+               free_token(token);
+               return process_hex(event, arg, tok);
+       }
        if (strcmp(token, "__get_str") == 0) {
                free_token(token);
                return process_str(event, arg, tok);
@@ -2995,6 +3042,7 @@ eval_num_arg(void *data, int size, struct event_format *event, struct print_arg
                break;
        case PRINT_FLAGS:
        case PRINT_SYMBOL:
+       case PRINT_HEX:
                break;
        case PRINT_TYPE:
                val = eval_num_arg(data, size, event, arg->typecast.item);
@@ -3218,8 +3266,9 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
        unsigned long long val, fval;
        unsigned long addr;
        char *str;
+       unsigned char *hex;
        int print;
-       int len;
+       int i, len;
 
        switch (arg->type) {
        case PRINT_NULL:
@@ -3284,6 +3333,23 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
                        }
                }
                break;
+       case PRINT_HEX:
+               field = arg->hex.field->field.field;
+               if (!field) {
+                       str = arg->hex.field->field.name;
+                       field = pevent_find_any_field(event, str);
+                       if (!field)
+                               die("field %s not found", str);
+                       arg->hex.field->field.field = field;
+               }
+               hex = data + field->offset;
+               len = eval_num_arg(data, size, event, arg->hex.size);
+               for (i = 0; i < len; i++) {
+                       if (i)
+                               trace_seq_putc(s, ' ');
+                       trace_seq_printf(s, "%02x", hex[i]);
+               }
+               break;
 
        case PRINT_TYPE:
                break;
@@ -4294,6 +4360,13 @@ static void print_args(struct print_arg *args)
                trace_seq_destroy(&s);
                printf(")");
                break;
+       case PRINT_HEX:
+               printf("__print_hex(");
+               print_args(args->hex.field);
+               printf(", ");
+               print_args(args->hex.size);
+               printf(")");
+               break;
        case PRINT_STRING:
        case PRINT_BSTRING:
                printf("__get_str(%s)", args->string.string);
index ac997bc7b59252e5fc0fb2cc9b1e9ef12bd15419..5772ad8cb38646fbd5a6375b528ad710ff217b3f 100644 (file)
@@ -226,6 +226,11 @@ struct print_arg_symbol {
        struct print_flag_sym   *symbols;
 };
 
+struct print_arg_hex {
+       struct print_arg        *field;
+       struct print_arg        *size;
+};
+
 struct print_arg_dynarray {
        struct format_field     *field;
        struct print_arg        *index;
@@ -253,6 +258,7 @@ enum print_arg_type {
        PRINT_FIELD,
        PRINT_FLAGS,
        PRINT_SYMBOL,
+       PRINT_HEX,
        PRINT_TYPE,
        PRINT_STRING,
        PRINT_BSTRING,
@@ -270,6 +276,7 @@ struct print_arg {
                struct print_arg_typecast       typecast;
                struct print_arg_flags          flags;
                struct print_arg_symbol         symbol;
+               struct print_arg_hex            hex;
                struct print_arg_func           func;
                struct print_arg_string         string;
                struct print_arg_op             op;
index b3620fe127630eba0e829ad31fcef9965fe40666..02dfa19a467fcde82abfb0e0802a26a5579c9890 100644 (file)
@@ -209,6 +209,10 @@ static void define_event_symbols(struct event_format *event,
                define_symbolic_values(args->symbol.symbols, ev_name,
                                       cur_field_name);
                break;
+       case PRINT_HEX:
+               define_event_symbols(event, ev_name, args->hex.field);
+               define_event_symbols(event, ev_name, args->hex.size);
+               break;
        case PRINT_BSTRING:
        case PRINT_DYNAMIC_ARRAY:
        case PRINT_STRING:
index a8ca2f8179a951beb7b5fec1f0422e51063bd5fd..ce4d1b0c38626d800defaf373b231ae9171f3904 100644 (file)
@@ -166,6 +166,10 @@ static void define_event_symbols(struct event_format *event,
                define_values(PRINT_SYMBOL, args->symbol.symbols, ev_name,
                              cur_field_name);
                break;
+       case PRINT_HEX:
+               define_event_symbols(event, ev_name, args->hex.field);
+               define_event_symbols(event, ev_name, args->hex.size);
+               break;
        case PRINT_STRING:
                break;
        case PRINT_TYPE: