--- ray/src/util/rtcontrib.c 2005/09/13 22:58:22 1.25 +++ ray/src/util/rtcontrib.c 2005/10/05 05:20:21 1.29 @@ -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.29 2005/10/05 05:20:21 greg Exp $"; #endif /* * Gather rtrace output to compute contributions from particular sources @@ -112,6 +112,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 +130,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 +344,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; @@ -713,7 +730,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 +929,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 +970,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 +1124,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");