1 /* -----------------------------------------------------------------------------
2 * $Id: RtsFlags.c,v 1.7 1999/01/26 16:16:28 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.pcFreeHeap = 3; /* 3% */
68 RtsFlags.GcFlags.oldGenFactor = 2;
69 RtsFlags.GcFlags.generations = 2;
70 RtsFlags.GcFlags.steps = 2;
72 RtsFlags.GcFlags.forceGC = rtsFalse;
73 RtsFlags.GcFlags.forcingInterval = 5000000; /* 5MB (or words?) */
74 RtsFlags.GcFlags.ringBell = rtsFalse;
76 RtsFlags.GcFlags.squeezeUpdFrames = rtsTrue;
78 #if defined(PROFILING) || defined(PAR)
79 RtsFlags.CcFlags.doCostCentres = 0;
80 RtsFlags.CcFlags.sortBy = SORTCC_TIME;
81 #endif /* PROFILING or PAR */
84 RtsFlags.ProfFlags.doHeapProfile = rtsFalse;
86 RtsFlags.ProfFlags.ccSelector = NULL;
87 RtsFlags.ProfFlags.modSelector = NULL;
88 RtsFlags.ProfFlags.grpSelector = NULL;
89 RtsFlags.ProfFlags.descrSelector = NULL;
90 RtsFlags.ProfFlags.typeSelector = NULL;
91 RtsFlags.ProfFlags.kindSelector = NULL;
93 RtsFlags.ProfFlags.doHeapProfile = rtsFalse;
96 /* there really shouldn't be a threads limit for concurrent mandatory threads.
97 For now, unlimitied means less than 64k (there's a storage overhead) -- SOF
99 #if defined(CONCURRENT) && !defined(GRAN)
100 RtsFlags.ConcFlags.ctxtSwitchTime = CS_MIN_MILLISECS; /* In milliseconds */
101 RtsFlags.ConcFlags.maxThreads = 65536;
102 RtsFlags.ConcFlags.stkChunkSize = 1024;
103 RtsFlags.ConcFlags.maxLocalSparks = 65536;
104 #endif /* CONCURRENT only */
107 RtsFlags.ConcFlags.ctxtSwitchTime = CS_MIN_MILLISECS; /* In milliseconds */
108 RtsFlags.ConcFlags.maxThreads = 32;
109 RtsFlags.ConcFlags.stkChunkSize = 1024;
110 RtsFlags.ConcFlags.maxLocalSparks = 500;
114 RtsFlags.ParFlags.parallelStats = rtsFalse;
115 RtsFlags.ParFlags.granSimStats = rtsFalse;
116 RtsFlags.ParFlags.granSimStats_Binary = rtsFalse;
118 RtsFlags.ParFlags.outputDisabled = rtsFalse;
120 RtsFlags.ParFlags.packBufferSize = 1024;
121 RtsFlags.ParFlags.maxLocalSparks = 4096;
125 RtsFlags.GranFlags.granSimStats = rtsFalse;
126 RtsFlags.GranFlags.granSimStats_suppressed = rtsFalse;
127 RtsFlags.GranFlags.granSimStats_Binary = rtsFalse;
128 RtsFlags.GranFlags.granSimStats_Sparks = rtsFalse;
129 RtsFlags.GranFlags.granSimStats_Heap = rtsFalse;
130 RtsFlags.GranFlags.labelling = rtsFalse;
131 RtsFlags.GranFlags.packBufferSize = 1024;
132 RtsFlags.GranFlags.packBufferSize_internal = GRANSIM_DEFAULT_PACK_BUFFER_SIZE;
134 RtsFlags.GranFlags.proc = MAX_PROC;
135 RtsFlags.GranFlags.max_fishes = MAX_FISHES;
136 RtsFlags.GranFlags.time_slice = GRAN_TIME_SLICE;
137 RtsFlags.GranFlags.Light = rtsFalse;
139 RtsFlags.GranFlags.gran_latency = LATENCY;
140 RtsFlags.GranFlags.gran_additional_latency = ADDITIONAL_LATENCY;
141 RtsFlags.GranFlags.gran_fetchtime = FETCHTIME;
142 RtsFlags.GranFlags.gran_lunblocktime = LOCALUNBLOCKTIME;
143 RtsFlags.GranFlags.gran_gunblocktime = GLOBALUNBLOCKTIME;
144 RtsFlags.GranFlags.gran_mpacktime = MSGPACKTIME;
145 RtsFlags.GranFlags.gran_munpacktime = MSGUNPACKTIME;
146 RtsFlags.GranFlags.gran_mtidytime = MSGTIDYTIME;
148 RtsFlags.GranFlags.gran_threadcreatetime = THREADCREATETIME;
149 RtsFlags.GranFlags.gran_threadqueuetime = THREADQUEUETIME;
150 RtsFlags.GranFlags.gran_threaddescheduletime = THREADDESCHEDULETIME;
151 RtsFlags.GranFlags.gran_threadscheduletime = THREADSCHEDULETIME;
152 RtsFlags.GranFlags.gran_threadcontextswitchtime = THREADCONTEXTSWITCHTIME;
154 RtsFlags.GranFlags.gran_arith_cost = ARITH_COST;
155 RtsFlags.GranFlags.gran_branch_cost = BRANCH_COST;
156 RtsFlags.GranFlags.gran_load_cost = LOAD_COST;
157 RtsFlags.GranFlags.gran_store_cost = STORE_COST;
158 RtsFlags.GranFlags.gran_float_cost = FLOAT_COST;
160 RtsFlags.GranFlags.gran_heapalloc_cost = HEAPALLOC_COST;
162 RtsFlags.GranFlags.gran_pri_spark_overhead = PRI_SPARK_OVERHEAD;
163 RtsFlags.GranFlags.gran_pri_sched_overhead = PRI_SCHED_OVERHEAD;
165 RtsFlags.GranFlags.DoFairSchedule = rtsFalse;
166 RtsFlags.GranFlags.DoReScheduleOnFetch = rtsFalse;
167 RtsFlags.GranFlags.DoStealThreadsFirst = rtsFalse;
168 RtsFlags.GranFlags.SimplifiedFetch = rtsFalse;
169 RtsFlags.GranFlags.DoAlwaysCreateThreads = rtsFalse;
170 RtsFlags.GranFlags.DoGUMMFetching = rtsFalse;
171 RtsFlags.GranFlags.DoThreadMigration = rtsFalse;
172 RtsFlags.GranFlags.FetchStrategy = 2;
173 RtsFlags.GranFlags.PreferSparksOfLocalNodes = rtsFalse;
174 RtsFlags.GranFlags.DoPrioritySparking = rtsFalse;
175 RtsFlags.GranFlags.DoPriorityScheduling = rtsFalse;
176 RtsFlags.GranFlags.SparkPriority = 0;
177 RtsFlags.GranFlags.SparkPriority2 = 0;
178 RtsFlags.GranFlags.RandomPriorities = rtsFalse;
179 RtsFlags.GranFlags.InversePriorities = rtsFalse;
180 RtsFlags.GranFlags.IgnorePriorities = rtsFalse;
181 RtsFlags.GranFlags.ThunksToPack = 0;
182 RtsFlags.GranFlags.RandomSteal = rtsTrue;
183 RtsFlags.GranFlags.NoForward = rtsFalse;
184 RtsFlags.GranFlags.PrintFetchMisses = rtsFalse;
186 RtsFlags.GranFlags.debug = 0x0;
187 RtsFlags.GranFlags.event_trace = rtsFalse;
188 RtsFlags.GranFlags.event_trace_all = rtsFalse;
192 RtsFlags.TickyFlags.showTickyStats = rtsFalse;
193 RtsFlags.TickyFlags.tickyFile = NULL;
200 "Usage: <prog> <args> [+RTS <rtsopts> | -RTS <args>] ... --RTS <args>",
202 " +RTS Indicates run time system options follow",
203 " -RTS Indicates program arguments follow",
204 " --RTS Indicates that ALL subsequent arguments will be given to the",
205 " program (including any of these RTS flags)",
207 "The following run time system options are available:",
209 " -? -f Prints this message and exits; the program is not executed",
211 " -K<size> Sets the maximum stack size (default 1M) Egs: -K32k -K512k",
212 " -k<size> Sets the initial thread stack size (default 1k) Egs: -K4k -K2m",
214 " -A<size> Sets the minimum allocation area size (default 256k) Egs: -A1m -A10k",
215 " -M<size> Sets the maximum heap size (default 64M) Egs: -H256k -H1G",
216 " -m<n>% Minimum % of heap which must be available (default 3%)",
217 " -G<n> Number of generations (default: 2)",
218 " -T<n> Number of steps in younger generations (default: 2)",
219 " -s<file> Summary GC statistics (default file: <program>.stat)",
220 " -S<file> Detailed GC statistics (with -Sstderr going to stderr)",
223 " -Z Don't squeeze out update frames on stack overflow",
224 " -B Sound the bell at the start of each garbage collection",
225 #if defined(PROFILING) || defined(PAR)
227 " -p<sort> Produce cost centre time profile (output file <program>.prof)",
228 " sort: T = time (default), A = alloc, C = cost centre label",
229 " -P<sort> Produce serial time profile (output file <program>.time)",
230 " and a -p profile with detailed tick/alloc info",
231 # if defined(PROFILING)
233 " -h<break-down> Heap residency profile (output file <program>.hp)",
234 " break-down: C = cost centre (default), M = module, G = group",
235 " D = closure description, Y = type description",
236 " T<ints>,<start> = time closure created",
237 " ints: no. of interval bands plotted (default 18)",
238 " start: seconds after which intervals start (default 0.0)",
239 " A subset of closures may be selected by the attached cost centre using:",
240 " -c{mod:lab,mod:lab...}, specific module:label cost centre(s)",
241 " -m{mod,mod...} all cost centres from the specified modules(s)",
242 " -g{grp,grp...} all cost centres from the specified group(s)",
243 " Selections can also be made by description, type, kind and age:",
244 " -d{des,des...} closures with specified closure descriptions",
245 " -y{typ,typ...} closures with specified type descriptions",
246 " -k{knd,knd...} closures of the specified kinds",
247 " -a<age> closures which survived <age> complete intervals",
248 " The selection logic used is summarised as follows:",
249 " ([-c] or [-m] or [-g]) and ([-d] or [-y] or [-k]) and [-a]",
250 " where an option is true if not specified",
253 " -z<tbl><size> set hash table <size> for <tbl> (C, M, G, D or Y)",
255 " -i<secs> Number of seconds in a profiling interval (default 1.0):",
256 " heap profile (-h) and/or serial time profile (-P) frequency",
257 #endif /* PROFILING or PAR */
258 #if !defined(PROFILING) && defined(DEBUG)
260 " -h<break-down> Debugging Heap residency profile",
261 " (output file <program>.hp)",
262 " break-down: L = closure label (default)",
263 " T = closure type (constructor, thunk etc.)",
266 #if defined(TICKY_TICKY)
267 " -r<file> Produce reduction profiling statistics (with -rstderr for stderr)",
271 " -N<n> Use <n> PVMish processors in parallel (default: 2)",
272 /* NB: the -N<n> is implemented by the driver!! */
274 " -C<secs> Context-switch interval in seconds",
275 " (0 or no argument means switch as often as possible)",
276 " the default is .01 sec; resolution is .01 sec",
277 " -e<size> Size of spark pools (default 100)",
279 " -q Enable activity profile (output files in ~/<program>*.gr)",
280 " -qb Enable binary activity profile (output file /tmp/<program>.gb)",
281 " -Q<size> Set pack-buffer size (default: 1024)",
283 " -q[v] Enable quasi-parallel profile (output file <program>.qp)",
285 " -t<num> Set maximum number of advisory threads per PE (default 32)",
286 " -o<num> Set stack chunk size (default 1024)",
288 " -d Turn on PVM-ish debugging",
289 " -O Disable output for performance measurement",
291 # ifdef GRAN /* ToDo: fill in decent Docu here */
292 " -b... All GranSim options start with -b; see GranSim User's Guide for details",
295 "Other RTS options may be available for programs compiled a different way.",
296 "The GHC User's Guide has full details.",
301 static __inline__ rtsBool
302 strequal(const char *a, const char * b)
304 return(strcmp(a, b) == 0);
308 setupRtsFlags(int *argc, char *argv[], int *rts_argc, char *rts_argv[])
310 rtsBool error = rtsFalse;
315 /* Remove directory from argv[0] -- default files in current directory */
317 if ((last_slash = (char *) strrchr(argv[0], '/')) != NULL)
318 strcpy(argv[0], last_slash+1);
320 /* Split arguments (argv) into PGM (argv) and RTS (rts_argv) parts */
321 /* argv[0] must be PGM argument -- leave in argv */
329 for (mode = PGM; arg < total_arg && ! strequal("--RTS", argv[arg]); arg++) {
330 if (strequal("+RTS", argv[arg])) {
333 else if (strequal("-RTS", argv[arg])) {
336 else if (mode == RTS && *rts_argc < MAX_RTS_ARGS-1) {
337 rts_argv[(*rts_argc)++] = argv[arg];
339 else if (mode == PGM) {
340 argv[(*argc)++] = argv[arg];
343 barf("too many RTS arguments (max %d)", MAX_RTS_ARGS-1);
346 if (arg < total_arg) {
347 /* arg must be --RTS; process remaining program arguments */
348 while (++arg < total_arg) {
349 argv[(*argc)++] = argv[arg];
352 argv[*argc] = (char *) 0;
353 rts_argv[*rts_argc] = (char *) 0;
355 /* Process RTS (rts_argv) part: mainly to determine statsfile */
357 for (arg = 0; arg < *rts_argc; arg++) {
358 if (rts_argv[arg][0] != '-') {
360 fprintf(stderr, "setupRtsFlags: Unexpected RTS argument: %s\n",
365 switch(rts_argv[arg][1]) {
367 /* process: general args, then PROFILING-only ones,
368 then CONCURRENT-only, PARallel-only, GRAN-only,
369 TICKY-only (same order as defined in RtsFlags.lh);
370 within those groups, mostly in case-insensitive
375 # define TICKY_BUILD_ONLY(x) x
377 # define TICKY_BUILD_ONLY(x) \
378 fprintf(stderr, "setupRtsFlags: GHC not built for: ticky-ticky stats\n"); \
382 #if defined(PROFILING)
383 # define COST_CENTRE_USING_BUILD_ONLY(x) x
385 # define COST_CENTRE_USING_BUILD_ONLY(x) \
386 fprintf(stderr, "setupRtsFlags: GHC not built for: -prof or -parallel\n"); \
391 # define PROFILING_BUILD_ONLY(x) x
393 # define PROFILING_BUILD_ONLY(x) \
394 fprintf(stderr, "setupRtsFlags: GHC not built for: -prof\n"); \
399 # define PAR_BUILD_ONLY(x) x
401 # define PAR_BUILD_ONLY(x) \
402 fprintf(stderr, "setupRtsFlags: GHC not built for: -parallel\n"); \
407 # define GRAN_BUILD_ONLY(x) x
409 # define GRAN_BUILD_ONLY(x) \
410 fprintf(stderr, "setupRtsFlags: GHC not built for: -gransim\n"); \
414 /* =========== GENERAL ========================== */
421 RtsFlags.GcFlags.minAllocAreaSize
422 = decode(rts_argv[arg]+2) / BLOCK_SIZE;
423 if (RtsFlags.GcFlags.minAllocAreaSize <= 0) {
424 bad_option(rts_argv[arg]);
429 RtsFlags.GcFlags.ringBell = rtsTrue;
433 RtsFlags.GcFlags.oldGenFactor = atof(rts_argv[arg]+2);
435 if (RtsFlags.GcFlags.oldGenFactor < 0)
436 bad_option( rts_argv[arg] );
441 /* hack warning: interpret the flags as a binary number */
442 *(int*)(&RtsFlags.DebugFlags) = decode(rts_argv[arg]+2);
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 /* ignore for compatibility with older versions */
498 case 'j': /* force GC option */
499 RtsFlags.GcFlags.forceGC = rtsTrue;
500 if (rts_argv[arg][2]) {
501 RtsFlags.GcFlags.forcingInterval
502 = decode(rts_argv[arg]+2) / sizeof(W_);
506 case 'S': /* NB: no difference at present ! */
508 RtsFlags.GcFlags.giveStats ++; /* will be VERBOSE_GC_STATS */
510 /* Opening all those files would almost certainly fail... */
511 RtsFlags.ParFlags.parallelStats = rtsTrue;
512 RtsFlags.GcFlags.statsFile = stderr; /* temporary; ToDo: rm */
514 RtsFlags.GcFlags.statsFile
515 = open_stats_file(arg, *argc, argv,
516 *rts_argc, rts_argv, STAT_FILENAME_FMT);
518 if (RtsFlags.GcFlags.statsFile == NULL) error = rtsTrue;
523 RtsFlags.GcFlags.squeezeUpdFrames = rtsFalse;
526 /* =========== PROFILING ========================== */
528 case 'P': /* detailed cost centre profiling (time/alloc) */
529 COST_CENTRE_USING_BUILD_ONLY(
530 RtsFlags.CcFlags.doCostCentres++;
532 case 'p': /* cost centre profiling (time/alloc) */
533 COST_CENTRE_USING_BUILD_ONLY(
534 RtsFlags.CcFlags.doCostCentres++;
536 switch (rts_argv[arg][2]) {
540 RtsFlags.CcFlags.sortBy = rts_argv[arg][2];
543 RtsFlags.CcFlags.sortBy = SORTCC_TIME;
548 case 'i': /* serial profiling -- initial timer interval */
549 COST_CENTRE_USING_BUILD_ONLY(
550 interval_ticks = (I_) ((atof(rts_argv[arg]+2) * TICK_FREQUENCY));
551 if (interval_ticks <= 0)
555 case 'h': /* serial heap profile */
556 #if !defined(PROFILING) && defined(DEBUG)
557 switch (rts_argv[arg][2]) {
560 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_INFOPTR;
563 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_CLOSURE_TYPE;
566 fprintf(stderr, "Invalid heap profile option: %s\n",
571 PROFILING_BUILD_ONLY(
572 switch (rts_argv[arg][2]) {
575 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_CC;
578 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_MOD;
581 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_GRP;
584 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_DESCR;
587 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_TYPE;
590 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_TIME;
591 if (rts_argv[arg][3]) {
592 char *start_str = strchr(rts_argv[arg]+3, ',');
594 if (start_str) *start_str = '\0';
596 if ((intervals = decode(rts_argv[arg]+3)) != 0) {
597 time_intervals = (hash_t) intervals;
598 /* ToDo: and what if it *is* zero intervals??? */
601 earlier_ticks = (I_)((atof(start_str + 1) * TICK_FREQUENCY));
606 fprintf(stderr, "Invalid heap profile option: %s\n",
614 case 'z': /* size of index tables */
615 PROFILING_BUILD_ONLY(
616 switch (rts_argv[arg][2]) {
618 max_cc_no = (hash_t) decode(rts_argv[arg]+3);
619 if (max_cc_no == 0) {
620 fprintf(stderr, "Bad number of cost centres %s\n", rts_argv[arg]);
625 max_mod_no = (hash_t) decode(rts_argv[arg]+3);
626 if (max_mod_no == 0) {
627 fprintf(stderr, "Bad number of modules %s\n", rts_argv[arg]);
632 max_grp_no = (hash_t) decode(rts_argv[arg]+3);
633 if (max_grp_no == 0) {
634 fprintf(stderr, "Bad number of groups %s\n", rts_argv[arg]);
639 max_descr_no = (hash_t) decode(rts_argv[arg]+3);
640 if (max_descr_no == 0) {
641 fprintf(stderr, "Bad number of closure descriptions %s\n", rts_argv[arg]);
646 max_type_no = (hash_t) decode(rts_argv[arg]+3);
647 if (max_type_no == 0) {
648 fprintf(stderr, "Bad number of type descriptions %s\n", rts_argv[arg]);
653 fprintf(stderr, "Invalid index table size option: %s\n",
659 case 'c': /* cost centre label select */
660 case 'g': /* cost centre group select */
661 case 'd': /* closure descr select */
662 case 'y': /* closure type select */
663 PROFILING_BUILD_ONLY(
664 {char *left = strchr(rts_argv[arg], '{');
665 char *right = strrchr(rts_argv[arg], '}');
667 if (! left || ! right ||
668 strrchr(rts_argv[arg], '{') != left ||
669 strchr(rts_argv[arg], '}') != right) {
670 fprintf(stderr, "Invalid heap profiling selection bracketing\n %s\n", rts_argv[arg]);
674 switch (rts_argv[arg][1]) {
675 case 'c': /* cost centre label select */
676 RtsFlags.ProfFlags.ccSelector = left + 1;
678 case 'm': /* cost centre module select */
679 RtsFlags.ProfFlags.modSelector = left + 1;
681 case 'g': /* cost centre group select */
682 RtsFlags.ProfFlags.grpSelector = left + 1;
684 case 'd': /* closure descr select */
685 RtsFlags.ProfFlags.descrSelector = left + 1;
687 case 'y': /* closure type select */
688 RtsFlags.ProfFlags.typeSelector = left + 1;
690 case 'k': /* closure kind select */
691 RtsFlags.ProfFlags.kindSelector = left + 1;
697 /* =========== CONCURRENT ========================= */
698 case 'C': /* context switch interval */
699 if (rts_argv[arg][2] == '\0')
700 RtsFlags.ConcFlags.ctxtSwitchTime = 0;
704 /* Convert to milliseconds */
705 cst = (I_) ((atof(rts_argv[arg]+2) * 1000));
706 cst = (cst / CS_MIN_MILLISECS) * CS_MIN_MILLISECS;
707 if (cst < CS_MIN_MILLISECS)
708 cst = CS_MIN_MILLISECS;
710 RtsFlags.ConcFlags.ctxtSwitchTime = cst;
715 if (rts_argv[arg][2] != '\0') {
716 RtsFlags.ConcFlags.maxThreads
717 = strtol(rts_argv[arg]+2, (char **) NULL, 10);
719 fprintf(stderr, "setupRtsFlags: missing size for -t\n");
724 /* =========== PARALLEL =========================== */
727 if (rts_argv[arg][2] != '\0') { /* otherwise, stick w/ the default */
729 RtsFlags.ParFlags.maxLocalSparks
730 = strtol(rts_argv[arg]+2, (char **) NULL, 10);
732 if (RtsFlags.ParFlags.maxLocalSparks <= 0) {
733 fprintf(stderr, "setupRtsFlags: bad value for -e\n");
741 RtsFlags.ParFlags.outputDisabled = rtsTrue;
744 case 'q': /* activity profile option */
746 if (rts_argv[arg][2] == 'b')
747 RtsFlags.ParFlags.granSimStats_Binary = rtsTrue;
749 RtsFlags.ParFlags.granSimStats = rtsTrue;
753 case 'q': /* quasi-parallel profile option */
755 if (rts_argv[arg][2] == 'v')
762 case 'Q': /* Set pack buffer size */
764 if (rts_argv[arg][2] != '\0') {
765 RtsFlags.ParFlags.packBufferSize = decode(rts_argv[arg]+2);
767 fprintf(stderr, "setupRtsFlags: missing size of PackBuffer (for -Q)\n");
772 /* =========== GRAN =============================== */
776 process_gran_option(arg, rts_argc, rts_argv, &error);
779 /* =========== TICKY ============================== */
781 case 'r': /* Basic profiling stats */
784 RtsFlags.TickyFlags.showTickyStats = rtsTrue;
785 RtsFlags.TickyFlags.tickyFile
786 = open_stats_file(arg, *argc, argv,
787 *rts_argc, rts_argv, TICKY_FILENAME_FMT);
789 if (RtsFlags.TickyFlags.tickyFile == NULL) error = rtsTrue;
792 /* =========== OH DEAR ============================ */
794 fprintf(stderr, "setupRtsFlags: Unknown RTS option: %s\n",rts_argv[arg]);
804 for (p = usage_text; *p; p++)
805 fprintf(stderr, "%s\n", *p);
806 stg_exit(EXIT_FAILURE);
811 static FILE * /* return NULL on error */
814 int argc, char *argv[],
815 int rts_argc, char *rts_argv[],
816 const char *FILENAME_FMT)
820 if (strequal(rts_argv[arg]+2, "stderr")) /* use real stderr */
822 else if (rts_argv[arg][2] != '\0') /* stats file specified */
823 f = fopen(rts_argv[arg]+2,"w");
825 char stats_filename[STATS_FILENAME_MAXLEN]; /* default <program>.<ext> */
826 sprintf(stats_filename, FILENAME_FMT, argv[0]);
827 f = fopen(stats_filename,"w");
830 fprintf(stderr, "Can't open stats file %s\n", rts_argv[arg]+2);
832 /* Write argv and rtsv into start of stats file */
834 for(count = 0; count < argc; count++)
835 fprintf(f, "%s ", argv[count]);
837 for(count = 0; count < rts_argc; count++)
838 fprintf(f, "%s ", rts_argv[count]);
846 decode(const char *s)
857 if (c == 'g' || c == 'G')
858 m *= 1000*1000*1000; /* UNchecked! */
859 else if (c == 'm' || c == 'M')
860 m *= 1000*1000; /* We do not use powers of 2 (1024) */
861 else if (c == 'k' || c == 'K') /* to avoid possible bad effects on */
862 m *= 1000; /* a direct-mapped cache. */
863 else if (c == 'w' || c == 'W')
870 bad_option(const char *s)
873 fprintf(stderr, "initSM: Bad RTS option: %s\n", s);
874 stg_exit(EXIT_FAILURE);