Linux-Trace-Devel Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] tools/lib/traceevent, perf tools: Handle %pU format correctly
@ 2019-10-16  6:39 Qu Wenruo
  2019-10-16  7:39 ` Nikolay Borisov
  2019-10-16 14:54 ` Steven Rostedt
  0 siblings, 2 replies; 5+ messages in thread
From: Qu Wenruo @ 2019-10-16  6:39 UTC (permalink / raw)
  To: linux-btrfs, linux-kernel, linux-trace-devel

[BUG]
For btrfs related events, there is a field for fsid, but perf never
parse it correctly.

 # perf trace -e btrfS:qgroup_meta_convert xfs_io -f -c "pwrite 0 4k" \
   /mnt/btrfs/file1
     0.000 xfs_io/77915 btrfs:qgroup_meta_reserve:(nil)U: refroot=5(FS_TREE) type=0x0 diff=2
                                                  ^^^^^^ Not a correct UUID
     ...

[CAUSE]
The pretty_print() function doesn't handle the %pU format correctly.
In fact it doesn't handle %pU as uuid at all.

[FIX]
Add a new functiono, print_uuid_arg(), to handle %pU correctly.

Now perf trace can at least print fsid correctly:
     0.000 xfs_io/79619 btrfs:qgroup_meta_reserve:23ad1511-dd83-47d4-a79c-e96625a15a6e refroot=5(FS_TREE) type=0x0 diff=2

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
Please note in above case, the @type and @diff are not properly showed.
That's another problem, will be addressed in later patches.
---
 tools/lib/traceevent/event-parse.c | 38 ++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
index d948475585ce..4f730ed527b0 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/lib/traceevent/event-parse.c
@@ -18,6 +18,7 @@
 #include <errno.h>
 #include <stdint.h>
 #include <limits.h>
+#include <linux/uuid.h>
 #include <linux/time64.h>
 
 #include <netinet/in.h>
@@ -4508,6 +4509,33 @@ get_bprint_format(void *data, int size __maybe_unused,
 	return format;
 }
 
+static void print_uuid_arg(struct trace_seq *s, void *data, int size,
+			   struct tep_event *event, struct tep_print_arg *arg)
+{
+	const char *fmt;
+	unsigned char *buf;
+
+	fmt = "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x";
+	if (arg->type != TEP_PRINT_FIELD) {
+		trace_seq_printf(s, "ARG TYPE NOT FIELID but %d", arg->type);
+		return;
+	}
+
+	if (!arg->field.field) {
+		arg->field.field = tep_find_any_field(event, arg->field.name);
+		if (!arg->field.field) {
+			do_warning("%s: field %s not found",
+				   __func__, arg->field.name);
+			return;
+		}
+	}
+	buf = data + arg->field.field->offset;
+
+	trace_seq_printf(s, fmt, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5],
+		         buf[6], buf[7], buf[8], buf[9], buf[10], buf[11], buf[12],
+			 buf[13], buf[14], buf[15]);
+}
+
 static void print_mac_arg(struct trace_seq *s, int mac, void *data, int size,
 			  struct tep_event *event, struct tep_print_arg *arg)
 {
@@ -5074,6 +5102,16 @@ static void pretty_print(struct trace_seq *s, void *data, int size, struct tep_e
 						arg = arg->next;
 						break;
 					}
+				} else if (*ptr == 'U') {
+					/* Those finetunings are ignored for now */
+					if (isalpha(ptr[1]))
+						ptr += 2;
+					else
+						ptr++;
+
+					print_uuid_arg(s, data, size, event, arg);
+					arg = arg->next;
+					break;
 				}
 
 				/* fall through */
-- 
2.23.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] tools/lib/traceevent, perf tools: Handle %pU format correctly
  2019-10-16  6:39 [PATCH] tools/lib/traceevent, perf tools: Handle %pU format correctly Qu Wenruo
@ 2019-10-16  7:39 ` Nikolay Borisov
  2019-10-16  7:44   ` Qu WenRuo
  2019-10-16 14:54 ` Steven Rostedt
  1 sibling, 1 reply; 5+ messages in thread
From: Nikolay Borisov @ 2019-10-16  7:39 UTC (permalink / raw)
  To: Qu Wenruo, linux-btrfs, linux-kernel, linux-trace-devel



On 16.10.19 г. 9:39 ч., Qu Wenruo wrote:
> [BUG]
> For btrfs related events, there is a field for fsid, but perf never
> parse it correctly.
> 
>  # perf trace -e btrfS:qgroup_meta_convert xfs_io -f -c "pwrite 0 4k" \
>    /mnt/btrfs/file1
>      0.000 xfs_io/77915 btrfs:qgroup_meta_reserve:(nil)U: refroot=5(FS_TREE) type=0x0 diff=2
>                                                   ^^^^^^ Not a correct UUID
>      ...
> 
> [CAUSE]
> The pretty_print() function doesn't handle the %pU format correctly.
> In fact it doesn't handle %pU as uuid at all.
> 
> [FIX]
> Add a new functiono, print_uuid_arg(), to handle %pU correctly.
> 
> Now perf trace can at least print fsid correctly:
>      0.000 xfs_io/79619 btrfs:qgroup_meta_reserve:23ad1511-dd83-47d4-a79c-e96625a15a6e refroot=5(FS_TREE) type=0x0 diff=2
> 
> Signed-off-by: Qu Wenruo <wqu@suse.com>
> ---
> Please note in above case, the @type and @diff are not properly showed.
> That's another problem, will be addressed in later patches.
> ---
>  tools/lib/traceevent/event-parse.c | 38 ++++++++++++++++++++++++++++++
>  1 file changed, 38 insertions(+)
> 
> diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
> index d948475585ce..4f730ed527b0 100644
> --- a/tools/lib/traceevent/event-parse.c
> +++ b/tools/lib/traceevent/event-parse.c
> @@ -18,6 +18,7 @@
>  #include <errno.h>
>  #include <stdint.h>
>  #include <limits.h>
> +#include <linux/uuid.h>
>  #include <linux/time64.h>
>  
>  #include <netinet/in.h>
> @@ -4508,6 +4509,33 @@ get_bprint_format(void *data, int size __maybe_unused,
>  	return format;
>  }
>  
> +static void print_uuid_arg(struct trace_seq *s, void *data, int size,
> +			   struct tep_event *event, struct tep_print_arg *arg)
> +{
> +	const char *fmt;
> +	unsigned char *buf;
> +
> +	fmt = "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x";
> +	if (arg->type != TEP_PRINT_FIELD) {
> +		trace_seq_printf(s, "ARG TYPE NOT FIELID but %d", arg->type);
> +		return;
> +	}
> +
> +	if (!arg->field.field) {
> +		arg->field.field = tep_find_any_field(event, arg->field.name);
> +		if (!arg->field.field) {
> +			do_warning("%s: field %s not found",
> +				   __func__, arg->field.name);
> +			return;
> +		}
> +	}
> +	buf = data + arg->field.field->offset;
> +
> +	trace_seq_printf(s, fmt, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5],
> +		         buf[6], buf[7], buf[8], buf[9], buf[10], buf[11], buf[12],
> +			 buf[13], buf[14], buf[15]);
> +}
> +
>  static void print_mac_arg(struct trace_seq *s, int mac, void *data, int size,
>  			  struct tep_event *event, struct tep_print_arg *arg)
>  {
> @@ -5074,6 +5102,16 @@ static void pretty_print(struct trace_seq *s, void *data, int size, struct tep_e
>  						arg = arg->next;
>  						break;
>  					}
> +				} else if (*ptr == 'U') {
> +					/* Those finetunings are ignored for now */

I think this comment is cryptic. What do you mean by "finetunings"?

> +					if (isalpha(ptr[1]))
> +						ptr += 2;
> +					else
> +						ptr++;
> +
> +					print_uuid_arg(s, data, size, event, arg);
> +					arg = arg->next;
> +					break;
>  				}
>  
>  				/* fall through */
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] tools/lib/traceevent, perf tools: Handle %pU format correctly
  2019-10-16  7:39 ` Nikolay Borisov
@ 2019-10-16  7:44   ` Qu WenRuo
  0 siblings, 0 replies; 5+ messages in thread
From: Qu WenRuo @ 2019-10-16  7:44 UTC (permalink / raw)
  To: Nikolay Borisov, linux-btrfs, linux-kernel, linux-trace-devel



On 2019/10/16 下午3:39, Nikolay Borisov wrote:
> 
> 
> On 16.10.19 г. 9:39 ч., Qu Wenruo wrote:
>> [BUG]
>> For btrfs related events, there is a field for fsid, but perf never
>> parse it correctly.
>>
>>  # perf trace -e btrfS:qgroup_meta_convert xfs_io -f -c "pwrite 0 4k" \
>>    /mnt/btrfs/file1
>>      0.000 xfs_io/77915 btrfs:qgroup_meta_reserve:(nil)U: refroot=5(FS_TREE) type=0x0 diff=2
>>                                                   ^^^^^^ Not a correct UUID
>>      ...
>>
>> [CAUSE]
>> The pretty_print() function doesn't handle the %pU format correctly.
>> In fact it doesn't handle %pU as uuid at all.
>>
>> [FIX]
>> Add a new functiono, print_uuid_arg(), to handle %pU correctly.
>>
>> Now perf trace can at least print fsid correctly:
>>      0.000 xfs_io/79619 btrfs:qgroup_meta_reserve:23ad1511-dd83-47d4-a79c-e96625a15a6e refroot=5(FS_TREE) type=0x0 diff=2
>>
>> Signed-off-by: Qu Wenruo <wqu@suse.com>
>> ---
>> Please note in above case, the @type and @diff are not properly showed.
>> That's another problem, will be addressed in later patches.
>> ---
>>  tools/lib/traceevent/event-parse.c | 38 ++++++++++++++++++++++++++++++
>>  1 file changed, 38 insertions(+)
>>
>> diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
>> index d948475585ce..4f730ed527b0 100644
>> --- a/tools/lib/traceevent/event-parse.c
>> +++ b/tools/lib/traceevent/event-parse.c
>> @@ -18,6 +18,7 @@
>>  #include <errno.h>
>>  #include <stdint.h>
>>  #include <limits.h>
>> +#include <linux/uuid.h>
>>  #include <linux/time64.h>
>>  
>>  #include <netinet/in.h>
>> @@ -4508,6 +4509,33 @@ get_bprint_format(void *data, int size __maybe_unused,
>>  	return format;
>>  }
>>  
>> +static void print_uuid_arg(struct trace_seq *s, void *data, int size,
>> +			   struct tep_event *event, struct tep_print_arg *arg)
>> +{
>> +	const char *fmt;
>> +	unsigned char *buf;
>> +
>> +	fmt = "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x";
>> +	if (arg->type != TEP_PRINT_FIELD) {
>> +		trace_seq_printf(s, "ARG TYPE NOT FIELID but %d", arg->type);
>> +		return;
>> +	}
>> +
>> +	if (!arg->field.field) {
>> +		arg->field.field = tep_find_any_field(event, arg->field.name);
>> +		if (!arg->field.field) {
>> +			do_warning("%s: field %s not found",
>> +				   __func__, arg->field.name);
>> +			return;
>> +		}
>> +	}
>> +	buf = data + arg->field.field->offset;
>> +
>> +	trace_seq_printf(s, fmt, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5],
>> +		         buf[6], buf[7], buf[8], buf[9], buf[10], buf[11], buf[12],
>> +			 buf[13], buf[14], buf[15]);
>> +}
>> +
>>  static void print_mac_arg(struct trace_seq *s, int mac, void *data, int size,
>>  			  struct tep_event *event, struct tep_print_arg *arg)
>>  {
>> @@ -5074,6 +5102,16 @@ static void pretty_print(struct trace_seq *s, void *data, int size, struct tep_e
>>  						arg = arg->next;
>>  						break;
>>  					}
>> +				} else if (*ptr == 'U') {
>> +					/* Those finetunings are ignored for now */
> 
> I think this comment is cryptic. What do you mean by "finetunings"?

Oh, the original planned check is:
if (ptr[1] == 'b' || ptr[1] == 'B' ||
    ptr[1] == 'l' || ptr[1] == 'L')

Those options are finetunes for endian and upper/lower characters.

However I just choose to be lazy and use isalpha() to check them in one
line.
I will change the comment to make it more clear.

Thanks,
Qu
> 
>> +					if (isalpha(ptr[1]))
>> +						ptr += 2;
>> +					else
>> +						ptr++;
>> +
>> +					print_uuid_arg(s, data, size, event, arg);
>> +					arg = arg->next;
>> +					break;
>>  				}
>>  
>>  				/* fall through */
>>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] tools/lib/traceevent, perf tools: Handle %pU format correctly
  2019-10-16  6:39 [PATCH] tools/lib/traceevent, perf tools: Handle %pU format correctly Qu Wenruo
  2019-10-16  7:39 ` Nikolay Borisov
@ 2019-10-16 14:54 ` Steven Rostedt
  2019-10-16 23:46   ` Qu Wenruo
  1 sibling, 1 reply; 5+ messages in thread
From: Steven Rostedt @ 2019-10-16 14:54 UTC (permalink / raw)
  To: Qu Wenruo; +Cc: linux-btrfs, linux-kernel, linux-trace-devel

On Wed, 16 Oct 2019 14:39:20 +0800
Qu Wenruo <wqu@suse.com> wrote:

> +static void print_uuid_arg(struct trace_seq *s, void *data, int size,
> +			   struct tep_event *event, struct tep_print_arg *arg)
> +{
> +	const char *fmt;
> +	unsigned char *buf;
> +
> +	fmt = "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x";
> +	if (arg->type != TEP_PRINT_FIELD) {
> +		trace_seq_printf(s, "ARG TYPE NOT FIELID but %d", arg->type);
> +		return;
> +	}
> +
> +	if (!arg->field.field) {
> +		arg->field.field = tep_find_any_field(event, arg->field.name);
> +		if (!arg->field.field) {
> +			do_warning("%s: field %s not found",
> +				   __func__, arg->field.name);
> +			return;
> +		}
> +	}
> +	buf = data + arg->field.field->offset;

You also need to make sure the data field is not smaller than 16 bytes.

	if (arg->field.field->size < 16) {
		trace_seq_puts(s, "INVALIDUUID");
		return;
	}

> +
> +	trace_seq_printf(s, fmt, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5],
> +		         buf[6], buf[7], buf[8], buf[9], buf[10], buf[11], buf[12],
> +			 buf[13], buf[14], buf[15]);
> +}
> +

Hmm, I know print_mac_addr() does something similar as this, but this
is getting a bit extreme (too many arguments!). What about doing:

	for (i = 0; i < 4; i++)
		trace_seq_printf(s, "%02x", buf++);

	for (i = 0; i < 3; i++)
		trace_seq_printf(s, "-%02x%02x", buf[i * 2], buf[i * 2 + 1]);

	buf += 6;

	trace_seq_putc(s, '-');

	for (i = 0; i < 6; i++)
		trace_seq_printf(s, "%02x", buf++);



Hmm, not sure the above is better, but having that many arguments just
looks ugly to me.

-- Steve

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] tools/lib/traceevent, perf tools: Handle %pU format correctly
  2019-10-16 14:54 ` Steven Rostedt
@ 2019-10-16 23:46   ` Qu Wenruo
  0 siblings, 0 replies; 5+ messages in thread
From: Qu Wenruo @ 2019-10-16 23:46 UTC (permalink / raw)
  To: Steven Rostedt, Qu Wenruo; +Cc: linux-btrfs, linux-kernel, linux-trace-devel

[-- Attachment #1.1: Type: text/plain, Size: 1923 bytes --]



On 2019/10/16 下午10:54, Steven Rostedt wrote:
> On Wed, 16 Oct 2019 14:39:20 +0800
> Qu Wenruo <wqu@suse.com> wrote:
> 
>> +static void print_uuid_arg(struct trace_seq *s, void *data, int size,
>> +			   struct tep_event *event, struct tep_print_arg *arg)
>> +{
>> +	const char *fmt;
>> +	unsigned char *buf;
>> +
>> +	fmt = "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x";
>> +	if (arg->type != TEP_PRINT_FIELD) {
>> +		trace_seq_printf(s, "ARG TYPE NOT FIELID but %d", arg->type);
>> +		return;
>> +	}
>> +
>> +	if (!arg->field.field) {
>> +		arg->field.field = tep_find_any_field(event, arg->field.name);
>> +		if (!arg->field.field) {
>> +			do_warning("%s: field %s not found",
>> +				   __func__, arg->field.name);
>> +			return;
>> +		}
>> +	}
>> +	buf = data + arg->field.field->offset;
> 
> You also need to make sure the data field is not smaller than 16 bytes.
> 
> 	if (arg->field.field->size < 16) {
> 		trace_seq_puts(s, "INVALIDUUID");
> 		return;
> 	}
> 

Oh, forgot that sanity check.

>> +
>> +	trace_seq_printf(s, fmt, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5],
>> +		         buf[6], buf[7], buf[8], buf[9], buf[10], buf[11], buf[12],
>> +			 buf[13], buf[14], buf[15]);
>> +}
>> +
> 
> Hmm, I know print_mac_addr() does something similar as this, but this
> is getting a bit extreme (too many arguments!). What about doing:
> 
> 	for (i = 0; i < 4; i++)
> 		trace_seq_printf(s, "%02x", buf++);
> 
> 	for (i = 0; i < 3; i++)
> 		trace_seq_printf(s, "-%02x%02x", buf[i * 2], buf[i * 2 + 1]);
> 
> 	buf += 6;
> 
> 	trace_seq_putc(s, '-');
> 
> 	for (i = 0; i < 6; i++)
> 		trace_seq_printf(s, "%02x", buf++);
> 
> 
> 
> Hmm, not sure the above is better, but having that many arguments just
> looks ugly to me.

Indeed, I'll update the patchset to make it more sane.

Thanks,
Qu
> 
> -- Steve
> 


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, back to index

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-16  6:39 [PATCH] tools/lib/traceevent, perf tools: Handle %pU format correctly Qu Wenruo
2019-10-16  7:39 ` Nikolay Borisov
2019-10-16  7:44   ` Qu WenRuo
2019-10-16 14:54 ` Steven Rostedt
2019-10-16 23:46   ` Qu Wenruo

Linux-Trace-Devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-trace-devel/0 linux-trace-devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-trace-devel linux-trace-devel/ https://lore.kernel.org/linux-trace-devel \
		linux-trace-devel@vger.kernel.org
	public-inbox-index linux-trace-devel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-trace-devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git