public inbox for igt-dev@lists.freedesktop.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: Caleb Callaway <caleb.callaway@intel.com>,
	Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Subject: [igt-dev] [PATCH i-g-t 3/3] intel_gpu_top: Add CVS output format
Date: Fri,  3 Feb 2023 11:16:36 +0000	[thread overview]
Message-ID: <20230203111636.4138202-4-tvrtko.ursulin@linux.intel.com> (raw)
In-Reply-To: <20230203111636.4138202-1-tvrtko.ursulin@linux.intel.com>

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

Add CVS output mode.

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: Caleb Callaway <caleb.callaway@intel.com>
---
 man/intel_gpu_top.rst |  3 ++
 tools/intel_gpu_top.c | 78 +++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 78 insertions(+), 3 deletions(-)

diff --git a/man/intel_gpu_top.rst b/man/intel_gpu_top.rst
index 69834756b81e..77228277b9bf 100644
--- a/man/intel_gpu_top.rst
+++ b/man/intel_gpu_top.rst
@@ -31,6 +31,9 @@ OPTIONS
 -h
     Show help text.
 
+-c
+    Output CVS formatted data.
+
 -J
     Output JSON formatted data.
 
diff --git a/tools/intel_gpu_top.c b/tools/intel_gpu_top.c
index a980cc7043dc..4c425ca027e3 100644
--- a/tools/intel_gpu_top.c
+++ b/tools/intel_gpu_top.c
@@ -1268,6 +1268,7 @@ usage(const char *appname)
 		"\n"
 		"\tThe following parameters are optional:\n\n"
 		"\t[-h]            Show this help text.\n"
+		"\t[-c]            Output CVS formatted data.\n"
 		"\t[-J]            Output JSON formatted data.\n"
 		"\t[-l]            List plain text data.\n"
 		"\t[-o <file|->]   Output to specified file or '-' for standard out.\n"
@@ -1283,6 +1284,7 @@ usage(const char *appname)
 static enum {
 	INTERACTIVE,
 	TEXT,
+	CVS,
 	JSON
 } output_mode;
 
@@ -1457,6 +1459,22 @@ text_add_member(const struct cnt_group *parent, struct cnt_item *item,
 	return len > 0 ? len : 0;
 }
 
+static unsigned int
+cvs_add_member(const struct cnt_group *parent, struct cnt_item *item,
+	       unsigned int headers)
+{
+	int len = 0;
+
+	if (headers)
+		fprintf(out, "%s %s", parent->display_name, item->unit);
+	else
+		len = fprintf(out, "%f",
+			      pmu_calc(&item->pmu->val, item->d, item->t,
+				       item->s));
+
+	return len > 0 ? len : 0;
+}
+
 static void
 term_open_struct(const char *name)
 {
@@ -1540,6 +1558,46 @@ print_group(struct cnt_group *grp, unsigned int headers)
 	return consumed;
 }
 
+static unsigned int cvs_count, prev_cvs_count;
+
+static void cvs_close_struct(void)
+{
+	assert(text_level > 0);
+	if (--text_level == 0) {
+		cvs_count = prev_cvs_count = 0;
+		text_lines++;
+		fputs("\n", out);
+		fflush(out);
+	}
+}
+
+static bool
+cvs_print_group(struct cnt_group *grp, unsigned int headers)
+{
+	unsigned int consumed = 0;
+	struct cnt_item *item;
+
+	if (!present_in_group(grp))
+		return false;
+
+	text_open_struct(grp->name);
+
+	for (item = grp->items; item->name; item++) {
+		if (!item->pmu || !item->pmu->present)
+			continue;
+
+		if (cvs_count != prev_cvs_count)
+			fprintf(out, ",");
+		prev_cvs_count = cvs_count++;
+
+		consumed += cvs_add_member(grp, item, headers);
+	}
+
+	cvs_close_struct();
+
+	return consumed;
+}
+
 static bool
 term_print_group(struct cnt_group *grp, unsigned int headers)
 {
@@ -1570,6 +1628,13 @@ static const struct print_operations text_pops = {
 	.print_group = print_group,
 };
 
+static const struct print_operations cvs_pops = {
+	.open_struct = text_open_struct,
+	.close_struct = cvs_close_struct,
+	.add_member = cvs_add_member,
+	.print_group = cvs_print_group,
+};
+
 static const struct print_operations term_pops = {
 	.open_struct = term_open_struct,
 	.close_struct = term_close_struct,
@@ -1582,11 +1647,12 @@ static bool print_groups(struct cnt_group **groups)
 	static bool headers_printed = false;
 	bool print_data = true;
 
-	if (output_mode == TEXT &&
+	if ((output_mode == TEXT || output_mode == CVS) &&
 	    (text_header_repeat || !headers_printed)) {
+		const unsigned int header_lines = output_mode == TEXT ? 2 : 1;
 		unsigned int headers = text_lines % TEXT_HEADER_REPEAT + 1;
 
-		if (headers == 1 || headers == 2)
+		if (headers > 0 && headers <= header_lines)
 			for (struct cnt_group **grp = groups; *grp; grp++)
 				print_data = pops->print_group(*grp, headers);
 
@@ -2469,7 +2535,7 @@ int main(int argc, char **argv)
 	char *codename = NULL;
 
 	/* Parse options */
-	while ((ch = getopt(argc, argv, "o:s:d:pJLlh")) != -1) {
+	while ((ch = getopt(argc, argv, "o:s:d:pcJLlh")) != -1) {
 		switch (ch) {
 		case 'o':
 			output_path = optarg;
@@ -2483,6 +2549,9 @@ int main(int argc, char **argv)
 		case 'p':
 			physical_engines = true;
 			break;
+		case 'c':
+			output_mode = CVS;
+			break;
 		case 'J':
 			output_mode = JSON;
 			break;
@@ -2532,6 +2601,9 @@ int main(int argc, char **argv)
 	case TEXT:
 		pops = &text_pops;
 		break;
+	case CVS:
+		pops = &cvs_pops;
+		break;
 	case JSON:
 		pops = &json_pops;
 		break;
-- 
2.34.1

  parent reply	other threads:[~2023-02-03 11:16 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-03 11:16 [igt-dev] [PATCH i-g-t 0/3] More intel_gpu_top improvements Tvrtko Ursulin
2023-02-03 11:16 ` [igt-dev] [PATCH i-g-t 1/3] intel_gpu_top: Do not repeat header lines in non-interactive output Tvrtko Ursulin
2023-02-07 13:25   ` [igt-dev] [Intel-gfx] " Kamil Konieczny
2023-02-08 12:31   ` Kamil Konieczny
2023-02-09  8:24     ` Tvrtko Ursulin
2023-02-03 11:16 ` [igt-dev] [PATCH i-g-t 2/3] intel_gpu_top: Rename STDOUT to TEXT Tvrtko Ursulin
2023-02-07 13:15   ` Kamil Konieczny
2023-02-03 11:16 ` Tvrtko Ursulin [this message]
2023-02-03 11:22   ` [igt-dev] [PATCH i-g-t 3/3] intel_gpu_top: Add CVS output format Ville Syrjälä
2023-02-03 11:27     ` Tvrtko Ursulin
2023-02-03 11:30   ` [igt-dev] [PATCH i-g-t 3/3] intel_gpu_top: Add CSV " Tvrtko Ursulin
2023-02-03 11:31   ` Tvrtko Ursulin
2023-02-07 13:29     ` [igt-dev] [Intel-gfx] " Kamil Konieczny
2023-02-03 14:49 ` [igt-dev] ✓ Fi.CI.BAT: success for More intel_gpu_top improvements (rev3) Patchwork
2023-02-04 17:27 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork

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=20230203111636.4138202-4-tvrtko.ursulin@linux.intel.com \
    --to=tvrtko.ursulin@linux.intel.com \
    --cc=Intel-gfx@lists.freedesktop.org \
    --cc=caleb.callaway@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=tvrtko.ursulin@intel.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox