Re: [rt-tests v2 12/18] queuelat: Streamline usage and man page

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On Wed, 7 Oct 2020, Daniel Wagner wrote:

> Signed-off-by: Daniel Wagner <dwagner@xxxxxxx>
> ---
>  src/queuelat/queuelat.8 | 41 +++++++----------
>  src/queuelat/queuelat.c | 99 +++++++++++++++++++----------------------
>  2 files changed, 62 insertions(+), 78 deletions(-)
> 
> diff --git a/src/queuelat/queuelat.8 b/src/queuelat/queuelat.8
> index f67a0bb7556e..2f99e703c990 100644
> --- a/src/queuelat/queuelat.8
> +++ b/src/queuelat/queuelat.8
> @@ -15,9 +15,8 @@
>  .SH NAME
>  queuelat \- Queue latency test program
>  .SH SYNOPSIS
> -.B queuelat
> -.RI "[\-h] [\-m " max-queue-len "] [\-c " cycles-per-packet "] [\-p " mpps "] [\-f " tsc-freq "] [\-t " timeout "] \
> -
> +.LP
> +queuelat [-c|--cycles N] [-f|--freq F] [-h|--help] [-m|--max-len LEN] [-p|--packets F] [-q|--queue-len N] [-t|--timeout TIME]
>  .SH DESCRIPTION
>  queuelat simulates a network queue checking for latency
>  violations in packet processing.
> @@ -25,36 +24,26 @@ violations in packet processing.
>  .SH OPTIONS
>  A summary of options is included below.
>  .TP
> -.B \-h
> -Show help
> -.br
> +.B \-c, \-\-cycles=N
> +Estimated number of cycles it takes to process one packet. This value should come from the envisioned packet forwarding application being simulated.
>  .TP
> -.B \-m max-queue-len
> -Maximum allowed latency, in nanoseconds. If latency to process
> -.br
> -any packet exceeds this value, the program quits,
> -writing
> -.br
> -a message to the trace buffer.
> +.B \-f, \-\-freq=F
> +TSC frequency in MHz.
>  .TP
> -.B \-c cycles-per-packet
> -Estimated number of cycles it takes to process one packet.
> -.br
> -This value should come from the envisioned packet
> -.br
> -forwarding application being simulated.
> +.B \-h, \-\-help
> +Show help
>  .TP
> -.B \-p mpps
> +.B \-m, \-\-max-len=N
> +Maximum allowed latency, in nanoseconds. If latency to process any packet exceeds this value, the program quits, writing a message to the trace buffer.
> +.TP
> +.B \-p, \-\-packets=F
>  Million packets per second that arrive for processing.
>  .TP
> -.B \-f tsc-freq-mhz
> -TSC frequency in MHz.
> +.B \-q, \-\-queue-len=N
> +Minimum queue length to print in the trace
>  .TP
> -.B \-t timeout
> +.B \-t, \-\-timeout=TIME
>  Timeout in seconds to quit the program.
> -.TP
> -.B \-q min_queue_len_to_print_trace
> -Minimum queue length to print in the trace
>  
>  .SH AUTHOR
>  queuelat was written by Marcelo Tosatti <mtosatti@xxxxxxxxxx>
> diff --git a/src/queuelat/queuelat.c b/src/queuelat/queuelat.c
> index 2b9118d8a8a5..661e48db88ac 100644
> --- a/src/queuelat/queuelat.c
> +++ b/src/queuelat/queuelat.c
> @@ -16,6 +16,7 @@
>  #include <unistd.h>
>  #include <signal.h>
>  #include <time.h>
> +#include <getopt.h>
>  
>  #include "rt-utils.h"
>  
> @@ -560,17 +561,20 @@ int calculate_nr_packets_drain_per_block(void)
>  	return nr_packets_drain_per_block;
>  }
>  
> -
> -void print_help(void)
> +static void print_help(int error)
>  {
> -	printf("usage: queuelat [options]\n");
> -	printf("-h show this help menu\n");
> -	printf("-m max-queue-len (maximum latency allowed, in nanoseconds) (int)\n");
> -	printf("-c cycles-per-packet (number of cycles to process one packet (int)\n");
> -	printf("-p million-packet-per-sec (million packets per second) (float)\n");
> -	printf("-f tsc-freq-mhz (TSC frequency in MHz) (float)\n");
> -	printf("-t timeout (timeout, in seconds) (int)\n");
> -	printf("-q min_queue_len_to_print_trace (int)\n");
> +	printf("queuelat V %1.2f\n", VERSION);
> +	printf("Usage:\n"
> +	       "queuelat <options>\n\n"
> +	       "-c N     --cycles N        number of cycles to process one packet (int)\n"
> +	       "-f F     --freq F          TSC frequency in MHz (float)\n"
> +	       "-h       --help            show this help menu\n"
> +	       "-m LEN   --max-len LEN     maximum latency allowed, in nanoseconds (int)\n"
> +	       "-p F     --packets F       million packets per second (float)\n"
> +	       "-q N     --queue-len N     minimum queue len to print trace (int)\n"
> +	       "-t TIME  --timeout TIME    timeout, in seconds (int)\n"
> +	       );
> +	exit(error);
>  }
>  
>  int main(int argc, char **argv)
> @@ -584,61 +588,59 @@ int main(int argc, char **argv)
>  	char *tvalue = NULL;
>  	char *qvalue = NULL;
>  	int index;
> -	int c;
> -
> -	install_signals();
>  
>  	opterr = 0;
>  
> -	while ((c = getopt (argc, argv, "m:c:p:f:t:q:h")) != -1)
> -		switch (c)
> -		{
> -		case 'm':
> -			mvalue = optarg;
> +	for (;;) {
> +		static struct option options[] = {
> +			{"cycles",	required_argument,	NULL, 'c'},
> +			{"freq",	required_argument,	NULL, 'f'},
> +			{"help",	no_argument,		NULL, 'h'},
> +			{"max-len",	required_argument,	NULL, 'm'},
> +			{"packets",	required_argument,	NULL, 'p'},
> +			{"queue-len",	required_argument,	NULL, 'q'},
> +			{"timeout",	required_argument,	NULL, 't'},
> +			{NULL, 0, NULL, 0}
> +		};
> +		int c = getopt_long(argc, argv, "c:f:hm:p:q:t:", options, NULL);
> +		if (c == -1)
>  			break;
> +		switch (c) {
>  		case 'c':
>  			cvalue = optarg;
>  			break;
> -		case 'p':
> -			pvalue = optarg;
> -			break;
>  		case 'f':
>  			fvalue = optarg;
>  			break;
> -		case 't':
> -			tvalue = optarg;
> +		case '?':
> +		case 'h':
> +			print_help(0);
> +			break;
> +		case 'm':
> +			mvalue = optarg;
> +			break;
> +		case 'p':
> +			pvalue = optarg;
>  			break;
>  		case 'q':
>  			qvalue = optarg;
>  			break;
> -		case 'h':
> -			print_help();
> -			return 0;
> -		case '?':
> -			if (optopt == 'm' || optopt == 'c' || optopt == 'p' ||
> -			    optopt == 'f' || optopt == 't' || optopt == 'q') {
> -				printf ("Option -%c requires an argument.\n", optopt);
> -			} else if (isprint (optopt)) {
> -				printf ("Unknown option `-%c'.\n", optopt);
> -				print_help();
> -				return 1;
> -			} else {
> -				printf ( "Unknown option character `\\x%x'.\n", optopt);
> -				print_help();
> -				return 1;
> -			}
> +		case 't':
> +			tvalue = optarg;
>  			break;
>  		default:
> -			abort ();
> +			print_help(1);
> +			break;
>  		}
> +	}
>  
> -	if (mvalue == NULL || cvalue == NULL || pvalue == NULL ||
> -	    fvalue == NULL) {
> -		printf("options -m, -c, -p and -f are required.\n");
> -		printf("usage: %s -m maxlatency -c cycles_per_packet -p mpps(million-packet-per-sec) -f tsc_freq_mhz [-t timeout (in secs)] [-q min_queue_len_to_print_trace]\n", argv[0]);
> -		return 1;
> +	if (mvalue == NULL || cvalue == NULL || pvalue == NULL || fvalue == NULL) {
> +		printf("options -m, -c, -p and -f are required\n");
> +		exit(1);
>  	}
>  
> +	install_signals();
> +
>  	maxlatency = atoi(mvalue);
>          cycles_per_packet = atoi(cvalue);
>          mpps = atof(pvalue);
> @@ -654,13 +656,6 @@ int main(int argc, char **argv)
>  		min_queue_size_to_print = atoi(qvalue);
>  	}
>  
> -	if (optind != argc) {
> -		for (index = optind; index < argc; index++) {
> -			printf ("Error, non-option argument %s\n", argv[index]);
> -		}
> -		return 1;
> -	}
> -
>  	convert_to_ghz(tsc_freq_mhz);
>  
>  	max_queue_len_f = maxlatency / (cycles_per_packet*cycles_to_ns);
> -- 
> 2.28.0
> 
> 
Signed-off-by: John Kacur <jkacur@xxxxxxxxxx>



[Index of Archives]     [RT Stable]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux