All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tzvetomir Stoyanov <tz.stoyanov@gmail.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: linux-trace-devel@vger.kernel.org
Subject: Re: [PATCH] trace-cmd: Optimize pretty_print() function
Date: Fri, 15 May 2020 07:53:22 +0300	[thread overview]
Message-ID: <CAPpZLN6g3CmBngdH==3yjTdoyT5th2M-Cd=xU4FBMQ534xYM+g@mail.gmail.com> (raw)
In-Reply-To: <20200514211410.0362161b@oasis.local.home>

On Fri, May 15, 2020 at 4:14 AM Steven Rostedt <rostedt@goodmis.org> wrote:
>
[...]
> > +static int parse_arg_format(struct tep_print_parse **parse,
> > +                         struct tep_event *event,
> > +                         const char *format, struct tep_print_arg
> > **arg) +{
> > +     struct tep_print_arg *len_arg = NULL;
> > +     char print_format[32];
> > +     const char *start = format;
> > +     int ret = 0;
> > +     int ls = 0;
> > +     int res;
> > +     int len;
> > +
> > +     if (*format != '%')
> > +             return ret;
> > +     format++;
> > +
> > +     /* %% */
> > +     if (*format == '%')
> > +             return ret;
>
> The above two checks for '%' isn't needed as it is checked by the
> caller. If for some reason that the caller didn't catch it, and we
> return here,  it would return zero and the calling loop would never
> proceed. It's not protecting anything, I would just remove these two
> checks.
>
> > +     ret++;
> > +
> > +     for (; *format; format++) {
> > +             switch (*format) {
> > +             case '#':
> > +                     /* FIXME: need to handle properly */
> > +                     break;
> > +             case 'h':
> > +                     ls--;
> > +                     break;
> > +             case 'l':
> > +                     ls++;
> > +                     break;
> > +             case 'L':
> > +                     ls = 2;
> > +                     break;
> > +             case '.':
> > +             case 'z':
> > +             case 'Z':
> > +             case '0' ... '9':
> > +             case '-':
> > +                     break;
> > +             case '*':
> > +                     /* The argument is the length. */
> > +                     if (!arg) {
> > +                             do_warning_event(event, "no argument match");
> > +                             event->flags |= TEP_EVENT_FL_FAILED;
> > +                             goto out_failed;
> > +                     }
>
> Since all cases to exit this loop do the same check, I think we can
> move this check before the loop. The old code didn't do this check
> properly for %p, but that was a bug in the old code.
>

We still have to check for a valid argument inside the switch for almost all
exit cases, as the '*' case can consume the argument that would be verified
before the loop. And there is one exit that does not require a valid argument -
the default case. The old code just prints the unknown character, without
consuming an argument.

>
> > +                     len_arg = *arg;
>
[...]
> -- Steve

Thanks, Steve!

-- 
Tzvetomir (Ceco) Stoyanov
VMware Open Source Technology Center

      reply	other threads:[~2020-05-15  4:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-14  7:12 [PATCH] trace-cmd: Optimize pretty_print() function Tzvetomir Stoyanov (VMware)
2020-05-15  1:14 ` Steven Rostedt
2020-05-15  4:53   ` Tzvetomir Stoyanov [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='CAPpZLN6g3CmBngdH==3yjTdoyT5th2M-Cd=xU4FBMQ534xYM+g@mail.gmail.com' \
    --to=tz.stoyanov@gmail.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.