17 #include <sys/resource.h> 20 #include <sys/types.h> 21 #include <sys/times.h> 22 #include <sys/param.h> 25 #include <sys/types.h> 26 #include <sys/timeb.h> 31 #ifndef HAVE_GETRUSAGE 34 static struct timeb timebegin;
35 static struct timeb lasttime;
50 extern char * _memavl();
68 if (wl && (
eq(wl->wl_word,
"everything") ||
eq(wl->wl_word,
"all"))) {
72 for (; wl; wl = wl->wl_next) {
73 c =
copy(wl->wl_word);
98 getrlimit(RLIMIT_DATA, &rld);
99 if (rld.rlim_cur == RLIM_INFINITY)
103 if ((
int) (hi - (
char *)
enddata) > rld.rlim_max * 0.9) {
104 fprintf(
cp_err,
"Warning - approaching max data size: ");
105 fprintf(
cp_err,
"cur size = %d, hard limit = %d.\n",
106 (
int) hi, (
int) lim);
108 else if ((
int) (hi - (
char *) enddata) > rld.rlim_cur * 0.9) {
109 fprintf(
cp_err,
"Warning - approaching max data size: ");
110 fprintf(
cp_err,
"cur size = %d, soft limit = %d.\n",
111 (
int) hi, (
int) rld.rlim_cur);
120 if ((
int) (hi - (
char *) enddata) > lim * 0.9) {
121 fprintf(
cp_err,
"Warning - approaching max data size: ");
122 fprintf(
cp_err,
"cur size = %d, hard limit = %d.\n",
123 (
int) hi, (
int) lim);
126 #ifdef HAVE_DOSRLIMIT 129 lim = (long)_memavl( );
130 if ((
long) (enddata - lim) > ((
long)
enddata) * 0.9) {
131 fprintf(
cp_err,
"Warning - approaching max data size: ");
132 fprintf(
cp_err,
"cur size = %ld, hard limit = %ld.\n",
133 (
long) (enddata - lim), (
long) enddata);
145 #ifdef HAVE_GETRUSAGE 147 #ifdef HAVE_GETTIMEOFDAY 151 (void) gettimeofday(&tv, &tz);
157 (void) getrusage(RUSAGE_SELF, &ruse);
177 #ifdef HAVE_GETRLIMIT 183 #ifdef HAVE_DOSRLIMIT 202 char *fmtf =
"%-15s%-10.2f%s\n";
203 char *fmtx =
"%-15s%-10x%s\n";
204 char *fmtd =
"%-15s%-10d%s\n";
206 if (!name ||
eq(name,
"totaltime")) {
208 #ifdef HAVE_GETRUSAGE 210 #ifdef HAVE_GETTIMEOFDAY 214 (void) gettimeofday(&tv, &tz);
216 (
double)(tv.tv_sec -
origsec) +
217 (
double)(tv.tv_usec -
origusec)/1.0e6,
218 "Total elapsed seconds");
220 (void) getrusage(RUSAGE_SELF, &ruse);
221 #ifndef HAVE_GETTIMEOFDAY 226 (
double)ruse.ru_utime.tv_sec +
227 (
double)ruse.ru_utime.tv_usec/1.0e6,
228 "Total user cpu seconds");
230 (
double)ruse.ru_stime.tv_sec +
231 (
double)ruse.ru_stime.tv_usec/1.0e6,
232 "Total system cpu seconds");
237 realt = times(&ruse);
240 (
double)((realt -
origsec)%HZ)/HZ,
241 "Total elapsed seconds");
244 (
double)ruse.tms_utime/HZ +
245 (
double)(ruse.tms_utime%HZ)/HZ,
246 "Total user cpu seconds");
248 (
double)ruse.tms_stime/HZ +
249 (
double)(ruse.tms_stime%HZ)/HZ,
250 "Total system cpu seconds");
253 struct timeb timenow;
257 timediff(&timenow, &timebegin, &sec, &msec);
258 out_printf(fmtf,
"totaltime",(
double)sec + (
double)msec/1000,
259 "Total run time seconds");
266 if (!name ||
eq(name,
"elapsed")) {
268 #ifdef HAVE_GETRUSAGE 270 #ifdef HAVE_GETTIMEOFDAY 274 (void) gettimeofday(&tv, &tz);
276 (
double)(tv.tv_sec -
lastsec) +
277 (
double)(tv.tv_usec -
lastusec)/1.0e6,
278 "Seconds since last call");
282 (void) getrusage(RUSAGE_SELF, &ruse);
283 #ifndef HAVE_GETTIMEOFDAY 289 (
double)(ruse.ru_utime.tv_usec -
lastusrusec)/1.0e6,
290 "User cpu seconds since last call");
295 (
double)(ruse.ru_stime.tv_usec -
lastsysusec)/1.0e6,
296 "System cpu seconds since last call");
303 realt = times(&ruse);
306 (
double)((realt -
lastsec)%HZ)/HZ,
307 "Seconds since last call");
310 (
double)((ruse.tms_utime -
lastusrsec)%HZ)/HZ,
311 "User cpu seconds since last call");
314 (
double)((ruse.tms_stime -
lastsyssec)%HZ)/HZ,
315 "System cpu seconds since last call");
322 struct timeb timenow;
326 if (lasttime.time != 0 || lasttime.millitm != 0) {
327 timediff(&timenow, &lasttime, &sec, &msec);
328 out_printf(fmtf,
"elapsed",(
double)sec + (
double)msec/1000,
329 "Seconds since last call");
338 if (!name ||
eq(name,
"space")) {
339 #ifdef HAVE_GETRLIMIT 343 getrlimit(RLIMIT_DATA, &rld);
346 "Current data size");
347 out_printf(fmtd,
"", (
unsigned)rld.rlim_max,
"Hard data limit");
348 out_printf(fmtd,
"", (
unsigned)rld.rlim_cur,
"Soft data limit");
357 "Current data size");
360 #ifdef HAVE_DOSRLIMIT 363 lim = (long)_memavl( );
372 if (!name ||
eq(name,
"faults")) {
373 #ifdef HAVE_GETRUSAGE 376 (void) getrusage(RUSAGE_SELF, &ruse);
377 out_printf(fmtd,
"faults",ruse.ru_majflt,
"Page Faults");
378 out_printf(
"%-15s%-10d%s (vol %d + invol %d)\n",
"",
379 ruse.ru_nvcsw + ruse.ru_nivcsw,
380 "Context switches",ruse.ru_nvcsw,ruse.ru_nivcsw);
392 switch (v->va_type) {
394 out_printf(fmtd,tw->wl_word,v->va_num,v->va_name);
397 out_printf(fmtf,tw->wl_word,v->va_real,v->va_name);
409 "Note: no resource usage information on %s,\n", name);
413 fprintf(
cp_err,
"Note: no active circuit available\n");
static char buf[MAXPROMPT]
void com_rusage(wordlist *wl)
struct variable * if_getstat(char *n, char *c, wordlist **w)