X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Frts%2FRtsFlags.c;h=f9ddc832f18a90dd5b4ee5b5065de2a5e6084d2f;hb=6561aa4e8adf3e0a3a22f1de75b238b6463d1828;hp=3f44ccb342949bca8d85c66769c4cc6e5174de5e;hpb=f3d40a6e45424480276d701f20b1ab4ea4278af4;p=ghc-hetmet.git diff --git a/ghc/rts/RtsFlags.c b/ghc/rts/RtsFlags.c index 3f44ccb..f9ddc83 100644 --- a/ghc/rts/RtsFlags.c +++ b/ghc/rts/RtsFlags.c @@ -1,5 +1,5 @@ /* ----------------------------------------------------------------------------- - * $Id: RtsFlags.c,v 1.46 2001/08/08 14:14:08 simonmar Exp $ + * $Id: RtsFlags.c,v 1.56 2001/12/12 14:31:43 simonmar 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" @@ -249,12 +250,17 @@ void initRtsFlagsDefaults(void) #ifdef PROFILING RtsFlags.ProfFlags.doHeapProfile = rtsFalse; - RtsFlags.ProfFlags.profileFrequency = 20; + RtsFlags.ProfFlags.profileInterval = 100; RtsFlags.ProfFlags.showCCSOnException = rtsFalse; + RtsFlags.ProfFlags.maxRetainerSetSize = 8; RtsFlags.ProfFlags.modSelector = NULL; RtsFlags.ProfFlags.descrSelector = NULL; RtsFlags.ProfFlags.typeSelector = NULL; RtsFlags.ProfFlags.ccSelector = NULL; + RtsFlags.ProfFlags.ccsSelector = NULL; + RtsFlags.ProfFlags.retainerSelector = NULL; + RtsFlags.ProfFlags.bioSelector = NULL; + #elif defined(DEBUG) RtsFlags.ProfFlags.doHeapProfile = rtsFalse; #endif @@ -384,7 +390,7 @@ usage_text[] = { " -k Sets the initial thread stack size (default 1k) Egs: -K4k -K2m", "", " -A Sets the minimum allocation area size (default 256k) Egs: -A1m -A10k", -" -M Sets the maximum heap size (default 64M) Egs: -M256k -M1G", +" -M Sets the maximum heap size (default unlimited) Egs: -M256k -M1G", " -H Sets the minimum heap size (default 0M) Egs: -H24m -H1G", " -m Minimum % of heap which must be available (default 3%)", " -G Number of generations (default: 2)", @@ -412,17 +418,26 @@ usage_text[] = { # if defined(PROFILING) "", -" -hx Heap residency profile (XML) (output file .prof)", -" -h Heap residency profile (text) (output file .prof)", -" break-down: C = cost centre stack (default), M = module", -" D = closure description, Y = type description", +" -hx Heap residency profile (XML) (output file .prof)", +" -h Heap residency profile (hp2ps) (output file .hp)", +" break-down: c = cost centre stack (default)", +" m = module", +" d = closure description", +" y = type description", +" r = retainer", +" b = biography (LAG,DRAG,VOID,USE)", " A subset of closures may be selected thusly:", -" -hc{cc, cc ...} specific cost centre(s) (NOT STACKS!)", -" -hm{mod,mod...} all cost centres from the specified modules(s)", -" -hd{des,des...} closures with specified closure descriptions", -" -hy{typ,typ...} closures with specified type descriptions", +" -hc,... specific cost centre(s) (top of stack only)", +" -hC,... specific cost centre(s) (anywhere in stack)", +" -hm... all cost centres from the specified modules(s)", +" -hd,... closures with specified closure descriptions", +" -hy... closures with specified type descriptions", +" -hr... closures with specified retainers", +" -hb... closures with specified biographies (lag,drag,void,use)", +"", +" -R Set the maximum retainer set size (default: 8)", "", -" -i Time between heap samples (msec, default: 20)", +" -i Time between heap samples (msec, default: 100)", "", " -xc Show current cost centre stack on raising an exception", # endif @@ -484,6 +499,32 @@ strequal(const char *a, const char * b) return(strcmp(a, b) == 0); } +static void +splitRtsFlags(char *s, int *rts_argc, char *rts_argv[]) +{ + char *c1, *c2; + + c1 = s; + 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'); +} + void setupRtsFlags(int *argc, char *argv[], int *rts_argc, char *rts_argv[]) { @@ -503,40 +544,40 @@ setupRtsFlags(int *argc, char *argv[], int *rts_argc, char *rts_argv[]) *argc = 1; *rts_argc = 0; + // process arguments from the ghc_rts_opts global variable first. + // (arguments from the GHCRTS environment variable and the command + // line override these). + { + if (ghc_rts_opts != NULL) { + splitRtsFlags(ghc_rts_opts, rts_argc, rts_argv); + } + } + // 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'); + splitRtsFlags(ghc_rts, rts_argc, rts_argv); } } // 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 && ! strequal("--RTS", argv[arg]); arg++) { - if (strequal("+RTS", argv[arg])) { + 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])) { @@ -552,11 +593,9 @@ 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; @@ -774,9 +813,6 @@ 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]) { @@ -787,11 +823,26 @@ error = rtsTrue; RtsFlags.CcFlags.doCostCentres = COST_CENTRES_ALL; break; default: - RtsFlags.CcFlags.doCostCentres = COST_CENTRES_SUMMARY; - break; + if (rts_argv[arg][1] == 'P') { + RtsFlags.CcFlags.doCostCentres = + COST_CENTRES_VERBOSE; + } else { + RtsFlags.CcFlags.doCostCentres = + COST_CENTRES_SUMMARY; + } + break; } ) break; + case 'R': + PROFILING_BUILD_ONLY( + RtsFlags.ProfFlags.maxRetainerSetSize = atof(rts_argv[arg]+2); + + if (RtsFlags.ProfFlags.maxRetainerSetSize < 0) + bad_option( rts_argv[arg] ); + break; + ) break; + case 'h': /* serial heap profile */ #if !defined(PROFILING) && defined(DEBUG) switch (rts_argv[arg][2]) { @@ -809,58 +860,109 @@ error = rtsTrue; #else PROFILING_BUILD_ONLY( switch (rts_argv[arg][2]) { - case '\0': - case CCchar: - RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_CCS; - break; - case MODchar: - RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_MOD; - break; - case DESCRchar: - RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_DESCR; - break; - case TYPEchar: - RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_TYPE; + case '\0': + case 'C': + case 'c': + case 'M': + case 'm': + case 'D': + case 'd': + case 'Y': + case 'y': + case 'R': + case 'r': + case 'B': + case 'b': + if (rts_argv[arg][2] != '\0' && rts_argv[arg][3] != '\0') { + { + char *left = strchr(rts_argv[arg], '{'); + char *right = strrchr(rts_argv[arg], '}'); + + // curly braces are optional, for + // backwards compat. + if (left) + left = left+1; + else + left = rts_argv[arg] + 3; + + if (!right) + right = rts_argv[arg] + strlen(rts_argv[arg]); + + *right = '\0'; + + switch (rts_argv[arg][2]) { + case 'c': // cost centre label select + RtsFlags.ProfFlags.ccSelector = left; + break; + case 'C': + RtsFlags.ProfFlags.ccsSelector = left; + break; + case 'M': + case 'm': // cost centre module select + RtsFlags.ProfFlags.modSelector = left; + break; + case 'D': + case 'd': // closure descr select + RtsFlags.ProfFlags.descrSelector = left; + break; + case 'Y': + case 'y': // closure type select + RtsFlags.ProfFlags.typeSelector = left; + break; + case 'R': + case 'r': // retainer select + RtsFlags.ProfFlags.retainerSelector = left; + break; + case 'B': + case 'b': // biography select + RtsFlags.ProfFlags.bioSelector = left; + break; + } + } + break; + } + + if (RtsFlags.ProfFlags.doHeapProfile != 0) { + prog_belch("multiple heap profile options"); + error = rtsTrue; + break; + } + + switch (rts_argv[arg][2]) { + case '\0': + case 'C': + case 'c': + RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_CCS; + break; + case 'M': + case 'm': + RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_MOD; + break; + case 'D': + case 'd': + RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_DESCR; + break; + case 'Y': + case 'y': + RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_TYPE; + break; + case 'R': + case 'r': + RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_RETAINER; + break; + case 'B': + case 'b': + RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_LDV; + break; + } break; - case 'c': /* cost centre label select */ - case 'm': /* cost centre module select */ - case 'd': /* closure descr select */ - case 'y': /* closure type select */ - {char *left = strchr(rts_argv[arg], '{'); - char *right = strrchr(rts_argv[arg], '}'); - if (! left || ! right || - strrchr(rts_argv[arg], '{') != left || - strchr(rts_argv[arg], '}') != right) { - prog_belch( - "Invalid heap profiling selection bracketing\n %s\n", - rts_argv[arg]); - error = rtsTrue; - } else { - *right = '\0'; - switch (rts_argv[arg][2]) { - case 'c': /* cost centre label select */ - RtsFlags.ProfFlags.ccSelector = left + 1; - break; - case 'm': /* cost centre module select */ - RtsFlags.ProfFlags.modSelector = left + 1; - break; - case 'd': /* closure descr select */ - RtsFlags.ProfFlags.descrSelector = left + 1; - break; - case 'y': /* closure type select */ - RtsFlags.ProfFlags.typeSelector = left + 1; - break; - } - } - } - break; - default: + + default: prog_belch("invalid heap profile option: %s",rts_argv[arg]); error = rtsTrue; } ) - -#endif +#endif // PROFILING break; #if defined(PROFILING) @@ -876,11 +978,9 @@ error = rtsTrue; if (cst != 0 && cst < CS_MIN_MILLISECS) cst = CS_MIN_MILLISECS; - RtsFlags.ProfFlags.profileFrequency = cst; + RtsFlags.ProfFlags.profileInterval = cst; } - break; - #endif /* =========== CONCURRENT ========================= */ @@ -1990,6 +2090,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 */