16 |
|
#include "lookup.h" |
17 |
|
#include "calcomp.h" |
18 |
|
|
19 |
+ |
#ifndef MAXMODLIST |
20 |
|
#define MAXMODLIST 1024 /* maximum modifiers we'll track */ |
21 |
+ |
#endif |
22 |
|
|
23 |
|
int treebufsiz = BUFSIZ; /* current tree buffer size */ |
24 |
|
|
74 |
|
}; /* rtrace process buffer */ |
75 |
|
|
76 |
|
/* rtrace command and defaults */ |
77 |
< |
char *rtargv[256] = { "rtrace", "-dj", ".5", "-dr", "3", |
77 |
> |
char *rtargv[256+2*MAXMODLIST] = { "rtrace", |
78 |
> |
"-dj", ".5", "-dr", "3", |
79 |
|
"-ab", "1", "-ad", "128", }; |
80 |
|
int rtargc = 9; |
81 |
|
/* overriding rtrace options */ |
112 |
|
const char *modname[MAXMODLIST]; /* ordered modifier name list */ |
113 |
|
int nmods = 0; /* number of modifiers */ |
114 |
|
|
115 |
+ |
#define queue_length() (lastray - lastdone) |
116 |
+ |
|
117 |
|
MODCONT *addmodifier(char *modn, char *outf, char *binv); |
118 |
+ |
void addmodfile(char *fname, char *outf, char *binv); |
119 |
|
|
120 |
|
void init(int np); |
121 |
|
int done_rprocs(struct rtproc *rtp); |
130 |
|
void add_contrib(const char *modn); |
131 |
|
void done_contrib(void); |
132 |
|
|
133 |
+ |
/* return number of open rtrace processes */ |
134 |
+ |
static int |
135 |
+ |
nrtprocs(void) |
136 |
+ |
{ |
137 |
+ |
int nrtp = 0; |
138 |
+ |
struct rtproc *rtp; |
139 |
+ |
|
140 |
+ |
for (rtp = &rt0; rtp != NULL; rtp = rtp->next) |
141 |
+ |
nrtp += rtp->pd.running; |
142 |
+ |
return(nrtp); |
143 |
+ |
} |
144 |
+ |
|
145 |
|
/* set input/output format */ |
146 |
|
static void |
147 |
|
setformat(const char *fmt) |
187 |
|
char *binval = NULL; |
188 |
|
char fmt[8]; |
189 |
|
int i, j; |
190 |
+ |
/* need at least one argument */ |
191 |
+ |
if (argc < 2) { |
192 |
+ |
fprintf(stderr, |
193 |
+ |
"Usage: %s [-n nprocs][-r][-e expr][-f source][-o ospec][-b binv] {-m mod | -M file} [rtrace options] octree\n", |
194 |
+ |
argv[0]); |
195 |
+ |
exit(1); |
196 |
+ |
} |
197 |
|
/* global program name */ |
198 |
|
gargv = argv; |
199 |
|
/* initialize calcomp routines */ |
217 |
|
recover++; |
218 |
|
continue; |
219 |
|
case 'n': /* number of processes */ |
220 |
< |
if (argv[i][2] || i >= argc-1) break; |
220 |
> |
if (argv[i][2] || i >= argc-2) break; |
221 |
|
nprocs = atoi(argv[++i]); |
222 |
|
if (nprocs <= 0) |
223 |
|
error(USER, "illegal number of processes"); |
242 |
|
case 'f': /* file or i/o format */ |
243 |
|
if (!argv[i][2]) { |
244 |
|
char *fpath; |
245 |
< |
if (i >= argc-1) break; |
245 |
> |
if (i >= argc-2) break; |
246 |
|
fpath = getpath(argv[++i], |
247 |
|
getrlibpath(), R_OK); |
248 |
|
if (fpath == NULL) { |
257 |
|
setformat(argv[i]+2); |
258 |
|
continue; |
259 |
|
case 'e': /* expression */ |
260 |
< |
if (argv[i][2] || i >= argc-1) break; |
260 |
> |
if (argv[i][2] || i >= argc-2) break; |
261 |
|
scompile(argv[++i], NULL, 0); |
262 |
|
continue; |
263 |
|
case 'o': /* output file spec. */ |
264 |
< |
if (argv[i][2] || i >= argc-1) break; |
264 |
> |
if (argv[i][2] || i >= argc-2) break; |
265 |
|
curout = argv[++i]; |
266 |
|
continue; |
267 |
|
case 'x': /* horiz. output resolution */ |
268 |
< |
if (argv[i][2] || i >= argc-1) break; |
268 |
> |
if (argv[i][2] || i >= argc-2) break; |
269 |
|
xres = atoi(argv[++i]); |
270 |
|
continue; |
271 |
|
case 'y': /* vert. output resolution */ |
272 |
< |
if (argv[i][2] || i >= argc-1) break; |
272 |
> |
if (argv[i][2] || i >= argc-2) break; |
273 |
|
yres = atoi(argv[++i]); |
274 |
|
continue; |
275 |
|
case 'b': /* bin expression */ |
276 |
< |
if (argv[i][2] || i >= argc-1) break; |
276 |
> |
if (argv[i][2] || i >= argc-2) break; |
277 |
|
binval = argv[++i]; |
278 |
|
continue; |
279 |
|
case 'm': /* modifier name */ |
280 |
< |
if (argv[i][2] || i >= argc-1) break; |
280 |
> |
if (argv[i][2] || i >= argc-2) break; |
281 |
|
rtargv[rtargc++] = "-ti"; |
282 |
|
rtargv[rtargc++] = argv[++i]; |
283 |
|
addmodifier(argv[i], curout, binval); |
284 |
|
continue; |
285 |
+ |
case 'M': /* modifier file */ |
286 |
+ |
if (argv[i][2] || i >= argc-2) break; |
287 |
+ |
rtargv[rtargc++] = "-tI"; |
288 |
+ |
rtargv[rtargc++] = argv[++i]; |
289 |
+ |
addmodfile(argv[i], curout, binval); |
290 |
+ |
continue; |
291 |
|
} |
292 |
|
rtargv[rtargc++] = argv[i]; /* assume rtrace option */ |
293 |
|
} |
336 |
|
error(USER, "missing octree argument"); |
337 |
|
rtargv[rtargc++] = octree = argv[i]; |
338 |
|
rtargv[rtargc] = NULL; |
339 |
< |
/* start rtrace & compute contributions */ |
339 |
> |
/* start rtrace */ |
340 |
|
init(nprocs); |
341 |
|
if (recover) /* perform recovery if requested */ |
342 |
|
recover_output(stdin); |
343 |
< |
trace_contribs(stdin); |
343 |
> |
trace_contribs(stdin); /* compute contributions */ |
344 |
|
quit(0); |
345 |
|
} |
346 |
|
|
347 |
+ |
#ifndef SIGALRM |
348 |
+ |
#define SIGALRM SIGTERM |
349 |
+ |
#endif |
350 |
|
/* kill persistent rtrace process */ |
351 |
|
static void |
352 |
|
killpersist(void) |
353 |
|
{ |
354 |
|
FILE *fp = fopen(persistfn, "r"); |
355 |
< |
int pid; |
355 |
> |
RT_PID pid; |
356 |
|
|
357 |
|
if (fp == NULL) |
358 |
|
return; |
486 |
|
return mp; |
487 |
|
} |
488 |
|
|
489 |
+ |
/* add modifiers from a file list */ |
490 |
+ |
void |
491 |
+ |
addmodfile(char *fname, char *outf, char *binv) |
492 |
+ |
{ |
493 |
+ |
char *mname[MAXMODLIST]; |
494 |
+ |
int i; |
495 |
+ |
/* find the file & store strings */ |
496 |
+ |
if (wordfile(mname, getpath(fname, getrlibpath(), R_OK)) < 0) { |
497 |
+ |
sprintf(errmsg, "cannot find modifier file '%s'", fname); |
498 |
+ |
error(SYSTEM, errmsg); |
499 |
+ |
} |
500 |
+ |
for (i = 0; mname[i]; i++) /* add each one */ |
501 |
+ |
addmodifier(mname[i], outf, binv); |
502 |
+ |
} |
503 |
+ |
|
504 |
|
/* put string to stderr */ |
505 |
|
void |
506 |
|
eputs(char *s) |
647 |
|
if (header) { |
648 |
|
char info[512]; |
649 |
|
char *cp = info; |
650 |
< |
if (ofl & OF_MODIFIER) { |
651 |
< |
sprintf(cp, "MODIFIER=%s\n", mname); |
603 |
< |
while (*cp) ++cp; |
604 |
< |
} |
650 |
> |
sprintf(cp, "MODIFIER=%s\n", mname); |
651 |
> |
while (*cp) ++cp; |
652 |
|
if (ofl & OF_BIN) { |
653 |
|
sprintf(cp, "BIN=%d\n", bn); |
654 |
|
while (*cp) ++cp; |
730 |
|
bn = (int)(evalue(mp->binv) + .5); |
731 |
|
if (bn <= 0) |
732 |
|
bn = 0; |
733 |
< |
else if (bn > mp->nbins) { /* new bin */ |
733 |
> |
else if (bn >= mp->nbins) { /* new bin */ |
734 |
|
mp = (MODCONT *)realloc(mp, sizeof(MODCONT) + |
735 |
|
bn*sizeof(DCOLOR)); |
736 |
|
if (mp == NULL) |
929 |
|
if (rt->bsiz + BUFSIZ <= treebufsiz) |
930 |
|
rt->bsiz = treebufsiz; |
931 |
|
else |
932 |
< |
rt->bsiz = treebufsiz += BUFSIZ; |
932 |
> |
treebufsiz = rt->bsiz += BUFSIZ; |
933 |
|
rt->buf = (char *)realloc(rt->buf, rt->bsiz); |
934 |
|
} |
935 |
|
if (rt->buf == NULL) |
970 |
|
struct rtproc *rtp; |
971 |
|
/* loop over input */ |
972 |
|
while ((iblen = getinp(inpbuf, fin)) > 0) { |
973 |
< |
if (lastray+1 < lastray) { /* counter rollover? */ |
973 |
> |
if (lastray+1 < lastray || /* need reset? */ |
974 |
> |
queue_length() > 5*nrtprocs()) { |
975 |
|
while (wait_rproc() != NULL) |
976 |
|
process_queue(); |
977 |
|
lastdone = lastray = 0; |
1055 |
|
error(USER, "cannot recover from command"); |
1056 |
|
/* open output */ |
1057 |
|
fp = fopen(oname, "rb+"); |
1058 |
< |
if (fp == NULL) |
1059 |
< |
break; /* must be end of modifier */ |
1058 |
> |
if (fp == NULL) { |
1059 |
> |
if (j) |
1060 |
> |
break; /* assume end of modifier */ |
1061 |
> |
sprintf(errmsg, "missing recover file '%s'", |
1062 |
> |
oname); |
1063 |
> |
error(USER, errmsg); |
1064 |
> |
} |
1065 |
|
nvals = lseek(fileno(fp), 0, SEEK_END); |
1066 |
|
if (nvals <= 0) { |
1067 |
|
lastout = 0; /* empty output, quit here */ |
1116 |
|
error(WARNING, "no output files to recover"); |
1117 |
|
return; |
1118 |
|
} |
1119 |
+ |
if (raysleft && lastout >= raysleft) { |
1120 |
+ |
error(WARNING, "output appears to be complete"); |
1121 |
+ |
/* XXX should read & discard input? */ |
1122 |
+ |
quit(0); |
1123 |
+ |
} |
1124 |
|
/* seek on all files */ |
1125 |
|
nvals = lastout * outvsiz; |
1126 |
|
lu_doall(&ofiletab, myseeko, &nvals); |
1127 |
< |
/* discard input */ |
1127 |
> |
/* skip repeated input */ |
1128 |
|
for (nvals = 0; nvals < lastout; nvals++) |
1129 |
|
if (getinp(oname, fin) <= 0) |
1130 |
|
error(USER, "unexpected EOF on input"); |