Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t9F23-008cLb-62 for pgsql-hackers@arkaria.postgresql.org; Fri, 08 Nov 2024 02:47:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1t9F20-005EOn-Kf for pgsql-hackers@arkaria.postgresql.org; Fri, 08 Nov 2024 02:47:29 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t9F20-005EOf-As for pgsql-hackers@lists.postgresql.org; Fri, 08 Nov 2024 02:47:28 +0000 Received: from meldrar.postgresql.org ([2a02:c0:301:0:ffff::31]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t9F1w-000mF8-Pk for pgsql-hackers@postgresql.org; Fri, 08 Nov 2024 02:47:28 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Content-Transfer-Encoding:Content-Type: Mime-Version:References:In-Reply-To:From:Subject:Cc:To:Message-Id:Date:Sender :Reply-To:Content-ID:Content-Description; bh=/47ug701ONRPXuoqBf49tr3JPEhi4ourha0CW+Npogk=; b=a9SRfGsjGsYfTMH5buKWdIUOSF QV8u2v5O5bYmDPJcbLGJxzHG6crz8ZELX3mRCHy1IenDP1BNbJPErxQMv5zT8hM4X0JZov25HfGsU cyZ0ydRQ8G71bVQefRR5x4r3xrFmzo/UYDNr6voMJ5CO76CGCIbbrUY0HvLEsm6jYViuJVJRbsl9u KDvPN23cGrmH27UC+DG1fc0FXgnWchMYwfzIzoydQk9O43Yrp+Qq0GEYo5JPNcvPhEOXo3CxzNXS3 XVsp+XPXOJUpXJPb94NbLTWdGoDBPk7XQtZFwpJFbFNJeLe4hXNaP0pDt6mLvLS/XCK+pQwuhoVln OYQfKjSQ==; Received: from [2409:11:4120:300:59bb:1b22:ba02:be15] (helo=localhost) by meldrar.postgresql.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 (Exim 4.94.2) (envelope-from ) id 1t9F1t-001XE7-MI; Fri, 08 Nov 2024 02:47:25 +0000 Date: Fri, 08 Nov 2024 11:47:13 +0900 (JST) Message-Id: <20241108.114713.484828673471024549.ishii@postgresql.org> To: masao.fujii@oss.nttdata.com Cc: btogiwarayuushi@oss.nttdata.com, pgsql-hackers@postgresql.org Subject: Re: Fix for Extra Parenthesis in pgbench progress message From: Tatsuo Ishii In-Reply-To: <85fe426d-248a-47f7-8784-22af811ee572@oss.nttdata.com> References: <0f7ac0fa-f26b-49dc-b9a0-d35c29ace3a5@oss.nttdata.com> <20241107.104143.1498084100859794666.ishii@postgresql.org> <85fe426d-248a-47f7-8784-22af811ee572@oss.nttdata.com> X-Mailer: Mew version 6.8 on Emacs 26.3 Mime-Version: 1.0 Content-Type: Text/Plain; charset=iso-2022-jp Content-Transfer-Encoding: 7bit X-Host-Lookup-Failed: Reverse DNS lookup failed for 2409:11:4120:300:59bb:1b22:ba02:be15 (failed) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk >> Maybe. But I am also worried about the case when we would want to >> change the log line format in the future. We might introduce this kind >> of bug again. By dynamically calculating the number of necessary >> spaces, we don't need to think about the concern. > > +1 > > + if (previous_chars != 0) > + { > + int n_spaces = chars - previous_chars; > + fprintf(stderr, "%*s", n_spaces, ""); > + chars += n_spaces; > + } > > Currently, this is added only when use_quiet is false, but shouldn’t > it also apply when use_quiet is true? Yes. The patch just showed my idea and I thought I needed to apply the case when use_quiet is true. But the fix should be applied to after "else if (use_quiet && (j % 100 == 0))" as shown in your patch. > Also, what happens if chars is smaller than previous_chars? My oversight. Better to check if chars is smaller than previous_chars. > I’m unsure why chars needs to be incremented by n_spaces. Yeah, it's not necessary. > I’ve created an updated patch based on your idea―could you take a > look? Sure. I think you need to adjust fprintf(stderr, "%*c\r", chars - 1, ' '); /* Clear the current line */ to: fprintf(stderr, "%*c\r", chars, ' '); /* Clear the current line */ since now chars does not consider the EOL char. By clearing chars - 1, the closing parenthesis will be left on the screen. Best reagards, -- Tatsuo Ishii SRA OSS K.K. English: http://www.sraoss.co.jp/index_en/ Japanese:http://www.sraoss.co.jp