All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
To: igt-dev@lists.freedesktop.org, Intel-gfx@lists.freedesktop.org
Cc: Eero Tamminen <eero.t.tamminen@intel.com>
Subject: [Intel-gfx] [PATCH i-g-t 2/4] intel_gpu_top: Automatically enclose JSON output into brackets
Date: Thu, 12 Jan 2023 17:47:28 +0000	[thread overview]
Message-ID: <20230112174730.1101192-3-tvrtko.ursulin@linux.intel.com> (raw)
In-Reply-To: <20230112174730.1101192-1-tvrtko.ursulin@linux.intel.com>

From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>

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 <tvrtko.ursulin@intel.com>
Cc: Eero Tamminen <eero.t.tamminen@intel.com>
---
 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 b0c95446a011..3317e04816b4 100644
--- a/man/intel_gpu_top.rst
+++ b/man/intel_gpu_top.rst
@@ -85,7 +85,7 @@ Filter types: ::
 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);
 
-- 
2.34.1


WARNING: multiple messages have this Message-ID (diff)
From: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
To: igt-dev@lists.freedesktop.org, Intel-gfx@lists.freedesktop.org
Cc: Eero Tamminen <eero.t.tamminen@intel.com>,
	Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Subject: [igt-dev] [PATCH i-g-t 2/4] intel_gpu_top: Automatically enclose JSON output into brackets
Date: Thu, 12 Jan 2023 17:47:28 +0000	[thread overview]
Message-ID: <20230112174730.1101192-3-tvrtko.ursulin@linux.intel.com> (raw)
In-Reply-To: <20230112174730.1101192-1-tvrtko.ursulin@linux.intel.com>

From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>

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 <tvrtko.ursulin@intel.com>
Cc: Eero Tamminen <eero.t.tamminen@intel.com>
---
 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 b0c95446a011..3317e04816b4 100644
--- a/man/intel_gpu_top.rst
+++ b/man/intel_gpu_top.rst
@@ -85,7 +85,7 @@ Filter types: ::
 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);
 
-- 
2.34.1

  parent reply	other threads:[~2023-01-12 17:47 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-12 17:47 [Intel-gfx] [PATCH i-g-t 0/4] Some intel_gpu_top tweaks Tvrtko Ursulin
2023-01-12 17:47 ` [igt-dev] " Tvrtko Ursulin
2023-01-12 17:47 ` [Intel-gfx] [PATCH i-g-t 1/4] intel_gpu_top: Fix man page formatting Tvrtko Ursulin
2023-01-12 17:47   ` [igt-dev] " Tvrtko Ursulin
2023-01-26 15:39   ` [Intel-gfx] " Kamil Konieczny
2023-01-26 15:39     ` Kamil Konieczny
2023-01-26 16:09     ` [Intel-gfx] " Tvrtko Ursulin
2023-01-26 16:09       ` Tvrtko Ursulin
2023-01-26 17:08       ` [Intel-gfx] " Kamil Konieczny
2023-01-26 17:08         ` Kamil Konieczny
2023-01-12 17:47 ` Tvrtko Ursulin [this message]
2023-01-12 17:47   ` [igt-dev] [PATCH i-g-t 2/4] intel_gpu_top: Automatically enclose JSON output into brackets Tvrtko Ursulin
2023-01-26 15:41   ` [Intel-gfx] " Kamil Konieczny
2023-01-26 15:41     ` [igt-dev] " Kamil Konieczny
2023-01-26 16:10     ` [Intel-gfx] [igt-dev] " Tvrtko Ursulin
2023-01-26 16:10       ` [igt-dev] [Intel-gfx] " Tvrtko Ursulin
2023-01-12 17:47 ` [Intel-gfx] [PATCH i-g-t 3/4] intel_gpu_top: Add command line switch to start in physical engine mode Tvrtko Ursulin
2023-01-12 17:47   ` [igt-dev] " Tvrtko Ursulin
2023-01-26 15:48   ` [Intel-gfx] " Kamil Konieczny
2023-01-26 15:48     ` [igt-dev] " Kamil Konieczny
2023-01-12 17:47 ` [Intel-gfx] [PATCH i-g-t 4/4] intel_gpu_top: Aggregate engine classes in all output modes Tvrtko Ursulin
2023-01-12 17:47   ` [igt-dev] " Tvrtko Ursulin
2023-01-26 15:50   ` [Intel-gfx] " Kamil Konieczny
2023-01-26 15:50     ` [igt-dev] " Kamil Konieczny
2023-01-26 16:12     ` [Intel-gfx] [igt-dev] " Tvrtko Ursulin
2023-01-26 16:12       ` [igt-dev] [Intel-gfx] " Tvrtko Ursulin
2023-01-12 18:34 ` [igt-dev] ✓ Fi.CI.BAT: success for Some intel_gpu_top tweaks Patchwork
2023-01-13  7:47 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork
2023-01-26 15:53 ` [Intel-gfx] [PATCH i-g-t 0/4] " Kamil Konieczny
2023-01-26 15:53   ` [igt-dev] " Kamil Konieczny

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230112174730.1101192-3-tvrtko.ursulin@linux.intel.com \
    --to=tvrtko.ursulin@linux.intel.com \
    --cc=Intel-gfx@lists.freedesktop.org \
    --cc=eero.t.tamminen@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.