Changeset: a4d2c4c827d3 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a4d2c4c827d3
Modified Files:
        clients/ChangeLog
        clients/mapiclient/mclient.1
        clients/mapiclient/mclient.c
Branch: default
Log Message:

mclient: allow specifying time formatting

This makes one of my collegues happy, or mad.  Depends on how she looks
at it.
Implemented a simple overrride for the human-biased time formatting used
by mclient.  Instead of adjusting the time format to the value being
printed, allow forcing a certain representation (one of the three that
the human-biased method choses).


diffs (117 lines):

diff --git a/clients/ChangeLog b/clients/ChangeLog
--- a/clients/ChangeLog
+++ b/clients/ChangeLog
@@ -1,3 +1,8 @@
 # ChangeLog file for clients
 # This file is updated with Maddlog
 
+* Thu Aug 18 2011 Fabian Groffen <[email protected]>
+- The time format of the timer output can now be controlled with an
+  optional argument to the -i option.  ms, s and m force the time to be
+  formatted as milliseconds, seconds or minutes + seconds respectively.
+
diff --git a/clients/mapiclient/mclient.1 b/clients/mapiclient/mclient.1
--- a/clients/mapiclient/mclient.1
+++ b/clients/mapiclient/mclient.1
@@ -123,13 +123,17 @@ platforms where these are supported.
 \fB\-\-port=\fP\fIportnr\fP (\fB\-p\fP \fIportnr\fP)
 Specify the portnumber of the server (default: 50000).
 .TP
-\fB\-\-interactive\fP (\fB\-i\fP)
+\fB\-\-interactive[=\fP\fItimermode\fP\fB]\fP 
(\fB\-i[\fP\fItimermode\fP\fB]\fP)
 After executing the queries from the
 .B \-\-statement
-option and any file specified on the command
+option (if given) and any file specified on the command
 line, read queries from standard input.  When this option is set, all
 files are read line by line, like if it were entered on mclient's
-console.
+console.  The optional \fItimermode\fP argument controls the
+format of the time reported for queries.  The default mode is
+\fBhuman\fP which adjusts the time precision to the measured value.  The
+modes \fBms\fP, \fBs\fP and \fBm\fP force millisecond, second and minute
++ second precision respectively.
 .TP
 \fB\-\-user\fP\fB=\fP\fIuser\fP (\fB\-u\fP \fIuser\fP)
 Specify the user to connect as.  If this flag is absent, the client will
diff --git a/clients/mapiclient/mclient.c b/clients/mapiclient/mclient.c
--- a/clients/mapiclient/mclient.c
+++ b/clients/mapiclient/mclient.c
@@ -288,6 +288,13 @@ timerHumanStop(void)
        th = gettime();
 }
 
+static enum itimers {
+       T_HUMAN = 0,
+       T_MILLIS,
+       T_SECS,
+       T_MINSECS
+} itimemode = T_HUMAN;
+
 static char htimbuf[32];
 static char *
 timerHuman(void)
@@ -296,17 +303,18 @@ timerHuman(void)
 
        assert(th >= t0);
 
-       if (t / 1000 < 950) {
+       if (itimemode == T_MILLIS || (itimemode == T_HUMAN && t / 1000 < 950)) {
                snprintf(htimbuf, 32, "%ld.%03ldms", (long) (t / 1000), (long) 
(t % 1000));
                return(htimbuf);
        }
        t /= 1000;
-       if (t / 1000 < 60) {
+       if (itimemode == T_SECS || (itimemode == T_HUMAN && t / 1000 < 60)) {
                snprintf(htimbuf, 32, "%ld.%lds", (long) (t / 1000),
                                (long) ((t % 1000) / 100));
                return(htimbuf);
        }
        t /= 1000;
+       /* itimemode == T_MINSECS || itimemode == T_HUMAN */
        snprintf(htimbuf, 32, "%ldm %lds", (long) (t / 60), (long) (t % 60));
        return(htimbuf);
 }
@@ -2416,7 +2424,7 @@ usage(const char *prog, int xit)
 #endif
        fprintf(stderr, " -f kind     | --format=kind      specify output 
format {csv,tab,raw,sql,xml}\n");
        fprintf(stderr, " -H          | --history          load/save cmdline 
history (default off)\n");
-       fprintf(stderr, " -i          | --interactive      read stdin after 
command line args\n");
+       fprintf(stderr, " -i          | --interactive[=tm] read stdin after 
command line args, use time formatting {ms,s,m}\n");
        fprintf(stderr, " -l language | --language=lang    {sql,mal}\n");
        fprintf(stderr, " -L logfile  | --log=logfile      save client/server 
interaction\n");
        fprintf(stderr, " -s stmt     | --statement=stmt   run single 
statement\n");
@@ -2473,7 +2481,7 @@ main(int argc, char **argv)
                {"help", 0, 0, '?'},
                {"history", 0, 0, 'H'},
                {"host", 1, 0, 'h'},
-               {"interactive", 0, 0, 'i'},
+               {"interactive", 2, 0, 'i'},
                {"language", 1, 0, 'l'},
                {"log", 1, 0, 'L'},
                {"null", 1, 0, 'n'},
@@ -2613,7 +2621,7 @@ main(int argc, char **argv)
 #ifdef HAVE_ICONV
                                "E:"
 #endif
-                               "f:h:iL:l:n:"
+                               "f:h:i::L:l:n:"
 #ifdef HAVE_POPEN
                                "|:"
 #endif
@@ -2675,6 +2683,15 @@ main(int argc, char **argv)
                        break;
                case 'i':
                        interactive = 1;
+                       if (optarg != NULL) {
+                               if (strcmp(optarg, "ms") == 0) {
+                                       itimemode = T_MILLIS;
+                               } else if (strcmp(optarg, "s") == 0) {
+                                       itimemode = T_SECS;
+                               } else if (strcmp(optarg, "m") == 0) {
+                                       itimemode = T_MINSECS;
+                               } /* else: fall back to default (human) */
+                       }
                        break;
                case 'h':
                        host = optarg;
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to