Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp2513849rwj; Mon, 19 Dec 2022 05:43:12 -0800 (PST) X-Google-Smtp-Source: AMrXdXtIQ9gl3p7jTGLSgabZS/nKZrIbxoTgd1uXd51gSKV6bn1CvGK0LBJjRMw7zwI3wcT83zIw X-Received: by 2002:a17:90a:ea83:b0:219:c591:6de3 with SMTP id h3-20020a17090aea8300b00219c5916de3mr8678329pjz.20.1671457392710; Mon, 19 Dec 2022 05:43:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671457392; cv=none; d=google.com; s=arc-20160816; b=RSLqfGZRYWdbStZvPVuVi+a0VsxSAcMmLfKO7YAZX/NG4MUeZSuuP0TKp5GGSYn8Rv QY56l/S15Li0inqn202uSfF7mos4iti6e9zlifkDEz254O1oLgbxb/tQAy1VDkp7vqZe 9UU2LaUlQ9dwZuOkKqbfIYTTGSrrTQ8LTMegmN1JmzUvU42DyuU+TAp5kmcN7Y5E6Tgi 6iCyOKaX7AnYtazQGG3PhJv6KZTLlrCjtyvK/LRxJX/PcCPj9hFZJU1F/p3NH3YxGYNy vmuD/ud6AyJI0LasJKpp6XJPSrOCr2RQWIf+uArS5SvWUolFiPCbzJfBLR2+onIBgLui MlYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :to:subject; bh=1VY7YX4tRJAa0aUWX6qTCdF/KPAc/n7MeIObPGWDYuI=; b=jo6eEhqfxh4i7833OA7tw6xQ41ftSgENt/Zj/0bGXA+OXEeuvZfaEI08eu8Mrf2Hnj z3ACzOjwlEi5kTAOBTr3i845j7473euMnKHcKAABPtQsELmv1OXCDRDHJyB3O7gG9nXh RuBinkZ5JxkvWnQFIjAGIGjiZrBCe4Rkv1Tfftp6bIdJI3fxLdcnk/HLg9NTztQkcE2u C/jDEzrJXaNPQ5lOE1m4gWNCPcMtRcBCEcibR6W1XABouxpqg+ppa1B7SI9Lm1+QhqdY 3pfWmdKWFZpO9EjiU/AyzeMoKsNOA5xY3LUJ+aaVwDnrDDRrFMwxAy+jaX2hSj0t4wrO XKkQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c14-20020a17090abf0e00b002193e1a906esi15579292pjs.133.2022.12.19.05.43.03; Mon, 19 Dec 2022 05:43:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232019AbiLSNOQ (ORCPT + 71 others); Mon, 19 Dec 2022 08:14:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231292AbiLSNOO (ORCPT ); Mon, 19 Dec 2022 08:14:14 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 681A17670; Mon, 19 Dec 2022 05:14:12 -0800 (PST) Received: from kwepemm600003.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4NbKrc1gn0zmWjX; Mon, 19 Dec 2022 21:13:04 +0800 (CST) Received: from [10.67.111.205] (10.67.111.205) by kwepemm600003.china.huawei.com (7.193.23.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Mon, 19 Dec 2022 21:14:09 +0800 Subject: Re: [PATCH] perf tool: Fix output unexpected messages in quiet mode To: Adrian Hunter , , , , , , , , , , , , , , References: <20221219024911.62741-1-yangjihong1@huawei.com> <194c676b-3a73-7f34-1f29-a157b5e4731f@intel.com> <7aecae79-5b6d-09ea-dfd5-4d4810875f3d@huawei.com> From: Yang Jihong Message-ID: <0e06416c-fac3-1149-2660-9a1981e3460d@huawei.com> Date: Mon, 19 Dec 2022 21:14:08 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Originating-IP: [10.67.111.205] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemm600003.china.huawei.com (7.193.23.202) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-5.3 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, On 2022/12/19 18:28, Adrian Hunter wrote: > On 19/12/22 11:28, Yang Jihong wrote: >> 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? > > tools/perf/Documentation/perf.txt says debug variables are in value > range (0, 10), so -1 is invalid anyway. > Okay, I see. >> >> 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. > > perf_quiet_option() sets redirect_to_stderr = -1 with the intention > that it turns it off, but it doesn't, although it gets turned of by > verbose = -1. Perhaps set redirect_to_stderr = 0 in perf_quiet_option() ? > I think it's better to fix redirect_to_stderr and debug_peo_args in the same way (because they're similar): Solution A: diff --git a/tools/perf/util/debug.c b/tools/perf/util/debug.c index 65e6c22f38e4..908b26e579e5 100644 --- a/tools/perf/util/debug.c +++ b/tools/perf/util/debug.c @@ -68,7 +68,7 @@ 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) { + if (use_browser >= 1 && redirect_to_stderr <= 0) { ui_helpline__vshow(fmt, args); } else { ret = fprintf_time(debug_file); diff --git a/tools/perf/util/debug.h b/tools/perf/util/debug.h index f99468a7f681..f6ab84c93ec0 100644 --- a/tools/perf/util/debug.h +++ b/tools/perf/util/debug.h @@ -41,7 +41,7 @@ extern int debug_data_convert; /* Special macro to print perf_event_open arguments/return value. */ #define pr_debug2_peo(fmt, ...) { \ - if (debug_peo_args) \ + if (debug_peo_args > 0) \ pr_debugN(0, pr_fmt(fmt), ##__VA_ARGS__); \ else \ pr_debugN(2, pr_fmt(fmt), ##__VA_ARGS__); \ diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 999dd1700502..45cf144c5d5d 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1775,7 +1775,7 @@ static int __open_attr__fprintf(FILE *fp, const char *name, const char *val, static void display_attr(struct perf_event_attr *attr) { - if (verbose >= 2 || debug_peo_args) { + if (verbose >= 2 || debug_peo_args > 0) { fprintf(stderr, "%.60s\n", graph_dotted_line); fprintf(stderr, "perf_event_attr:\n"); perf_event_attr__fprintf(stderr, attr, __open_attr__fprintf, NULL); or Solution B: diff --git a/tools/perf/util/debug.c b/tools/perf/util/debug.c index 908b26e579e5..e3acc213edd1 100644 --- a/tools/perf/util/debug.c +++ b/tools/perf/util/debug.c @@ -241,6 +241,9 @@ int perf_quiet_option(void) opt++; } + redirect_to_stderr = 0; + debug_peo_args = 0; + > I see we have another problem as well: places that check "if (verbose)" > instead of "if (verbose > 0)" Yes, places that "if (verbose)" also have problems, I'll submit a patch to change them to "if (verbose > 0)" In addition, I found another problem, perf lock/stat/probe does not call the perf_quiet_option function when quiet is true. Thanks, Yang