[PATCH i-g-t v2 19/21] gputop: Allow to limit number of executions

Lucas De Marchi lucas.demarchi at intel.com
Tue Apr 23 23:44:29 UTC 2024


Add argument to limit number of executions, similar to the one accepted
by `top`. This allows testing changes and optimizations more easily.

Signed-off-by: Lucas De Marchi <lucas.demarchi at intel.com>
---
 tools/gputop.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/tools/gputop.c b/tools/gputop.c
index d9a151d3b..e99aa56e5 100644
--- a/tools/gputop.c
+++ b/tools/gputop.c
@@ -301,6 +301,7 @@ static void clrscr(void)
 }
 
 struct gputop_args {
+	long n_iter;
 };
 
 static void help(void)
@@ -309,19 +310,22 @@ static void help(void)
 	       "\t%s [options]\n\n"
 	       "Options:\n"
 	       "\t-h, --help                show this help\n"
+	       "\t-n, --iterations =NUMBER  number of executions\n"
 	       , program_invocation_short_name);
 }
 
 static int parse_args(int argc, char * const argv[], struct gputop_args *args)
 {
-	static const char cmdopts_s[] = "h";
+	static const char cmdopts_s[] = "hn:";
 	static const struct option cmdopts[] = {
 	       {"help", no_argument, 0, 'h'},
+	       {"iterations", required_argument, 0, 'n'},
 	       { }
 	};
 
 	/* defaults */
 	memset(args, 0, sizeof(*args));
+	args->n_iter = -1;
 
 	for (;;) {
 		int c, idx = 0;
@@ -331,6 +335,9 @@ static int parse_args(int argc, char * const argv[], struct gputop_args *args)
 			break;
 
 		switch (c) {
+		case 'n':
+			args->n_iter = strtol(optarg, NULL, 10);
+			break;
 		case 'h':
 			help();
 			return 0;
@@ -350,6 +357,7 @@ int main(int argc, char **argv)
 	struct igt_drm_clients *clients = NULL;
 	int con_w = -1, con_h = -1;
 	int ret;
+	long n;
 
 	ret = parse_args(argc, argv, &args);
 	if (ret < 0)
@@ -357,13 +365,15 @@ int main(int argc, char **argv)
 	if (!ret)
 		return EXIT_SUCCESS;
 
+	n = args.n_iter;
+
 	clients = igt_drm_clients_init(NULL);
 	if (!clients)
 		exit(1);
 
 	igt_drm_clients_scan(clients, NULL, NULL, 0, NULL, 0);
 
-	for (;;) {
+	while (n != 0) {
 		struct igt_drm_client *c, *prevc = NULL;
 		int i, engine_w = 0, lines = 0;
 
@@ -389,6 +399,8 @@ int main(int argc, char **argv)
 			printf("\n");
 
 		usleep(period_us);
+		if (n > 0)
+			n--;
 	}
 
 	igt_drm_clients_free(clients);
-- 
2.43.0



More information about the igt-dev mailing list