Commit 265b7115 authored by Breno Leitao's avatar Breno Leitao Committed by Namhyung Kim

perf list: Fix the --no-desc option

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: default avatarBreno Leitao <leitao@debian.org>
Reviewed-by: default avatarIan Rogers <irogers@google.com>
Cc: leit@meta.com
Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/20240517141427.1905691-1-leitao@debian.org
parent cbd446b4
...@@ -162,7 +162,11 @@ static void default_print_event(void *ps, const char *pmu_name, const char *topi ...@@ -162,7 +162,11 @@ static void default_print_event(void *ps, const char *pmu_name, const char *topi
} else } else
fputc('\n', fp); 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; char *desc_with_unit = NULL;
int desc_len = -1; int desc_len = -1;
...@@ -178,12 +182,6 @@ static void default_print_event(void *ps, const char *pmu_name, const char *topi ...@@ -178,12 +182,6 @@ static void default_print_event(void *ps, const char *pmu_name, const char *topi
fprintf(fp, "]\n"); fprintf(fp, "]\n");
free(desc_with_unit); 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) { if (print_state->detailed && encoding_desc) {
fprintf(fp, "%*s", 8, ""); fprintf(fp, "%*s", 8, "");
...@@ -256,15 +254,14 @@ static void default_print_metric(void *ps, ...@@ -256,15 +254,14 @@ static void default_print_metric(void *ps,
} }
fprintf(fp, " %s\n", name); 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) { if (long_desc && print_state->long_desc) {
fprintf(fp, "%*s", 8, "["); fprintf(fp, "%*s", 8, "[");
wordwrap(fp, long_desc, 8, pager_get_columns(), 0); wordwrap(fp, long_desc, 8, pager_get_columns(), 0);
fprintf(fp, "]\n"); 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) { if (expr && print_state->detailed) {
fprintf(fp, "%*s", 8, "["); fprintf(fp, "%*s", 8, "[");
...@@ -507,6 +504,7 @@ int cmd_list(int argc, const char **argv) ...@@ -507,6 +504,7 @@ int cmd_list(int argc, const char **argv)
int i, ret = 0; int i, ret = 0;
struct print_state default_ps = { struct print_state default_ps = {
.fp = stdout, .fp = stdout,
.desc = true,
}; };
struct print_state json_ps = { struct print_state json_ps = {
.fp = stdout, .fp = stdout,
...@@ -579,7 +577,6 @@ int cmd_list(int argc, const char **argv) ...@@ -579,7 +577,6 @@ int cmd_list(int argc, const char **argv)
}; };
ps = &json_ps; ps = &json_ps;
} else { } else {
default_ps.desc = !default_ps.long_desc;
default_ps.last_topic = strdup(""); default_ps.last_topic = strdup("");
assert(default_ps.last_topic); assert(default_ps.last_topic);
default_ps.visited_metrics = strlist__new(NULL, NULL); default_ps.visited_metrics = strlist__new(NULL, NULL);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment