Linux-Trace-Devel Archive on lore.kernel.org
 help / color / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
Cc: linux-trace-devel@vger.kernel.org,
	Johannes Berg <johannes@sipsolutions.net>
Subject: Re: [PATCH] trace-cmd: Add support for more printk format specifiers
Date: Tue, 12 May 2020 10:26:11 -0400
Message-ID: <20200512102611.62504f3d@gandalf.local.home> (raw)
In-Reply-To: <20200508094547.2420964-1-tz.stoyanov@gmail.com>

On Fri,  8 May 2020 12:45:47 +0300
"Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com> wrote:

Hi Tzvetomir,

First, please add some blank lines in the change log. It gets a bit run-on,
and hard to read without them.

> The printk format specifiers used in event's print format files extend
> the standard printf formats. There are a lot of new options related to
> printing pointers and kernel specific structures. Currently trace-cmd
> does not support many of them.

<blank line here>

> Support for these new printk specifiers is added to the pretty_print()
> function:
>  - UUID/GUID address: %pU[bBlL]
>  - Raw buffer as a hex string: %*ph[CDN]

<blank line here>

> add these ones are improved:

s/add these ones are improved:/These are improved:/

>  - MAC address: %pMF, %pM and %pmR
>  - IPv4 adderss: %p[Ii]4[hnbl]

<blank line here>

> Function pretty_print() is refactored. The logic for printing pointers
> %p[...] is moved to its own function.
> 
> Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=207605
> Reported-by: Johannes Berg <johannes@sipsolutions.net>

Also, its good to include anyone listed in the tags in the Cc of the patch.
I added Johannes here.

> Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
> ---
>  lib/traceevent/event-parse.c | 363 ++++++++++++++++++++++++++++-------
>  1 file changed, 289 insertions(+), 74 deletions(-)
> 
> diff --git a/lib/traceevent/event-parse.c b/lib/traceevent/event-parse.c
> index 064c100d..879e4bf8 100644
> --- a/lib/traceevent/event-parse.c
> +++ b/lib/traceevent/event-parse.c
> @@ -4510,43 +4510,93 @@ get_bprint_format(void *data, int size __maybe_unused,
>  	return format;
>  }
>  
> -static void print_mac_arg(struct trace_seq *s, int mac, void *data, int size,
> -			  struct tep_event *event, struct tep_print_arg *arg)
> +static int print_mac_arg(struct trace_seq *s, const char *format,
> +			 void *data, int size, struct tep_event *event,
> +			 struct tep_print_arg *arg)
>  {
> -	unsigned char *buf;
>  	const char *fmt = "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x";
> +	unsigned char *buf;
> +	int ret = 0;
> +	bool reverse = false;

Upside-down x-mas tree please ;-)

	const char *fmt = "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x";
	bool reverse = false;
	unsigned char *buf;
	int ret = 0;

>  
>  	if (arg->type == TEP_PRINT_FUNC) {
>  		process_defined_func(s, data, size, event, arg);
> -		return;
> +		return 0;
>  	}
>  
>  	if (arg->type != TEP_PRINT_FIELD) {
>  		trace_seq_printf(s, "ARG TYPE NOT FIELD BUT %d",
>  				 arg->type);
> -		return;
> +		return 0;
>  	}
>  
> -	if (mac == 'm')
> +	if (*format == 'm')
>  		fmt = "%.2x%.2x%.2x%.2x%.2x%.2x";
> +

Make the condition below "else if" as it's a bit better code generation,
and also comments to the reader of the code that only one of these can be
true.

> +	if (format[1] == 'F' && *format == 'M') {

If using "format[1]" then please use "format[0]" instead of *format. And
you can swap them as well:

	if (format[0] == 'M' && format[1] == 'F') {

As then the reader can see this would be if the format started with "MF".


> +		fmt = "%.2x-%.2x-%.2x-%.2x-%.2x-%.2x";
> +		ret++;
> +	}


> +	if (format[1] == 'R') {
> +		reverse = true;
> +		ret++;
> +	}
> +
>  	if (!arg->field.field) {
>  		arg->field.field =
>  			tep_find_any_field(event, arg->field.name);
>  		if (!arg->field.field) {
>  			do_warning_event(event, "%s: field %s not found",
>  					 __func__, arg->field.name);
> -			return;
> +			return ret;
>  		}
>  	}
>  	if (arg->field.field->size != 6) {
>  		trace_seq_printf(s, "INVALIDMAC");
> -		return;
> +		return ret;
>  	}
> +
>  	buf = data + arg->field.field->offset;
> -	trace_seq_printf(s, fmt, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
> +	if (reverse)
> +		trace_seq_printf(s, fmt, buf[5], buf[4], buf[3], buf[2], buf[1], buf[0]);
> +	else
> +		trace_seq_printf(s, fmt, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
> +
> +	return ret;
>  }
>  
> -static void print_ip4_addr(struct trace_seq *s, char i, unsigned char *buf)
> +static int parse_ip4_print_args(const char *ptr, bool *reverse)
> +{
> +	int ret = 0;
> +
> +	*reverse = false;
> +
> +	/* hnbl */
> +	switch (*ptr) {
> +	case 'h':
> +#ifdef __BIG_ENDIAN

Do we care what the machine is? Shouldn't this be checking if the file is
big endian or not?

I'll wait for a v2 and then start testing it.

Thanks Ceco!

-- Steve

> +		*reverse = false;
> +#else
> +		*reverse = true;
> +#endif
> +		ret++;
> +	break;
> +	case 'l':
> +		*reverse = true;
> +		ret++;
> +	break;
> +	case 'n':
> +	case 'b':
> +		ret++;
> +		/* fall through */
> +	default:
> +		*reverse = false;
> +		break;
> +	}
> +
> +	return ret;
> +}


      reply index

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-08  9:45 Tzvetomir Stoyanov (VMware)
2020-05-12 14:26 ` Steven Rostedt [this message]

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=20200512102611.62504f3d@gandalf.local.home \
    --to=rostedt@goodmis.org \
    --cc=johannes@sipsolutions.net \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=tz.stoyanov@gmail.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

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