Message ID | 20201118190642.16006-5-dwagner@suse.de |
---|---|
State | New |
Headers | show |
Series | Add quiet command line option | expand |
On Wed, 18 Nov 2020, Daniel Wagner wrote: > 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/pmqtest/pmqtest.c | 64 ++++++++++++++++++------------------------- > 1 file changed, 26 insertions(+), 38 deletions(-) > > diff --git a/src/pmqtest/pmqtest.c b/src/pmqtest/pmqtest.c > index a1e487b85d2c..b0a2cbede4a0 100644 > --- a/src/pmqtest/pmqtest.c > +++ b/src/pmqtest/pmqtest.c > @@ -64,7 +64,6 @@ struct params { > char recvsyncmsg[MSG_SIZE]; > char recvtestmsg[MSG_SIZE]; > struct params *neighbor; > - char error[MAX_PATH * 2]; > }; > > void *pmqthread(void *param) > @@ -192,9 +191,7 @@ void *pmqthread(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; > } > @@ -376,6 +373,27 @@ 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, TO %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, > + receiver[i].timeoutcount, 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; > @@ -385,8 +403,6 @@ int main(int argc, char *argv[]) > sigset_t sigset; > int oldsamples = INT_MAX; > int oldtimeoutcount = INT_MAX; > - int first = 1; > - int errorlines = 0; > struct timespec maindelay; > int oflag = O_CREAT|O_RDWR; > struct mq_attr mqstat; > @@ -489,38 +505,8 @@ int main(int argc, char *argv[]) > > if (minsamples > 1 && (shutdown || newsamples > oldsamples || > newtimeoutcount > oldtimeoutcount)) { > - > - if (!first) > - printf("\033[%dA", num_threads*2 + errorlines); > - first = 0; > - > - for (i = 0; i < num_threads; i++) { > - printf("#%1d: ID%d, P%d, CPU%d, I%ld; #%1d: ID%d, P%d, CPU%d, TO %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, > - receiver[i].timeoutcount, 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'; > - } > - } > - } else { > - if (minsamples < 1) > - printf("Collecting ...\n\033[1A"); > + print_stat(stdout, receiver, sender, 0, 0); > + printf("\033[%dA", num_threads*2); > } > > fflush(NULL); > @@ -539,6 +525,8 @@ int main(int argc, char *argv[]) > > } while (!shutdown); > > + printf("\033[%dB", num_threads*2 + 2); > + > for (i = 0; i < num_threads; i++) { > receiver[i].shutdown = 1; > sender[i].shutdown = 1; > -- > 2.29.2 > > Signed-off-by: John Kacur <jkacur@redhat.com>
diff --git a/src/pmqtest/pmqtest.c b/src/pmqtest/pmqtest.c index a1e487b85d2c..b0a2cbede4a0 100644 --- a/src/pmqtest/pmqtest.c +++ b/src/pmqtest/pmqtest.c @@ -64,7 +64,6 @@ struct params { char recvsyncmsg[MSG_SIZE]; char recvtestmsg[MSG_SIZE]; struct params *neighbor; - char error[MAX_PATH * 2]; }; void *pmqthread(void *param) @@ -192,9 +191,7 @@ void *pmqthread(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; } @@ -376,6 +373,27 @@ 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, TO %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, + receiver[i].timeoutcount, 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; @@ -385,8 +403,6 @@ int main(int argc, char *argv[]) sigset_t sigset; int oldsamples = INT_MAX; int oldtimeoutcount = INT_MAX; - int first = 1; - int errorlines = 0; struct timespec maindelay; int oflag = O_CREAT|O_RDWR; struct mq_attr mqstat; @@ -489,38 +505,8 @@ int main(int argc, char *argv[]) if (minsamples > 1 && (shutdown || newsamples > oldsamples || newtimeoutcount > oldtimeoutcount)) { - - if (!first) - printf("\033[%dA", num_threads*2 + errorlines); - first = 0; - - for (i = 0; i < num_threads; i++) { - printf("#%1d: ID%d, P%d, CPU%d, I%ld; #%1d: ID%d, P%d, CPU%d, TO %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, - receiver[i].timeoutcount, 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'; - } - } - } else { - if (minsamples < 1) - printf("Collecting ...\n\033[1A"); + print_stat(stdout, receiver, sender, 0, 0); + printf("\033[%dA", num_threads*2); } fflush(NULL); @@ -539,6 +525,8 @@ int main(int argc, char *argv[]) } while (!shutdown); + printf("\033[%dB", num_threads*2 + 2); + for (i = 0; i < num_threads; i++) { receiver[i].shutdown = 1; sender[i].shutdown = 1;
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/pmqtest/pmqtest.c | 64 ++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 38 deletions(-)