Re: [PATCH] perf tool: Fix output unexpected messages in quiet mode

From: Yang Jihong
Date: Mon Dec 19 2022 - 04:28:13 EST


Hello,

On 2022/12/19 14:59, Adrian Hunter wrote:
On 19/12/22 04:49, Yang Jihong wrote:
When perf uses quiet mode, perf_quiet_option sets debug_peo_args to -1,

Seems like redirect_to_stderr has similar issue?
The redirect_to_stderr is used only in the veprintf function:

int veprintf(int level, int var, const char *fmt, va_list args)
{
int ret = 0;

if (var >= level) {
if (use_browser >= 1 && redirect_to_stderr <= 0) {
ui_helpline__vshow(fmt, args);
} else {
ret = fprintf_time(debug_file);
ret += vfprintf(debug_file, fmt, args);
}
}

return ret;
}

If use quiet mode, verbose sets to -1. (also assigned in the perf_quiet_option function)
Because "var >= level" is false, veprintf function returns directly, which avoids this problem.

However, there are cases where:
# perf --debug stderr=-1 report -vvv 2>/tmp/debug

If stderr is -1, should we redirect pr_debug in this case?

Because I'm not sure if this is a problem,
if redirect_to_stderr needs to be fixed as well,
let me know and I'll submit a patch to fix it.


and display_attr incorrectly determines the value of debug_peo_args.
As a result, unexpected information is displayed.

Before:
# perf record --quiet -- ls > /dev/null
------------------------------------------------------------
perf_event_attr:
size 128
{ sample_period, sample_freq } 4000
sample_type IP|TID|TIME|PERIOD
read_format ID|LOST
disabled 1
inherit 1
mmap 1
comm 1
freq 1
enable_on_exec 1
task 1
precise_ip 3
sample_id_all 1
exclude_guest 1
mmap2 1
comm_exec 1
ksymbol 1
bpf_event 1
------------------------------------------------------------
...

After:
# perf record --quiet -- ls > /dev/null
#

Fixes: ccd26741f5e6 ("perf tool: Provide an option to print perf_event_open args and return value")
Signed-off-by: Yang Jihong <yangjihong1@xxxxxxxxxx>

Reviewed-by: Adrian Hunter <adrian.hunter@xxxxxxxxx>

Thanks for reviewed-by.

Thanks,
Yang