All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vincent Whitchurch <vincent.whitchurch@axis.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: "linux-trace-devel@vger.kernel.org" 
	<linux-trace-devel@vger.kernel.org>, kernel <kernel@axis.com>
Subject: Re: [PATCH] trace-cmd report: Avoid crash on unknown event
Date: Tue, 23 Nov 2021 09:55:14 +0100	[thread overview]
Message-ID: <20211123085514.GA12234@axis.com> (raw)
In-Reply-To: <20211119094434.718922fa@gandalf.local.home>

On Fri, Nov 19, 2021 at 03:44:34PM +0100, Steven Rostedt wrote:
> On Fri, 19 Nov 2021 12:24:20 +0100
> Vincent Whitchurch <vincent.whitchurch@axis.com> wrote:
> 
> > Do not segfault if the event cannot be found for some reason and
> > tep_find_event_by_record() returns NULL.
> > 
> > No extra warning is added since there are others ("UNKNOWN EVENT") which
> > already make it clear that something is wrong:
> > 
> >  kworker/u8:0-7 [003] 1.245773: sched_stat_runtime: comm=kworker/u8:...
> > [UNKNOWN EVENT][UNKNOWN EVENT][UNKNOWN EVENT]
> >  kworker/u8:0-7 [003] 1.245776: sched_switch: kworker/u8:0:7 [120] W...
> > 
> 
> I wonder if the following would be a better and more robust approach:
> 
> diff --git a/tracecmd/trace-read.c b/tracecmd/trace-read.c
> index f7ffb89e..4b27740a 100644
> --- a/tracecmd/trace-read.c
> +++ b/tracecmd/trace-read.c
> @@ -142,12 +142,15 @@ static struct trace_hash wakeup_hash;
>  static void print_event_name(struct trace_seq *s, struct tep_event *event)
>  {
>  	static const char *spaces = "                    "; /* 20 spaces */
> +	const char *name;
>  	int len;
>  
> -	trace_seq_printf(s, " %s: ", event->name);
> +	name = event ? event->name : "(NULL)";
> +
> +	trace_seq_printf(s, " %s: ", name);
>  
>  	/* Space out the event names evenly. */
> -	len = strlen(event->name);
> +	len = strlen(name);
>  	if (len < 20)
>  		trace_seq_printf(s, "%.*s", 20 - len, spaces);
>  }

Looks good to me.

  reply	other threads:[~2021-11-23  8:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-19 11:24 [PATCH] trace-cmd report: Avoid crash on unknown event Vincent Whitchurch
2021-11-19 14:44 ` Steven Rostedt
2021-11-23  8:55   ` Vincent Whitchurch [this message]
2021-11-23 15:38     ` 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=20211123085514.GA12234@axis.com \
    --to=vincent.whitchurch@axis.com \
    --cc=kernel@axis.com \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.