]> granicus.if.org Git - graphviz/commitdiff
Add verbose mode and timing to gvpr
authorEmden Gansner <erg@research.att.com>
Thu, 7 Jun 2012 21:23:51 +0000 (17:23 -0400)
committerEmden Gansner <erg@research.att.com>
Thu, 7 Jun 2012 21:23:51 +0000 (17:23 -0400)
lib/gvpr/actions.c
lib/gvpr/actions.h
lib/gvpr/gvpr.c

index 22c439048dfe42c9f2440cc49c7b5bbcd0c87224..87649253d30083db1fe156d0024b88a925421f78 100644 (file)
@@ -1335,3 +1335,46 @@ char *colorx (Expr_t* ex, char* incolor, char* fmt, Sfio_t* fp)
     return exstring(ex, sfstruse(fp));
 }
 
+#ifndef WIN32
+
+#include        <unistd.h>
+#include        <sys/types.h>
+#include        <sys/times.h>
+#include        <sys/param.h>
+
+
+
+#ifndef HZ
+#define HZ 60
+#endif
+typedef struct tms mytime_t;
+#define GET_TIME(S) times(&(S))
+#define DIFF_IN_SECS(S,T) ((S.tms_utime + S.tms_stime - T.tms_utime - T.tms_stime)/(double)HZ)
+
+#else
+
+#include        <time.h>
+
+typedef clock_t mytime_t;
+#define GET_TIME(S) S = clock()
+#define DIFF_IN_SECS(S,T) ((S - T) / (double)CLOCKS_PER_SEC)
+
+#endif
+
+static mytime_t T;
+
+void gvstart_timer(void)
+{
+    GET_TIME(T);
+}
+
+double gvelapsed_sec(void)
+{
+    mytime_t S;
+    double rv;
+
+    GET_TIME(S);
+    rv = DIFF_IN_SECS(S, T);
+    return rv;
+}
+
index aa95da2df89cf2d6e6814e09ef728f9689e77525..514a64a4cbe15eeb27e800b96a921704ba838805 100644 (file)
@@ -50,6 +50,8 @@ extern "C" {
     extern char *toUpper(Expr_t * pgm, char *, Sfio_t*);
     extern int deleteObj(Agraph_t * g, Agobj_t * obj);
     extern char *colorx (Expr_t* ex, char* incolor, char* fmt, Sfio_t* fp);
+    extern void gvstart_timer(void);
+    extern double gvelapsed_sec(void);
 
 #endif
 
index eb6b325456e3dc1d1b0577797c8e8d02fc4a3d60..f523dc89ffb830c0baa383501562ec7a929b809b 100644 (file)
@@ -80,6 +80,7 @@ typedef struct {
     int argc;
     char **argv;
     int state;                  /* > 0 : continue; <= 0 finish */
+    int verbose;
 } options;
 
 static Sfio_t *openOut(char *name)
@@ -351,6 +352,9 @@ doFlags(char* arg, int argi, int argc, char** argv, options* opts)
        case 'q':
            setTraceLevel (ERROR_ERROR);  /* Don't emit warning messages */
            break;
+       case 'v':
+           opts->verbose = 1;
+           break;
        case 'V':
            sfprintf(sfstderr, "%s version %s (%s)\n",
                    Info[0], Info[1], Info[2]);
@@ -400,6 +404,7 @@ static options* scanArgs(int argc, char **argv, gvpropts* uopts)
     opts->state = 1;
     opts->readAhead = 1;
     setErrorId (opts->cmdName);
+    opts->verbose = 0;
 
     /* estimate number of file names */
     nfiles = 0;
@@ -955,6 +960,8 @@ int gvpr (int argc, char *argv[], gvpropts * uopts)
        goto finish;
     }
 
+    if (opts->verbose)
+       gvstart_timer ();
     prog = parseProg(opts->program, opts->useFile);
     if (!prog) {
        rv = 1;
@@ -1004,6 +1011,8 @@ int gvpr (int argc, char *argv[], gvpropts * uopts)
     else
        incoreGraphs = 0;
 
+    if (opts->verbose)
+       sfprintf (sfstderr, "Parse/compile/init: %.2f secs.\n", gvelapsed_sec());
     /* do begin */
     if (xprog->begin_stmt)
        exeval(xprog->prog, xprog->begin_stmt, state);
@@ -1015,7 +1024,9 @@ int gvpr (int argc, char *argv[], gvpropts * uopts)
        else
            ing = newIng(0, opts->inFiles, &ingDisc);
        
+       if (opts->verbose) gvstart_timer ();
        for (state->curgraph = nextGraph(ing); state->curgraph; state->curgraph = nextg) {
+           if (opts->verbose) sfprintf (sfstderr, "Read graph: %.2f secs.\n", gvelapsed_sec());
            state->infname = fileName(ing);
            if (opts->readAhead)
                nextg = state->nextgraph = nextGraph(ing);
@@ -1043,6 +1054,7 @@ int gvpr (int argc, char *argv[], gvpropts * uopts)
            state->curobj = (Agobj_t *) state->curgraph;
            if (xprog->endg_stmt)
                exeval(xprog->prog, xprog->endg_stmt, state);
+           if (opts->verbose) sfprintf (sfstderr, "Finish graph: %.2f secs.\n", gvelapsed_sec());
 
            /* if $O == $G and $T is empty, delete $T */
            if ((state->outgraph == state->curgraph) &&
@@ -1066,8 +1078,10 @@ int gvpr (int argc, char *argv[], gvpropts * uopts)
            state->target = 0;
            state->outgraph = 0;
        
+           if (opts->verbose) gvstart_timer ();
            if (!opts->readAhead)
                nextg = nextGraph(ing);
+           if (opts->verbose && nextg) sfprintf (sfstderr, "Read graph: %.2f secs.\n", gvelapsed_sec());
        }
     }