1 /* -----------------------------------------------------------------------------
2 * $Id: RtsFlags.c,v 1.18 1999/09/13 08:14:51 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"
17 #if defined(PROFILING)
29 extern struct RTS_FLAGS RtsFlags;
32 * Split argument lists
34 int prog_argc; /* an "int" so as to match normal "argc" */
35 char **prog_argv = NULL;
36 int rts_argc; /* ditto */
37 char *rts_argv[MAX_RTS_ARGS];
40 * constants, used later
45 /* -----------------------------------------------------------------------------
47 -------------------------------------------------------------------------- */
49 static FILE * /* return NULL on error */
52 int argc, char *argv[],
53 int rts_argc, char *rts_argv[],
54 const char *FILENAME_FMT);
56 static I_ decode(const char *s);
57 static void bad_option(const char *s);
59 /* -----------------------------------------------------------------------------
60 * Command-line option parsing routines.
61 * ---------------------------------------------------------------------------*/
63 void initRtsFlagsDefaults(void)
65 RtsFlags.GcFlags.statsFile = NULL;
66 RtsFlags.GcFlags.giveStats = NO_GC_STATS;
68 RtsFlags.GcFlags.maxStkSize = (1024 * 1024) / sizeof(W_);
69 RtsFlags.GcFlags.initialStkSize = 1024 / sizeof(W_);
71 RtsFlags.GcFlags.minAllocAreaSize = (256 * 1024) / BLOCK_SIZE;
72 RtsFlags.GcFlags.minOldGenSize = (1024 * 1024) / BLOCK_SIZE;
73 RtsFlags.GcFlags.maxHeapSize = (64 * 1024 * 1024) / BLOCK_SIZE;
74 RtsFlags.GcFlags.heapSizeSuggestion = 0; /* none */
75 RtsFlags.GcFlags.pcFreeHeap = 3; /* 3% */
76 RtsFlags.GcFlags.oldGenFactor = 2;
77 RtsFlags.GcFlags.generations = 2;
78 RtsFlags.GcFlags.steps = 2;
80 RtsFlags.GcFlags.forceGC = rtsFalse;
81 RtsFlags.GcFlags.forcingInterval = 5000000; /* 5MB (or words?) */
82 RtsFlags.GcFlags.ringBell = rtsFalse;
84 RtsFlags.GcFlags.squeezeUpdFrames = rtsTrue;
86 #if defined(PROFILING) || defined(PAR)
87 RtsFlags.CcFlags.doCostCentres = 0;
88 RtsFlags.CcFlags.sortBy = SORTCC_TIME;
89 #endif /* PROFILING or PAR */
92 RtsFlags.ProfFlags.doHeapProfile = rtsFalse;
94 RtsFlags.ProfFlags.ccSelector = NULL;
95 RtsFlags.ProfFlags.modSelector = NULL;
96 RtsFlags.ProfFlags.grpSelector = NULL;
97 RtsFlags.ProfFlags.descrSelector = NULL;
98 RtsFlags.ProfFlags.typeSelector = NULL;
99 RtsFlags.ProfFlags.kindSelector = NULL;
101 RtsFlags.ProfFlags.doHeapProfile = rtsFalse;
104 RtsFlags.ConcFlags.ctxtSwitchTime = CS_MIN_MILLISECS; /* In milliseconds */
106 RtsFlags.ParFlags.parallelStats = rtsFalse;
107 RtsFlags.ParFlags.granSimStats = rtsFalse;
108 RtsFlags.ParFlags.granSimStats_Binary = rtsFalse;
110 RtsFlags.ParFlags.outputDisabled = rtsFalse;
112 RtsFlags.ParFlags.packBufferSize = 1024;
113 RtsFlags.ParFlags.maxLocalSparks = 4096;
117 RtsFlags.GranFlags.granSimStats = rtsFalse;
118 RtsFlags.GranFlags.granSimStats_suppressed = rtsFalse;
119 RtsFlags.GranFlags.granSimStats_Binary = rtsFalse;
120 RtsFlags.GranFlags.granSimStats_Sparks = rtsFalse;
121 RtsFlags.GranFlags.granSimStats_Heap = rtsFalse;
122 RtsFlags.GranFlags.labelling = rtsFalse;
123 RtsFlags.GranFlags.packBufferSize = 1024;
124 RtsFlags.GranFlags.packBufferSize_internal = GRANSIM_DEFAULT_PACK_BUFFER_SIZE;
126 RtsFlags.GranFlags.proc = MAX_PROC;
127 RtsFlags.GranFlags.max_fishes = MAX_FISHES;
128 RtsFlags.GranFlags.time_slice = GRAN_TIME_SLICE;
129 RtsFlags.GranFlags.Light = rtsFalse;
131 RtsFlags.GranFlags.gran_latency = LATENCY;
132 RtsFlags.GranFlags.gran_additional_latency = ADDITIONAL_LATENCY;
133 RtsFlags.GranFlags.gran_fetchtime = FETCHTIME;
134 RtsFlags.GranFlags.gran_lunblocktime = LOCALUNBLOCKTIME;
135 RtsFlags.GranFlags.gran_gunblocktime = GLOBALUNBLOCKTIME;
136 RtsFlags.GranFlags.gran_mpacktime = MSGPACKTIME;
137 RtsFlags.GranFlags.gran_munpacktime = MSGUNPACKTIME;
138 RtsFlags.GranFlags.gran_mtidytime = MSGTIDYTIME;
140 RtsFlags.GranFlags.gran_threadcreatetime = THREADCREATETIME;
141 RtsFlags.GranFlags.gran_threadqueuetime = THREADQUEUETIME;
142 RtsFlags.GranFlags.gran_threaddescheduletime = THREADDESCHEDULETIME;
143 RtsFlags.GranFlags.gran_threadscheduletime = THREADSCHEDULETIME;
144 RtsFlags.GranFlags.gran_threadcontextswitchtime = THREADCONTEXTSWITCHTIME;
146 RtsFlags.GranFlags.gran_arith_cost = ARITH_COST;
147 RtsFlags.GranFlags.gran_branch_cost = BRANCH_COST;
148 RtsFlags.GranFlags.gran_load_cost = LOAD_COST;
149 RtsFlags.GranFlags.gran_store_cost = STORE_COST;
150 RtsFlags.GranFlags.gran_float_cost = FLOAT_COST;
152 RtsFlags.GranFlags.gran_heapalloc_cost = HEAPALLOC_COST;
154 RtsFlags.GranFlags.gran_pri_spark_overhead = PRI_SPARK_OVERHEAD;
155 RtsFlags.GranFlags.gran_pri_sched_overhead = PRI_SCHED_OVERHEAD;
157 RtsFlags.GranFlags.DoFairSchedule = rtsFalse;
158 RtsFlags.GranFlags.DoReScheduleOnFetch = rtsFalse;
159 RtsFlags.GranFlags.DoStealThreadsFirst = rtsFalse;
160 RtsFlags.GranFlags.SimplifiedFetch = rtsFalse;
161 RtsFlags.GranFlags.DoAlwaysCreateThreads = rtsFalse;
162 RtsFlags.GranFlags.DoGUMMFetching = rtsFalse;
163 RtsFlags.GranFlags.DoThreadMigration = rtsFalse;
164 RtsFlags.GranFlags.FetchStrategy = 2;
165 RtsFlags.GranFlags.PreferSparksOfLocalNodes = rtsFalse;
166 RtsFlags.GranFlags.DoPrioritySparking = rtsFalse;
167 RtsFlags.GranFlags.DoPriorityScheduling = rtsFalse;
168 RtsFlags.GranFlags.SparkPriority = 0;
169 RtsFlags.GranFlags.SparkPriority2 = 0;
170 RtsFlags.GranFlags.RandomPriorities = rtsFalse;
171 RtsFlags.GranFlags.InversePriorities = rtsFalse;
172 RtsFlags.GranFlags.IgnorePriorities = rtsFalse;
173 RtsFlags.GranFlags.ThunksToPack = 0;
174 RtsFlags.GranFlags.RandomSteal = rtsTrue;
175 RtsFlags.GranFlags.NoForward = rtsFalse;
176 RtsFlags.GranFlags.PrintFetchMisses = rtsFalse;
178 RtsFlags.GranFlags.debug = 0x0;
179 RtsFlags.GranFlags.event_trace = rtsFalse;
180 RtsFlags.GranFlags.event_trace_all = rtsFalse;
184 RtsFlags.TickyFlags.showTickyStats = rtsFalse;
185 RtsFlags.TickyFlags.tickyFile = NULL;
192 "Usage: <prog> <args> [+RTS <rtsopts> | -RTS <args>] ... --RTS <args>",
194 " +RTS Indicates run time system options follow",
195 " -RTS Indicates program arguments follow",
196 " --RTS Indicates that ALL subsequent arguments will be given to the",
197 " program (including any of these RTS flags)",
199 "The following run time system options are available:",
201 " -? -f Prints this message and exits; the program is not executed",
203 " -K<size> Sets the maximum stack size (default 1M) Egs: -K32k -K512k",
204 " -k<size> Sets the initial thread stack size (default 1k) Egs: -K4k -K2m",
206 " -A<size> Sets the minimum allocation area size (default 256k) Egs: -A1m -A10k",
207 " -M<size> Sets the maximum heap size (default 64M) Egs: -M256k -M1G",
208 " -H<size> Sets the minimum heap size (default 0M) Egs: -H24m -H1G",
209 " -m<n>% Minimum % of heap which must be available (default 3%)",
210 " -G<n> Number of generations (default: 2)",
211 " -T<n> Number of steps in younger generations (default: 2)",
212 " -s<file> Summary GC statistics (default file: <program>.stat)",
213 " -S<file> Detailed GC statistics (with -Sstderr going to stderr)",
216 " -Z Don't squeeze out update frames on stack overflow",
217 " -B Sound the bell at the start of each garbage collection",
218 #if defined(PROFILING) || defined(PAR)
220 " -p<sort> Produce cost centre time profile (output file <program>.prof)",
221 " sort: T = time (default), A = alloc, C = cost centre label",
222 " -P<sort> Produce serial time profile (output file <program>.time)",
223 " and a -p profile with detailed tick/alloc info",
224 # if defined(PROFILING)
226 " -h<break-down> Heap residency profile (output file <program>.hp)",
227 " break-down: C = cost centre (default), M = module, G = group",
228 " D = closure description, Y = type description",
229 " T<ints>,<start> = time closure created",
230 " ints: no. of interval bands plotted (default 18)",
231 " start: seconds after which intervals start (default 0.0)",
232 " A subset of closures may be selected by the attached cost centre using:",
233 " -c{mod:lab,mod:lab...}, specific module:label cost centre(s)",
234 " -m{mod,mod...} all cost centres from the specified modules(s)",
235 " -g{grp,grp...} all cost centres from the specified group(s)",
236 " Selections can also be made by description, type, kind and age:",
237 " -d{des,des...} closures with specified closure descriptions",
238 " -y{typ,typ...} closures with specified type descriptions",
239 " -k{knd,knd...} closures of the specified kinds",
240 " -a<age> closures which survived <age> complete intervals",
241 " The selection logic used is summarised as follows:",
242 " ([-c] or [-m] or [-g]) and ([-d] or [-y] or [-k]) and [-a]",
243 " where an option is true if not specified",
246 " -z<tbl><size> set hash table <size> for <tbl> (C, M, G, D or Y)",
248 " -i<secs> Number of seconds in a profiling interval (default 1.0):",
249 " heap profile (-h) and/or serial time profile (-P) frequency",
250 #endif /* PROFILING or PAR */
251 #if !defined(PROFILING) && defined(DEBUG)
253 " -h<break-down> Debugging Heap residency profile",
254 " (output file <program>.hp)",
255 " break-down: L = closure label (default)",
256 " T = closure type (constructor, thunk etc.)",
259 #if defined(TICKY_TICKY)
260 " -r<file> Produce reduction profiling statistics (with -rstderr for stderr)",
264 " -N<n> Use <n> PVMish processors in parallel (default: 2)",
265 /* NB: the -N<n> is implemented by the driver!! */
267 " -C<secs> Context-switch interval in seconds",
268 " (0 or no argument means switch as often as possible)",
269 " the default is .01 sec; resolution is .01 sec",
271 " -q Enable activity profile (output files in ~/<program>*.gr)",
272 " -qb Enable binary activity profile (output file /tmp/<program>.gb)",
273 " -Q<size> Set pack-buffer size (default: 1024)",
276 " -d Turn on PVM-ish debugging",
277 " -O Disable output for performance measurement",
279 # ifdef GRAN /* ToDo: fill in decent Docu here */
280 " -b... All GranSim options start with -b; see GranSim User's Guide for details",
283 "Other RTS options may be available for programs compiled a different way.",
284 "The GHC User's Guide has full details.",
289 static __inline__ rtsBool
290 strequal(const char *a, const char * b)
292 return(strcmp(a, b) == 0);
296 setupRtsFlags(int *argc, char *argv[], int *rts_argc, char *rts_argv[])
298 rtsBool error = rtsFalse;
303 /* Remove directory from argv[0] -- default files in current directory */
305 if ((last_slash = (char *) strrchr(argv[0], '/')) != NULL)
306 strcpy(argv[0], last_slash+1);
308 /* Split arguments (argv) into PGM (argv) and RTS (rts_argv) parts */
309 /* argv[0] must be PGM argument -- leave in argv */
317 for (mode = PGM; arg < total_arg && ! strequal("--RTS", argv[arg]); arg++) {
318 if (strequal("+RTS", argv[arg])) {
321 else if (strequal("-RTS", argv[arg])) {
324 else if (mode == RTS && *rts_argc < MAX_RTS_ARGS-1) {
325 rts_argv[(*rts_argc)++] = argv[arg];
327 else if (mode == PGM) {
328 argv[(*argc)++] = argv[arg];
331 barf("too many RTS arguments (max %d)", MAX_RTS_ARGS-1);
334 if (arg < total_arg) {
335 /* arg must be --RTS; process remaining program arguments */
336 while (++arg < total_arg) {
337 argv[(*argc)++] = argv[arg];
340 argv[*argc] = (char *) 0;
341 rts_argv[*rts_argc] = (char *) 0;
343 /* Process RTS (rts_argv) part: mainly to determine statsfile */
345 for (arg = 0; arg < *rts_argc; arg++) {
346 if (rts_argv[arg][0] != '-') {
348 fprintf(stderr, "setupRtsFlags: Unexpected RTS argument: %s\n",
353 switch(rts_argv[arg][1]) {
355 /* process: general args, then PROFILING-only ones,
356 then CONCURRENT-only, PARallel-only, GRAN-only,
357 TICKY-only (same order as defined in RtsFlags.lh);
358 within those groups, mostly in case-insensitive
363 # define TICKY_BUILD_ONLY(x) x
365 # define TICKY_BUILD_ONLY(x) \
366 fprintf(stderr, "setupRtsFlags: GHC not built for: ticky-ticky stats\n"); \
370 #if defined(PROFILING)
371 # define COST_CENTRE_USING_BUILD_ONLY(x) x
373 # define COST_CENTRE_USING_BUILD_ONLY(x) \
374 fprintf(stderr, "setupRtsFlags: GHC not built for: -prof or -parallel\n"); \
379 # define PROFILING_BUILD_ONLY(x) x
381 # define PROFILING_BUILD_ONLY(x) \
382 fprintf(stderr, "setupRtsFlags: GHC not built for: -prof\n"); \
387 # define PAR_BUILD_ONLY(x) x
389 # define PAR_BUILD_ONLY(x) \
390 fprintf(stderr, "setupRtsFlags: GHC not built for: -parallel\n"); \
395 # define GRAN_BUILD_ONLY(x) x
397 # define GRAN_BUILD_ONLY(x) \
398 fprintf(stderr, "setupRtsFlags: GHC not built for: -gransim\n"); \
402 /* =========== GENERAL ========================== */
409 RtsFlags.GcFlags.minAllocAreaSize
410 = decode(rts_argv[arg]+2) / BLOCK_SIZE;
411 if (RtsFlags.GcFlags.minAllocAreaSize <= 0) {
412 bad_option(rts_argv[arg]);
417 RtsFlags.GcFlags.ringBell = rtsTrue;
421 RtsFlags.GcFlags.oldGenFactor = atof(rts_argv[arg]+2);
423 if (RtsFlags.GcFlags.oldGenFactor < 0)
424 bad_option( rts_argv[arg] );
429 /* hack warning: interpret the flags as a binary number */
431 I_ n = decode(rts_argv[arg]+2);
432 if (n &1) RtsFlags.DebugFlags.scheduler = rtsTrue;
433 if ((n>>1)&1) RtsFlags.DebugFlags.evaluator = rtsTrue;
434 if ((n>>2)&1) RtsFlags.DebugFlags.codegen = rtsTrue;
435 if ((n>>3)&1) RtsFlags.DebugFlags.weak = rtsTrue;
436 if ((n>>4)&1) RtsFlags.DebugFlags.gccafs = rtsTrue;
437 if ((n>>5)&1) RtsFlags.DebugFlags.gc = rtsTrue;
438 if ((n>>6)&1) RtsFlags.DebugFlags.block_alloc = rtsTrue;
439 if ((n>>7)&1) RtsFlags.DebugFlags.sanity = rtsTrue;
440 if ((n>>8)&1) RtsFlags.DebugFlags.stable = rtsTrue;
441 if ((n>>9)&1) RtsFlags.DebugFlags.prof = rtsTrue;
447 RtsFlags.GcFlags.maxStkSize =
448 decode(rts_argv[arg]+2) / sizeof(W_);
450 if (RtsFlags.GcFlags.maxStkSize == 0)
451 bad_option( rts_argv[arg] );
455 RtsFlags.GcFlags.initialStkSize =
456 decode(rts_argv[arg]+2) / sizeof(W_);
458 if (RtsFlags.GcFlags.initialStkSize == 0)
459 bad_option( rts_argv[arg] );
463 RtsFlags.GcFlags.maxHeapSize =
464 decode(rts_argv[arg]+2) / BLOCK_SIZE;
465 /* user give size in *bytes* but "maxHeapSize" is in *blocks* */
467 if (RtsFlags.GcFlags.maxHeapSize <= 0) {
468 bad_option(rts_argv[arg]);
473 RtsFlags.GcFlags.pcFreeHeap = atof(rts_argv[arg]+2);
475 if (RtsFlags.GcFlags.pcFreeHeap < 0 ||
476 RtsFlags.GcFlags.pcFreeHeap > 100)
477 bad_option( rts_argv[arg] );
481 RtsFlags.GcFlags.generations = decode(rts_argv[arg]+2);
482 if (RtsFlags.GcFlags.generations < 1) {
483 bad_option(rts_argv[arg]);
488 RtsFlags.GcFlags.steps = decode(rts_argv[arg]+2);
489 if (RtsFlags.GcFlags.steps < 1) {
490 bad_option(rts_argv[arg]);
495 RtsFlags.GcFlags.heapSizeSuggestion =
496 decode(rts_argv[arg]+2) / BLOCK_SIZE;
498 if (RtsFlags.GcFlags.heapSizeSuggestion <= 0) {
499 bad_option(rts_argv[arg]);
503 case 'j': /* force GC option */
504 RtsFlags.GcFlags.forceGC = rtsTrue;
505 if (rts_argv[arg][2]) {
506 RtsFlags.GcFlags.forcingInterval
507 = decode(rts_argv[arg]+2) / sizeof(W_);
512 RtsFlags.GcFlags.giveStats ++;
515 RtsFlags.GcFlags.giveStats ++;
517 /* Opening all those files would almost certainly fail... */
518 RtsFlags.ParFlags.parallelStats = rtsTrue;
519 RtsFlags.GcFlags.statsFile = stderr; /* temporary; ToDo: rm */
521 RtsFlags.GcFlags.statsFile
522 = open_stats_file(arg, *argc, argv,
523 *rts_argc, rts_argv, STAT_FILENAME_FMT);
525 if (RtsFlags.GcFlags.statsFile == NULL) error = rtsTrue;
530 RtsFlags.GcFlags.squeezeUpdFrames = rtsFalse;
533 /* =========== PROFILING ========================== */
535 case 'P': /* detailed cost centre profiling (time/alloc) */
536 COST_CENTRE_USING_BUILD_ONLY(
537 RtsFlags.CcFlags.doCostCentres++;
539 case 'p': /* cost centre profiling (time/alloc) */
540 COST_CENTRE_USING_BUILD_ONLY(
541 RtsFlags.CcFlags.doCostCentres++;
543 switch (rts_argv[arg][2]) {
547 RtsFlags.CcFlags.sortBy = rts_argv[arg][2];
550 RtsFlags.CcFlags.sortBy = SORTCC_TIME;
555 case 'i': /* serial profiling -- initial timer interval */
556 COST_CENTRE_USING_BUILD_ONLY(
557 interval_ticks = (I_) ((atof(rts_argv[arg]+2) * TICK_FREQUENCY));
558 if (interval_ticks <= 0)
562 case 'h': /* serial heap profile */
563 #if !defined(PROFILING) && defined(DEBUG)
564 switch (rts_argv[arg][2]) {
567 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_INFOPTR;
570 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_CLOSURE_TYPE;
573 fprintf(stderr, "Invalid heap profile option: %s\n",
578 PROFILING_BUILD_ONLY(
579 switch (rts_argv[arg][2]) {
582 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_CC;
585 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_MOD;
588 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_GRP;
591 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_DESCR;
594 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_TYPE;
597 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_TIME;
598 if (rts_argv[arg][3]) {
599 char *start_str = strchr(rts_argv[arg]+3, ',');
601 if (start_str) *start_str = '\0';
603 if ((intervals = decode(rts_argv[arg]+3)) != 0) {
604 time_intervals = (hash_t) intervals;
605 /* ToDo: and what if it *is* zero intervals??? */
608 earlier_ticks = (I_)((atof(start_str + 1) * TICK_FREQUENCY));
613 fprintf(stderr, "Invalid heap profile option: %s\n",
621 case 'z': /* size of index tables */
622 PROFILING_BUILD_ONLY(
623 switch (rts_argv[arg][2]) {
625 max_cc_no = (hash_t) decode(rts_argv[arg]+3);
626 if (max_cc_no == 0) {
627 fprintf(stderr, "Bad number of cost centres %s\n", rts_argv[arg]);
632 max_mod_no = (hash_t) decode(rts_argv[arg]+3);
633 if (max_mod_no == 0) {
634 fprintf(stderr, "Bad number of modules %s\n", rts_argv[arg]);
639 max_grp_no = (hash_t) decode(rts_argv[arg]+3);
640 if (max_grp_no == 0) {
641 fprintf(stderr, "Bad number of groups %s\n", rts_argv[arg]);
646 max_descr_no = (hash_t) decode(rts_argv[arg]+3);
647 if (max_descr_no == 0) {
648 fprintf(stderr, "Bad number of closure descriptions %s\n", rts_argv[arg]);
653 max_type_no = (hash_t) decode(rts_argv[arg]+3);
654 if (max_type_no == 0) {
655 fprintf(stderr, "Bad number of type descriptions %s\n", rts_argv[arg]);
660 fprintf(stderr, "Invalid index table size option: %s\n",
666 case 'c': /* cost centre label select */
667 case 'g': /* cost centre group select */
668 case 'd': /* closure descr select */
669 case 'y': /* closure type select */
670 PROFILING_BUILD_ONLY(
671 {char *left = strchr(rts_argv[arg], '{');
672 char *right = strrchr(rts_argv[arg], '}');
674 if (! left || ! right ||
675 strrchr(rts_argv[arg], '{') != left ||
676 strchr(rts_argv[arg], '}') != right) {
677 fprintf(stderr, "Invalid heap profiling selection bracketing\n %s\n", rts_argv[arg]);
681 switch (rts_argv[arg][1]) {
682 case 'c': /* cost centre label select */
683 RtsFlags.ProfFlags.ccSelector = left + 1;
685 case 'm': /* cost centre module select */
686 RtsFlags.ProfFlags.modSelector = left + 1;
688 case 'g': /* cost centre group select */
689 RtsFlags.ProfFlags.grpSelector = left + 1;
691 case 'd': /* closure descr select */
692 RtsFlags.ProfFlags.descrSelector = left + 1;
694 case 'y': /* closure type select */
695 RtsFlags.ProfFlags.typeSelector = left + 1;
697 case 'k': /* closure kind select */
698 RtsFlags.ProfFlags.kindSelector = left + 1;
704 /* =========== CONCURRENT ========================= */
705 case 'C': /* context switch interval */
706 if (rts_argv[arg][2] == '\0')
707 RtsFlags.ConcFlags.ctxtSwitchTime = 0;
711 /* Convert to milliseconds */
712 cst = (I_) ((atof(rts_argv[arg]+2) * 1000));
713 cst = (cst / CS_MIN_MILLISECS) * CS_MIN_MILLISECS;
714 if (cst < CS_MIN_MILLISECS)
715 cst = CS_MIN_MILLISECS;
717 RtsFlags.ConcFlags.ctxtSwitchTime = cst;
721 /* =========== PARALLEL =========================== */
724 if (rts_argv[arg][2] != '\0') { /* otherwise, stick w/ the default */
726 RtsFlags.ParFlags.maxLocalSparks
727 = strtol(rts_argv[arg]+2, (char **) NULL, 10);
729 if (RtsFlags.ParFlags.maxLocalSparks <= 0) {
730 fprintf(stderr, "setupRtsFlags: bad value for -e\n");
738 RtsFlags.ParFlags.outputDisabled = rtsTrue;
741 case 'q': /* activity profile option */
743 if (rts_argv[arg][2] == 'b')
744 RtsFlags.ParFlags.granSimStats_Binary = rtsTrue;
746 RtsFlags.ParFlags.granSimStats = rtsTrue;
750 case 'q': /* quasi-parallel profile option */
752 if (rts_argv[arg][2] == 'v')
759 case 'Q': /* Set pack buffer size */
761 if (rts_argv[arg][2] != '\0') {
762 RtsFlags.ParFlags.packBufferSize = decode(rts_argv[arg]+2);
764 fprintf(stderr, "setupRtsFlags: missing size of PackBuffer (for -Q)\n");
769 /* =========== GRAN =============================== */
773 process_gran_option(arg, rts_argc, rts_argv, &error);
776 /* =========== TICKY ============================== */
778 case 'r': /* Basic profiling stats */
781 RtsFlags.TickyFlags.showTickyStats = rtsTrue;
782 RtsFlags.TickyFlags.tickyFile
783 = open_stats_file(arg, *argc, argv,
784 *rts_argc, rts_argv, TICKY_FILENAME_FMT);
786 if (RtsFlags.TickyFlags.tickyFile == NULL) error = rtsTrue;
789 /* =========== OH DEAR ============================ */
791 fprintf(stderr, "setupRtsFlags: Unknown RTS option: %s\n",rts_argv[arg]);
801 for (p = usage_text; *p; p++)
802 fprintf(stderr, "%s\n", *p);
803 stg_exit(EXIT_FAILURE);
808 static FILE * /* return NULL on error */
811 int argc, char *argv[],
812 int rts_argc, char *rts_argv[],
813 const char *FILENAME_FMT)
817 if (strequal(rts_argv[arg]+2, "stderr")) /* use real stderr */
819 else if (rts_argv[arg][2] != '\0') /* stats file specified */
820 f = fopen(rts_argv[arg]+2,"w");
822 char stats_filename[STATS_FILENAME_MAXLEN]; /* default <program>.<ext> */
823 sprintf(stats_filename, FILENAME_FMT, argv[0]);
824 f = fopen(stats_filename,"w");
827 fprintf(stderr, "Can't open stats file %s\n", rts_argv[arg]+2);
829 /* Write argv and rtsv into start of stats file */
831 for(count = 0; count < argc; count++)
832 fprintf(f, "%s ", argv[count]);
834 for(count = 0; count < rts_argc; count++)
835 fprintf(f, "%s ", rts_argv[count]);
843 decode(const char *s)
854 if (c == 'g' || c == 'G')
855 m *= 1000*1000*1000; /* UNchecked! */
856 else if (c == 'm' || c == 'M')
857 m *= 1000*1000; /* We do not use powers of 2 (1024) */
858 else if (c == 'k' || c == 'K') /* to avoid possible bad effects on */
859 m *= 1000; /* a direct-mapped cache. */
860 else if (c == 'w' || c == 'W')
867 bad_option(const char *s)
870 fprintf(stderr, "initSM: Bad RTS option: %s\n", s);
871 stg_exit(EXIT_FAILURE);