[project @ 1996-01-11 14:06:51 by partain]
[ghc-hetmet.git] / ghc / runtime / storage / SMstats.lc
index 3f6dfc3..37e4895 100644 (file)
@@ -19,7 +19,7 @@ stat_exit
 
 #define NULL_REG_MAP
 #include "SMinternal.h"
-#include "RednCounts.h"
+#include "Ticky.h"
 
 #ifdef HAVE_SYS_TYPES_H
 #include <sys/types.h>
@@ -70,14 +70,7 @@ static ullong GC_tot_alloc = 0;        /* Total heap allocated -- 64 bits? */
 static I_ GC_start_faults = 0, GC_end_faults = 0;
 
 char *
-#ifdef __STDC__ 
 ullong_format_string(ullong x, char *s, rtsBool with_commas)
-#else
-ullong_format_string(x, s, with_commas)
-    ullong x;
-    char  *s;
-    rtsBool with_commas;
-#endif
 {
     if (x < (ullong)1000) 
        sprintf(s, "%ld", (I_)x);
@@ -226,52 +219,54 @@ pagefaults(STG_NO_ARGS)
 /* Called at the beginning of execution of the program */
 /* Writes the command line and inits stats header */
 
-void stat_init(collector, comment1, comment2)
-char *collector, *comment1, *comment2;
+void
+stat_init(char *collector, char *comment1, char *comment2)
 {
-    if (SM_statsfile != NULL) {
+    FILE *sf = RTSflags.GcFlags.statsFile;
+
+    if (sf != NULL) {
        char temp[BIG_STRING_LEN];
-       ullong_format_string( (ullong)SM_word_heap_size*sizeof(W_), temp, rtsTrue/*commas*/);
-       fprintf(SM_statsfile, "\nCollector: %s  HeapSize: %s (bytes)\n\n", collector, temp);
-       if (SM_stats_verbose) {
+       ullong_format_string( (ullong)RTSflags.GcFlags.heapSize*sizeof(W_), temp, rtsTrue/*commas*/);
+       fprintf(sf, "\nCollector: %s  HeapSize: %s (bytes)\n\n", collector, temp);
+       if (RTSflags.GcFlags.giveStats) {
 #if !defined(HAVE_GETRUSAGE) || irix_TARGET_OS
-           fprintf(SM_statsfile, "NOTE: `pagefaults' does nothing!\n");
+           fprintf(sf, "NOTE: `pagefaults' does nothing!\n");
 #endif
-           fprintf(SM_statsfile,
+           fprintf(sf,
 /*######## ####### #######  ##.#  ##.## ##.## ####.## ####.## #### ####*/
  "  Alloc  Collect   Live   Resid   GC    GC     TOT     TOT  Page Flts  %s\n",
                    comment1);
-           fprintf(SM_statsfile,
+           fprintf(sf,
  "  bytes   bytes    bytes   ency  user  elap    user    elap   GC  MUT  %s\n",
                    comment2);
        }
 
 #if defined(GCap) || defined(GCgn)
         else {
-           fprintf(SM_statsfile,
+           fprintf(sf,
 /*######## #######  ##.#  #######  ##.#   ###  ##.## ##.## ##.## ##.## ####.## ####.## #### ####*/
  "  Alloc  Promote  Promo   Live   Resid Minor Minor Minor Major Major    TOT     TOT  Page Flts\n");
-           fprintf(SM_statsfile,
+           fprintf(sf,
  "  bytes   bytes    ted    bytes   ency   No   user  elap  user  elap    user    elap  MUT Major\n");
        }
 #endif /* generational */
 
-       fflush(SM_statsfile);
+       fflush(sf);
     }
 }
 
-
 /* Called at the beginning of each GC */
 static I_ rub_bell = 0;
 
 void
-stat_startGC(alloc)
-  I_ alloc;
+stat_startGC(I_ alloc)
 {
+    FILE *sf = RTSflags.GcFlags.statsFile;
+
 #if defined(GCap) || defined(GCgn)
-    I_ bell = alloc == 0 ? SM_ring_bell : 0;
+    I_ bell = alloc == 0 ? RTSflags.GcFlags.ringBell : 0;
 #else  /* ! generational */
-    I_ bell = SM_ring_bell;
+    I_ bell = RTSflags.GcFlags.ringBell;
 #endif /* ! generational */
 
     if (bell) {
@@ -283,16 +278,16 @@ stat_startGC(alloc)
        }
     }
 
-    if (SM_statsfile != NULL) {
+    if (sf != NULL) {
        GC_start_time = usertime();
        GCe_start_time = elapsedtime();
        
 #if defined(GCap) || defined(GCgn)
-        if (SM_stats_verbose || alloc == 0) {
+        if (RTSflags.GcFlags.giveStats || alloc == 0) {
            GC_start_faults = pagefaults();
        }
 #else  /* ! generational */
-       if (SM_stats_verbose) {
+       if (RTSflags.GcFlags.giveStats) {
            GC_start_faults = pagefaults();
        }
 #endif /* ! generational */
@@ -300,24 +295,23 @@ stat_startGC(alloc)
     }
 }
 
-
 /* Called at the end of each GC */
 
 void
-stat_endGC(alloc, collect, live, comment)
-  I_ alloc, collect, live;
-  char *comment;
+stat_endGC(I_ alloc, I_ collect, I_ live, char *comment)
 {
-    if (SM_statsfile != NULL) {
+    FILE *sf = RTSflags.GcFlags.statsFile;
+
+    if (sf != NULL) {
        StgDouble time = usertime();
        StgDouble etime = elapsedtime();
 
-       if (SM_stats_verbose){
+       if (RTSflags.GcFlags.giveStats) {
            I_ faults = pagefaults();
 
-           fprintf(SM_statsfile, "%8ld %7ld %7ld %5.1f%%",
-                   alloc*sizeof(W_), collect*sizeof(W_), live*sizeof(W_), collect == 0 ? 0.0 : (live / (StgFloat) collect * 100));
-           fprintf(SM_statsfile, " %5.2f %5.2f %7.2f %7.2f %4ld %4ld  %s\n", 
+           fprintf(sf, "%8ld %7ld %7ld %5.1f%%",
+                   alloc*sizeof(W_), collect*sizeof(W_), live*sizeof(W_), collect == 0 ? 0.0 : (live / (StgDouble) collect * 100));
+           fprintf(sf, " %5.2f %5.2f %7.2f %7.2f %4ld %4ld  %s\n", 
                    (time-GC_start_time), 
                    (etime-GCe_start_time), 
                    time,
@@ -327,18 +321,18 @@ stat_endGC(alloc, collect, live, comment)
                    comment);
 
            GC_end_faults = faults;
-           fflush(SM_statsfile);
+           fflush(sf);
        }
 
 #if defined(GCap) || defined(GCgn)
         else if(alloc == 0 && collect != 0) {
            I_ faults = pagefaults();
 
-           fprintf(SM_statsfile, "%8ld %7ld %5.1f%% %7ld %5.1f%%",
+           fprintf(sf, "%8ld %7ld %5.1f%% %7ld %5.1f%%",
                    GC_alloc_since_maj*sizeof(W_), (collect - GC_live_maj)*sizeof(W_),
-                   (collect - GC_live_maj) / (StgFloat) GC_alloc_since_maj * 100,
-                   live*sizeof(W_), live / (StgFloat) SM_word_heap_size * 100);
-           fprintf(SM_statsfile, "  %3ld  %5.2f %5.2f %5.2f %5.2f %7.2f %7.2f %4ld %4ld\n",
+                   (collect - GC_live_maj) / (StgDouble) GC_alloc_since_maj * 100,
+                   live*sizeof(W_), live / (StgDouble) RTSflags.GcFlags.heapSize * 100);
+           fprintf(sf, "  %3ld  %5.2f %5.2f %5.2f %5.2f %7.2f %7.2f %4ld %4ld\n",
                    GC_min_since_maj, GC_min_time, GCe_min_time,
                    (time-GC_start_time), 
                    (etime-GCe_start_time), 
@@ -349,7 +343,7 @@ stat_endGC(alloc, collect, live, comment)
                    );
 
            GC_end_faults = faults;
-           fflush(SM_statsfile);
+           fflush(sf);
        }
 #endif /* generational */
 
@@ -386,27 +380,27 @@ stat_endGC(alloc, collect, live, comment)
     }
 }
 
-
 /* Called at the end of execution -- to print a summary of statistics */
 
 void
-stat_exit(alloc)
-  I_ alloc;
+stat_exit(I_ alloc)
 {
-    if (SM_statsfile != NULL){
+    FILE *sf = RTSflags.GcFlags.statsFile;
+
+    if (sf != NULL){
        char temp[BIG_STRING_LEN];
        StgDouble time = usertime();
        StgDouble etime = elapsedtime();
 
-       if (SM_stats_verbose) {
-           fprintf(SM_statsfile, "%8ld\n\n", alloc*sizeof(W_));
+       if (RTSflags.GcFlags.giveStats) {
+           fprintf(sf, "%8ld\n\n", alloc*sizeof(W_));
        }
 
 #if defined(GCap) || defined (GCgn)
        else {
-           fprintf(SM_statsfile, "%8ld %7.7s %6.6s %7.7s %6.6s",
+           fprintf(sf, "%8ld %7.7s %6.6s %7.7s %6.6s",
                    (GC_alloc_since_maj + alloc)*sizeof(W_), "", "", "", "");
-           fprintf(SM_statsfile, "  %3ld  %5.2f %5.2f\n\n",
+           fprintf(sf, "  %3ld  %5.2f %5.2f\n\n",
                    GC_min_since_maj, GC_min_time, GCe_min_time);
        }
        GC_min_no    += GC_min_since_maj;
@@ -414,55 +408,54 @@ stat_exit(alloc)
        GCe_tot_time += GCe_min_time;
        GC_tot_alloc += (ullong) (GC_alloc_since_maj + alloc);
        ullong_format_string(GC_tot_alloc*sizeof(W_), temp, rtsTrue/*commas*/);
-       fprintf(SM_statsfile, "%11s bytes allocated in the heap\n", temp);
+       fprintf(sf, "%11s bytes allocated in the heap\n", temp);
        if ( ResidencySamples > 0 ) {
            ullong_format_string(MaxResidency*sizeof(W_), temp, rtsTrue/*commas*/);
-           fprintf(SM_statsfile, "%11s bytes maximum residency (%.1f%%, %ld sample(s))\n",
+           fprintf(sf, "%11s bytes maximum residency (%.1f%%, %ld sample(s))\n",
                              temp,
-                             MaxResidency / (StgFloat) SM_word_heap_size * 100,
+                             MaxResidency / (StgDouble) RTSflags.GcFlags.heapSize * 100,
                              ResidencySamples);
        }
-       fprintf(SM_statsfile, "%11ld garbage collections performed (%ld major, %ld minor)\n\n",
+       fprintf(sf, "%11ld garbage collections performed (%ld major, %ld minor)\n\n",
                GC_maj_no + GC_min_no, GC_maj_no, GC_min_no);
 
 #else  /* ! generational */
 
        GC_tot_alloc += (ullong) alloc;
        ullong_format_string(GC_tot_alloc*sizeof(W_), temp, rtsTrue/*commas*/);
-       fprintf(SM_statsfile, "%11s bytes allocated in the heap\n", temp);
+       fprintf(sf, "%11s bytes allocated in the heap\n", temp);
        if ( ResidencySamples > 0 ) {
            ullong_format_string(MaxResidency*sizeof(W_), temp, rtsTrue/*commas*/);
-           fprintf(SM_statsfile, "%11s bytes maximum residency (%.1f%%, %ld sample(s))\n",
+           fprintf(sf, "%11s bytes maximum residency (%.1f%%, %ld sample(s))\n",
                              temp,
-                             MaxResidency / (StgFloat) SM_word_heap_size * 100,
+                             MaxResidency / (StgDouble) RTSflags.GcFlags.heapSize * 100,
                              ResidencySamples);
        }
-       fprintf(SM_statsfile, "%11ld garbage collections performed\n\n", GC_maj_no);
+       fprintf(sf, "%11ld garbage collections performed\n\n", GC_maj_no);
 
 #endif /* ! generational */
 
-       fprintf(SM_statsfile, "  INIT  time  %6.2fs  (%6.2fs elapsed)\n",
+       fprintf(sf, "  INIT  time  %6.2fs  (%6.2fs elapsed)\n",
                InitUserTime, InitElapsedTime);
-       fprintf(SM_statsfile, "  MUT   time  %6.2fs  (%6.2fs elapsed)\n",
+       fprintf(sf, "  MUT   time  %6.2fs  (%6.2fs elapsed)\n",
                time - GC_tot_time - InitUserTime, 
                 etime - GCe_tot_time - InitElapsedTime);
-       fprintf(SM_statsfile, "  GC    time  %6.2fs  (%6.2fs elapsed)\n",
+       fprintf(sf, "  GC    time  %6.2fs  (%6.2fs elapsed)\n",
                GC_tot_time, GCe_tot_time);
-       fprintf(SM_statsfile, "  Total time  %6.2fs  (%6.2fs elapsed)\n\n",
+       fprintf(sf, "  Total time  %6.2fs  (%6.2fs elapsed)\n\n",
                time, etime);
 
-       fprintf(SM_statsfile, "  %%GC time     %5.1f%%  (%.1f%% elapsed)\n\n",
+       fprintf(sf, "  %%GC time     %5.1f%%  (%.1f%% elapsed)\n\n",
                GC_tot_time*100./time, GCe_tot_time*100./etime);
 
        ullong_format_string((ullong)(GC_tot_alloc*sizeof(W_)/(time - GC_tot_time)), temp, rtsTrue/*commas*/);
-       fprintf(SM_statsfile, "  Alloc rate    %s bytes per MUT second\n\n", temp);
+       fprintf(sf, "  Alloc rate    %s bytes per MUT second\n\n", temp);
 
-       fprintf(SM_statsfile, "  Productivity %5.1f%% of total user, %.1f%% of total elapsed\n\n",
+       fprintf(sf, "  Productivity %5.1f%% of total user, %.1f%% of total elapsed\n\n",
                (time - GC_tot_time - InitUserTime) * 100. / time, 
                 (time - GC_tot_time - InitUserTime) * 100. / etime);
-       fflush(SM_statsfile);
-       fclose(SM_statsfile);
+       fflush(sf);
+       fclose(sf);
     }
 }
-
 \end{code}