/* -----------------------------------------------------------------------------
- * $Id: Stats.c,v 1.24 2001/03/14 15:01:04 sewardj Exp $
+ * $Id: Stats.c,v 1.30 2001/07/08 17:04:04 sof Exp $
*
* (c) The GHC Team, 1998-1999
*
#include "MBlock.h"
#include "Schedule.h"
#include "Stats.h"
+#include "ParTicky.h" // ToDo: move into Rts.h
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#include <windows.h>
#endif
+#if defined(PAR) || !(!defined(HAVE_GETRUSAGE) || irix_TARGET_OS || defined(mingw32_TARGET_OS) || defined(cygwin32_TARGET_OS))
+#include <sys/resource.h>
+#endif
+
/* huh? */
#define BIG_STRING_LEN 512
/* elapsedtime() -- The current elapsed time in seconds */
-#ifdef _WIN32
-#define NS_PER_SEC 10000000LL
-/* Convert FILETIMEs into secs since the Epoch (Jan1-1970) */
+#if defined(mingw32_TARGET_OS) || defined(cygwin32_TARGET_OS)
+#define HNS_PER_SEC 10000000LL /* FILETIMES are in units of 100ns */
+/* Convert FILETIMEs into secs */
#define FT2longlong(ll,ft) \
(ll)=(ft).dwHighDateTime; \
(ll) <<= 32; \
(ll) |= (ft).dwLowDateTime; \
- (ll) /= (unsigned long long) (NS_PER_SEC / CLOCKS_PER_SEC)
+ (ll) /= (unsigned long long) (HNS_PER_SEC / CLOCKS_PER_SEC)
#endif
-#ifdef _WIN32
+#if defined(mingw32_TARGET_OS) || defined(cygwin32_TARGET_OS)
/* cygwin32 or mingw32 version */
static void
getTimes(void)
if (!GetProcessTimes (GetCurrentProcess(), &creationTime,
&exitTime, &kernelTime, &userTime)) {
/* Probably on a Win95 box..*/
- return 0;
+ CurrentElapsedTime = 0;
+ CurrentUserTime = 0;
+ return;
}
FT2longlong(kT,kernelTime);
CurrentUserTime = uT;
}
-#else /* !_WIN32 */
+#else /* !win32 */
static void
getTimes(void)
{
-# if !defined(HAVE_TIMES)
+#ifndef HAVE_TIMES
/* We will #ifdef around the fprintf for machines
we *know* are unsupported. (WDP 94/05)
*/
fprintf(stderr, "NOTE: `getTimes' does nothing!\n");
return 0.0;
-# else /* not stumped */
+#else /* not stumped */
struct tms t;
clock_t r = times(&t);
#endif
}
-#endif /* !_WIN32 */
+#endif /* !win32 */
/* mut_user_time_during_GC() and mut_user_time()
*
{
/* ToDo (on NT): better, get this via the performance data
that's stored in the registry. */
-# if !defined(HAVE_GETRUSAGE) || irix_TARGET_OS || defined(_WIN32)
+# if !defined(HAVE_GETRUSAGE) || irix_TARGET_OS || defined(mingw32_TARGET_OS) || defined(cygwin32_TARGET_OS)
return 0;
# else
struct rusage t;
fprintf(stderr, "stat_init: bad call to 'sysconf'!\n");
stg_exit(EXIT_FAILURE);
}
- TicksPerSecond = (double) ticks;
+ TicksPerSecond = ticks;
/* no "sysconf" or CLK_TCK; had better guess */
#elif defined(HZ)
- TicksPerSecond = (StgDouble) (HZ);
+ TicksPerSecond = HZ;
#elif defined(CLOCKS_PER_SEC)
- TicksPerSecond = (StgDouble) (CLOCKS_PER_SEC);
+ TicksPerSecond = CLOCKS_PER_SEC;
+
#else /* had better guess wildly */
/* We will #ifdef around the fprintf for machines
we *know* are unsupported. (WDP 94/05)
*/
fprintf(stderr, "NOTE: Guessing `TicksPerSecond = 60'!\n");
- TicksPerSecond = 60.0;
+ TicksPerSecond = 60;
#endif
getTimes();
}
if (RtsFlags.GcFlags.giveStats == ONELINE_GC_STATS && sf != NULL) {
- fprintf(sf, "<<ghc: %lld bytes, %d GCs, %ld/%ld avg/max bytes residency (%ld samples), %ldM in use, %.2f INIT (%.2f elapsed), %.2f MUT (%.2f elapsed), %.2f GC (%.2f elapsed) :ghc>>\n",
- GC_tot_alloc*sizeof(W_), total_collections,
+ /* print the long long separately to avoid bugginess on mingwin (2001-07-02, mingw-0.5) */
+ fprintf(sf, "<<ghc: %llu bytes, ", GC_tot_alloc*sizeof(W_));
+ fprintf(sf, "%d GCs, %ld/%ld avg/max bytes residency (%ld samples), %luM in use, %.2f INIT (%.2f elapsed), %.2f MUT (%.2f elapsed), %.2f GC (%.2f elapsed) :ghc>>\n",
+ total_collections,
AvgResidency*sizeof(W_)/ResidencySamples,
MaxResidency*sizeof(W_),
- ResidencySamples,
- mblocks_allocated * MBLOCK_SIZE / (1024 * 1024),
+ ResidencySamples,
+ (unsigned long)(mblocks_allocated * MBLOCK_SIZE / (1024L * 1024L)),
TICK_TO_DBL(InitUserTime), TICK_TO_DBL(InitElapsedTime),
TICK_TO_DBL(MutUserTime), TICK_TO_DBL(MutElapsedTime),
TICK_TO_DBL(GC_tot_time), TICK_TO_DBL(GCe_tot_time));