lib, traceevent: add PRINT_HEX_STR variant
authorDaniel Borkmann <daniel@iogearbox.net>
Wed, 25 Jan 2017 01:28:17 +0000 (02:28 +0100)
committerDavid S. Miller <davem@davemloft.net>
Wed, 25 Jan 2017 18:17:47 +0000 (13:17 -0500)
Add support for the __print_hex_str() macro that was added for
tracing, so that user space tools such as perf can understand
it as well.

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
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 14a4f623c1a57353e49869974125eee71c0e9671..f2ea78021450a53390b6754a78d25851317a1d2a 100644 (file)
@@ -831,6 +831,7 @@ static void free_arg(struct print_arg *arg)
                free_flag_sym(arg->symbol.symbols);
                break;
        case PRINT_HEX:
+       case PRINT_HEX_STR:
                free_arg(arg->hex.field);
                free_arg(arg->hex.size);
                break;
@@ -2629,10 +2630,11 @@ out_free:
 }
 
 static enum event_type
-process_hex(struct event_format *event, struct print_arg *arg, char **tok)
+process_hex_common(struct event_format *event, struct print_arg *arg,
+                  char **tok, enum print_arg_type type)
 {
        memset(arg, 0, sizeof(*arg));
-       arg->type = PRINT_HEX;
+       arg->type = type;
 
        if (alloc_and_process_delim(event, ",", &arg->hex.field))
                goto out;
@@ -2650,6 +2652,19 @@ out:
        return EVENT_ERROR;
 }
 
+static enum event_type
+process_hex(struct event_format *event, struct print_arg *arg, char **tok)
+{
+       return process_hex_common(event, arg, tok, PRINT_HEX);
+}
+
+static enum event_type
+process_hex_str(struct event_format *event, struct print_arg *arg,
+               char **tok)
+{
+       return process_hex_common(event, arg, tok, PRINT_HEX_STR);
+}
+
 static enum event_type
 process_int_array(struct event_format *event, struct print_arg *arg, char **tok)
 {
@@ -3009,6 +3024,10 @@ process_function(struct event_format *event, struct print_arg *arg,
                free_token(token);
                return process_hex(event, arg, tok);
        }
+       if (strcmp(token, "__print_hex_str") == 0) {
+               free_token(token);
+               return process_hex_str(event, arg, tok);
+       }
        if (strcmp(token, "__print_array") == 0) {
                free_token(token);
                return process_int_array(event, arg, tok);
@@ -3547,6 +3566,7 @@ eval_num_arg(void *data, int size, struct event_format *event, struct print_arg
        case PRINT_SYMBOL:
        case PRINT_INT_ARRAY:
        case PRINT_HEX:
+       case PRINT_HEX_STR:
                break;
        case PRINT_TYPE:
                val = eval_num_arg(data, size, event, arg->typecast.item);
@@ -3962,6 +3982,7 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
                }
                break;
        case PRINT_HEX:
+       case PRINT_HEX_STR:
                if (arg->hex.field->type == PRINT_DYNAMIC_ARRAY) {
                        unsigned long offset;
                        offset = pevent_read_number(pevent,
@@ -3981,7 +4002,7 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
                }
                len = eval_num_arg(data, size, event, arg->hex.size);
                for (i = 0; i < len; i++) {
-                       if (i)
+                       if (i && arg->type == PRINT_HEX)
                                trace_seq_putc(s, ' ');
                        trace_seq_printf(s, "%02x", hex[i]);
                }
@@ -5727,6 +5748,13 @@ static void print_args(struct print_arg *args)
                print_args(args->hex.size);
                printf(")");
                break;
+       case PRINT_HEX_STR:
+               printf("__print_hex_str(");
+               print_args(args->hex.field);
+               printf(", ");
+               print_args(args->hex.size);
+               printf(")");
+               break;
        case PRINT_INT_ARRAY:
                printf("__print_array(");
                print_args(args->int_array.field);
index 7aae746ec2fee7a6d1e19de8dcb720fecb5a11ef..74cecba87daaa654504a7c66154b70490c23e8bd 100644 (file)
@@ -292,6 +292,7 @@ enum print_arg_type {
        PRINT_FUNC,
        PRINT_BITMASK,
        PRINT_DYNAMIC_ARRAY_LEN,
+       PRINT_HEX_STR,
 };
 
 struct print_arg {
index e55a132f69b73e23661bf1a6e21aaac36cbb85ad..e74adfbd6a2ed7296125b0a41a6ea33d3c036dea 100644 (file)
@@ -217,6 +217,7 @@ static void define_event_symbols(struct event_format *event,
                                       cur_field_name);
                break;
        case PRINT_HEX:
+       case PRINT_HEX_STR:
                define_event_symbols(event, ev_name, args->hex.field);
                define_event_symbols(event, ev_name, args->hex.size);
                break;
index 089438da1f7f76b2318dd2f5b10bc039441e2fc4..581e0efd6356839567a9ae5303a3fa6581b8ee3b 100644 (file)
@@ -236,6 +236,7 @@ static void define_event_symbols(struct event_format *event,
                              cur_field_name);
                break;
        case PRINT_HEX:
+       case PRINT_HEX_STR:
                define_event_symbols(event, ev_name, args->hex.field);
                define_event_symbols(event, ev_name, args->hex.size);
                break;