1 /* -----------------------------------------------------------------------------
2 * $Id: RtsFlags.c,v 1.8 1999/01/27 16:41:16 simonm Exp $
4 * Functions for parsing the argument list.
6 * ---------------------------------------------------------------------------*/
11 #include "BlockAlloc.h"
22 extern struct RTS_FLAGS RtsFlags;
25 * Split argument lists
27 int prog_argc; /* an "int" so as to match normal "argc" */
28 char **prog_argv = NULL;
29 int rts_argc; /* ditto */
30 char *rts_argv[MAX_RTS_ARGS];
33 * constants, used later
38 /* -----------------------------------------------------------------------------
40 -------------------------------------------------------------------------- */
42 static FILE * /* return NULL on error */
45 int argc, char *argv[],
46 int rts_argc, char *rts_argv[],
47 const char *FILENAME_FMT);
49 static I_ decode(const char *s);
50 static void bad_option(const char *s);
52 /* -----------------------------------------------------------------------------
53 * Command-line option parsing routines.
54 * ---------------------------------------------------------------------------*/
56 void initRtsFlagsDefaults(void)
58 RtsFlags.GcFlags.statsFile = NULL;
59 RtsFlags.GcFlags.giveStats = NO_GC_STATS;
61 RtsFlags.GcFlags.maxStkSize = (1024 * 1024) / sizeof(W_);
62 RtsFlags.GcFlags.initialStkSize = 1024 / sizeof(W_);
64 RtsFlags.GcFlags.minAllocAreaSize = (256 * 1024) / BLOCK_SIZE;
65 RtsFlags.GcFlags.minOldGenSize = (1024 * 1024) / BLOCK_SIZE;
66 RtsFlags.GcFlags.maxHeapSize = (64 * 1024 * 1024) / BLOCK_SIZE;
67 RtsFlags.GcFlags.heapSizeSuggestion = 0; /* none */
68 RtsFlags.GcFlags.pcFreeHeap = 3; /* 3% */
69 RtsFlags.GcFlags.oldGenFactor = 2;
70 RtsFlags.GcFlags.generations = 2;
71 RtsFlags.GcFlags.steps = 2;
73 RtsFlags.GcFlags.forceGC = rtsFalse;
74 RtsFlags.GcFlags.forcingInterval = 5000000; /* 5MB (or words?) */
75 RtsFlags.GcFlags.ringBell = rtsFalse;
77 RtsFlags.GcFlags.squeezeUpdFrames = rtsTrue;
79 #if defined(PROFILING) || defined(PAR)
80 RtsFlags.CcFlags.doCostCentres = 0;
81 RtsFlags.CcFlags.sortBy = SORTCC_TIME;
82 #endif /* PROFILING or PAR */
85 RtsFlags.ProfFlags.doHeapProfile = rtsFalse;
87 RtsFlags.ProfFlags.ccSelector = NULL;
88 RtsFlags.ProfFlags.modSelector = NULL;
89 RtsFlags.ProfFlags.grpSelector = NULL;
90 RtsFlags.ProfFlags.descrSelector = NULL;
91 RtsFlags.ProfFlags.typeSelector = NULL;
92 RtsFlags.ProfFlags.kindSelector = NULL;
94 RtsFlags.ProfFlags.doHeapProfile = rtsFalse;
97 /* there really shouldn't be a threads limit for concurrent mandatory threads.
98 For now, unlimitied means less than 64k (there's a storage overhead) -- SOF
100 #if defined(CONCURRENT) && !defined(GRAN)
101 RtsFlags.ConcFlags.ctxtSwitchTime = CS_MIN_MILLISECS; /* In milliseconds */
102 RtsFlags.ConcFlags.maxThreads = 65536;
103 RtsFlags.ConcFlags.stkChunkSize = 1024;
104 RtsFlags.ConcFlags.maxLocalSparks = 65536;
105 #endif /* CONCURRENT only */
108 RtsFlags.ConcFlags.ctxtSwitchTime = CS_MIN_MILLISECS; /* In milliseconds */
109 RtsFlags.ConcFlags.maxThreads = 32;
110 RtsFlags.ConcFlags.stkChunkSize = 1024;
111 RtsFlags.ConcFlags.maxLocalSparks = 500;
115 RtsFlags.ParFlags.parallelStats = rtsFalse;
116 RtsFlags.ParFlags.granSimStats = rtsFalse;
117 RtsFlags.ParFlags.granSimStats_Binary = rtsFalse;
119 RtsFlags.ParFlags.outputDisabled = rtsFalse;
121 RtsFlags.ParFlags.packBufferSize = 1024;
122 RtsFlags.ParFlags.maxLocalSparks = 4096;
126 RtsFlags.GranFlags.granSimStats = rtsFalse;
127 RtsFlags.GranFlags.granSimStats_suppressed = rtsFalse;
128 RtsFlags.GranFlags.granSimStats_Binary = rtsFalse;
129 RtsFlags.GranFlags.granSimStats_Sparks = rtsFalse;
130 RtsFlags.GranFlags.granSimStats_Heap = rtsFalse;
131 RtsFlags.GranFlags.labelling = rtsFalse;
132 RtsFlags.GranFlags.packBufferSize = 1024;
133 RtsFlags.GranFlags.packBufferSize_internal = GRANSIM_DEFAULT_PACK_BUFFER_SIZE;
135 RtsFlags.GranFlags.proc = MAX_PROC;
136 RtsFlags.GranFlags.max_fishes = MAX_FISHES;
137 RtsFlags.GranFlags.time_slice = GRAN_TIME_SLICE;
138 RtsFlags.GranFlags.Light = rtsFalse;
140 RtsFlags.GranFlags.gran_latency = LATENCY;
141 RtsFlags.GranFlags.gran_additional_latency = ADDITIONAL_LATENCY;
142 RtsFlags.GranFlags.gran_fetchtime = FETCHTIME;
143 RtsFlags.GranFlags.gran_lunblocktime = LOCALUNBLOCKTIME;
144 RtsFlags.GranFlags.gran_gunblocktime = GLOBALUNBLOCKTIME;
145 RtsFlags.GranFlags.gran_mpacktime = MSGPACKTIME;
146 RtsFlags.GranFlags.gran_munpacktime = MSGUNPACKTIME;
147 RtsFlags.GranFlags.gran_mtidytime = MSGTIDYTIME;
149 RtsFlags.GranFlags.gran_threadcreatetime = THREADCREATETIME;
150 RtsFlags.GranFlags.gran_threadqueuetime = THREADQUEUETIME;
151 RtsFlags.GranFlags.gran_threaddescheduletime = THREADDESCHEDULETIME;
152 RtsFlags.GranFlags.gran_threadscheduletime = THREADSCHEDULETIME;
153 RtsFlags.GranFlags.gran_threadcontextswitchtime = THREADCONTEXTSWITCHTIME;
155 RtsFlags.GranFlags.gran_arith_cost = ARITH_COST;
156 RtsFlags.GranFlags.gran_branch_cost = BRANCH_COST;
157 RtsFlags.GranFlags.gran_load_cost = LOAD_COST;
158 RtsFlags.GranFlags.gran_store_cost = STORE_COST;
159 RtsFlags.GranFlags.gran_float_cost = FLOAT_COST;
161 RtsFlags.GranFlags.gran_heapalloc_cost = HEAPALLOC_COST;
163 RtsFlags.GranFlags.gran_pri_spark_overhead = PRI_SPARK_OVERHEAD;
164 RtsFlags.GranFlags.gran_pri_sched_overhead = PRI_SCHED_OVERHEAD;
166 RtsFlags.GranFlags.DoFairSchedule = rtsFalse;
167 RtsFlags.GranFlags.DoReScheduleOnFetch = rtsFalse;
168 RtsFlags.GranFlags.DoStealThreadsFirst = rtsFalse;
169 RtsFlags.GranFlags.SimplifiedFetch = rtsFalse;
170 RtsFlags.GranFlags.DoAlwaysCreateThreads = rtsFalse;
171 RtsFlags.GranFlags.DoGUMMFetching = rtsFalse;
172 RtsFlags.GranFlags.DoThreadMigration = rtsFalse;
173 RtsFlags.GranFlags.FetchStrategy = 2;
174 RtsFlags.GranFlags.PreferSparksOfLocalNodes = rtsFalse;
175 RtsFlags.GranFlags.DoPrioritySparking = rtsFalse;
176 RtsFlags.GranFlags.DoPriorityScheduling = rtsFalse;
177 RtsFlags.GranFlags.SparkPriority = 0;
178 RtsFlags.GranFlags.SparkPriority2 = 0;
179 RtsFlags.GranFlags.RandomPriorities = rtsFalse;
180 RtsFlags.GranFlags.InversePriorities = rtsFalse;
181 RtsFlags.GranFlags.IgnorePriorities = rtsFalse;
182 RtsFlags.GranFlags.ThunksToPack = 0;
183 RtsFlags.GranFlags.RandomSteal = rtsTrue;
184 RtsFlags.GranFlags.NoForward = rtsFalse;
185 RtsFlags.GranFlags.PrintFetchMisses = rtsFalse;
187 RtsFlags.GranFlags.debug = 0x0;
188 RtsFlags.GranFlags.event_trace = rtsFalse;
189 RtsFlags.GranFlags.event_trace_all = rtsFalse;
193 RtsFlags.TickyFlags.showTickyStats = rtsFalse;
194 RtsFlags.TickyFlags.tickyFile = NULL;
201 "Usage: <prog> <args> [+RTS <rtsopts> | -RTS <args>] ... --RTS <args>",
203 " +RTS Indicates run time system options follow",
204 " -RTS Indicates program arguments follow",
205 " --RTS Indicates that ALL subsequent arguments will be given to the",
206 " program (including any of these RTS flags)",
208 "The following run time system options are available:",
210 " -? -f Prints this message and exits; the program is not executed",
212 " -K<size> Sets the maximum stack size (default 1M) Egs: -K32k -K512k",
213 " -k<size> Sets the initial thread stack size (default 1k) Egs: -K4k -K2m",
215 " -A<size> Sets the minimum allocation area size (default 256k) Egs: -A1m -A10k",
216 " -M<size> Sets the maximum heap size (default 64M) Egs: -H256k -H1G",
217 " -m<n>% Minimum % of heap which must be available (default 3%)",
218 " -G<n> Number of generations (default: 2)",
219 " -T<n> Number of steps in younger generations (default: 2)",
220 " -s<file> Summary GC statistics (default file: <program>.stat)",
221 " -S<file> Detailed GC statistics (with -Sstderr going to stderr)",
224 " -Z Don't squeeze out update frames on stack overflow",
225 " -B Sound the bell at the start of each garbage collection",
226 #if defined(PROFILING) || defined(PAR)
228 " -p<sort> Produce cost centre time profile (output file <program>.prof)",
229 " sort: T = time (default), A = alloc, C = cost centre label",
230 " -P<sort> Produce serial time profile (output file <program>.time)",
231 " and a -p profile with detailed tick/alloc info",
232 # if defined(PROFILING)
234 " -h<break-down> Heap residency profile (output file <program>.hp)",
235 " break-down: C = cost centre (default), M = module, G = group",
236 " D = closure description, Y = type description",
237 " T<ints>,<start> = time closure created",
238 " ints: no. of interval bands plotted (default 18)",
239 " start: seconds after which intervals start (default 0.0)",
240 " A subset of closures may be selected by the attached cost centre using:",
241 " -c{mod:lab,mod:lab...}, specific module:label cost centre(s)",
242 " -m{mod,mod...} all cost centres from the specified modules(s)",
243 " -g{grp,grp...} all cost centres from the specified group(s)",
244 " Selections can also be made by description, type, kind and age:",
245 " -d{des,des...} closures with specified closure descriptions",
246 " -y{typ,typ...} closures with specified type descriptions",
247 " -k{knd,knd...} closures of the specified kinds",
248 " -a<age> closures which survived <age> complete intervals",
249 " The selection logic used is summarised as follows:",
250 " ([-c] or [-m] or [-g]) and ([-d] or [-y] or [-k]) and [-a]",
251 " where an option is true if not specified",
254 " -z<tbl><size> set hash table <size> for <tbl> (C, M, G, D or Y)",
256 " -i<secs> Number of seconds in a profiling interval (default 1.0):",
257 " heap profile (-h) and/or serial time profile (-P) frequency",
258 #endif /* PROFILING or PAR */
259 #if !defined(PROFILING) && defined(DEBUG)
261 " -h<break-down> Debugging Heap residency profile",
262 " (output file <program>.hp)",
263 " break-down: L = closure label (default)",
264 " T = closure type (constructor, thunk etc.)",
267 #if defined(TICKY_TICKY)
268 " -r<file> Produce reduction profiling statistics (with -rstderr for stderr)",
272 " -N<n> Use <n> PVMish processors in parallel (default: 2)",
273 /* NB: the -N<n> is implemented by the driver!! */
275 " -C<secs> Context-switch interval in seconds",
276 " (0 or no argument means switch as often as possible)",
277 " the default is .01 sec; resolution is .01 sec",
278 " -e<size> Size of spark pools (default 100)",
280 " -q Enable activity profile (output files in ~/<program>*.gr)",
281 " -qb Enable binary activity profile (output file /tmp/<program>.gb)",
282 " -Q<size> Set pack-buffer size (default: 1024)",
284 " -q[v] Enable quasi-parallel profile (output file <program>.qp)",
286 " -t<num> Set maximum number of advisory threads per PE (default 32)",
287 " -o<num> Set stack chunk size (default 1024)",
289 " -d Turn on PVM-ish debugging",
290 " -O Disable output for performance measurement",
292 # ifdef GRAN /* ToDo: fill in decent Docu here */
293 " -b... All GranSim options start with -b; see GranSim User's Guide for details",
296 "Other RTS options may be available for programs compiled a different way.",
297 "The GHC User's Guide has full details.",
302 static __inline__ rtsBool
303 strequal(const char *a, const char * b)
305 return(strcmp(a, b) == 0);
309 setupRtsFlags(int *argc, char *argv[], int *rts_argc, char *rts_argv[])
311 rtsBool error = rtsFalse;
316 /* Remove directory from argv[0] -- default files in current directory */
318 if ((last_slash = (char *) strrchr(argv[0], '/')) != NULL)
319 strcpy(argv[0], last_slash+1);
321 /* Split arguments (argv) into PGM (argv) and RTS (rts_argv) parts */
322 /* argv[0] must be PGM argument -- leave in argv */
330 for (mode = PGM; arg < total_arg && ! strequal("--RTS", argv[arg]); arg++) {
331 if (strequal("+RTS", argv[arg])) {
334 else if (strequal("-RTS", argv[arg])) {
337 else if (mode == RTS && *rts_argc < MAX_RTS_ARGS-1) {
338 rts_argv[(*rts_argc)++] = argv[arg];
340 else if (mode == PGM) {
341 argv[(*argc)++] = argv[arg];
344 barf("too many RTS arguments (max %d)", MAX_RTS_ARGS-1);
347 if (arg < total_arg) {
348 /* arg must be --RTS; process remaining program arguments */
349 while (++arg < total_arg) {
350 argv[(*argc)++] = argv[arg];
353 argv[*argc] = (char *) 0;
354 rts_argv[*rts_argc] = (char *) 0;
356 /* Process RTS (rts_argv) part: mainly to determine statsfile */
358 for (arg = 0; arg < *rts_argc; arg++) {
359 if (rts_argv[arg][0] != '-') {
361 fprintf(stderr, "setupRtsFlags: Unexpected RTS argument: %s\n",
366 switch(rts_argv[arg][1]) {
368 /* process: general args, then PROFILING-only ones,
369 then CONCURRENT-only, PARallel-only, GRAN-only,
370 TICKY-only (same order as defined in RtsFlags.lh);
371 within those groups, mostly in case-insensitive
376 # define TICKY_BUILD_ONLY(x) x
378 # define TICKY_BUILD_ONLY(x) \
379 fprintf(stderr, "setupRtsFlags: GHC not built for: ticky-ticky stats\n"); \
383 #if defined(PROFILING)
384 # define COST_CENTRE_USING_BUILD_ONLY(x) x
386 # define COST_CENTRE_USING_BUILD_ONLY(x) \
387 fprintf(stderr, "setupRtsFlags: GHC not built for: -prof or -parallel\n"); \
392 # define PROFILING_BUILD_ONLY(x) x
394 # define PROFILING_BUILD_ONLY(x) \
395 fprintf(stderr, "setupRtsFlags: GHC not built for: -prof\n"); \
400 # define PAR_BUILD_ONLY(x) x
402 # define PAR_BUILD_ONLY(x) \
403 fprintf(stderr, "setupRtsFlags: GHC not built for: -parallel\n"); \
408 # define GRAN_BUILD_ONLY(x) x
410 # define GRAN_BUILD_ONLY(x) \
411 fprintf(stderr, "setupRtsFlags: GHC not built for: -gransim\n"); \
415 /* =========== GENERAL ========================== */
422 RtsFlags.GcFlags.minAllocAreaSize
423 = decode(rts_argv[arg]+2) / BLOCK_SIZE;
424 if (RtsFlags.GcFlags.minAllocAreaSize <= 0) {
425 bad_option(rts_argv[arg]);
430 RtsFlags.GcFlags.ringBell = rtsTrue;
434 RtsFlags.GcFlags.oldGenFactor = atof(rts_argv[arg]+2);
436 if (RtsFlags.GcFlags.oldGenFactor < 0)
437 bad_option( rts_argv[arg] );
442 /* hack warning: interpret the flags as a binary number */
443 *(int*)(&RtsFlags.DebugFlags) = decode(rts_argv[arg]+2);
448 RtsFlags.GcFlags.maxStkSize =
449 decode(rts_argv[arg]+2) / sizeof(W_);
451 if (RtsFlags.GcFlags.maxStkSize == 0)
452 bad_option( rts_argv[arg] );
456 RtsFlags.GcFlags.initialStkSize =
457 decode(rts_argv[arg]+2) / sizeof(W_);
459 if (RtsFlags.GcFlags.initialStkSize == 0)
460 bad_option( rts_argv[arg] );
464 RtsFlags.GcFlags.maxHeapSize =
465 decode(rts_argv[arg]+2) / BLOCK_SIZE;
466 /* user give size in *bytes* but "maxHeapSize" is in *blocks* */
468 if (RtsFlags.GcFlags.maxHeapSize <= 0) {
469 bad_option(rts_argv[arg]);
474 RtsFlags.GcFlags.pcFreeHeap = atof(rts_argv[arg]+2);
476 if (RtsFlags.GcFlags.pcFreeHeap < 0 ||
477 RtsFlags.GcFlags.pcFreeHeap > 100)
478 bad_option( rts_argv[arg] );
482 RtsFlags.GcFlags.generations = decode(rts_argv[arg]+2);
483 if (RtsFlags.GcFlags.generations < 1) {
484 bad_option(rts_argv[arg]);
489 RtsFlags.GcFlags.steps = decode(rts_argv[arg]+2);
490 if (RtsFlags.GcFlags.steps < 1) {
491 bad_option(rts_argv[arg]);
496 RtsFlags.GcFlags.heapSizeSuggestion =
497 decode(rts_argv[arg]+2) / BLOCK_SIZE;
499 if (RtsFlags.GcFlags.heapSizeSuggestion <= 0) {
500 bad_option(rts_argv[arg]);
504 case 'j': /* force GC option */
505 RtsFlags.GcFlags.forceGC = rtsTrue;
506 if (rts_argv[arg][2]) {
507 RtsFlags.GcFlags.forcingInterval
508 = decode(rts_argv[arg]+2) / sizeof(W_);
512 case 'S': /* NB: no difference at present ! */
514 RtsFlags.GcFlags.giveStats ++; /* will be VERBOSE_GC_STATS */
516 /* Opening all those files would almost certainly fail... */
517 RtsFlags.ParFlags.parallelStats = rtsTrue;
518 RtsFlags.GcFlags.statsFile = stderr; /* temporary; ToDo: rm */
520 RtsFlags.GcFlags.statsFile
521 = open_stats_file(arg, *argc, argv,
522 *rts_argc, rts_argv, STAT_FILENAME_FMT);
524 if (RtsFlags.GcFlags.statsFile == NULL) error = rtsTrue;
529 RtsFlags.GcFlags.squeezeUpdFrames = rtsFalse;
532 /* =========== PROFILING ========================== */
534 case 'P': /* detailed cost centre profiling (time/alloc) */
535 COST_CENTRE_USING_BUILD_ONLY(
536 RtsFlags.CcFlags.doCostCentres++;
538 case 'p': /* cost centre profiling (time/alloc) */
539 COST_CENTRE_USING_BUILD_ONLY(
540 RtsFlags.CcFlags.doCostCentres++;
542 switch (rts_argv[arg][2]) {
546 RtsFlags.CcFlags.sortBy = rts_argv[arg][2];
549 RtsFlags.CcFlags.sortBy = SORTCC_TIME;
554 case 'i': /* serial profiling -- initial timer interval */
555 COST_CENTRE_USING_BUILD_ONLY(
556 interval_ticks = (I_) ((atof(rts_argv[arg]+2) * TICK_FREQUENCY));
557 if (interval_ticks <= 0)
561 case 'h': /* serial heap profile */
562 #if !defined(PROFILING) && defined(DEBUG)
563 switch (rts_argv[arg][2]) {
566 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_INFOPTR;
569 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_CLOSURE_TYPE;
572 fprintf(stderr, "Invalid heap profile option: %s\n",
577 PROFILING_BUILD_ONLY(
578 switch (rts_argv[arg][2]) {
581 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_CC;
584 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_MOD;
587 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_GRP;
590 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_DESCR;
593 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_TYPE;
596 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_TIME;
597 if (rts_argv[arg][3]) {
598 char *start_str = strchr(rts_argv[arg]+3, ',');
600 if (start_str) *start_str = '\0';
602 if ((intervals = decode(rts_argv[arg]+3)) != 0) {
603 time_intervals = (hash_t) intervals;
604 /* ToDo: and what if it *is* zero intervals??? */
607 earlier_ticks = (I_)((atof(start_str + 1) * TICK_FREQUENCY));
612 fprintf(stderr, "Invalid heap profile option: %s\n",
620 case 'z': /* size of index tables */
621 PROFILING_BUILD_ONLY(
622 switch (rts_argv[arg][2]) {
624 max_cc_no = (hash_t) decode(rts_argv[arg]+3);
625 if (max_cc_no == 0) {
626 fprintf(stderr, "Bad number of cost centres %s\n", rts_argv[arg]);
631 max_mod_no = (hash_t) decode(rts_argv[arg]+3);
632 if (max_mod_no == 0) {
633 fprintf(stderr, "Bad number of modules %s\n", rts_argv[arg]);
638 max_grp_no = (hash_t) decode(rts_argv[arg]+3);
639 if (max_grp_no == 0) {
640 fprintf(stderr, "Bad number of groups %s\n", rts_argv[arg]);
645 max_descr_no = (hash_t) decode(rts_argv[arg]+3);
646 if (max_descr_no == 0) {
647 fprintf(stderr, "Bad number of closure descriptions %s\n", rts_argv[arg]);
652 max_type_no = (hash_t) decode(rts_argv[arg]+3);
653 if (max_type_no == 0) {
654 fprintf(stderr, "Bad number of type descriptions %s\n", rts_argv[arg]);
659 fprintf(stderr, "Invalid index table size option: %s\n",
665 case 'c': /* cost centre label select */
666 case 'g': /* cost centre group select */
667 case 'd': /* closure descr select */
668 case 'y': /* closure type select */
669 PROFILING_BUILD_ONLY(
670 {char *left = strchr(rts_argv[arg], '{');
671 char *right = strrchr(rts_argv[arg], '}');
673 if (! left || ! right ||
674 strrchr(rts_argv[arg], '{') != left ||
675 strchr(rts_argv[arg], '}') != right) {
676 fprintf(stderr, "Invalid heap profiling selection bracketing\n %s\n", rts_argv[arg]);
680 switch (rts_argv[arg][1]) {
681 case 'c': /* cost centre label select */
682 RtsFlags.ProfFlags.ccSelector = left + 1;
684 case 'm': /* cost centre module select */
685 RtsFlags.ProfFlags.modSelector = left + 1;
687 case 'g': /* cost centre group select */
688 RtsFlags.ProfFlags.grpSelector = left + 1;
690 case 'd': /* closure descr select */
691 RtsFlags.ProfFlags.descrSelector = left + 1;
693 case 'y': /* closure type select */
694 RtsFlags.ProfFlags.typeSelector = left + 1;
696 case 'k': /* closure kind select */
697 RtsFlags.ProfFlags.kindSelector = left + 1;
703 /* =========== CONCURRENT ========================= */
704 case 'C': /* context switch interval */
705 if (rts_argv[arg][2] == '\0')
706 RtsFlags.ConcFlags.ctxtSwitchTime = 0;
710 /* Convert to milliseconds */
711 cst = (I_) ((atof(rts_argv[arg]+2) * 1000));
712 cst = (cst / CS_MIN_MILLISECS) * CS_MIN_MILLISECS;
713 if (cst < CS_MIN_MILLISECS)
714 cst = CS_MIN_MILLISECS;
716 RtsFlags.ConcFlags.ctxtSwitchTime = cst;
721 if (rts_argv[arg][2] != '\0') {
722 RtsFlags.ConcFlags.maxThreads
723 = strtol(rts_argv[arg]+2, (char **) NULL, 10);
725 fprintf(stderr, "setupRtsFlags: missing size for -t\n");
730 /* =========== PARALLEL =========================== */
733 if (rts_argv[arg][2] != '\0') { /* otherwise, stick w/ the default */
735 RtsFlags.ParFlags.maxLocalSparks
736 = strtol(rts_argv[arg]+2, (char **) NULL, 10);
738 if (RtsFlags.ParFlags.maxLocalSparks <= 0) {
739 fprintf(stderr, "setupRtsFlags: bad value for -e\n");
747 RtsFlags.ParFlags.outputDisabled = rtsTrue;
750 case 'q': /* activity profile option */
752 if (rts_argv[arg][2] == 'b')
753 RtsFlags.ParFlags.granSimStats_Binary = rtsTrue;
755 RtsFlags.ParFlags.granSimStats = rtsTrue;
759 case 'q': /* quasi-parallel profile option */
761 if (rts_argv[arg][2] == 'v')
768 case 'Q': /* Set pack buffer size */
770 if (rts_argv[arg][2] != '\0') {
771 RtsFlags.ParFlags.packBufferSize = decode(rts_argv[arg]+2);
773 fprintf(stderr, "setupRtsFlags: missing size of PackBuffer (for -Q)\n");
778 /* =========== GRAN =============================== */
782 process_gran_option(arg, rts_argc, rts_argv, &error);
785 /* =========== TICKY ============================== */
787 case 'r': /* Basic profiling stats */
790 RtsFlags.TickyFlags.showTickyStats = rtsTrue;
791 RtsFlags.TickyFlags.tickyFile
792 = open_stats_file(arg, *argc, argv,
793 *rts_argc, rts_argv, TICKY_FILENAME_FMT);
795 if (RtsFlags.TickyFlags.tickyFile == NULL) error = rtsTrue;
798 /* =========== OH DEAR ============================ */
800 fprintf(stderr, "setupRtsFlags: Unknown RTS option: %s\n",rts_argv[arg]);
810 for (p = usage_text; *p; p++)
811 fprintf(stderr, "%s\n", *p);
812 stg_exit(EXIT_FAILURE);
817 static FILE * /* return NULL on error */
820 int argc, char *argv[],
821 int rts_argc, char *rts_argv[],
822 const char *FILENAME_FMT)
826 if (strequal(rts_argv[arg]+2, "stderr")) /* use real stderr */
828 else if (rts_argv[arg][2] != '\0') /* stats file specified */
829 f = fopen(rts_argv[arg]+2,"w");
831 char stats_filename[STATS_FILENAME_MAXLEN]; /* default <program>.<ext> */
832 sprintf(stats_filename, FILENAME_FMT, argv[0]);
833 f = fopen(stats_filename,"w");
836 fprintf(stderr, "Can't open stats file %s\n", rts_argv[arg]+2);
838 /* Write argv and rtsv into start of stats file */
840 for(count = 0; count < argc; count++)
841 fprintf(f, "%s ", argv[count]);
843 for(count = 0; count < rts_argc; count++)
844 fprintf(f, "%s ", rts_argv[count]);
852 decode(const char *s)
863 if (c == 'g' || c == 'G')
864 m *= 1000*1000*1000; /* UNchecked! */
865 else if (c == 'm' || c == 'M')
866 m *= 1000*1000; /* We do not use powers of 2 (1024) */
867 else if (c == 'k' || c == 'K') /* to avoid possible bad effects on */
868 m *= 1000; /* a direct-mapped cache. */
869 else if (c == 'w' || c == 'W')
876 bad_option(const char *s)
879 fprintf(stderr, "initSM: Bad RTS option: %s\n", s);
880 stg_exit(EXIT_FAILURE);