[project @ 2003-12-16 13:27:31 by simonmar]
[ghc-hetmet.git] / ghc / rts / Stats.c
index 1991090..5d4f772 100644 (file)
@@ -1,5 +1,5 @@
 /* -----------------------------------------------------------------------------
- * $Id: Stats.c,v 1.40 2001/11/27 16:35:57 simonmar Exp $
+ * $Id: Stats.c,v 1.46 2002/08/19 16:02:26 simonmar Exp $
  *
  * (c) The GHC Team, 1998-1999
  *
@@ -111,9 +111,9 @@ static TICK_TYPE HCe_start_time, HCe_tot_time = 0;   // heap census prof elap ti
 #define PROF_VAL(x)   0
 #endif
 
-lnat MaxResidency = 0;     /* in words; for stats only */
-lnat AvgResidency = 0;
-lnat ResidencySamples = 0; /* for stats only */
+static lnat MaxResidency = 0;     // in words; for stats only
+static lnat AvgResidency = 0;
+static lnat ResidencySamples = 0; // for stats only
 
 static lnat GC_start_faults = 0, GC_end_faults = 0;
 
@@ -579,17 +579,19 @@ stat_endHeapCensus(void)
    stats for this thread into the task_ids struct for that thread.
    -------------------------------------------------------------------------- */
 
-#ifdef SMP
+#if defined(SMP)
 void
 stat_workerStop(void)
 {
     nat i;
     pthread_t me = pthread_self();
 
+    getTimes();
+
     for (i = 0; i < RtsFlags.ParFlags.nNodes; i++) {
        if (task_ids[i].id == me) {
-           task_ids[i].mut_time = usertime() - task_ids[i].gc_time;
-           task_ids[i].mut_etime = elapsedtime()
+           task_ids[i].mut_time = CurrentUserTime - task_ids[i].gc_time;
+           task_ids[i].mut_etime = CurrentElapsedTime
                - GCe_tot_time
                - task_ids[i].elapsedtimestart;
            if (task_ids[i].mut_time < 0.0)  { task_ids[i].mut_time = 0.0;  }
@@ -599,6 +601,14 @@ stat_workerStop(void)
 }
 #endif
 
+#if defined(SMP)
+long int stat_getElapsedTime ()
+{
+  getTimes();
+  return CurrentElapsedTime;
+}
+#endif
+
 /* -----------------------------------------------------------------------------
    Called at the end of execution
 
@@ -739,7 +749,8 @@ stat_exit(int alloc)
          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, 
+                   ResidencySamples == 0 ? 0 : 
+                       AvgResidency*sizeof(W_)/ResidencySamples, 
                    MaxResidency*sizeof(W_), 
                    ResidencySamples,
                    (unsigned long)(mblocks_allocated * MBLOCK_SIZE / (1024L * 1024L)),
@@ -749,7 +760,9 @@ stat_exit(int alloc)
        }
 
        fflush(sf);
-       fclose(sf);
+       if (sf != stderr) {
+           fclose(sf);
+       }
     }
 }