[project @ 2001-09-04 18:29:20 by ken]
[ghc-hetmet.git] / ghc / rts / Stats.c
index 31edb31..3c4d6e6 100644 (file)
@@ -1,5 +1,5 @@
 /* -----------------------------------------------------------------------------
- * $Id: Stats.c,v 1.26 2001/07/02 13:02:29 rrt Exp $
+ * $Id: Stats.c,v 1.32 2001/08/14 13:40:09 sewardj Exp $
  *
  * (c) The GHC Team, 1998-1999
  *
@@ -7,7 +7,9 @@
  *
  * ---------------------------------------------------------------------------*/
 
-#define NON_POSIX_SOURCE
+/* Alas, no.  This source is non-posix.
+   #include "PosixSource.h" 
+*/
 
 #include "Rts.h"
 #include "RtsFlags.h"
@@ -56,7 +58,7 @@
 #include <windows.h>
 #endif
 
-#if defined(PAR) || !(!defined(HAVE_GETRUSAGE) || irix_TARGET_OS || defined(_WIN32))
+#if defined(PAR) || !(!defined(HAVE_GETRUSAGE) || irix_TARGET_OS || defined(mingw32_TARGET_OS) || defined(cygwin32_TARGET_OS))
 #include <sys/resource.h>
 #endif
 
@@ -108,16 +110,16 @@ static nat   pageFaults(void);
 /* elapsedtime() -- The current elapsed time in seconds */
 
 #if defined(mingw32_TARGET_OS) || defined(cygwin32_TARGET_OS)
-#define NS_PER_SEC 10000000LL
-/* Convert FILETIMEs into secs since the Epoch (Jan1-1970) */
+#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 defined(mingw32_TARGET_OS) || defined(cygwin32_TARGET_OS)
+#if defined(mingw32_TARGET_OS) || defined(cygwin32_TARGET_OS)
 /* cygwin32 or mingw32 version */
 static void
 getTimes(void)
@@ -131,7 +133,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);
@@ -146,14 +150,14 @@ 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);
 
@@ -162,7 +166,7 @@ getTimes(void)
 #endif
 
 }
-#endif /* !_WIN32 */
+#endif /* !win32 */
 
 /* mut_user_time_during_GC() and mut_user_time()
  *
@@ -194,7 +198,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;
@@ -242,20 +246,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();
@@ -590,12 +595,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));
@@ -612,14 +619,14 @@ stat_exit(int alloc)
    Produce some detailed info on the state of the generational GC.
    -------------------------------------------------------------------------- */
 void
-stat_describe_gens(void)
+statDescribeGens(void)
 {
   nat g, s, mut, mut_once, lge, live;
   StgMutClosure *m;
   bdescr *bd;
   step *step;
 
-  fprintf(stderr, "     Gen    Steps      Max   Mutable  Mut-Once  Step   Blocks     Live    Large\n                    Blocks  Closures  Closures                         Objects\n");
+  fprintf(stderr, "     Gen    Steps      Max   Mutable  Mut-Once  Step   Blocks     Live    Large\n                    Blocks  Closures  Closures                          Objects\n");
 
   for (g = 0; g < RtsFlags.GcFlags.generations; g++) {
     for (m = generations[g].mut_list, mut = 0; m != END_MUT_LIST; 
@@ -637,7 +644,7 @@ stat_describe_gens(void)
        lge++;
       live = 0;
       if (RtsFlags.GcFlags.generations == 1) {
-       bd = step->to_space;
+       bd = step->to_blocks;
       } else {
        bd = step->blocks;
       }