[project @ 2001-10-01 11:09:02 by simonmar]
[ghc-hetmet.git] / ghc / rts / RtsFlags.c
index d9e51fc..a95d443 100644 (file)
@@ -1,5 +1,5 @@
 /* -----------------------------------------------------------------------------
- * $Id: RtsFlags.c,v 1.41 2001/07/23 17:23:19 simonmar Exp $
+ * $Id: RtsFlags.c,v 1.50 2001/08/31 11:42:44 sewardj Exp $
  *
  * (c) The AQUA Project, Glasgow University, 1994-1997
  * (c) The GHC Team, 1998-1999
@@ -21,6 +21,7 @@
 //@node Includes, Constants
 //@subsection Includes
 
+#include "PosixSource.h"
 #include "Rts.h"
 #include "RtsFlags.h"
 #include "RtsUtils.h"
@@ -223,7 +224,7 @@ void initRtsFlagsDefaults(void)
 
     RtsFlags.GcFlags.minAllocAreaSize   = (256 * 1024)        / BLOCK_SIZE;
     RtsFlags.GcFlags.minOldGenSize      = (1024 * 1024)       / BLOCK_SIZE;
-    RtsFlags.GcFlags.maxHeapSize       = (64  * 1024 * 1024) / BLOCK_SIZE;
+    RtsFlags.GcFlags.maxHeapSize       = 0;    /* off by default */
     RtsFlags.GcFlags.heapSizeSuggestion        = 0;    /* none */
     RtsFlags.GcFlags.pcFreeHeap                = 3;    /* 3% */
     RtsFlags.GcFlags.oldGenFactor       = 2;
@@ -235,9 +236,10 @@ void initRtsFlagsDefaults(void)
 #else
     RtsFlags.GcFlags.generations        = 2;
     RtsFlags.GcFlags.steps              = 2;
-    RtsFlags.GcFlags.compact            = rtsFalse;
     RtsFlags.GcFlags.squeezeUpdFrames  = rtsTrue;
 #endif
+    RtsFlags.GcFlags.compact            = rtsFalse;
+    RtsFlags.GcFlags.compactThreshold   = 30.0;
 #ifdef RTS_GTK_FRONTPANEL
     RtsFlags.GcFlags.frontpanel         = rtsFalse;
 #endif
@@ -383,12 +385,14 @@ usage_text[] = {
 "  -k<size> Sets the initial thread stack size (default 1k)  Egs: -K4k   -K2m",
 "",
 "  -A<size> Sets the minimum allocation area size (default 256k) Egs: -A1m -A10k",
-"  -M<size> Sets the maximum heap size (default 64M)  Egs: -M256k -M1G",
+"  -M<size> Sets the maximum heap size (default unlimited)  Egs: -M256k -M1G",
 "  -H<size> Sets the minimum heap size (default 0M)   Egs: -H24m  -H1G",
-"  -m<n>%   Minimum % of heap which must be available (default 3%)",
+"  -m<n>    Minimum % of heap which must be available (default 3%)",
 "  -G<n>    Number of generations (default: 2)",
 "  -T<n>    Number of steps in younger generations (default: 2)",
-"  -c       Enable compaction for the oldest generation",
+"  -c<n>    Auto-enable compaction of the oldest generation when live data is",
+"           at least <n>% of the maximum heap size set with -M (default: 30%)",
+"  -c       Enable compaction for all major collections",
 "",
 "  -t<file> One-line GC statistics  (default file: <program>.stat)",
 "  -s<file> Summary  GC statistics  (with -Sstderr going to stderr)",
@@ -403,9 +407,9 @@ usage_text[] = {
 #if defined(PROFILING) || defined(PAR)
 "",
 "  -px      Time/allocation profile (XML)  (output file <program>.prof)",
-"  -p<sort> Time/allocation profile        (output file <program>.prof)",
-"             sort: T = time (default), A = alloc, C = cost centre label",
-"  -P<sort> More detailed Time/Allocation profile",
+"  -p       Time/allocation profile        (output file <program>.prof)",
+"  -P       More detailed Time/Allocation profile",
+"  -Pa      Give information about *all* cost centres",
 
 # if defined(PROFILING)
 "",
@@ -467,6 +471,8 @@ usage_text[] = {
 "  -b...     All GranSim options start with -b; see GranSim User's Guide for details",
 #endif
 "",
+"RTS options may also be specified using the GHCRTS environment variable.",
+"",
 "Other RTS options may be available for programs compiled a different way.",
 "The GHC User's Guide has full details.",
 "",
@@ -492,17 +498,56 @@ setupRtsFlags(int *argc, char *argv[], int *rts_argc, char *rts_argv[])
     if ((last_slash = (char *) strrchr(argv[0], '/')) != NULL)
        strcpy(argv[0], last_slash+1);
 
-    /* Split arguments (argv) into PGM (argv) and RTS (rts_argv) parts */
-    /*   argv[0] must be PGM argument -- leave in argv                 */
-
     total_arg = *argc;
     arg = 1;
 
     *argc = 1;
     *rts_argc = 0;
 
-    for (mode = PGM; arg < total_arg && ! strequal("--RTS", argv[arg]); arg++) {
-       if (strequal("+RTS", argv[arg])) {
+    // process arguments from the GHCRTS environment variable first
+    // (arguments from the command line override these).
+    {
+       char *ghc_rts = getenv("GHCRTS");
+       char *c1, *c2, *s;
+
+       if (ghc_rts != NULL) {
+           c1 = ghc_rts;
+           do {
+               while (isspace(*c1)) { c1++; };
+               c2 = c1;
+               while (!isspace(*c2) && *c2 != '\0') { c2++; };
+
+               if (c1 == c2) { break; }
+
+               if (*rts_argc < MAX_RTS_ARGS-1) {
+                   s = malloc(c2-c1+1);
+                   strncpy(s, c1, c2-c1);
+                   s[c2-c1] = '\0';
+                   rts_argv[(*rts_argc)++] = s;
+               } else {
+                   barf("too many RTS arguments (max %d)", MAX_RTS_ARGS-1);
+               }
+
+               c1 = c2;
+           } while (*c1 != '\0');
+       }
+    }
+
+    // Split arguments (argv) into PGM (argv) and RTS (rts_argv) parts
+    //   argv[0] must be PGM argument -- leave in argv
+
+    for (mode = PGM; arg < total_arg; arg++) {
+       // The '--RTS' argument disables all future +RTS ... -RTS processing.
+       if (strequal("--RTS", argv[arg])) {
+           arg++;
+           break;
+       }
+       // The '--' argument is passed through to the program, but
+       // disables all further +RTS ... -RTS processing.
+       else if (strequal("--", argv[arg])) {
+           break;
+       }
+       else if (strequal("+RTS", argv[arg])) {
            mode = RTS;
        }
        else if (strequal("-RTS", argv[arg])) {
@@ -518,17 +563,14 @@ setupRtsFlags(int *argc, char *argv[], int *rts_argc, char *rts_argv[])
          barf("too many RTS arguments (max %d)", MAX_RTS_ARGS-1);
        }
     }
-    if (arg < total_arg) {
-       /* arg must be --RTS; process remaining program arguments */
-       while (++arg < total_arg) {
-           argv[(*argc)++] = argv[arg];
-       }
+    // process remaining program arguments
+    for (; arg < total_arg; arg++) {
+       argv[(*argc)++] = argv[arg];
     }
     argv[*argc] = (char *) 0;
     rts_argv[*rts_argc] = (char *) 0;
 
-    /* Process RTS (rts_argv) part: mainly to determine statsfile */
-
+    // Process RTS (rts_argv) part: mainly to determine statsfile
     for (arg = 0; arg < *rts_argc; arg++) {
        if (rts_argv[arg][0] != '-') {
            fflush(stdout);
@@ -620,8 +662,13 @@ error = rtsTrue;
                break;
 
              case 'c':
-               RtsFlags.GcFlags.compact = rtsTrue;
-               break;
+                 if (rts_argv[arg][2] != '\0') {
+                     RtsFlags.GcFlags.compactThreshold =
+                         atof(rts_argv[arg]+2);
+                 } else {
+                     RtsFlags.GcFlags.compact = rtsTrue;
+                 }
+                 break;
 
              case 'F':
                RtsFlags.GcFlags.oldGenFactor = atof(rts_argv[arg]+2);
@@ -736,18 +783,24 @@ error = rtsTrue;
              /* =========== PROFILING ========================== */
 
              case 'P': /* detailed cost centre profiling (time/alloc) */
-               COST_CENTRE_USING_BUILD_ONLY(
-               RtsFlags.CcFlags.doCostCentres = COST_CENTRES_VERBOSE;
-               )
              case 'p': /* cost centre profiling (time/alloc) */
                COST_CENTRE_USING_BUILD_ONLY(
                switch (rts_argv[arg][2]) {
                  case 'x':
                    RtsFlags.CcFlags.doCostCentres = COST_CENTRES_XML;
                    break;
-                 default:
-                   RtsFlags.CcFlags.doCostCentres = COST_CENTRES_SUMMARY;
+                 case 'a':
+                   RtsFlags.CcFlags.doCostCentres = COST_CENTRES_ALL;
                    break;
+                 default:
+                     if (rts_argv[arg][1] == 'P') {
+                         RtsFlags.CcFlags.doCostCentres =
+                             COST_CENTRES_VERBOSE;
+                     } else {
+                         RtsFlags.CcFlags.doCostCentres =
+                             COST_CENTRES_SUMMARY;
+                     }
+                     break;
                }
                ) break;
 
@@ -1949,6 +2002,7 @@ set_debug_options(nat n) {
         case 9: RtsFlags.DebugFlags.prof        = rtsTrue; break;
         case 10:  RtsFlags.DebugFlags.gran       = rtsTrue; break;
         case 11:  RtsFlags.DebugFlags.par        = rtsTrue; break;
+        case 12:  RtsFlags.DebugFlags.linker     = rtsTrue; break;
         default: barf("set_debug_options: only %d debug options expected",
                      MAX_DEBUG_OPTION);
       } /* switch */