public inbox for linux-rt-users@vger.kernel.org
 help / color / mirror / Atom feed
From: Daniel Wagner <dwagner@suse.de>
To: Clark Williams <williams@redhat.com>, John Kacur <jkacur@redhat.com>
Cc: linux-rt-users@vger.kernel.org, Daniel Wagner <dwagner@suse.de>
Subject: [rt-tests v1 06/12] ptsematest: Move statictic output into print_stat()
Date: Wed, 18 Nov 2020 20:06:36 +0100	[thread overview]
Message-ID: <20201118190642.16006-7-dwagner@suse.de> (raw)
In-Reply-To: <20201118190642.16006-1-dwagner@suse.de>

Prepare the code to introduce the quiet command line option by moving
the statistic output code into print_stat(). We follow here the
pattern from cyclictest.

While at it replace the rather sophisticated error printing code with
a fatal(). Just fail if something is not working.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
---
 src/ptsematest/ptsematest.c | 65 ++++++++++++++++---------------------
 1 file changed, 28 insertions(+), 37 deletions(-)

diff --git a/src/ptsematest/ptsematest.c b/src/ptsematest/ptsematest.c
index 9cd5f34509a8..69b4e1221361 100644
--- a/src/ptsematest/ptsematest.c
+++ b/src/ptsematest/ptsematest.c
@@ -52,7 +52,6 @@ struct params {
 	struct timeval unblocked, received, diff;
 	pthread_t threadid;
 	struct params *neighbor;
-	char error[MAX_PATH * 2];
 };
 
 void *semathread(void *param)
@@ -121,9 +120,8 @@ void *semathread(void *param)
 					write(tracing_enabled, "0", 1);
 					close(tracing_enabled);
 				} else
-					snprintf(par->error, sizeof(par->error),
-					    "Could not access %s\n",
-					    tracing_enabled_file);
+					fatal("Could not access %s\n",
+					      tracing_enabled_file);
 				par->shutdown = 1;
 				par->neighbor->shutdown = 1;
 			}
@@ -290,6 +288,28 @@ static void sighand(int sig)
 	shutdown = 1;
 }
 
+static void print_stat(FILE *fp, struct params *receiver, struct params *sender,
+		       int verbose, int quiet)
+{
+	int i;
+
+	for (i = 0; i < num_threads; i++) {
+		printf("#%1d: ID%d, P%d, CPU%d, I%ld; #%1d: ID%d, P%d, CPU%d, Cycles %d\n",
+			i*2, receiver[i].tid, receiver[i].priority, receiver[i].cpu,
+			receiver[i].delay.tv_nsec / 1000,
+			i*2+1, sender[i].tid, sender[i].priority, sender[i].cpu,
+			sender[i].samples);
+	}
+	for (i = 0; i < num_threads; i++) {
+		printf("#%d -> #%d, Min %4d, Cur %4d, Avg %4d, Max %4d\n",
+			i*2+1, i*2,
+			receiver[i].mindiff, (int) receiver[i].diff.tv_usec,
+			(int) ((receiver[i].sumdiff / receiver[i].samples) + 0.5),
+			receiver[i].maxdiff);
+	}
+}
+
+
 int main(int argc, char *argv[])
 {
 	int i;
@@ -367,40 +387,13 @@ int main(int argc, char *argv[])
 	maindelay.tv_nsec = 50000000; /* 50 ms */
 
 	while (!shutdown) {
-		int printed;
-		int errorlines = 0;
-
 		for (i = 0; i < num_threads; i++)
 			shutdown |= receiver[i].shutdown | sender[i].shutdown;
 
 		if (receiver[0].samples > oldsamples || shutdown) {
-			for (i = 0; i < num_threads; i++) {
-				printf("#%1d: ID%d, P%d, CPU%d, I%ld; #%1d: ID%d, P%d, CPU%d, Cycles %d\n",
-				    i*2, receiver[i].tid, receiver[i].priority, receiver[i].cpu,
-				    receiver[i].delay.tv_nsec / 1000,
-				    i*2+1, sender[i].tid, sender[i].priority, sender[i].cpu,
-				    sender[i].samples);
-			}
-			for (i = 0; i < num_threads; i++) {
-				printf("#%d -> #%d, Min %4d, Cur %4d, Avg %4d, Max %4d\n",
-					i*2+1, i*2,
-					receiver[i].mindiff, (int) receiver[i].diff.tv_usec,
-					(int) ((receiver[i].sumdiff / receiver[i].samples) + 0.5),
-					receiver[i].maxdiff);
-				if (receiver[i].error[0] != '\0') {
-					printf("%s", receiver[i].error);
-					errorlines++;
-					receiver[i].error[0] = '\0';
-				}
-				if (sender[i].error[0] != '\0') {
-					printf("%s", sender[i].error);
-					errorlines++;
-					receiver[i].error[0] = '\0';
-				}
-			}
-			printed = 1;
-		} else
-			printed = 0;
+			print_stat(stdout, receiver, sender, 0, 0);
+			printf("\033[%dA", num_threads*2);
+		}
 
 		sigemptyset(&sigset);
 		sigaddset(&sigset, SIGTERM);
@@ -411,10 +404,8 @@ int main(int argc, char *argv[])
 
 		sigemptyset(&sigset);
 		pthread_sigmask(SIG_SETMASK, &sigset, NULL);
-
-		if (printed && !shutdown)
-			printf("\033[%dA", num_threads*2 + errorlines);
 	}
+	printf("\033[%dB", num_threads*2 + 2);
 
 	for (i = 0; i < num_threads; i++) {
 		receiver[i].shutdown = 1;
-- 
2.29.2


  parent reply	other threads:[~2020-11-18 19:07 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-18 19:06 [rt-tests v1 00/12] Add quiet command line option Daniel Wagner
2020-11-18 19:06 ` [rt-tests v1 01/12] cyclicdeadline: Remove dead code Daniel Wagner
2020-11-19  6:54   ` Punit Agrawal
2020-11-19  8:19     ` Daniel Wagner
2020-12-01  6:30   ` John Kacur
2020-12-01  8:21     ` Daniel Wagner
2020-11-18 19:06 ` [rt-tests v1 02/12] cyclicdeadline: Use common error handlers Daniel Wagner
2020-12-01  6:57   ` John Kacur
2020-11-18 19:06 ` [rt-tests v1 03/12] cyclicdeadline: Add quiet command line option Daniel Wagner
2020-12-01  7:00   ` John Kacur
2020-11-18 19:06 ` [rt-tests v1 04/12] pmqtest: Move statictic output into print_stat() Daniel Wagner
2020-12-01  7:02   ` John Kacur
2020-11-18 19:06 ` [rt-tests v1 05/12] pmqtest: Add quiet command line option Daniel Wagner
2020-12-01  7:04   ` John Kacur
2020-11-18 19:06 ` Daniel Wagner [this message]
2020-12-01  7:06   ` [rt-tests v1 06/12] ptsematest: Move statictic output into print_stat() John Kacur
2020-11-18 19:06 ` [rt-tests v1 07/12] ptsematest: Add quiet command line option Daniel Wagner
2020-12-01  7:09   ` John Kacur
2020-11-18 19:06 ` [rt-tests v1 08/12] svsematest: Move statictic output into print_stat() Daniel Wagner
2020-12-01  7:11   ` John Kacur
2020-11-18 19:06 ` [rt-tests v1 09/12] svsematest: Add quiet command line option Daniel Wagner
2020-12-01  7:12   ` John Kacur
2020-11-18 19:06 ` [rt-tests v1 10/12] sigwaittest: Move statictic output into print_stat() Daniel Wagner
2020-12-01  7:14   ` John Kacur
2020-11-18 19:06 ` [rt-tests v1 11/12] sigwaittest: Add quiet command line option Daniel Wagner
2020-12-01  7:16   ` John Kacur
2020-11-18 19:06 ` [rt-tests v1 12/12] rt-migrate-test: " Daniel Wagner
2020-12-01  7:17   ` John Kacur
2020-11-20 16:33 ` [rt-tests v1 00/12] " Daniel Wagner

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=20201118190642.16006-7-dwagner@suse.de \
    --to=dwagner@suse.de \
    --cc=jkacur@redhat.com \
    --cc=linux-rt-users@vger.kernel.org \
    --cc=williams@redhat.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