Skip to contentSkip to conversation

trace-cmd: Handle __print_hex(__get_dynamic_array(fieldname), len)

PATCH In review Howard Cochran 3 participants 4 messages Oct 11, 2013 – Nov 4, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 trace-cmd: Handle __print_hex(__get_dynamic_array(fieldname), len)

The kernel has a few events with a format similar to this excerpt:

        field:unsigned int len;     offset:12;      size:4; signed:0;
        field:__data_loc unsigned char[] data_array;  offset:16;      size:4; signed:0;

print fmt: "%s", __print_hex(__get_dynamic_array(data_array), REC->len)

trace-cmd could already parse that arg correctly, but print_str_arg() was unable to handle the first parameter being a dynamic array. (It just printed a "field not found" warning).

Teach print_str_arg's PRINT_HEX case to handle the nested PRINT_DYNAMIC_ARRAY correctly. The output now matches the kernel's own formatting for this case.

---
 event-parse.c |   24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)
event-parse.c +16 -8
index e961553..fdb176e 100644
@@ -3550,15 +3550,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)
-				goto out_warning_field;
-			arg->hex.field->field.field = field;
+		if (PRINT_DYNAMIC_ARRAY == arg->hex.field->type) {
+			unsigned long offset;
+			offset = pevent_read_number(pevent,
+				data + arg->hex.field->dynarray.field->offset,
+				arg->hex.field->dynarray.field->size);
+			hex = data + (offset & 0xffff);
+		} else {
+			field = arg->hex.field->field.field;
+			if (!field) {
+				str = arg->hex.field->field.name;
+				field = pevent_find_any_field(event, str);
+				if (!field)
+					goto out_warning_field;
+				arg->hex.field->field.field = field;
+			}
+			hex = data + field->offset;
 		}
-		hex = data + field->offset;
 		len = eval_num_arg(data, size, event, arg->hex.size);
 		for (i = 0; i < len; i++) {
 			if (i)
Signature · 1 line
1.7.10.2.4.g36f8dc1
#1 lore raw

Hi Howard,

Quoted 5 lines · Howard Cochran

The kernel has a few events with a format similar to this excerpt:

        field:unsigned int len;     offset:12;      size:4; signed:0;
        field:__data_loc unsigned char[] data_array;  offset:16;      size:4; signed:0;

print fmt: "%s", __print_hex(__get_dynamic_array(data_array), REC->len)

Quoted 7 lines

trace-cmd could already parse that arg correctly, but print_str_arg() was unable to handle the first parameter being a dynamic array. (It just printed a "field not found" warning).

Teach print_str_arg's PRINT_HEX case to handle the nested PRINT_DYNAMIC_ARRAY correctly. The output now matches the kernel's own formatting for this case.

It seems that it needs to be added to libtraceevent also. Could you also send a patch against tools/lib/traceevent/event-parse.c in the Linux kernel source?

Thanks,
Namhyung

Quoted 42 lines
---
 event-parse.c |   24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)
event-parse.c +16 -8
index e961553..fdb176e 100644
@@ -3550,15 +3550,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)
-				goto out_warning_field;
-			arg->hex.field->field.field = field;
+		if (PRINT_DYNAMIC_ARRAY == arg->hex.field->type) {
+			unsigned long offset;
+			offset = pevent_read_number(pevent,
+				data + arg->hex.field->dynarray.field->offset,
+				arg->hex.field->dynarray.field->size);
+			hex = data + (offset & 0xffff);
+		} else {
+			field = arg->hex.field->field.field;
+			if (!field) {
+				str = arg->hex.field->field.name;
+				field = pevent_find_any_field(event, str);
+				if (!field)
+					goto out_warning_field;
+				arg->hex.field->field.field = field;
+			}
+			hex = data + field->offset;
 		}
-		hex = data + field->offset;
 		len = eval_num_arg(data, size, event, arg->hex.size);
 		for (i = 0; i < len; i++) {
 			if (i)
#2 lore raw

PATCH 1/1 tools lib traceevent: Handle __print_hex(__get_dynamic_array(fld), len)

The kernel has a few events with a format similar to this excerpt:

        field:unsigned int len;     offset:12;      size:4; signed:0;
        field:__data_loc unsigned char[] data_array;  offset:16;      size:4; signed:0;

print fmt: "%s", __print_hex(__get_dynamic_array(data_array), REC->len)

event-parse could already parse that arg correctly, but print_str_arg() was unable to handle the first parameter being a dynamic array. (It just printed a "field not found" warning).

Teach print_str_arg's PRINT_HEX case to handle the nested PRINT_DYNAMIC_ARRAY correctly. The output now matches the kernel's own formatting for this case.

---
 tools/lib/traceevent/event-parse.c |   24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)
tools/lib/traceevent/event-parse.c +16 -8
index d1c2a6a..bcfa6b7 100644
@@ -3565,15 +3565,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)
-				goto out_warning_field;
-			arg->hex.field->field.field = field;
+		if (PRINT_DYNAMIC_ARRAY == arg->hex.field->type) {
+			unsigned long offset;
+			offset = pevent_read_number(pevent,
+				data + arg->hex.field->dynarray.field->offset,
+				arg->hex.field->dynarray.field->size);
+			hex = data + (offset & 0xffff);
+		} else {
+			field = arg->hex.field->field.field;
+			if (!field) {
+				str = arg->hex.field->field.name;
+				field = pevent_find_any_field(event, str);
+				if (!field)
+					goto out_warning_field;
+				arg->hex.field->field.field = field;
+			}
+			hex = data + field->offset;
 		}
-		hex = data + field->offset;
 		len = eval_num_arg(data, size, event, arg->hex.size);
 		for (i = 0; i < len; i++) {
 			if (i)
Signature · 1 line
1.7.10.2.4.g36f8dc1
#3 lore raw

[tip:perf/core] tools lib traceevent: Handle __print_hex( __get_dynamic_array(fieldname), len)

In reply to Howard Cochran
tools lib traceevent: Handle __print_hex(__get_dynamic_array(fieldname), len)
Commit-ID:  b30f75eba27a9ab0704cbc501e9be3b025ce56fe
Gitweb:     http://git.kernel.org/tip/b30f75eba27a9ab0704cbc501e9be3b025ce56fe
Author:     Howard Cochran <[email protected]>
AuthorDate: Fri, 1 Nov 2013 17:53:56 -0400
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 4 Nov 2013 14:34:43 -0300

tools lib traceevent: Handle __print_hex(__get_dynamic_array(fieldname), len)

The kernel has a few events with a format similar to this excerpt:

        field:unsigned int len;     offset:12;      size:4; signed:0;
        field:__data_loc unsigned char[] data_array;  offset:16;      size:4; signed:0;

print fmt: "%s", __print_hex(__get_dynamic_array(data_array), REC->len)

trace-cmd could already parse that arg correctly, but print_str_arg() was unable to handle the first parameter being a dynamic array. (It just printed a "field not found" warning).

Teach print_str_arg's PRINT_HEX case to handle the nested PRINT_DYNAMIC_ARRAY correctly. The output now matches the kernel's own formatting for this case.

Cc Andrew Morton <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Namhyung Kim <[email protected]>
[ Removed "polish compare", we don't do that here ]
---
 tools/lib/traceevent/event-parse.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)
tools/lib/traceevent/event-parse.c +16 -8
index 013c8d3..0a1ffe0 100644
@@ -3588,15 +3588,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)
-				goto out_warning_field;
-			arg->hex.field->field.field = field;
+		if (arg->hex.field->type == PRINT_DYNAMIC_ARRAY) {
+			unsigned long offset;
+			offset = pevent_read_number(pevent,
+				data + arg->hex.field->dynarray.field->offset,
+				arg->hex.field->dynarray.field->size);
+			hex = data + (offset & 0xffff);
+		} else {
+			field = arg->hex.field->field.field;
+			if (!field) {
+				str = arg->hex.field->field.name;
+				field = pevent_find_any_field(event, str);
+				if (!field)
+					goto out_warning_field;
+				arg->hex.field->field.field = field;
+			}
+			hex = data + field->offset;
 		}
-		hex = data + field->offset;
 		len = eval_num_arg(data, size, event, arg->hex.size);
 		for (i = 0; i < len; i++) {
 			if (i)