Fixed problems of reporting resource usage for MacOSX (should help other platforms too).

This commit is contained in:
sjborley 2005-10-15 13:56:44 +00:00
parent 1f5695a34c
commit 869f5add68
1 changed files with 92 additions and 84 deletions

View File

@ -41,6 +41,7 @@ $Id$
/* static declarations */
static void printres(char *name);
static void fprintmem(FILE* stream, size_t memory);
static RETSIGTYPE fault(void);
static void * baseaddr(void);
@ -73,15 +74,11 @@ init_rlimits(void)
startdata = (char *) baseaddr( );
enddata = sbrk(0);
# endif
/* startdata = (char *) baseaddr( );
enddata = sbrk(0); */
}
void
init_time(void)
{
#ifdef HAVE_GETRUSAGE
#else
# ifdef HAVE_TIMES
@ -91,7 +88,6 @@ init_time(void)
# endif
# endif
#endif
}
@ -122,8 +118,9 @@ char* copyword;
return;
}
/* Find out if the user is approaching his maximum data size. */
/* Find out if the user is approaching his maximum data size.
If usage is withing 90% of total available then a warning message is sent
to the error stream (cp_err) */
void
ft_ckspace(void)
{
@ -137,7 +134,7 @@ ft_ckspace(void)
usage = mem_avail - mem_avail_now;
limit = mem_avail;
#else /* HAVE__MEMAVL */
static long old_usage = 0;
static size_t old_usage = 0;
char *hi;
# ifdef HAVE_GETRLIMIT
@ -152,7 +149,7 @@ ft_ckspace(void)
# endif /* HAVE_GETRLIMIT */
hi=sbrk(0);
usage = (long) (hi - enddata);
usage = (size_t) (hi - enddata);
if (limit < 0)
return; /* what else do you do? */
@ -165,7 +162,11 @@ ft_ckspace(void)
if (usage > limit * 0.9) {
fprintf(cp_err, "Warning - approaching max data size: ");
fprintf(cp_err, "current size = %ld, limit = %ld.\n", (long)usage, (long)limit);
fprintf(cp_err, "current size = ");
fprintmem(cp_err, usage);
fprintf(cp_err,", limit = ");
fprintmem(cp_err, limit);
fprintf(cp_err,"\n");
}
return;
@ -275,7 +276,8 @@ printres(char *name)
}
if (!name || eq(name, "space")) {
long usage = 0, limit = 0;
size_t usage = 0;
size_t limit = 0;
#ifdef HAVE__MEMAVL
@ -284,15 +286,14 @@ printres(char *name)
mem_avail_now = _memavl( );
usage = mem_avail - mem_avail_now;
limit = mem_avail;
#else
#else /* HAVE__MEMAVL */
#ifdef ipsc
NXINFO cur = nxinfo, start = nxinfo_snap;
usage = cur.dataend - cur.datastart;
limit = start.availmem;
#else
#else /* ipsc */
# ifdef HAVE_GETRLIMIT
struct rlimit rld;
char *hi;
@ -300,29 +301,27 @@ printres(char *name)
getrlimit(RLIMIT_DATA, &rld);
limit = rld.rlim_cur - (enddata - startdata);
hi = sbrk(0);
usage = (long) (hi - enddata);
# else
usage = (size_t) (hi - enddata);
# else /* HAVE_GETRLIMIT */
# ifdef HAVE_ULIMIT
char *hi;
limit = ulimit(3, 0L) - (enddata - startdata);
hi = sbrk(0);
usage = (long) (hi - enddata);
# endif
# endif
#endif
#endif
#ifdef HAVE__MEMAVL
if (usage > 1000000)
fprintf(cp_out, "Current dynamic memory usage = %8.6f MB,\n", usage/1000000.);
else
fprintf(cp_out, "Current dynamic memory usage = %5.3f kB,\n", usage/1000.);
usage = (size_t) (hi - enddata);
# endif /* HAVE_ULIMIT */
# endif /* HAVE_GETRLIMIT */
#endif /* ipsc */
#endif /* HAVE__MEMAVL */
fprintf(cp_out, "Current dynamic memory usage = ");
fprintmem(cp_out, usage);
fprintf(cp_out, ",\n");
fprintf(cp_out, "Dynamic memory limit = ");
fprintmem(cp_out, limit);
fprintf(cp_out, ".\n");
fprintf(cp_out, "Dynamic memory limit = %8.6f MB.\n", limit/1000000.);
#else
fprintf(cp_out, "Current dynamic memory usage = %ld,\n", usage);
fprintf(cp_out, "Dynamic memory limit = %ld.\n", limit);
#endif
yy = TRUE;
}
@ -390,11 +389,21 @@ printres(char *name)
fprintf(cp_err, "Note: no resource usage information for '%s',\n",
name);
fprintf(cp_err, "\tor no active circuit available\n");
}
return;
}
/* Print to stream the given memory size in a human friendly format */
static void
fprintmem(FILE* stream, size_t memory) {
if (memory > 1000000)
fprintf(stream, "%8.6f MB", memory/1000000.);
else if (memory > 1000)
fprintf(stream, "%5.3f kB", memory/1000.);
else
fprintf(stream, "%lu bytes", (unsigned long)memory);
}
#include <signal.h>
#include <setjmp.h>
@ -426,7 +435,6 @@ baseaddr(void)
return 0;
#else
char *low, *high, *at;
/* char *sbrk(int); */
long x;
RETSIGTYPE (*orig_signal)( );