--- ray/src/util/rtcontrib.c 2005/09/13 22:58:22 1.25 +++ 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.25 2005/09/13 22:58:22 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) @@ -330,12 +345,15 @@ main(int argc, char *argv[]) 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; @@ -581,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); @@ -602,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; @@ -630,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; @@ -639,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; @@ -713,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) @@ -912,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) @@ -953,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; @@ -1106,7 +1135,7 @@ recover_output(FILE *fin) /* 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");