[project @ 2001-07-22 03:28:25 by chak]
[ghc-hetmet.git] / ghc / rts / Stats.c
index ceaaaa7..3b12135 100644 (file)
@@ -1,5 +1,5 @@
 /* -----------------------------------------------------------------------------
- * $Id: Stats.c,v 1.23 2000/12/19 14:30:17 simonmar Exp $
+ * $Id: Stats.c,v 1.30 2001/07/08 17:04:04 sof Exp $
  *
  * (c) The GHC Team, 1998-1999
  *
@@ -16,6 +16,7 @@
 #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
 
@@ -102,17 +107,17 @@ static nat   pageFaults(void);
 
 /* 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)
@@ -126,7 +131,9 @@ getTimes(void)
     if (!GetProcessTimes (GetCurrentProcess(), &creationTime,
                          &exitTime, &kernelTime, &userTime)) {
        /* Probably on a Win95 box..*/
-       return 0;
+       CurrentElapsedTime = 0;
+       CurrentUserTime = 0;
+       return;
     }
 
     FT2longlong(kT,kernelTime);
@@ -135,20 +142,20 @@ getTimes(void)
     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);
 
@@ -157,7 +164,7 @@ getTimes(void)
 #endif
 
 }
-#endif /* !_WIN32 */
+#endif /* !win32 */
 
 /* mut_user_time_during_GC() and mut_user_time()
  *
@@ -174,14 +181,14 @@ getTimes(void)
 double
 mut_user_time_during_GC(void)
 {
-    return ((double)GC_start_time - (double)GC_tot_time);
+  return TICK_TO_DBL(GC_start_time - GC_tot_time);
 }
 
 double
 mut_user_time(void)
 {
     getTimes();
-    return ((double)CurrentUserTime - (double)GC_tot_time);
+    return TICK_TO_DBL(CurrentUserTime - GC_tot_time);
 }
 
 static nat
@@ -189,7 +196,7 @@ pageFaults(void)
 {
   /* 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;
@@ -237,20 +244,21 @@ stat_startInit(void)
        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();
@@ -585,12 +593,14 @@ stat_exit(int alloc)
        }
 
        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));