[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAP-5=fUaUGJ-09N-u39YyZgJOnj_WE91-hUc8dv+tf7ozA3K2Q@mail.gmail.com>
Date: Thu, 16 May 2024 13:15:23 -0700
From: Ian Rogers <irogers@...gle.com>
To: Breno Leitao <leitao@...ian.org>
Cc: Peter Zijlstra <peterz@...radead.org>, Ingo Molnar <mingo@...hat.com>,
Arnaldo Carvalho de Melo <acme@...nel.org>, Namhyung Kim <namhyung@...nel.org>,
Mark Rutland <mark.rutland@....com>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>, Jiri Olsa <jolsa@...nel.org>,
Adrian Hunter <adrian.hunter@...el.com>, leit@...a.com,
"open list:PERFORMANCE EVENTS SUBSYSTEM" <linux-perf-users@...r.kernel.org>,
"open list:PERFORMANCE EVENTS SUBSYSTEM" <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v3] perf list: Fix the --no-desc option
On Thu, May 16, 2024 at 6:18 AM Breno Leitao <leitao@...ian.org> wrote:
>
> Currently, the --no-desc option in perf list isn't functioning as
> intended.
>
> This issue arises from the overwriting of struct option->desc with the
> opposite value of struct option->long_desc. Consequently, whatever
> parse_options() returns at struct option->desc gets overridden later,
> rendering the --desc or --no-desc arguments ineffective.
>
> To resolve this, set ->desc as true by default and allow parse_options()
> to adjust it accordingly. This adjustment will fix the --no-desc
> option while preserving the functionality of the other parameters.
>
> Signed-off-by: Breno Leitao <leitao@...ian.org>
> ---
> Changelog:
>
> v3:
> * Applied the same logic to default_print_metric() and
> json_print_event() functions, as identified by Ian Rogers.
I don't think we should change the json behavior. We're generating a
dictionary and the consumer of the dictionary isn't obligated to read
all of it. I tested the non-json output and it all looks good.
Thanks,
Ian
> v2:
> * Do not print desc if long_desc is being printed, as identified
> by Ian Rogers.
>
> ---
> tools/perf/builtin-list.c | 34 +++++++++++++++-------------------
> 1 file changed, 15 insertions(+), 19 deletions(-)
>
> diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c
> index 02bf608d585e..8a0e123587f3 100644
> --- a/tools/perf/builtin-list.c
> +++ b/tools/perf/builtin-list.c
> @@ -149,7 +149,11 @@ static void default_print_event(void *ps, const char *pmu_name, const char *topi
> } else
> fputc('\n', fp);
>
> - if (desc && print_state->desc) {
> + if (long_desc && print_state->long_desc) {
> + fprintf(fp, "%*s", 8, "[");
> + wordwrap(fp, long_desc, 8, pager_get_columns(), 0);
> + fprintf(fp, "]\n");
> + } else if (desc && print_state->desc) {
> char *desc_with_unit = NULL;
> int desc_len = -1;
>
> @@ -165,12 +169,6 @@ static void default_print_event(void *ps, const char *pmu_name, const char *topi
> fprintf(fp, "]\n");
> free(desc_with_unit);
> }
> - long_desc = long_desc ?: desc;
> - if (long_desc && print_state->long_desc) {
> - fprintf(fp, "%*s", 8, "[");
> - wordwrap(fp, long_desc, 8, pager_get_columns(), 0);
> - fprintf(fp, "]\n");
> - }
>
> if (print_state->detailed && encoding_desc) {
> fprintf(fp, "%*s", 8, "");
> @@ -243,15 +241,14 @@ static void default_print_metric(void *ps,
> }
> fprintf(fp, " %s\n", name);
>
> - if (desc && print_state->desc) {
> - fprintf(fp, "%*s", 8, "[");
> - wordwrap(fp, desc, 8, pager_get_columns(), 0);
> - fprintf(fp, "]\n");
> - }
> if (long_desc && print_state->long_desc) {
> fprintf(fp, "%*s", 8, "[");
> wordwrap(fp, long_desc, 8, pager_get_columns(), 0);
> fprintf(fp, "]\n");
> + } else if (desc && print_state->desc) {
> + fprintf(fp, "%*s", 8, "[");
> + wordwrap(fp, desc, 8, pager_get_columns(), 0);
> + fprintf(fp, "]\n");
> }
> if (expr && print_state->detailed) {
> fprintf(fp, "%*s", 8, "[");
> @@ -395,17 +392,16 @@ static void json_print_event(void *ps, const char *pmu_name, const char *topic,
> deprecated ? "1" : "0");
> need_sep = true;
> }
> - if (desc) {
> - fix_escape_fprintf(fp, &buf, "%s\t\"BriefDescription\": \"%S\"",
> - need_sep ? ",\n" : "",
> - desc);
> - need_sep = true;
> - }
> if (long_desc) {
> fix_escape_fprintf(fp, &buf, "%s\t\"PublicDescription\": \"%S\"",
> need_sep ? ",\n" : "",
> long_desc);
> need_sep = true;
> + } else if (desc) {
> + fix_escape_fprintf(fp, &buf, "%s\t\"BriefDescription\": \"%S\"",
> + need_sep ? ",\n" : "",
> + desc);
> + need_sep = true;
> }
> if (encoding_desc) {
> fix_escape_fprintf(fp, &buf, "%s\t\"Encoding\": \"%S\"",
> @@ -491,6 +487,7 @@ int cmd_list(int argc, const char **argv)
> int i, ret = 0;
> struct print_state default_ps = {
> .fp = stdout,
> + .desc = true,
> };
> struct print_state json_ps = {
> .fp = stdout,
> @@ -563,7 +560,6 @@ int cmd_list(int argc, const char **argv)
> };
> ps = &json_ps;
> } else {
> - default_ps.desc = !default_ps.long_desc;
> default_ps.last_topic = strdup("");
> assert(default_ps.last_topic);
> default_ps.visited_metrics = strlist__new(NULL, NULL);
> --
> 2.43.0
>
Powered by blists - more mailing lists