diff mbox series

[rt-tests,v2,15/18] sigwaittest: Streamline usage and man page

Message ID 20201007085653.11961-16-dwagner@suse.de
State New
Headers show
Series Streamline command line | expand

Commit Message

Daniel Wagner Oct. 7, 2020, 8:56 a.m. UTC
Signed-off-by: Daniel Wagner <dwagner@suse.de>
---
 src/sigwaittest/sigwaittest.8 |  4 +-
 src/sigwaittest/sigwaittest.c | 76 +++++++++++++++++++----------------
 2 files changed, 44 insertions(+), 36 deletions(-)

Comments

John Kacur Oct. 23, 2020, 6:51 p.m. UTC | #1
On Wed, 7 Oct 2020, Daniel Wagner wrote:

> Signed-off-by: Daniel Wagner <dwagner@suse.de>
> ---
>  src/sigwaittest/sigwaittest.8 |  4 +-
>  src/sigwaittest/sigwaittest.c | 76 +++++++++++++++++++----------------
>  2 files changed, 44 insertions(+), 36 deletions(-)
> 
> diff --git a/src/sigwaittest/sigwaittest.8 b/src/sigwaittest/sigwaittest.8
> index 2be9c03d05ca..a2dc1bc080a3 100644
> --- a/src/sigwaittest/sigwaittest.8
> +++ b/src/sigwaittest/sigwaittest.8
> @@ -4,7 +4,7 @@
>  \fBsigwaittest\fR \- Start two threads or fork two processes and measure the latency between sending and receiving a signal
>  .SH "SYNTAX"
>  .LP
> -sigwaittest [-a|-a PROC] [-b USEC] [-d DIST] [-f] [-i INTV] [-l loops] [-p PRIO] [-t|-t NUM]
> +sigwaittest [-a|--affinity PROC] [-b|--breaktrace USEC] [-d|--distance DIST] [-D|--duration TIME] [-f|--fork [OPT]] [-i|--interval INTV] [-l|--loops LOOPS] [-p|--prio PRIO] [-t|--threads [NUM]]
>  .br
>  .SH "DESCRIPTION"
>  .LP
> @@ -26,7 +26,7 @@ Specify a length for the test run.
>  .br
>  Append 'm', 'h', or 'd' to specify minutes, hours or days.
>  .TP
> -.B \-f, \-\-fork
> +.B \-f, \-\-fork[=OPT]
>  Instead of creating threads (which is the default), fork new processes
>  .TP
>  .B \-i, \-\-interval=INTV
> diff --git a/src/sigwaittest/sigwaittest.c b/src/sigwaittest/sigwaittest.c
> index e7393f791519..12b55e901ce5 100644
> --- a/src/sigwaittest/sigwaittest.c
> +++ b/src/sigwaittest/sigwaittest.c
> @@ -206,28 +206,30 @@ void *semathread(void *param)
>  }
>  
>  
> -static void display_help(void)
> +static void display_help(int error)
>  {
>  	printf("sigwaittest V %1.2f\n", VERSION);
> -	puts("Usage: sigwaittest <options>");
> -	puts("Function: test sigwait() latency");
> -	puts(
> -	"Options:\n"
> -	"-a [NUM] --affinity        run thread #N on processor #N, if possible\n"
> -	"                           with NUM pin all threads to the processor NUM\n"
> -	"-b USEC  --breaktrace=USEC send break trace command when latency > USEC\n"
> -	"-d DIST  --distance=DIST   distance of thread intervals in us default=500\n"
> -	"-f       --fork            fork new processes instead of creating threads\n"
> -	"-i INTV  --interval=INTV   base interval of thread in us default=1000\n"
> -	"-l LOOPS --loops=LOOPS     number of loops: default=0(endless)\n"
> -	"-D       --duration=TIME   specify a length for the test run.\n"
> -	"                           Append 'm', 'h', or 'd' to specify minutes, hours or days.\n"
> -	"-p PRIO  --prio=PRIO       priority\n"
> -	"-t       --threads         one thread per available processor\n"
> -	"-t [NUM] --threads=NUM     number of threads:\n"
> -	"                           without NUM, threads = max_cpus\n"
> -	"                           without -t default = 1\n");
> -	exit(1);
> +	printf("Usage:\n"
> +	       "sigwaittest <options>\n\n"
> +	       "Function: test sigwait() latency\n\n"
> +	       "Available options:\n"
> +	       "-a [NUM] --affinity        run thread #N on processor #N, if possible\n"
> +	       "                           with NUM pin all threads to the processor NUM\n"
> +	       "-b USEC  --breaktrace=USEC send break trace command when latency > USEC\n"
> +	       "-d DIST  --distance=DIST   distance of thread intervals in us default=500\n"
> +	       "-D       --duration=TIME   specify a length for the test run.\n"
> +	       "                           Append 'm', 'h', or 'd' to specify minutes, hours or\n"
> +	       "                           days.\n"
> +	       "-f [OPT] --fork[=OPT]      fork new processes instead of creating threads\n"
> +	       "-i INTV  --interval=INTV   base interval of thread in us default=1000\n"
> +	       "-l LOOPS --loops=LOOPS     number of loops: default=0(endless)\n"
> +	       "-p PRIO  --prio=PRIO       priority\n"
> +	       "-t       --threads         one thread per available processor\n"
> +	       "-t [NUM] --threads=NUM     number of threads:\n"
> +	       "                           without NUM, threads = max_cpus\n"
> +	       "                           without -t default = 1\n"
> +	       );
> +	exit(error);
>  }
>  
>  
> @@ -250,19 +252,19 @@ static void process_options (int argc, char *argv[])
>  		int option_index = 0;
>  		/** Options for getopt */
>  		static struct option long_options[] = {
> -			{"affinity", optional_argument, NULL, 'a'},
> -			{"breaktrace", required_argument, NULL, 'b'},
> -			{"distance", required_argument, NULL, 'd'},
> -			{"fork", optional_argument, NULL, 'f'},
> -			{"interval", required_argument, NULL, 'i'},
> -			{"loops", required_argument, NULL, 'l'},
> -			{"duration", required_argument, NULL, 'D'},
> -			{"priority", required_argument, NULL, 'p'},
> -			{"threads", optional_argument, NULL, 't'},
> -			{"help", no_argument, NULL, '?'},
> +			{"affinity",		optional_argument,	NULL, 'a'},
> +			{"breaktrace",		required_argument,	NULL, 'b'},
> +			{"distance",		required_argument,	NULL, 'd'},
> +			{"duration",		required_argument,	NULL, 'D'},
> +			{"fork",		optional_argument,	NULL, 'f'},
> +			{"help",		no_argument,		NULL, 'h'},
> +			{"interval",		required_argument,	NULL, 'i'},
> +			{"loops",		required_argument,	NULL, 'l'},
> +			{"priority",		required_argument,	NULL, 'p'},
> +			{"threads",		optional_argument,	NULL, 't'},
>  			{NULL, 0, NULL, 0}
>  		};
> -		int c = getopt_long (argc, argv, "a::b:d:f::i:l:D:p:t::",
> +		int c = getopt_long (argc, argv, "a::b:d:D:f::hi:l:p:t::",
>  			long_options, &option_index);
>  		if (c == -1)
>  			break;
> @@ -280,6 +282,7 @@ static void process_options (int argc, char *argv[])
>  			break;
>  		case 'b': thistracelimit = atoi(optarg); break;
>  		case 'd': distance = atoi(optarg); break;
> +		case 'D': duration = parse_time_string(optarg); break;
>  		case 'f':
>  			if (optarg != NULL) {
>  				wasforked = 1;
> @@ -291,9 +294,12 @@ static void process_options (int argc, char *argv[])
>  			} else
>  				mustfork = 1;
>  			break;
> +		case '?':
> +		case 'h':
> +			display_help(0);
> +			break;
>  		case 'i': interval = atoi(optarg); break;
>  		case 'l': max_cycles = atoi(optarg); break;
> -		case 'D': duration = parse_time_string(optarg); break;
>  		case 'p': priority = atoi(optarg); break;
>  		case 't':
>  			if (optarg != NULL)
> @@ -303,7 +309,9 @@ static void process_options (int argc, char *argv[])
>  			else
>  				num_threads = max_cpus;
>  			break;
> -		case '?': error = 1; break;
> +		default:
> +			display_help(1);
> +			break;
>  		}
>  	}
>  
> @@ -331,7 +339,7 @@ static void process_options (int argc, char *argv[])
>  		tracelimit = thistracelimit;
>  	}
>  	if (error)
> -		display_help ();
> +		display_help (error);
>  }
>  
>  
> -- 
> 2.28.0
> 
> 
Signed-off-by: John Kacur <jkacur@redhat.com>
diff mbox series

Patch

diff --git a/src/sigwaittest/sigwaittest.8 b/src/sigwaittest/sigwaittest.8
index 2be9c03d05ca..a2dc1bc080a3 100644
--- a/src/sigwaittest/sigwaittest.8
+++ b/src/sigwaittest/sigwaittest.8
@@ -4,7 +4,7 @@ 
 \fBsigwaittest\fR \- Start two threads or fork two processes and measure the latency between sending and receiving a signal
 .SH "SYNTAX"
 .LP
-sigwaittest [-a|-a PROC] [-b USEC] [-d DIST] [-f] [-i INTV] [-l loops] [-p PRIO] [-t|-t NUM]
+sigwaittest [-a|--affinity PROC] [-b|--breaktrace USEC] [-d|--distance DIST] [-D|--duration TIME] [-f|--fork [OPT]] [-i|--interval INTV] [-l|--loops LOOPS] [-p|--prio PRIO] [-t|--threads [NUM]]
 .br
 .SH "DESCRIPTION"
 .LP
@@ -26,7 +26,7 @@  Specify a length for the test run.
 .br
 Append 'm', 'h', or 'd' to specify minutes, hours or days.
 .TP
-.B \-f, \-\-fork
+.B \-f, \-\-fork[=OPT]
 Instead of creating threads (which is the default), fork new processes
 .TP
 .B \-i, \-\-interval=INTV
diff --git a/src/sigwaittest/sigwaittest.c b/src/sigwaittest/sigwaittest.c
index e7393f791519..12b55e901ce5 100644
--- a/src/sigwaittest/sigwaittest.c
+++ b/src/sigwaittest/sigwaittest.c
@@ -206,28 +206,30 @@  void *semathread(void *param)
 }
 
 
-static void display_help(void)
+static void display_help(int error)
 {
 	printf("sigwaittest V %1.2f\n", VERSION);
-	puts("Usage: sigwaittest <options>");
-	puts("Function: test sigwait() latency");
-	puts(
-	"Options:\n"
-	"-a [NUM] --affinity        run thread #N on processor #N, if possible\n"
-	"                           with NUM pin all threads to the processor NUM\n"
-	"-b USEC  --breaktrace=USEC send break trace command when latency > USEC\n"
-	"-d DIST  --distance=DIST   distance of thread intervals in us default=500\n"
-	"-f       --fork            fork new processes instead of creating threads\n"
-	"-i INTV  --interval=INTV   base interval of thread in us default=1000\n"
-	"-l LOOPS --loops=LOOPS     number of loops: default=0(endless)\n"
-	"-D       --duration=TIME   specify a length for the test run.\n"
-	"                           Append 'm', 'h', or 'd' to specify minutes, hours or days.\n"
-	"-p PRIO  --prio=PRIO       priority\n"
-	"-t       --threads         one thread per available processor\n"
-	"-t [NUM] --threads=NUM     number of threads:\n"
-	"                           without NUM, threads = max_cpus\n"
-	"                           without -t default = 1\n");
-	exit(1);
+	printf("Usage:\n"
+	       "sigwaittest <options>\n\n"
+	       "Function: test sigwait() latency\n\n"
+	       "Available options:\n"
+	       "-a [NUM] --affinity        run thread #N on processor #N, if possible\n"
+	       "                           with NUM pin all threads to the processor NUM\n"
+	       "-b USEC  --breaktrace=USEC send break trace command when latency > USEC\n"
+	       "-d DIST  --distance=DIST   distance of thread intervals in us default=500\n"
+	       "-D       --duration=TIME   specify a length for the test run.\n"
+	       "                           Append 'm', 'h', or 'd' to specify minutes, hours or\n"
+	       "                           days.\n"
+	       "-f [OPT] --fork[=OPT]      fork new processes instead of creating threads\n"
+	       "-i INTV  --interval=INTV   base interval of thread in us default=1000\n"
+	       "-l LOOPS --loops=LOOPS     number of loops: default=0(endless)\n"
+	       "-p PRIO  --prio=PRIO       priority\n"
+	       "-t       --threads         one thread per available processor\n"
+	       "-t [NUM] --threads=NUM     number of threads:\n"
+	       "                           without NUM, threads = max_cpus\n"
+	       "                           without -t default = 1\n"
+	       );
+	exit(error);
 }
 
 
@@ -250,19 +252,19 @@  static void process_options (int argc, char *argv[])
 		int option_index = 0;
 		/** Options for getopt */
 		static struct option long_options[] = {
-			{"affinity", optional_argument, NULL, 'a'},
-			{"breaktrace", required_argument, NULL, 'b'},
-			{"distance", required_argument, NULL, 'd'},
-			{"fork", optional_argument, NULL, 'f'},
-			{"interval", required_argument, NULL, 'i'},
-			{"loops", required_argument, NULL, 'l'},
-			{"duration", required_argument, NULL, 'D'},
-			{"priority", required_argument, NULL, 'p'},
-			{"threads", optional_argument, NULL, 't'},
-			{"help", no_argument, NULL, '?'},
+			{"affinity",		optional_argument,	NULL, 'a'},
+			{"breaktrace",		required_argument,	NULL, 'b'},
+			{"distance",		required_argument,	NULL, 'd'},
+			{"duration",		required_argument,	NULL, 'D'},
+			{"fork",		optional_argument,	NULL, 'f'},
+			{"help",		no_argument,		NULL, 'h'},
+			{"interval",		required_argument,	NULL, 'i'},
+			{"loops",		required_argument,	NULL, 'l'},
+			{"priority",		required_argument,	NULL, 'p'},
+			{"threads",		optional_argument,	NULL, 't'},
 			{NULL, 0, NULL, 0}
 		};
-		int c = getopt_long (argc, argv, "a::b:d:f::i:l:D:p:t::",
+		int c = getopt_long (argc, argv, "a::b:d:D:f::hi:l:p:t::",
 			long_options, &option_index);
 		if (c == -1)
 			break;
@@ -280,6 +282,7 @@  static void process_options (int argc, char *argv[])
 			break;
 		case 'b': thistracelimit = atoi(optarg); break;
 		case 'd': distance = atoi(optarg); break;
+		case 'D': duration = parse_time_string(optarg); break;
 		case 'f':
 			if (optarg != NULL) {
 				wasforked = 1;
@@ -291,9 +294,12 @@  static void process_options (int argc, char *argv[])
 			} else
 				mustfork = 1;
 			break;
+		case '?':
+		case 'h':
+			display_help(0);
+			break;
 		case 'i': interval = atoi(optarg); break;
 		case 'l': max_cycles = atoi(optarg); break;
-		case 'D': duration = parse_time_string(optarg); break;
 		case 'p': priority = atoi(optarg); break;
 		case 't':
 			if (optarg != NULL)
@@ -303,7 +309,9 @@  static void process_options (int argc, char *argv[])
 			else
 				num_threads = max_cpus;
 			break;
-		case '?': error = 1; break;
+		default:
+			display_help(1);
+			break;
 		}
 	}
 
@@ -331,7 +339,7 @@  static void process_options (int argc, char *argv[])
 		tracelimit = thistracelimit;
 	}
 	if (error)
-		display_help ();
+		display_help (error);
 }