Re: [PATCH] trace-cmd: Add support for more printk format specifiers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri,  8 May 2020 12:45:47 +0300
"Tzvetomir Stoyanov (VMware)" <tz.stoyanov@xxxxxxxxx> 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@xxxxxxxxxxxxxxxx>

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@xxxxxxxxx>
> ---
>  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;
> +}




[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux