Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lMBV0-00038s-Va for pgsql-hackers@arkaria.postgresql.org; Tue, 16 Mar 2021 15:20:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lMBUz-0008AC-Tu for pgsql-hackers@arkaria.postgresql.org; Tue, 16 Mar 2021 15:20:45 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lMBUz-0008A5-N3 for pgsql-hackers@lists.postgresql.org; Tue, 16 Mar 2021 15:20:45 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lMBUx-0002Zm-Ci for pgsql-hackers@lists.postgresql.org; Tue, 16 Mar 2021 15:20:44 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id 78A0D5C0172; Tue, 16 Mar 2021 11:20:42 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Tue, 16 Mar 2021 11:20:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=osLeFbmDceYsY4jlm+9Pz4mkuyRE1DaNunlCYTgdk40=; b=O1QhxZjA VtgOtJhY3ehi98XNXu04A9poHJ7z7oOWaOS29OvrYPo6naORB2rydBiAaJo5r11C hh9kTdUu95imj82xEAT/VxEOnzKRnq2szQ6vg9JBKS2ZAEXDXUv+i5NINNqDAx3f 7UABnDtIs/Egx5zDUlitbh1W3y1g/Y3D5F3v2fPZezzgsgMa/hvTWWHzH6/McsDL O9qsBpp/6KO+Zy+H3RMSvycmM2QMDq/0HYYhgqtQ7u6AqS0RVsDKgRhrgSVU5Yc1 MxdIBj9opA/wu/4jGFZX4e9djPTkwpxLREvtkxrv8AtEC72gIGCgeON783O9TZ5Z nNPQa3gOnXzqkA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrudefvddgjeeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkgggtugfgjggfsehtke ertddtredunecuhfhrohhmpeetlhhvrghrohcujfgvrhhrvghrrgcuoegrlhhvhhgvrhhr vgesrghlvhhhrdhnohdqihhprdhorhhgqeenucggtffrrghtthgvrhhnpeeufffhjeeiue euffegvddukeegledtveeivdeiueefieeivefgteehueefteehvdenucfkphepudeltddr leehrdduledrleehnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilh hfrhhomheprghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgh X-ME-Proxy: Received: from perhan.alvh.no-ip.org (unknown [190.95.19.95]) by mail.messagingengine.com (Postfix) with ESMTPA id C88C724005B; Tue, 16 Mar 2021 11:20:41 -0400 (EDT) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id C990A2A0BA7; Tue, 16 Mar 2021 12:20:38 -0300 (-03) Date: Tue, 16 Mar 2021 12:20:38 -0300 From: Alvaro Herrera To: "iwata.aya@fujitsu.com" Cc: 'Tom Lane' , 'Kyotaro Horiguchi' , "tsunakawa.takay@fujitsu.com" , "k.jamison@fujitsu.com" , "pgsql-hackers@lists.postgresql.org" Subject: Re: libpq debug log Message-ID: <20210316152038.GA11819@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2021-Mar-15, iwata.aya@fujitsu.com wrote: > I create protocol message reading function for each protocol message type. (Ex. pqTraceOutputB() read Bind message) > This makes the nesting shallower and makes the code easier to read. I'm not sure I agree with this structural change. Yes, it is less indentation, but these functions are all quite short and simple anyway. But I don't disagree strongly with it either. Four issues: * There's no cross-check that the protocol message length word corresponds to what we actually print. I think one easy way to cross-check that would be to return the "count" from the type-specific routines, and verify that it matches "length" in pqTraceOutputMessage. (If the separate routines are removed and the code put back in one giant switch, then the "count" is already available when the switch ends.) * If we have separate functions for each message type, then we can have that function supply the message name by itself, rather than have the separate protocol_message_type_f / _b arrays that print it. * If we make each type-specific function print the message name, then we need to make the same function print the message length, because it comes after. So the function would have to receive the length (so that it can be printed). But I think we should still have the cross-check I mentioned in my first point occur in the main pqTraceOutputMessage, not the type-specific function, for fear that we will forget the cross-check in one of the functions and never realize that we did. * I would make the pqTraceOutputInt16() function and siblings advance the cursor themselves, actually. I think something like this: static int pqTraceOutputInt16(const char *data, int *cursor, FILE *pfdebug) { uint16 tmp; int result; memcpy(&tmp, data + *cursor, 2); *cursor += 2; result = (int) pg_ntoh16(tmp); fprintf(pfdebug, " #%d", result); return result; } (So the caller has to pass the original "data" pointer, not "data+cursor"). This means the caller no longer has to do "cursor+=N" at each place. Also, you get rid of the moveStrCursor() which does not look good. Bikeshedding item: * I'm not fond of the idea of prefixing "#" for 16bit ints and no prefix for 32bit ints. Seems obscure and the output looks weird. I would use a one-letter prefix for each type, "w" for 32-bit ints (stands for "word") and "h" for 16-bit ints (stands for "half-word"). Message length goes unadorned. Then you'd have lines like this 2021-03-15 08:10:44.324296 < RowDescription 35 h1 "spcoptions" w1213 h5 w1009 h65535 w-1 h0 2021-03-15 08:10:44.324335 < DataRow 32 h1 w22 '{random_page_cost=3.0}' * I don't like that pqTraceOutputS/H print nothing when !toServer. I think they should complain. -- Álvaro Herrera 39°49'30"S 73°17'W