lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAP-5=fWWML91BsOfF1wvJcDFPG4=S_b3cTe_gza6GDQyWYjksA@mail.gmail.com>
Date: Mon, 29 Apr 2024 20:36:38 -0700
From: Ian Rogers <irogers@...gle.com>
To: Namhyung Kim <namhyung@...nel.org>
Cc: Arnaldo Carvalho de Melo <acme@...nel.org>, Kan Liang <kan.liang@...ux.intel.com>, 
	Jiri Olsa <jolsa@...nel.org>, Adrian Hunter <adrian.hunter@...el.com>, 
	Peter Zijlstra <peterz@...radead.org>, Ingo Molnar <mingo@...nel.org>, 
	LKML <linux-kernel@...r.kernel.org>, linux-perf-users@...r.kernel.org
Subject: Re: [PATCH v2] tools lib subcmd: Show parent options in help

On Mon, Apr 29, 2024 at 4:37 PM Namhyung Kim <namhyung@...nel.org> wrote:
>
> I've just realized that help message in a subcommand didn't show one
> in the parent command.  Since the option parser understands the parent,
> display code should do the same.  For example, `perf ftrace latency -h`
> should show options in the `perf ftrace` command too.
>
> Before:
>
>   $ perf ftrace latency -h
>
>    Usage: perf ftrace [<options>] [<command>]
>       or: perf ftrace [<options>] -- [<command>] [<options>]
>       or: perf ftrace {trace|latency} [<options>] [<command>]
>       or: perf ftrace {trace|latency} [<options>] -- [<command>] [<options>]
>
>       -b, --use-bpf         Use BPF to measure function latency
>       -n, --use-nsec        Use nano-second histogram
>       -T, --trace-funcs <func>
>                             Show latency of given function
>
> After:
>
>   $ perf ftrace latency -h
>
>    Usage: perf ftrace [<options>] [<command>]
>       or: perf ftrace [<options>] -- [<command>] [<options>]
>       or: perf ftrace {trace|latency} [<options>] [<command>]
>       or: perf ftrace {trace|latency} [<options>] -- [<command>] [<options>]
>
>       -a, --all-cpus        System-wide collection from all CPUs
>       -b, --use-bpf         Use BPF to measure function latency
>       -C, --cpu <cpu>       List of cpus to monitor
>       -n, --use-nsec        Use nano-second histogram
>       -p, --pid <pid>       Trace on existing process id
>       -T, --trace-funcs <func>
>                             Show latency of given function
>       -v, --verbose         Be more verbose
>           --tid <tid>       Trace on existing thread id (exclusive to --pid)
>
> Signed-off-by: Namhyung Kim <namhyung@...nel.org>

Reviewed-by: Ian Rogers <irogers@...gle.com>

Thanks,
Ian

> ---
> *v2: remove goto and add comments  (Ian)
>
>  tools/lib/subcmd/parse-options.c | 36 +++++++++++++++++++++-----------
>  1 file changed, 24 insertions(+), 12 deletions(-)
>
> diff --git a/tools/lib/subcmd/parse-options.c b/tools/lib/subcmd/parse-options.c
> index 9fa75943f2ed..eb896d30545b 100644
> --- a/tools/lib/subcmd/parse-options.c
> +++ b/tools/lib/subcmd/parse-options.c
> @@ -806,18 +806,30 @@ static int option__cmp(const void *va, const void *vb)
>
>  static struct option *options__order(const struct option *opts)
>  {
> -       int nr_opts = 0, nr_group = 0, len;
> -       const struct option *o = opts;
> -       struct option *opt, *ordered, *group;
> -
> -       for (o = opts; o->type != OPTION_END; o++)
> -               ++nr_opts;
> -
> -       len = sizeof(*o) * (nr_opts + 1);
> -       ordered = malloc(len);
> -       if (!ordered)
> -               goto out;
> -       memcpy(ordered, opts, len);
> +       int nr_opts = 0, nr_group = 0, nr_parent = 0, len;
> +       const struct option *o, *p = opts;
> +       struct option *opt, *ordered = NULL, *group;
> +
> +       /* flatten the options that have parents */
> +       for (p = opts; p != NULL; p = o->parent) {
> +               for (o = p; o->type != OPTION_END; o++)
> +                       ++nr_opts;
> +
> +               /*
> +                * the length is given by the number of options plus a null
> +                * terminator for the last loop iteration.
> +                */
> +               len = sizeof(*o) * (nr_opts + !o->parent);
> +               group = realloc(ordered, len);
> +               if (!group)
> +                       goto out;
> +               ordered = group;
> +               memcpy(&ordered[nr_parent], p, sizeof(*o) * (nr_opts - nr_parent));
> +
> +               nr_parent = nr_opts;
> +       }
> +       /* copy the last OPTION_END */
> +       memcpy(&ordered[nr_opts], o, sizeof(*o));
>
>         /* sort each option group individually */
>         for (opt = group = ordered; opt->type != OPTION_END; opt++) {
> --
> 2.44.0.769.g3c40516874-goog
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ