--- ray/src/util/rtcontrib.c 2005/06/16 19:37:26 1.23 +++ ray/src/util/rtcontrib.c 2005/10/05 19:44:17 1.30 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rtcontrib.c,v 1.23 2005/06/16 19:37:26 greg Exp $"; +static const char RCSid[] = "$Id: rtcontrib.c,v 1.30 2005/10/05 19:44:17 greg Exp $"; #endif /* * Gather rtrace output to compute contributions from particular sources @@ -57,6 +57,7 @@ LUTAB ofiletab = LU_SINIT(free,closefile); /* output f FILE *getofile(const char *ospec, const char *mname, int bn); int ofname(char *oname, const char *ospec, const char *mname, int bn); void printheader(FILE *fout, const char *info); +void printresolu(FILE *fout); /* * The rcont structure is used to manage i/o with a particular @@ -112,6 +113,8 @@ int using_stdout = 0; /* are we using stdout? */ const char *modname[MAXMODLIST]; /* ordered modifier name list */ int nmods = 0; /* number of modifiers */ +#define queue_length() (lastray - lastdone) + MODCONT *addmodifier(char *modn, char *outf, char *binv); void addmodfile(char *fname, char *outf, char *binv); @@ -128,6 +131,18 @@ void put_contrib(const DCOLOR cnt, FILE *fout); void add_contrib(const char *modn); void done_contrib(void); +/* return number of open rtrace processes */ +static int +nrtprocs(void) +{ + int nrtp = 0; + struct rtproc *rtp; + + for (rtp = &rt0; rtp != NULL; rtp = rtp->next) + nrtp += rtp->pd.running; + return(nrtp); +} + /* set input/output format */ static void setformat(const char *fmt) @@ -173,6 +188,13 @@ main(int argc, char *argv[]) char *binval = NULL; char fmt[8]; int i, j; + /* need at least one argument */ + if (argc < 2) { + fprintf(stderr, +"Usage: %s [-n nprocs][-r][-e expr][-f source][-o ospec][-b binv] {-m mod | -M file} [rtrace options] octree\n", + argv[0]); + exit(1); + } /* global program name */ gargv = argv; /* initialize calcomp routines */ @@ -315,20 +337,23 @@ main(int argc, char *argv[]) error(USER, "missing octree argument"); rtargv[rtargc++] = octree = argv[i]; rtargv[rtargc] = NULL; - /* start rtrace & compute contributions */ + /* start rtrace */ init(nprocs); if (recover) /* perform recovery if requested */ recover_output(stdin); - trace_contribs(stdin); + trace_contribs(stdin); /* compute contributions */ quit(0); } +#ifndef SIGALRM +#define SIGALRM SIGTERM +#endif /* kill persistent rtrace process */ static void killpersist(void) { FILE *fp = fopen(persistfn, "r"); - int pid; + RT_PID pid; if (fp == NULL) return; @@ -574,6 +599,12 @@ printheader(FILE *fout, const char *info) break; } fputc('\n', fout); +} + +/* write resolution string to given output stream */ +void +printresolu(FILE *fout) +{ if (xres > 0) { if (yres > 0) /* resolution string */ fprtresolu(xres, yres, fout); @@ -595,6 +626,7 @@ getofile(const char *ospec, const char *mname, int bn) SET_FILE_BINARY(stdout); if (header) printheader(stdout, NULL); + printresolu(stdout); } using_stdout = 1; return stdout; @@ -623,8 +655,10 @@ getofile(const char *ospec, const char *mname, int bn) if (header) { char info[512]; char *cp = info; - sprintf(cp, "MODIFIER=%s\n", mname); - while (*cp) ++cp; + if (ofl & OF_MODIFIER) { + sprintf(cp, "MODIFIER=%s\n", mname); + while (*cp) ++cp; + } if (ofl & OF_BIN) { sprintf(cp, "BIN=%d\n", bn); while (*cp) ++cp; @@ -632,6 +666,7 @@ getofile(const char *ospec, const char *mname, int bn) *cp = '\0'; printheader(fp, info); } + printresolu(fp); /* play catch-up */ for (i = 0; i < lastdone; i++) { static const DCOLOR nocontrib = BLKCOLOR; @@ -706,7 +741,7 @@ add_contrib(const char *modn) bn = (int)(evalue(mp->binv) + .5); if (bn <= 0) bn = 0; - else if (bn > mp->nbins) { /* new bin */ + else if (bn >= mp->nbins) { /* new bin */ mp = (MODCONT *)realloc(mp, sizeof(MODCONT) + bn*sizeof(DCOLOR)); if (mp == NULL) @@ -905,7 +940,7 @@ wait_rproc(void) if (rt->bsiz + BUFSIZ <= treebufsiz) rt->bsiz = treebufsiz; else - rt->bsiz = treebufsiz += BUFSIZ; + treebufsiz = rt->bsiz += BUFSIZ; rt->buf = (char *)realloc(rt->buf, rt->bsiz); } if (rt->buf == NULL) @@ -946,7 +981,8 @@ trace_contribs(FILE *fin) struct rtproc *rtp; /* loop over input */ while ((iblen = getinp(inpbuf, fin)) > 0) { - if (lastray+1 < lastray) { /* counter rollover? */ + if (lastray+1 < lastray || /* need reset? */ + queue_length() > 5*nrtprocs()) { while (wait_rproc() != NULL) process_queue(); lastdone = lastray = 0; @@ -1091,10 +1127,15 @@ recover_output(FILE *fin) error(WARNING, "no output files to recover"); return; } + if (raysleft && lastout >= raysleft) { + error(WARNING, "output appears to be complete"); + /* XXX should read & discard input? */ + quit(0); + } /* seek on all files */ nvals = lastout * outvsiz; lu_doall(&ofiletab, myseeko, &nvals); - /* discard input */ + /* skip repeated input */ for (nvals = 0; nvals < lastout; nvals++) if (getinp(oname, fin) <= 0) error(USER, "unexpected EOF on input");