From: Namhyung Kim <namhyung@kernel.org>
To: Changbin Du <changbin.du@gmail.com>
Cc: 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: Fri, 10 Jul 2020 23:29:49 +0900 [thread overview]
Message-ID: <CAM9d7ciuzqbBb+POeuiFh-KOFKKzi7LOC6r2vu=WiQ_5tMe7Zw@mail.gmail.com> (raw)
In-Reply-To: <20200710134322.15400-9-changbin.du@gmail.com>
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().
Also I think you can just use the opts pointer..
> +
> + 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
>
next prev parent reply other threads:[~2020-07-10 14:30 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 [this message]
2020-07-11 12:37 ` Changbin Du
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='CAM9d7ciuzqbBb+POeuiFh-KOFKKzi7LOC6r2vu=WiQ_5tMe7Zw@mail.gmail.com' \
--to=namhyung@kernel.org \
--cc=acme@kernel.org \
--cc=changbin.du@gmail.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--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).