From: Emden Gansner Date: Thu, 7 Jun 2012 21:23:51 +0000 (-0400) Subject: Add verbose mode and timing to gvpr X-Git-Tag: LAST_LIBGRAPH~32^2~403 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7f61c34f47d23444956053843133f3feaa8ddff9;p=graphviz Add verbose mode and timing to gvpr --- diff --git a/lib/gvpr/actions.c b/lib/gvpr/actions.c index 22c439048..87649253d 100644 --- a/lib/gvpr/actions.c +++ b/lib/gvpr/actions.c @@ -1335,3 +1335,46 @@ char *colorx (Expr_t* ex, char* incolor, char* fmt, Sfio_t* fp) return exstring(ex, sfstruse(fp)); } +#ifndef WIN32 + +#include +#include +#include +#include + + + +#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 + +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; +} + diff --git a/lib/gvpr/actions.h b/lib/gvpr/actions.h index aa95da2df..514a64a4c 100644 --- a/lib/gvpr/actions.h +++ b/lib/gvpr/actions.h @@ -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 diff --git a/lib/gvpr/gvpr.c b/lib/gvpr/gvpr.c index eb6b32545..f523dc89f 100644 --- a/lib/gvpr/gvpr.c +++ b/lib/gvpr/gvpr.c @@ -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()); } }