linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Changbin Du <changbin.du@gmail.com>
To: Namhyung Kim <namhyung@kernel.org>
Cc: Changbin Du <changbin.du@gmail.com>, Jiri Olsa <jolsa@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v4 08/17] perf: util: add general function to parse sublevel options
Date: Sat, 11 Jul 2020 20:37:25 +0800	[thread overview]
Message-ID: <20200711123725.sojcctyvzyxzlfzs@mail.google.com> (raw)
In-Reply-To: <CAM9d7ciuzqbBb+POeuiFh-KOFKKzi7LOC6r2vu=WiQ_5tMe7Zw@mail.gmail.com>

On Fri, Jul 10, 2020 at 11:29:49PM +0900, Namhyung Kim wrote:
> On Fri, Jul 10, 2020 at 10:44 PM Changbin Du <changbin.du@gmail.com> wrote:
> >
> > This factors out a general function perf_parse_sublevel_options() to parse
> > sublevel options. The 'sublevel' options is something like the '--debug'
> > options which allow more sublevel options.
> >
> > Signed-off-by: Changbin Du <changbin.du@gmail.com>
> >
> > ---
> > v2: add util/parse-sublevel-options.c
> > ---
> [snip]
> > diff --git a/tools/perf/util/parse-sublevel-options.c b/tools/perf/util/parse-sublevel-options.c
> > new file mode 100644
> > index 000000000000..39798568547c
> > --- /dev/null
> > +++ b/tools/perf/util/parse-sublevel-options.c
> > @@ -0,0 +1,63 @@
> > +#include <stdlib.h>
> > +#include <stdint.h>
> > +#include <string.h>
> > +#include <stdio.h>
> > +
> > +#include "util/debug.h"
> > +#include "util/parse-sublevel-options.h"
> > +
> > +static int parse_one_sublevel_option(const char *str,
> > +                                    struct sublevel_option *opts)
> > +{
> > +       struct sublevel_option *opt = &opts[0];
> > +       char *vstr, *s = strdup(str);
> > +       int v = 1;
> 
> I know you just copied the code, but let's add a check for
> the return value of strdup().
>
yes, the 's' should be checked here.

> Also I think you can just use the opts pointer..
> 
For this, personally I prefer to opt as it's singular form. Because we are
dealing with single element.

> 
> > +
> > +       vstr = strchr(s, '=');
> > +       if (vstr)
> > +               *vstr++ = 0;
> > +
> > +       while (opt->name) {
> > +               if (!strcmp(s, opt->name))
> > +                       break;
> > +               opt++;
> > +       }
> > +
> > +       if (!opt->name) {
> > +               pr_err("Unknown option name '%s'\n", s);
> > +               free(s);
> > +               return -1;
> > +       }
> > +
> > +       if (vstr)
> > +               v = atoi(vstr);
> > +
> > +       *opt->value_ptr = v;
> > +       free(s);
> > +       return 0;
> > +}
> > +
> > +/* parse options like --foo a=<n>,b,c... */
> > +int perf_parse_sublevel_options(const char *str, struct sublevel_option *opts)
> > +{
> > +       char *s = strdup(str);
> > +       char *p = NULL;
> > +       int ret;
> > +
> > +       if (!s)
> > +               return -1;
> > +
> > +       p = strtok(s, ",");
> > +       while (p) {
> > +               ret = parse_one_sublevel_option(p, opts);
> > +               if (ret) {
> > +                       free(s);
> > +                       return ret;
> > +               }
> > +
> > +               p = strtok(NULL, ",");
> > +       }
> > +
> > +       free(s);
> > +       return 0;
> > +}
> > diff --git a/tools/perf/util/parse-sublevel-options.h b/tools/perf/util/parse-sublevel-options.h
> > new file mode 100644
> > index 000000000000..9b9efcc2aaad
> > --- /dev/null
> > +++ b/tools/perf/util/parse-sublevel-options.h
> > @@ -0,0 +1,11 @@
> > +#ifndef _PERF_PARSE_SUBLEVEL_OPTIONS_H
> > +#define _PERF_PARSE_SUBLEVEL_OPTIONS_H
> > +
> > +struct sublevel_option {
> > +       const char *name;
> > +       int *value_ptr;
> > +};
> > +
> > +int perf_parse_sublevel_options(const char *str, struct sublevel_option *opts);
> > +
> > +#endif
> > \ No newline at end of file
> 
> Please add a newline at the end.
> 
> Thanks
> Namhyung
> 
> 
> > --
> > 2.25.1
> >

-- 
Cheers,
Changbin Du

  reply	other threads:[~2020-07-11 12:37 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-10 13:43 [PATCH v4 00/17] perf: ftrace enhancement Changbin Du
2020-07-10 13:43 ` [PATCH v4 01/17] perf ftrace: select function/function_graph tracer automatically Changbin Du
2020-07-10 14:14   ` Namhyung Kim
2020-07-11 12:19     ` Changbin Du
2020-07-10 13:43 ` [PATCH v4 02/17] perf ftrace: add option '-F/--funcs' to list available functions Changbin Du
2020-07-10 13:43 ` [PATCH v4 03/17] perf ftrace: add option -t/--tid to filter by thread id Changbin Du
2020-07-10 13:43 ` [PATCH v4 04/17] perf ftrace: factor out function write_tracing_file_int() Changbin Du
2020-07-10 13:43 ` [PATCH v4 05/17] perf ftrace: add option '-m/--buffer-size' to set per-cpu buffer size Changbin Du
2020-07-10 13:43 ` [PATCH v4 06/17] perf ftrace: show trace column header Changbin Du
2020-07-10 13:43 ` [PATCH v4 07/17] perf ftrace: add option '--inherit' to trace children processes Changbin Du
2020-07-10 13:43 ` [PATCH v4 08/17] perf: util: add general function to parse sublevel options Changbin Du
2020-07-10 14:29   ` Namhyung Kim
2020-07-11 12:37     ` Changbin Du [this message]
2020-07-10 13:43 ` [PATCH v4 09/17] perf ftrace: add support for tracing option 'func_stack_trace' Changbin Du
2020-07-10 13:43 ` [PATCH v4 10/17] perf ftrace: add support for trace option sleep-time Changbin Du
2020-07-10 13:43 ` [PATCH v4 11/17] perf ftrace: add support for trace option funcgraph-irqs Changbin Du
2020-07-10 13:43 ` [PATCH v4 12/17] perf ftrace: add support for tracing option 'irq-info' Changbin Du

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=20200711123725.sojcctyvzyxzlfzs@mail.google.com \
    --to=changbin.du@gmail.com \
    --cc=acme@kernel.org \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.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 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).