[project @ 2004-02-12 02:04:59 by mthomas]
[ghc-hetmet.git] / ghc / rts / RtsFlags.c
index a8f02cb..1793104 100644 (file)
@@ -1,5 +1,5 @@
 /* -----------------------------------------------------------------------------
- * $Id: RtsFlags.c,v 1.60 2002/10/01 08:53:14 simonmar Exp $
+ * $Id: RtsFlags.c,v 1.72 2003/11/12 17:49:09 sof Exp $
  *
  * (c) The AQUA Project, Glasgow University, 1994-1997
  * (c) The GHC Team, 1998-1999
 #include "RtsFlags.h"
 #include "RtsUtils.h"
 #include "BlockAlloc.h"
-#include "Itimer.h"            /* CS_MIN_MILLISECS */
+#include "Timer.h"             /* CS_MIN_MILLISECS */
 #include "Profiling.h"
 
-#if defined(PROFILING) 
-#include "Itimer.h"
-#endif
-
 #ifdef HAVE_CTYPE_H
 #include <ctype.h>
 #endif
@@ -45,9 +41,10 @@ extern struct RTS_FLAGS RtsFlags;
 /*
  * Split argument lists
  */
-int     prog_argc; /* an "int" so as to match normal "argc" */
+int     prog_argc = 0;    /* an "int" so as to match normal "argc" */
 char  **prog_argv = NULL;
-int     rts_argc;  /* ditto */
+char   *prog_name = NULL; /* 'basename' of prog_argv[0] */
+int     rts_argc = 0;  /* ditto */
 char   *rts_argv[MAX_RTS_ARGS];
 
 //@node Constants, Static function decls, Includes
@@ -59,25 +56,9 @@ char   *rts_argv[MAX_RTS_ARGS];
 #define RTS 1
 #define PGM 0
 
-char *debug_opts_prefix[] = {
-  "_-", /* scheduler */
-  "_.", /* evaluator */
-  "_,", /* codegen */
-  "_;", /* weak */
-  "_~", /* gccafs */
-  "_@", /* gc */
-  "_#", /* block */
-  "_&", /* sanity */
-  "_:", /* stable */
-  "_!", /* prof */
-  "_=", /* gran */
-  "_=" /* par */
-  "_*" /* linker */
-};
-
 #if defined(GRAN)
 
-char *gran_debug_opts_strs[] = {
+static char *gran_debug_opts_strs[] = {
   "DEBUG (-bDe, -bD1): event_trace; printing event trace.\n",
   "DEBUG (-bDE, -bD2): event_stats; printing event statistics.\n",
   "DEBUG (-bDb, -bD4): bq; check blocking queues\n",
@@ -96,32 +77,13 @@ char *gran_debug_opts_strs[] = {
 };
 
 /* one character codes for the available debug options */
-char gran_debug_opts_flags[] = {
+static char gran_debug_opts_flags[] = {
   'e', 'E', 'b', 'G', 'q', 'f', 'r', 'F', 'u', 'S', ':', 'o', 'z', 'P', 't'
 };
 
-/* prefix strings printed with the debug messages of the corresponding type */
-char *gran_debug_opts_prefix[] = {
-  "", /* event_trace */ 
-  "", /* event_stats */
-  "##", /* bq */
-  "**", /* pack */
-  "^^", /* checkSparkQ */
-  "==", /* thunkStealing */
-  "^^", /* randomSteal */
-  "+-", /* findWork */
-  "", /* unused */
-  "++", /* pri */
-  "::", /* checkLight */
-  "##", /* sortedQ */
-  "", /* blockOnFetch */
-  "", /* packBuffer */
-  "" /* blockOnFetch_sanity */
-};
-
 #elif defined(PAR)
 
-char *par_debug_opts_strs[] = {
+static char *par_debug_opts_strs[] = {
   "DEBUG (-qDv, -qD1): verbose; be generally verbose with parallel related stuff.\n",
   "DEBUG (-qDq, -qD2): bq; print blocking queues.\n",
   "DEBUG (-qDs, -qD4): schedule; scheduling of parallel threads.\n",
@@ -139,27 +101,10 @@ char *par_debug_opts_strs[] = {
 };
 
 /* one character codes for the available debug options */
-char par_debug_opts_flags[] = {
+static char par_debug_opts_flags[] = {
   'v', 'q', 's', 'e', 'r', 'w', 'F', 'f', 'l', 'o', 'p', 'z'
 };
 
-/* prefix strings printed with the debug messages of the corresponding type */
-char *par_debug_opts_prefix[] = {
-  "  ", /* verbose */
-  "##", /* bq */
-  "--", /* schedule */
-  "!!", /* free */
-  "[]", /* resume */
-  ";;", /* weight */
-  "%%", /* fetch */
-  //",,", /* ack */
-  "$$", /* fish */
-  "", /* tables */
-  "**", /* packet */
-  "**" /* pack */
-  ":(" /* paranoia */
-};
-
 #endif /* PAR */
 
 //@node Static function decls, Command-line option parsing routines, Constants
@@ -229,7 +174,7 @@ void initRtsFlagsDefaults(void)
 
 #ifdef DEBUG
     RtsFlags.DebugFlags.scheduler      = rtsFalse;
-    RtsFlags.DebugFlags.evaluator      = rtsFalse;
+    RtsFlags.DebugFlags.interpreter    = rtsFalse;
     RtsFlags.DebugFlags.codegen                = rtsFalse;
     RtsFlags.DebugFlags.weak           = rtsFalse;
     RtsFlags.DebugFlags.gccafs         = rtsFalse;
@@ -250,6 +195,7 @@ void initRtsFlagsDefaults(void)
 #ifdef PROFILING
     RtsFlags.ProfFlags.doHeapProfile      = rtsFalse;
     RtsFlags.ProfFlags.profileInterval    = 100;
+    RtsFlags.ProfFlags.includeTSOs        = rtsFalse;
     RtsFlags.ProfFlags.showCCSOnException = rtsFalse;
     RtsFlags.ProfFlags.maxRetainerSetSize = 8;
     RtsFlags.ProfFlags.modSelector        = NULL;
@@ -386,7 +332,7 @@ usage_text[] = {
 "  -?       Prints this message and exits; the program is not executed",
 "",
 "  -K<size> Sets the maximum stack size (default 1M)  Egs: -K32k   -K512k",
-"  -k<size> Sets the initial thread stack size (default 1k)  Egs: -K4k   -K2m",
+"  -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 unlimited)  Egs: -M256k -M1G",
@@ -438,6 +384,8 @@ usage_text[] = {
 "",
 "  -i<sec>        Time between heap samples (seconds, default: 0.1)",
 "",
+"  -xt            Include threads (TSOs) in a heap profile",
+"",
 "  -xc      Show current cost centre stack on raising an exception",
 # endif
 #endif /* PROFILING or PAR */
@@ -463,7 +411,7 @@ usage_text[] = {
 "",
 #if defined(DEBUG)
 "  -Ds  DEBUG: scheduler",
-"  -De  DEBUG: evaluator",
+"  -Di  DEBUG: interpreter",
 "  -Dc  DEBUG: codegen",
 "  -Dw  DEBUG: weak",
 "  -DG  DEBUG: gccafs",
@@ -509,7 +457,7 @@ usage_text[] = {
 0
 };
 
-static __inline__ rtsBool
+STATIC_INLINE rtsBool
 strequal(const char *a, const char * b)
 {
     return(strcmp(a, b) == 0);
@@ -529,7 +477,7 @@ splitRtsFlags(char *s, int *rts_argc, char *rts_argv[])
        if (c1 == c2) { break; }
        
        if (*rts_argc < MAX_RTS_ARGS-1) {
-           s = malloc(c2-c1+1);
+           s = stgMallocBytes(c2-c1+1, "RtsFlags.c:splitRtsFlags()");
            strncpy(s, c1, c2-c1);
            s[c2-c1] = '\0';
            rts_argv[(*rts_argc)++] = s;
@@ -550,9 +498,17 @@ setupRtsFlags(int *argc, char *argv[], int *rts_argc, char *rts_argv[])
     char *last_slash;
 
     /* Remove directory from argv[0] -- default files in current directory */
-
-    if ((last_slash = (char *) strrchr(argv[0], '/')) != NULL)
-       strcpy(argv[0], last_slash+1);
+    if ((last_slash = (char *) strrchr(argv[0], 
+#if !defined(mingw32_TARGET_OS)
+                                      '/')
+#else
+                                      '\\')
+#endif
+                                      ) != NULL) {
+       prog_name = last_slash+1;
+    } else {
+       prog_name = argv[0];
+    }
 
     total_arg = *argc;
     arg = 1;
@@ -569,7 +525,7 @@ setupRtsFlags(int *argc, char *argv[], int *rts_argc, char *rts_argv[])
        }
     }
 
-    // process arguments from the GHCRTS environment variable first
+    // process arguments from the GHCRTS environment variable next
     // (arguments from the command line override these).
     {
        char *ghc_rts = getenv("GHCRTS");
@@ -733,8 +689,8 @@ error = rtsTrue;
                      case 's':
                          RtsFlags.DebugFlags.scheduler = rtsTrue;
                          break;
-                     case 'e':
-                         RtsFlags.DebugFlags.evaluator = rtsTrue;
+                     case 'i':
+                         RtsFlags.DebugFlags.interpreter = rtsTrue;
                          break;
                      case 'c':
                          RtsFlags.DebugFlags.codegen = rtsTrue;
@@ -769,6 +725,9 @@ error = rtsTrue;
                      case 'l':
                          RtsFlags.DebugFlags.linker = rtsTrue;
                          break;
+                     case 'a':
+                         RtsFlags.DebugFlags.apply = rtsTrue;
+                         break;
                      default:
                          bad_option( rts_argv[arg] );
                      }
@@ -1118,8 +1077,15 @@ error = rtsTrue;
 
                   case 'c': /* Debugging tool: show current cost centre on an exception */
                     PROFILING_BUILD_ONLY(
-                    RtsFlags.ProfFlags.showCCSOnException = rtsTrue;
-                    ) break;
+                       RtsFlags.ProfFlags.showCCSOnException = rtsTrue;
+                       );
+                   break;
+
+               case 't':  /* Include memory used by TSOs in a heap profile */
+                   PROFILING_BUILD_ONLY(
+                       RtsFlags.ProfFlags.includeTSOs = rtsTrue;
+                       );
+                   break;
 
                   /* The option prefix '-xx' is reserved for future extension.  KSW 1999-11. */
 
@@ -1439,8 +1405,7 @@ process_gran_option(int arg, int *rts_argc, char *rts_argv[], rtsBool *error)
              } else if (RtsFlags.GranFlags.proc > MAX_PROC || 
                         RtsFlags.GranFlags.proc < 1)
                {
-                 fprintf(stderr,"setupRtsFlags: no more than %u processors
-allowed\n", 
+                 fprintf(stderr,"setupRtsFlags: no more than %u processors allowed\n",
                          MAX_PROC);
                  *error = rtsTrue;
                }