Add quiet mode
authorteodor <teodor>
Thu, 26 Oct 2006 16:24:27 +0000 (16:24 +0000)
committerteodor <teodor>
Thu, 26 Oct 2006 16:24:27 +0000 (16:24 +0000)
ftsbench.c

index da6a4b0..86d9b14 100644 (file)
@@ -75,7 +75,7 @@ usage() {
        fputs(
                "ftsbench - full text search benchmark ofr RDBMS\n"
                "Initialization of DB:\n"
-               "\tftsbench -i [-b RDBMS] [-n NUMROW] [-l LEXFILE] [-g GAMMAFILE] [-f FLAGS] -d DBNAME\n"
+               "\tftsbench -i [-b RDBMS] [-n NUMROW] [-l LEXFILE] [-g GAMMAFILE] [-f FLAGS] [-q] -d DBNAME\n"
                "FLAGS are comma-separate list of:\n"
                "       gin  - use GIN index\n"
                "       gist - use GiST index\n"
@@ -84,7 +84,7 @@ usage() {
        );
        fputs(
                "Run tests:\n"
-               "\tftsbench [-b RDBMS] [-c NCLIENTS] [-n NUMQUERY] [-l LEXFILE] [-g GAMMAFILE] [-f FLAGS] -d DBNAME\n"
+               "\tftsbench [-b RDBMS] [-c NCLIENTS] [-n NUMQUERY] [-l LEXFILE] [-g GAMMAFILE] [-f FLAGS] [-q] -d DBNAME\n"
                "FLAGS are comma-separate list of:\n"
                "       and  - AND'ing lexemes in query (default)\n"
                "       or   - OR'ing lexemes in query\n"
@@ -231,9 +231,10 @@ main(int argn, char *argv[]) {
        RDBMS   rdbms = NULLSQL;
        int             flags = 0;
        int i;
+       int             quiet = 0;
        StringBuf       b = {NULL,0,0};
 
-       while((i=getopt(argn,argv,"ib:n:l:g:d:c:hf:")) != EOF) {
+       while((i=getopt(argn,argv,"ib:n:l:g:d:c:hf:q")) != EOF) {
                switch(i) {
                        case 'i': initMode = 1; break;
                        case 'b': rdbms = getRDBMS(optarg); break;
@@ -243,6 +244,7 @@ main(int argn, char *argv[]) {
                        case 'g': doc = strdup(optarg); break;
                        case 'd': dbname = strdup(optarg); break;
                        case 'f': flags = getFLAGS(optarg); break;
+                       case 'q': quiet = 1; break;
                        case 'h':
                        default:
                                usage();
@@ -270,13 +272,14 @@ main(int argn, char *argv[]) {
                for(i=0;i<n;i++) {
                        generate_doc(&b);
                        db->InsertRow(db, i+1, b.str);
-                       if ( prev!=time(NULL) ) {
+                       if ( !quiet && prev!=time(NULL) ) {
                                printf("\r%d(%.02f%%) rows inserted", i, (100.0*i)/n);
                                fflush(stdout);
                                prev = time(NULL);
                        }
                }
-               printf("\r%d(100.00%%) rows inserted. Finalyze insertion... ", i);
+               printf("%s%d(100.00%%) rows inserted. Finalyze insertion... ", 
+                       (quiet) ? "" : "\r", i);
                fflush(stdout);
                db->finishCreateScheme(db);
                printf("done\n");
@@ -299,8 +302,10 @@ main(int argn, char *argv[]) {
                /*
                 * Initial query
                 */
-               printf("\r0(0.00%%) queries proceed");
-               fflush(stdout);
+               if ( !quiet ) {
+                       printf("\r0(0.00%%) queries proceed");
+                       fflush(stdout);
+               }
                benchFlags = flags;
                benchCount = n;
 
@@ -314,9 +319,6 @@ main(int argn, char *argv[]) {
                        }
                }
 
-               printf("\r%d(%.02f%%) queries proceed", 0, 0.0);
-               fflush(stdout);
-
                for(;;) {
                        int res, ntogo = 0;
 
@@ -332,8 +334,10 @@ main(int argn, char *argv[]) {
                        if ( ntogo == 0 ) 
                                break;
 
-                       printf("\r%d(%.02f%%) queries proceed", total, (100.0*(float)total)/(nclients * n));
-                       fflush(stdout);
+                       if ( !quiet ) {
+                               printf("\r%d(%.02f%%) queries proceed", total, (100.0*(float)total)/(nclients * n));
+                               fflush(stdout);
+                       }
                        
                        sleepTo.tv_sec = time(NULL) + 1;
                        res = pthread_cond_timedwait( &condFinish, &mutexFinish, &sleepTo );
@@ -351,7 +355,8 @@ main(int argn, char *argv[]) {
                        dbs[i]->Close(dbs[i]);
                }
 
-               printf("\r%d(%.02f%%) queries proceed\n", total, (100.0*(float)total)/(nclients * n));
+               printf("%s%d(%.02f%%) queries proceed\n", 
+                       (quiet) ? "" : "\r", total, (100.0*(float)total)/(nclients * n));
                printf("Total time: %.02f sec, Queries per second: %.02f\n", elapsed, total/elapsed);
                fflush(stdout);
        }