From patchwork Fri Sep 24 10:17:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Ivanov X-Patchwork-Id: 1532192 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4HG7Jq3JVNz9sxS for ; Fri, 24 Sep 2021 20:18:01 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 20C1140590; Fri, 24 Sep 2021 10:17:58 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id b4q8jeHcfzeg; Fri, 24 Sep 2021 10:17:57 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp2.osuosl.org (Postfix) with ESMTPS id 2706C403E0; Fri, 24 Sep 2021 10:17:56 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id E6BCCC0011; Fri, 24 Sep 2021 10:17:55 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) by lists.linuxfoundation.org (Postfix) with ESMTP id D19C3C000D for ; Fri, 24 Sep 2021 10:17:54 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id B0A53403E0 for ; Fri, 24 Sep 2021 10:17:54 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id JwQfYF7YBg7v for ; Fri, 24 Sep 2021 10:17:52 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0 Received: from www.kot-begemot.co.uk (ivanoab7.miniserver.com [37.128.132.42]) by smtp2.osuosl.org (Postfix) with ESMTPS id AECD34013B for ; Fri, 24 Sep 2021 10:17:52 +0000 (UTC) Received: from tun252.jain.kot-begemot.co.uk ([192.168.18.6] helo=jain.kot-begemot.co.uk) by www.kot-begemot.co.uk with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mTiH7-00080W-0A for ovs-dev@openvswitch.org; Fri, 24 Sep 2021 10:17:49 +0000 Received: from jain.kot-begemot.co.uk ([192.168.3.3]) by jain.kot-begemot.co.uk with esmtp (Exim 4.92) (envelope-from ) id 1mTiH3-0007pu-VF; Fri, 24 Sep 2021 11:17:47 +0100 From: anton.ivanov@cambridgegreys.com To: ovs-dev@openvswitch.org Date: Fri, 24 Sep 2021 11:17:44 +0100 Message-Id: <20210924101744.30065-1-anton.ivanov@cambridgegreys.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett Cc: Anton Ivanov Subject: [ovs-dev] [PATCH v2] jsonrpc: Sort JSON objects only if debug is on X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" From: Anton Ivanov There is no point to sort JSON objects when nobody is observing them. Machines do not care if it is sorted or not. Signed-off-by: Anton Ivanov --- lib/jsonrpc.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/jsonrpc.c b/lib/jsonrpc.c index c8ce5362e..18777f4d6 100644 --- a/lib/jsonrpc.c +++ b/lib/jsonrpc.c @@ -802,7 +802,15 @@ jsonrpc_msg_to_string(const struct jsonrpc_msg *m) { struct jsonrpc_msg *copy = jsonrpc_msg_clone(m); struct json *json = jsonrpc_msg_to_json(copy); - char *s = json_to_string(json, JSSF_SORT); + char *s; + if (VLOG_IS_DBG_ENABLED()) { + /* We need json sorted only if a human is looking + * at it. No point to sort it if debug is not on. + */ + s = json_to_string(json, JSSF_SORT); + } else { + s = json_to_string(json, 0); + } json_destroy(json); return s; }