linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: Steven Rostedt <rostedt@goodmis.org>, Qu Wenruo <wqu@suse.com>
Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-trace-devel@vger.kernel.org
Subject: Re: [PATCH] tools/lib/traceevent, perf tools: Handle %pU format correctly
Date: Thu, 17 Oct 2019 07:46:03 +0800	[thread overview]
Message-ID: <ee81fc11-30ea-34d7-a19f-ce1811529ab4@gmx.com> (raw)
In-Reply-To: <20191016105456.0b8d2310@gandalf.local.home>


[-- 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 --]

  reply	other threads:[~2019-10-16 23:46 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2020-01-27 15:42 Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ee81fc11-30ea-34d7-a19f-ce1811529ab4@gmx.com \
    --to=quwenruo.btrfs@gmx.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=wqu@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).