1 /* -----------------------------------------------------------------------------
2 * $Id: RtsFlags.c,v 1.15 1999/08/25 16:11:50 simonmar Exp $
4 * (c) The AQUA Project, Glasgow University, 1994-1997
5 * (c) The GHC Team, 1998-1999
7 * Functions for parsing the argument list.
9 * ---------------------------------------------------------------------------*/
14 #include "BlockAlloc.h"
25 extern struct RTS_FLAGS RtsFlags;
28 * Split argument lists
30 int prog_argc; /* an "int" so as to match normal "argc" */
31 char **prog_argv = NULL;
32 int rts_argc; /* ditto */
33 char *rts_argv[MAX_RTS_ARGS];
36 * constants, used later
41 /* -----------------------------------------------------------------------------
43 -------------------------------------------------------------------------- */
45 static FILE * /* return NULL on error */
48 int argc, char *argv[],
49 int rts_argc, char *rts_argv[],
50 const char *FILENAME_FMT);
52 static I_ decode(const char *s);
53 static void bad_option(const char *s);
55 /* -----------------------------------------------------------------------------
56 * Command-line option parsing routines.
57 * ---------------------------------------------------------------------------*/
59 void initRtsFlagsDefaults(void)
61 RtsFlags.GcFlags.statsFile = NULL;
62 RtsFlags.GcFlags.giveStats = NO_GC_STATS;
64 RtsFlags.GcFlags.maxStkSize = (1024 * 1024) / sizeof(W_);
65 RtsFlags.GcFlags.initialStkSize = 1024 / sizeof(W_);
67 RtsFlags.GcFlags.minAllocAreaSize = (256 * 1024) / BLOCK_SIZE;
68 RtsFlags.GcFlags.minOldGenSize = (1024 * 1024) / BLOCK_SIZE;
69 RtsFlags.GcFlags.maxHeapSize = (64 * 1024 * 1024) / BLOCK_SIZE;
70 RtsFlags.GcFlags.heapSizeSuggestion = 0; /* none */
71 RtsFlags.GcFlags.pcFreeHeap = 3; /* 3% */
72 RtsFlags.GcFlags.oldGenFactor = 2;
73 RtsFlags.GcFlags.generations = 2;
74 RtsFlags.GcFlags.steps = 2;
76 RtsFlags.GcFlags.forceGC = rtsFalse;
77 RtsFlags.GcFlags.forcingInterval = 5000000; /* 5MB (or words?) */
78 RtsFlags.GcFlags.ringBell = rtsFalse;
80 RtsFlags.GcFlags.squeezeUpdFrames = rtsTrue;
82 #if defined(PROFILING) || defined(PAR)
83 RtsFlags.CcFlags.doCostCentres = 0;
84 RtsFlags.CcFlags.sortBy = SORTCC_TIME;
85 #endif /* PROFILING or PAR */
88 RtsFlags.ProfFlags.doHeapProfile = rtsFalse;
90 RtsFlags.ProfFlags.ccSelector = NULL;
91 RtsFlags.ProfFlags.modSelector = NULL;
92 RtsFlags.ProfFlags.grpSelector = NULL;
93 RtsFlags.ProfFlags.descrSelector = NULL;
94 RtsFlags.ProfFlags.typeSelector = NULL;
95 RtsFlags.ProfFlags.kindSelector = NULL;
97 RtsFlags.ProfFlags.doHeapProfile = rtsFalse;
100 RtsFlags.ConcFlags.ctxtSwitchTime = CS_MIN_MILLISECS; /* In milliseconds */
102 RtsFlags.ParFlags.parallelStats = rtsFalse;
103 RtsFlags.ParFlags.granSimStats = rtsFalse;
104 RtsFlags.ParFlags.granSimStats_Binary = rtsFalse;
106 RtsFlags.ParFlags.outputDisabled = rtsFalse;
108 RtsFlags.ParFlags.packBufferSize = 1024;
109 RtsFlags.ParFlags.maxLocalSparks = 4096;
113 RtsFlags.GranFlags.granSimStats = rtsFalse;
114 RtsFlags.GranFlags.granSimStats_suppressed = rtsFalse;
115 RtsFlags.GranFlags.granSimStats_Binary = rtsFalse;
116 RtsFlags.GranFlags.granSimStats_Sparks = rtsFalse;
117 RtsFlags.GranFlags.granSimStats_Heap = rtsFalse;
118 RtsFlags.GranFlags.labelling = rtsFalse;
119 RtsFlags.GranFlags.packBufferSize = 1024;
120 RtsFlags.GranFlags.packBufferSize_internal = GRANSIM_DEFAULT_PACK_BUFFER_SIZE;
122 RtsFlags.GranFlags.proc = MAX_PROC;
123 RtsFlags.GranFlags.max_fishes = MAX_FISHES;
124 RtsFlags.GranFlags.time_slice = GRAN_TIME_SLICE;
125 RtsFlags.GranFlags.Light = rtsFalse;
127 RtsFlags.GranFlags.gran_latency = LATENCY;
128 RtsFlags.GranFlags.gran_additional_latency = ADDITIONAL_LATENCY;
129 RtsFlags.GranFlags.gran_fetchtime = FETCHTIME;
130 RtsFlags.GranFlags.gran_lunblocktime = LOCALUNBLOCKTIME;
131 RtsFlags.GranFlags.gran_gunblocktime = GLOBALUNBLOCKTIME;
132 RtsFlags.GranFlags.gran_mpacktime = MSGPACKTIME;
133 RtsFlags.GranFlags.gran_munpacktime = MSGUNPACKTIME;
134 RtsFlags.GranFlags.gran_mtidytime = MSGTIDYTIME;
136 RtsFlags.GranFlags.gran_threadcreatetime = THREADCREATETIME;
137 RtsFlags.GranFlags.gran_threadqueuetime = THREADQUEUETIME;
138 RtsFlags.GranFlags.gran_threaddescheduletime = THREADDESCHEDULETIME;
139 RtsFlags.GranFlags.gran_threadscheduletime = THREADSCHEDULETIME;
140 RtsFlags.GranFlags.gran_threadcontextswitchtime = THREADCONTEXTSWITCHTIME;
142 RtsFlags.GranFlags.gran_arith_cost = ARITH_COST;
143 RtsFlags.GranFlags.gran_branch_cost = BRANCH_COST;
144 RtsFlags.GranFlags.gran_load_cost = LOAD_COST;
145 RtsFlags.GranFlags.gran_store_cost = STORE_COST;
146 RtsFlags.GranFlags.gran_float_cost = FLOAT_COST;
148 RtsFlags.GranFlags.gran_heapalloc_cost = HEAPALLOC_COST;
150 RtsFlags.GranFlags.gran_pri_spark_overhead = PRI_SPARK_OVERHEAD;
151 RtsFlags.GranFlags.gran_pri_sched_overhead = PRI_SCHED_OVERHEAD;
153 RtsFlags.GranFlags.DoFairSchedule = rtsFalse;
154 RtsFlags.GranFlags.DoReScheduleOnFetch = rtsFalse;
155 RtsFlags.GranFlags.DoStealThreadsFirst = rtsFalse;
156 RtsFlags.GranFlags.SimplifiedFetch = rtsFalse;
157 RtsFlags.GranFlags.DoAlwaysCreateThreads = rtsFalse;
158 RtsFlags.GranFlags.DoGUMMFetching = rtsFalse;
159 RtsFlags.GranFlags.DoThreadMigration = rtsFalse;
160 RtsFlags.GranFlags.FetchStrategy = 2;
161 RtsFlags.GranFlags.PreferSparksOfLocalNodes = rtsFalse;
162 RtsFlags.GranFlags.DoPrioritySparking = rtsFalse;
163 RtsFlags.GranFlags.DoPriorityScheduling = rtsFalse;
164 RtsFlags.GranFlags.SparkPriority = 0;
165 RtsFlags.GranFlags.SparkPriority2 = 0;
166 RtsFlags.GranFlags.RandomPriorities = rtsFalse;
167 RtsFlags.GranFlags.InversePriorities = rtsFalse;
168 RtsFlags.GranFlags.IgnorePriorities = rtsFalse;
169 RtsFlags.GranFlags.ThunksToPack = 0;
170 RtsFlags.GranFlags.RandomSteal = rtsTrue;
171 RtsFlags.GranFlags.NoForward = rtsFalse;
172 RtsFlags.GranFlags.PrintFetchMisses = rtsFalse;
174 RtsFlags.GranFlags.debug = 0x0;
175 RtsFlags.GranFlags.event_trace = rtsFalse;
176 RtsFlags.GranFlags.event_trace_all = rtsFalse;
180 RtsFlags.TickyFlags.showTickyStats = rtsFalse;
181 RtsFlags.TickyFlags.tickyFile = NULL;
188 "Usage: <prog> <args> [+RTS <rtsopts> | -RTS <args>] ... --RTS <args>",
190 " +RTS Indicates run time system options follow",
191 " -RTS Indicates program arguments follow",
192 " --RTS Indicates that ALL subsequent arguments will be given to the",
193 " program (including any of these RTS flags)",
195 "The following run time system options are available:",
197 " -? -f Prints this message and exits; the program is not executed",
199 " -K<size> Sets the maximum stack size (default 1M) Egs: -K32k -K512k",
200 " -k<size> Sets the initial thread stack size (default 1k) Egs: -K4k -K2m",
202 " -A<size> Sets the minimum allocation area size (default 256k) Egs: -A1m -A10k",
203 " -M<size> Sets the maximum heap size (default 64M) Egs: -M256k -M1G",
204 " -H<size> Sets the minimum heap size (default 0M) Egs: -H24m -H1G",
205 " -m<n>% Minimum % of heap which must be available (default 3%)",
206 " -G<n> Number of generations (default: 2)",
207 " -T<n> Number of steps in younger generations (default: 2)",
208 " -s<file> Summary GC statistics (default file: <program>.stat)",
209 " -S<file> Detailed GC statistics (with -Sstderr going to stderr)",
212 " -Z Don't squeeze out update frames on stack overflow",
213 " -B Sound the bell at the start of each garbage collection",
214 #if defined(PROFILING) || defined(PAR)
216 " -p<sort> Produce cost centre time profile (output file <program>.prof)",
217 " sort: T = time (default), A = alloc, C = cost centre label",
218 " -P<sort> Produce serial time profile (output file <program>.time)",
219 " and a -p profile with detailed tick/alloc info",
220 # if defined(PROFILING)
222 " -h<break-down> Heap residency profile (output file <program>.hp)",
223 " break-down: C = cost centre (default), M = module, G = group",
224 " D = closure description, Y = type description",
225 " T<ints>,<start> = time closure created",
226 " ints: no. of interval bands plotted (default 18)",
227 " start: seconds after which intervals start (default 0.0)",
228 " A subset of closures may be selected by the attached cost centre using:",
229 " -c{mod:lab,mod:lab...}, specific module:label cost centre(s)",
230 " -m{mod,mod...} all cost centres from the specified modules(s)",
231 " -g{grp,grp...} all cost centres from the specified group(s)",
232 " Selections can also be made by description, type, kind and age:",
233 " -d{des,des...} closures with specified closure descriptions",
234 " -y{typ,typ...} closures with specified type descriptions",
235 " -k{knd,knd...} closures of the specified kinds",
236 " -a<age> closures which survived <age> complete intervals",
237 " The selection logic used is summarised as follows:",
238 " ([-c] or [-m] or [-g]) and ([-d] or [-y] or [-k]) and [-a]",
239 " where an option is true if not specified",
242 " -z<tbl><size> set hash table <size> for <tbl> (C, M, G, D or Y)",
244 " -i<secs> Number of seconds in a profiling interval (default 1.0):",
245 " heap profile (-h) and/or serial time profile (-P) frequency",
246 #endif /* PROFILING or PAR */
247 #if !defined(PROFILING) && defined(DEBUG)
249 " -h<break-down> Debugging Heap residency profile",
250 " (output file <program>.hp)",
251 " break-down: L = closure label (default)",
252 " T = closure type (constructor, thunk etc.)",
255 #if defined(TICKY_TICKY)
256 " -r<file> Produce reduction profiling statistics (with -rstderr for stderr)",
260 " -N<n> Use <n> PVMish processors in parallel (default: 2)",
261 /* NB: the -N<n> is implemented by the driver!! */
263 " -C<secs> Context-switch interval in seconds",
264 " (0 or no argument means switch as often as possible)",
265 " the default is .01 sec; resolution is .01 sec",
267 " -q Enable activity profile (output files in ~/<program>*.gr)",
268 " -qb Enable binary activity profile (output file /tmp/<program>.gb)",
269 " -Q<size> Set pack-buffer size (default: 1024)",
272 " -d Turn on PVM-ish debugging",
273 " -O Disable output for performance measurement",
275 # ifdef GRAN /* ToDo: fill in decent Docu here */
276 " -b... All GranSim options start with -b; see GranSim User's Guide for details",
279 "Other RTS options may be available for programs compiled a different way.",
280 "The GHC User's Guide has full details.",
285 static __inline__ rtsBool
286 strequal(const char *a, const char * b)
288 return(strcmp(a, b) == 0);
292 setupRtsFlags(int *argc, char *argv[], int *rts_argc, char *rts_argv[])
294 rtsBool error = rtsFalse;
299 /* Remove directory from argv[0] -- default files in current directory */
301 if ((last_slash = (char *) strrchr(argv[0], '/')) != NULL)
302 strcpy(argv[0], last_slash+1);
304 /* Split arguments (argv) into PGM (argv) and RTS (rts_argv) parts */
305 /* argv[0] must be PGM argument -- leave in argv */
313 for (mode = PGM; arg < total_arg && ! strequal("--RTS", argv[arg]); arg++) {
314 if (strequal("+RTS", argv[arg])) {
317 else if (strequal("-RTS", argv[arg])) {
320 else if (mode == RTS && *rts_argc < MAX_RTS_ARGS-1) {
321 rts_argv[(*rts_argc)++] = argv[arg];
323 else if (mode == PGM) {
324 argv[(*argc)++] = argv[arg];
327 barf("too many RTS arguments (max %d)", MAX_RTS_ARGS-1);
330 if (arg < total_arg) {
331 /* arg must be --RTS; process remaining program arguments */
332 while (++arg < total_arg) {
333 argv[(*argc)++] = argv[arg];
336 argv[*argc] = (char *) 0;
337 rts_argv[*rts_argc] = (char *) 0;
339 /* Process RTS (rts_argv) part: mainly to determine statsfile */
341 for (arg = 0; arg < *rts_argc; arg++) {
342 if (rts_argv[arg][0] != '-') {
344 fprintf(stderr, "setupRtsFlags: Unexpected RTS argument: %s\n",
349 switch(rts_argv[arg][1]) {
351 /* process: general args, then PROFILING-only ones,
352 then CONCURRENT-only, PARallel-only, GRAN-only,
353 TICKY-only (same order as defined in RtsFlags.lh);
354 within those groups, mostly in case-insensitive
359 # define TICKY_BUILD_ONLY(x) x
361 # define TICKY_BUILD_ONLY(x) \
362 fprintf(stderr, "setupRtsFlags: GHC not built for: ticky-ticky stats\n"); \
366 #if defined(PROFILING)
367 # define COST_CENTRE_USING_BUILD_ONLY(x) x
369 # define COST_CENTRE_USING_BUILD_ONLY(x) \
370 fprintf(stderr, "setupRtsFlags: GHC not built for: -prof or -parallel\n"); \
375 # define PROFILING_BUILD_ONLY(x) x
377 # define PROFILING_BUILD_ONLY(x) \
378 fprintf(stderr, "setupRtsFlags: GHC not built for: -prof\n"); \
383 # define PAR_BUILD_ONLY(x) x
385 # define PAR_BUILD_ONLY(x) \
386 fprintf(stderr, "setupRtsFlags: GHC not built for: -parallel\n"); \
391 # define GRAN_BUILD_ONLY(x) x
393 # define GRAN_BUILD_ONLY(x) \
394 fprintf(stderr, "setupRtsFlags: GHC not built for: -gransim\n"); \
398 /* =========== GENERAL ========================== */
405 RtsFlags.GcFlags.minAllocAreaSize
406 = decode(rts_argv[arg]+2) / BLOCK_SIZE;
407 if (RtsFlags.GcFlags.minAllocAreaSize <= 0) {
408 bad_option(rts_argv[arg]);
413 RtsFlags.GcFlags.ringBell = rtsTrue;
417 RtsFlags.GcFlags.oldGenFactor = atof(rts_argv[arg]+2);
419 if (RtsFlags.GcFlags.oldGenFactor < 0)
420 bad_option( rts_argv[arg] );
425 /* hack warning: interpret the flags as a binary number */
427 I_ n = decode(rts_argv[arg]+2);
428 if (n &1) RtsFlags.DebugFlags.scheduler = rtsTrue;
429 if ((n>>1)&1) RtsFlags.DebugFlags.evaluator = rtsTrue;
430 if ((n>>2)&1) RtsFlags.DebugFlags.codegen = rtsTrue;
431 if ((n>>3)&1) RtsFlags.DebugFlags.weak = rtsTrue;
432 if ((n>>4)&1) RtsFlags.DebugFlags.gccafs = rtsTrue;
433 if ((n>>5)&1) RtsFlags.DebugFlags.gc = rtsTrue;
434 if ((n>>6)&1) RtsFlags.DebugFlags.block_alloc = rtsTrue;
435 if ((n>>7)&1) RtsFlags.DebugFlags.sanity = rtsTrue;
436 if ((n>>8)&1) RtsFlags.DebugFlags.stable = rtsTrue;
437 if ((n>>9)&1) RtsFlags.DebugFlags.prof = rtsTrue;
443 RtsFlags.GcFlags.maxStkSize =
444 decode(rts_argv[arg]+2) / sizeof(W_);
446 if (RtsFlags.GcFlags.maxStkSize == 0)
447 bad_option( rts_argv[arg] );
451 RtsFlags.GcFlags.initialStkSize =
452 decode(rts_argv[arg]+2) / sizeof(W_);
454 if (RtsFlags.GcFlags.initialStkSize == 0)
455 bad_option( rts_argv[arg] );
459 RtsFlags.GcFlags.maxHeapSize =
460 decode(rts_argv[arg]+2) / BLOCK_SIZE;
461 /* user give size in *bytes* but "maxHeapSize" is in *blocks* */
463 if (RtsFlags.GcFlags.maxHeapSize <= 0) {
464 bad_option(rts_argv[arg]);
469 RtsFlags.GcFlags.pcFreeHeap = atof(rts_argv[arg]+2);
471 if (RtsFlags.GcFlags.pcFreeHeap < 0 ||
472 RtsFlags.GcFlags.pcFreeHeap > 100)
473 bad_option( rts_argv[arg] );
477 RtsFlags.GcFlags.generations = decode(rts_argv[arg]+2);
478 if (RtsFlags.GcFlags.generations < 1) {
479 bad_option(rts_argv[arg]);
484 RtsFlags.GcFlags.steps = decode(rts_argv[arg]+2);
485 if (RtsFlags.GcFlags.steps < 1) {
486 bad_option(rts_argv[arg]);
491 RtsFlags.GcFlags.heapSizeSuggestion =
492 decode(rts_argv[arg]+2) / BLOCK_SIZE;
494 if (RtsFlags.GcFlags.heapSizeSuggestion <= 0) {
495 bad_option(rts_argv[arg]);
499 case 'j': /* force GC option */
500 RtsFlags.GcFlags.forceGC = rtsTrue;
501 if (rts_argv[arg][2]) {
502 RtsFlags.GcFlags.forcingInterval
503 = decode(rts_argv[arg]+2) / sizeof(W_);
508 RtsFlags.GcFlags.giveStats ++;
511 RtsFlags.GcFlags.giveStats ++;
513 /* Opening all those files would almost certainly fail... */
514 RtsFlags.ParFlags.parallelStats = rtsTrue;
515 RtsFlags.GcFlags.statsFile = stderr; /* temporary; ToDo: rm */
517 RtsFlags.GcFlags.statsFile
518 = open_stats_file(arg, *argc, argv,
519 *rts_argc, rts_argv, STAT_FILENAME_FMT);
521 if (RtsFlags.GcFlags.statsFile == NULL) error = rtsTrue;
526 RtsFlags.GcFlags.squeezeUpdFrames = rtsFalse;
529 /* =========== PROFILING ========================== */
531 case 'P': /* detailed cost centre profiling (time/alloc) */
532 COST_CENTRE_USING_BUILD_ONLY(
533 RtsFlags.CcFlags.doCostCentres++;
535 case 'p': /* cost centre profiling (time/alloc) */
536 COST_CENTRE_USING_BUILD_ONLY(
537 RtsFlags.CcFlags.doCostCentres++;
539 switch (rts_argv[arg][2]) {
543 RtsFlags.CcFlags.sortBy = rts_argv[arg][2];
546 RtsFlags.CcFlags.sortBy = SORTCC_TIME;
551 case 'i': /* serial profiling -- initial timer interval */
552 COST_CENTRE_USING_BUILD_ONLY(
553 interval_ticks = (I_) ((atof(rts_argv[arg]+2) * TICK_FREQUENCY));
554 if (interval_ticks <= 0)
558 case 'h': /* serial heap profile */
559 #if !defined(PROFILING) && defined(DEBUG)
560 switch (rts_argv[arg][2]) {
563 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_INFOPTR;
566 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_CLOSURE_TYPE;
569 fprintf(stderr, "Invalid heap profile option: %s\n",
574 PROFILING_BUILD_ONLY(
575 switch (rts_argv[arg][2]) {
578 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_CC;
581 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_MOD;
584 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_GRP;
587 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_DESCR;
590 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_TYPE;
593 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_TIME;
594 if (rts_argv[arg][3]) {
595 char *start_str = strchr(rts_argv[arg]+3, ',');
597 if (start_str) *start_str = '\0';
599 if ((intervals = decode(rts_argv[arg]+3)) != 0) {
600 time_intervals = (hash_t) intervals;
601 /* ToDo: and what if it *is* zero intervals??? */
604 earlier_ticks = (I_)((atof(start_str + 1) * TICK_FREQUENCY));
609 fprintf(stderr, "Invalid heap profile option: %s\n",
617 case 'z': /* size of index tables */
618 PROFILING_BUILD_ONLY(
619 switch (rts_argv[arg][2]) {
621 max_cc_no = (hash_t) decode(rts_argv[arg]+3);
622 if (max_cc_no == 0) {
623 fprintf(stderr, "Bad number of cost centres %s\n", rts_argv[arg]);
628 max_mod_no = (hash_t) decode(rts_argv[arg]+3);
629 if (max_mod_no == 0) {
630 fprintf(stderr, "Bad number of modules %s\n", rts_argv[arg]);
635 max_grp_no = (hash_t) decode(rts_argv[arg]+3);
636 if (max_grp_no == 0) {
637 fprintf(stderr, "Bad number of groups %s\n", rts_argv[arg]);
642 max_descr_no = (hash_t) decode(rts_argv[arg]+3);
643 if (max_descr_no == 0) {
644 fprintf(stderr, "Bad number of closure descriptions %s\n", rts_argv[arg]);
649 max_type_no = (hash_t) decode(rts_argv[arg]+3);
650 if (max_type_no == 0) {
651 fprintf(stderr, "Bad number of type descriptions %s\n", rts_argv[arg]);
656 fprintf(stderr, "Invalid index table size option: %s\n",
662 case 'c': /* cost centre label select */
663 case 'g': /* cost centre group select */
664 case 'd': /* closure descr select */
665 case 'y': /* closure type select */
666 PROFILING_BUILD_ONLY(
667 {char *left = strchr(rts_argv[arg], '{');
668 char *right = strrchr(rts_argv[arg], '}');
670 if (! left || ! right ||
671 strrchr(rts_argv[arg], '{') != left ||
672 strchr(rts_argv[arg], '}') != right) {
673 fprintf(stderr, "Invalid heap profiling selection bracketing\n %s\n", rts_argv[arg]);
677 switch (rts_argv[arg][1]) {
678 case 'c': /* cost centre label select */
679 RtsFlags.ProfFlags.ccSelector = left + 1;
681 case 'm': /* cost centre module select */
682 RtsFlags.ProfFlags.modSelector = left + 1;
684 case 'g': /* cost centre group select */
685 RtsFlags.ProfFlags.grpSelector = left + 1;
687 case 'd': /* closure descr select */
688 RtsFlags.ProfFlags.descrSelector = left + 1;
690 case 'y': /* closure type select */
691 RtsFlags.ProfFlags.typeSelector = left + 1;
693 case 'k': /* closure kind select */
694 RtsFlags.ProfFlags.kindSelector = left + 1;
700 /* =========== CONCURRENT ========================= */
701 case 'C': /* context switch interval */
702 if (rts_argv[arg][2] == '\0')
703 RtsFlags.ConcFlags.ctxtSwitchTime = 0;
707 /* Convert to milliseconds */
708 cst = (I_) ((atof(rts_argv[arg]+2) * 1000));
709 cst = (cst / CS_MIN_MILLISECS) * CS_MIN_MILLISECS;
710 if (cst < CS_MIN_MILLISECS)
711 cst = CS_MIN_MILLISECS;
713 RtsFlags.ConcFlags.ctxtSwitchTime = cst;
717 /* =========== PARALLEL =========================== */
720 if (rts_argv[arg][2] != '\0') { /* otherwise, stick w/ the default */
722 RtsFlags.ParFlags.maxLocalSparks
723 = strtol(rts_argv[arg]+2, (char **) NULL, 10);
725 if (RtsFlags.ParFlags.maxLocalSparks <= 0) {
726 fprintf(stderr, "setupRtsFlags: bad value for -e\n");
734 RtsFlags.ParFlags.outputDisabled = rtsTrue;
737 case 'q': /* activity profile option */
739 if (rts_argv[arg][2] == 'b')
740 RtsFlags.ParFlags.granSimStats_Binary = rtsTrue;
742 RtsFlags.ParFlags.granSimStats = rtsTrue;
746 case 'q': /* quasi-parallel profile option */
748 if (rts_argv[arg][2] == 'v')
755 case 'Q': /* Set pack buffer size */
757 if (rts_argv[arg][2] != '\0') {
758 RtsFlags.ParFlags.packBufferSize = decode(rts_argv[arg]+2);
760 fprintf(stderr, "setupRtsFlags: missing size of PackBuffer (for -Q)\n");
765 /* =========== GRAN =============================== */
769 process_gran_option(arg, rts_argc, rts_argv, &error);
772 /* =========== TICKY ============================== */
774 case 'r': /* Basic profiling stats */
777 RtsFlags.TickyFlags.showTickyStats = rtsTrue;
778 RtsFlags.TickyFlags.tickyFile
779 = open_stats_file(arg, *argc, argv,
780 *rts_argc, rts_argv, TICKY_FILENAME_FMT);
782 if (RtsFlags.TickyFlags.tickyFile == NULL) error = rtsTrue;
785 /* =========== OH DEAR ============================ */
787 fprintf(stderr, "setupRtsFlags: Unknown RTS option: %s\n",rts_argv[arg]);
797 for (p = usage_text; *p; p++)
798 fprintf(stderr, "%s\n", *p);
799 stg_exit(EXIT_FAILURE);
804 static FILE * /* return NULL on error */
807 int argc, char *argv[],
808 int rts_argc, char *rts_argv[],
809 const char *FILENAME_FMT)
813 if (strequal(rts_argv[arg]+2, "stderr")) /* use real stderr */
815 else if (rts_argv[arg][2] != '\0') /* stats file specified */
816 f = fopen(rts_argv[arg]+2,"w");
818 char stats_filename[STATS_FILENAME_MAXLEN]; /* default <program>.<ext> */
819 sprintf(stats_filename, FILENAME_FMT, argv[0]);
820 f = fopen(stats_filename,"w");
823 fprintf(stderr, "Can't open stats file %s\n", rts_argv[arg]+2);
825 /* Write argv and rtsv into start of stats file */
827 for(count = 0; count < argc; count++)
828 fprintf(f, "%s ", argv[count]);
830 for(count = 0; count < rts_argc; count++)
831 fprintf(f, "%s ", rts_argv[count]);
839 decode(const char *s)
850 if (c == 'g' || c == 'G')
851 m *= 1000*1000*1000; /* UNchecked! */
852 else if (c == 'm' || c == 'M')
853 m *= 1000*1000; /* We do not use powers of 2 (1024) */
854 else if (c == 'k' || c == 'K') /* to avoid possible bad effects on */
855 m *= 1000; /* a direct-mapped cache. */
856 else if (c == 'w' || c == 'W')
863 bad_option(const char *s)
866 fprintf(stderr, "initSM: Bad RTS option: %s\n", s);
867 stg_exit(EXIT_FAILURE);