12 |
|
|
13 |
|
#include "ray.h" |
14 |
|
|
15 |
+ |
#include <sys/types.h> |
16 |
+ |
|
17 |
+ |
#ifndef NIX |
18 |
|
#ifdef BSD |
19 |
|
#include <sys/time.h> |
20 |
|
#include <sys/resource.h> |
21 |
+ |
#else |
22 |
+ |
#include <sys/times.h> |
23 |
+ |
#include <sys/utsname.h> |
24 |
+ |
#include <unistd.h> |
25 |
|
#endif |
26 |
+ |
#endif |
27 |
|
|
28 |
+ |
extern time_t time(); |
29 |
+ |
|
30 |
|
#include <signal.h> |
31 |
|
|
32 |
|
#include "view.h" |
87 |
|
|
88 |
|
double pctdone = 0.0; /* percentage done */ |
89 |
|
|
90 |
< |
long tlastrept = 0L; /* time at last report */ |
90 |
> |
time_t tlastrept = 0L; /* time at last report */ |
91 |
|
|
92 |
< |
extern long time(); |
83 |
< |
extern long tstart; /* starting time */ |
92 |
> |
extern time_t tstart; /* starting time */ |
93 |
|
|
94 |
|
extern unsigned long nrays; /* number of rays traced */ |
95 |
|
|
130 |
|
} |
131 |
|
|
132 |
|
|
133 |
< |
#ifdef BSD |
133 |
> |
#ifndef NIX |
134 |
|
report() /* report progress */ |
135 |
|
{ |
136 |
+ |
double u, s; |
137 |
+ |
#ifdef BSD |
138 |
+ |
char hostname[257]; |
139 |
|
struct rusage rubuf; |
140 |
< |
double t; |
140 |
> |
#else |
141 |
> |
struct tms tbuf; |
142 |
> |
struct utsname nambuf; |
143 |
> |
double period; |
144 |
> |
#define hostname nambuf.nodename |
145 |
> |
#endif |
146 |
|
|
147 |
+ |
tlastrept = time((time_t *)NULL); |
148 |
+ |
#ifdef BSD |
149 |
|
getrusage(RUSAGE_SELF, &rubuf); |
150 |
< |
t = (rubuf.ru_utime.tv_usec + rubuf.ru_stime.tv_usec) / 1e6; |
151 |
< |
t += rubuf.ru_utime.tv_sec + rubuf.ru_stime.tv_sec; |
150 |
> |
u = rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec/1e6; |
151 |
> |
s = rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec/1e6; |
152 |
|
getrusage(RUSAGE_CHILDREN, &rubuf); |
153 |
< |
t += (rubuf.ru_utime.tv_usec + rubuf.ru_stime.tv_usec) / 1e6; |
154 |
< |
t += rubuf.ru_utime.tv_sec + rubuf.ru_stime.tv_sec; |
153 |
> |
u += rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec/1e6; |
154 |
> |
s += rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec/1e6; |
155 |
> |
gethostname(hostname, sizeof(hostname)); |
156 |
> |
#else |
157 |
> |
times(&tbuf); |
158 |
> |
period = 1.0 / sysconf(_SC_CLK_TCK); |
159 |
> |
u = ( tbuf.tms_utime + tbuf.tms_cutime ) * period; |
160 |
> |
s = ( tbuf.tms_stime + tbuf.tms_cstime ) * period; |
161 |
> |
uname(&nambuf); |
162 |
> |
#endif |
163 |
|
|
164 |
< |
sprintf(errmsg, "%lu rays, %4.2f%% done after %5.4f CPU hours\n", |
165 |
< |
nrays, pctdone, t/3600.0); |
164 |
> |
sprintf(errmsg, |
165 |
> |
"%lu rays, %4.2f%% after %.3fu %.3fs %.3fr hours on %s\n", |
166 |
> |
nrays, pctdone, u/3600., s/3600., |
167 |
> |
(tlastrept-tstart)/3600., hostname); |
168 |
|
eputs(errmsg); |
169 |
< |
tlastrept = time((long *)0); |
169 |
> |
#ifndef BSD |
170 |
> |
signal(SIGCONT, report); |
171 |
> |
#undef hostname |
172 |
> |
#endif |
173 |
|
} |
174 |
|
#else |
175 |
|
report() /* report progress */ |
176 |
|
{ |
177 |
< |
tlastrept = time((long *)0); |
178 |
< |
sprintf(errmsg, "%lu rays, %4.2f%% done after %5.4f hours\n", |
177 |
> |
tlastrept = time((time_t *)NULL); |
178 |
> |
sprintf(errmsg, "%lu rays, %4.2f%% after %5.4f hours\n", |
179 |
|
nrays, pctdone, (tlastrept-tstart)/3600.0); |
180 |
|
eputs(errmsg); |
149 |
– |
signal(SIGCONT, report); |
181 |
|
} |
182 |
|
#endif |
183 |
|
|
236 |
|
cp--; |
237 |
|
strcpy(cp, RFTEMPLATE); |
238 |
|
prvr = mktemp(fbuf2); |
239 |
< |
if (rename(fbuf, prvr) < 0 && errno != ENOENT) { |
240 |
< |
sprintf(errmsg, |
239 |
> |
if (rename(fbuf, prvr) < 0) |
240 |
> |
if (errno == ENOENT) { /* ghost file */ |
241 |
> |
sprintf(errmsg, |
242 |
> |
"new output file \"%s\"", |
243 |
> |
fbuf); |
244 |
> |
error(WARNING, errmsg); |
245 |
> |
prvr = NULL; |
246 |
> |
} else { /* serious error */ |
247 |
> |
sprintf(errmsg, |
248 |
|
"cannot rename \"%s\" to \"%s\"", |
249 |
|
fbuf, prvr); |
250 |
< |
error(SYSTEM, errmsg); |
251 |
< |
} |
250 |
> |
error(SYSTEM, errmsg); |
251 |
> |
} |
252 |
|
} |
253 |
|
} |
254 |
|
npicts = 0; /* render sequence */ |
433 |
|
goto writerr; |
434 |
|
/* record progress */ |
435 |
|
pctdone = 100.0*(vres-1-ypos)/vres; |
436 |
< |
if (ralrm > 0 && time((long *)0) >= tlastrept+ralrm) |
436 |
> |
if (ralrm > 0 && time((time_t *)NULL) >= tlastrept+ralrm) |
437 |
|
report(); |
438 |
|
#ifndef BSD |
439 |
|
else |
638 |
|
getheader(fp, NULL, NULL); |
639 |
|
/* get picture size */ |
640 |
|
if (!fscnresolu(&x, &y, fp)) { |
641 |
< |
sprintf(errmsg, "bad recover file \"%s\"", oldfile); |
641 |
> |
sprintf(errmsg, "bad recover file \"%s\" - not removed", |
642 |
> |
oldfile); |
643 |
|
error(WARNING, errmsg); |
644 |
|
fclose(fp); |
645 |
|
return(0); |