From patchwork Fri Jan 27 11:12:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 13118384 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4B9B8C38142 for ; Fri, 27 Jan 2023 11:13:05 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B325310E461; Fri, 27 Jan 2023 11:13:03 +0000 (UTC) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9A32F10E452; Fri, 27 Jan 2023 11:12:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1674817973; x=1706353973; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4EUo78eqCR4vzVuzw9kpw88MrcKCkVdPmbiE3N//srs=; b=Ujn9tQlMCq9jkqn6KRGEo8qGYP0WFEW5eYEU0ISX+TzS0/XoBKA5e8+F mD1Xqnh3vlQyWPD9Aqvgr892b9tqNPHEccOA4hpTZdjxFG+BmB6R6tE7N 4R0XSeS1tSRJLIBC5VM2RqycCMszZQYMOa/UX7LpZhy6xRgePo5FUl08H /Rpm4TSmyRY8W9EiUN/UhFFn39hLemqQu0z5AIla7+eahhdFxp6vXx02P +8fI9cIgy5JqNSh5+ohLiHnFxN8WueR937VNrq3ZGwNyfVjtt998xBSK4 uiGODn0vpVWeVSHO4dVza9nEg5JZDbQTQQquHdTNfRYOdQooPfaYupn/c g==; X-IronPort-AV: E=McAfee;i="6500,9779,10602"; a="328352649" X-IronPort-AV: E=Sophos;i="5.97,250,1669104000"; d="scan'208";a="328352649" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jan 2023 03:12:53 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10602"; a="908638125" X-IronPort-AV: E=Sophos;i="5.97,250,1669104000"; d="scan'208";a="908638125" Received: from jgeary-mobl1.ger.corp.intel.com (HELO localhost.localdomain) ([10.213.233.162]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jan 2023 03:12:51 -0800 From: Tvrtko Ursulin To: igt-dev@lists.freedesktop.org, Intel-gfx@lists.freedesktop.org Date: Fri, 27 Jan 2023 11:12:37 +0000 Message-Id: <20230127111241.3624629-3-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127111241.3624629-1-tvrtko.ursulin@linux.intel.com> References: <20230127111241.3624629-1-tvrtko.ursulin@linux.intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH i-g-t 2/6] intel_gpu_top: Automatically enclose JSON output into brackets X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eero Tamminen Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" From: Tvrtko Ursulin Parsers need the whole output enclosed into square brackets so every period sample becomes an array element. So far we have been suggesting this in the man page but we can trivially make the tool output that itself. Signed-off-by: Tvrtko Ursulin Cc: Eero Tamminen Reviewed-by: Kamil Konieczny --- man/intel_gpu_top.rst | 2 +- tools/intel_gpu_top.c | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/man/intel_gpu_top.rst b/man/intel_gpu_top.rst index 4417bcff0d5b..caf0a9f9432c 100644 --- a/man/intel_gpu_top.rst +++ b/man/intel_gpu_top.rst @@ -79,7 +79,7 @@ pci | ``pci:[vendor=%04x/name][,device=%04x][,card=%d]`` Select using JSON OUTPUT =========== -To parse the JSON as output by the tool the consumer should wrap its entirety into square brackets ([ ]). This will make each sample point a JSON array element and will avoid "Multiple root elements" JSON validation error. +JSON output will be correctly terminated when the tool cleanly exits, otherwise one square bracket needs to be added before parsing. LIMITATIONS =========== diff --git a/tools/intel_gpu_top.c b/tools/intel_gpu_top.c index 6de8a164fcff..c4d98de4fe31 100644 --- a/tools/intel_gpu_top.c +++ b/tools/intel_gpu_top.c @@ -2597,6 +2597,9 @@ int main(int argc, char **argv) scan_clients(clients, false); codename = igt_device_get_pretty_name(&card, false); + if (output_mode == JSON) + printf("[\n"); + while (!stop_top) { struct clients *disp_clients; bool consumed = false; @@ -2683,6 +2686,9 @@ int main(int argc, char **argv) usleep(period_us); } + if (output_mode == JSON) + printf("]\n"); + if (clients) free_clients(clients);