1 /* -----------------------------------------------------------------------------
2 * $Id: RtsFlags.c,v 1.2 1998/12/02 13:28:39 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.maxHeapSize = (64 * 1024 * 1024) / BLOCK_SIZE;
66 RtsFlags.GcFlags.pcFreeHeap = 3; /* 3% */
68 RtsFlags.GcFlags.force2s = rtsFalse;
69 RtsFlags.GcFlags.forceGC = rtsFalse;
70 RtsFlags.GcFlags.forcingInterval = 5000000; /* 5MB (or words?) */
71 RtsFlags.GcFlags.ringBell = rtsFalse;
73 RtsFlags.GcFlags.squeezeUpdFrames = rtsTrue;
75 #if defined(PROFILING) || defined(PAR)
76 RtsFlags.CcFlags.doCostCentres = 0;
77 RtsFlags.CcFlags.sortBy = SORTCC_TIME;
78 #endif /* PROFILING or PAR */
81 RtsFlags.ProfFlags.doHeapProfile = rtsFalse;
83 RtsFlags.ProfFlags.ccSelector = NULL;
84 RtsFlags.ProfFlags.modSelector = NULL;
85 RtsFlags.ProfFlags.grpSelector = NULL;
86 RtsFlags.ProfFlags.descrSelector = NULL;
87 RtsFlags.ProfFlags.typeSelector = NULL;
88 RtsFlags.ProfFlags.kindSelector = NULL;
90 RtsFlags.ProfFlags.doHeapProfile = rtsFalse;
93 /* there really shouldn't be a threads limit for concurrent mandatory threads.
94 For now, unlimitied means less than 64k (there's a storage overhead) -- SOF
96 #if defined(CONCURRENT) && !defined(GRAN)
97 RtsFlags.ConcFlags.ctxtSwitchTime = CS_MIN_MILLISECS; /* In milliseconds */
98 RtsFlags.ConcFlags.maxThreads = 65536;
99 RtsFlags.ConcFlags.stkChunkSize = 1024;
100 RtsFlags.ConcFlags.maxLocalSparks = 65536;
101 #endif /* CONCURRENT only */
104 RtsFlags.ConcFlags.ctxtSwitchTime = CS_MIN_MILLISECS; /* In milliseconds */
105 RtsFlags.ConcFlags.maxThreads = 32;
106 RtsFlags.ConcFlags.stkChunkSize = 1024;
107 RtsFlags.ConcFlags.maxLocalSparks = 500;
111 RtsFlags.ParFlags.parallelStats = rtsFalse;
112 RtsFlags.ParFlags.granSimStats = rtsFalse;
113 RtsFlags.ParFlags.granSimStats_Binary = rtsFalse;
115 RtsFlags.ParFlags.outputDisabled = rtsFalse;
117 RtsFlags.ParFlags.packBufferSize = 1024;
118 RtsFlags.ParFlags.maxLocalSparks = 4096;
122 RtsFlags.GranFlags.granSimStats = rtsFalse;
123 RtsFlags.GranFlags.granSimStats_suppressed = rtsFalse;
124 RtsFlags.GranFlags.granSimStats_Binary = rtsFalse;
125 RtsFlags.GranFlags.granSimStats_Sparks = rtsFalse;
126 RtsFlags.GranFlags.granSimStats_Heap = rtsFalse;
127 RtsFlags.GranFlags.labelling = rtsFalse;
128 RtsFlags.GranFlags.packBufferSize = 1024;
129 RtsFlags.GranFlags.packBufferSize_internal = GRANSIM_DEFAULT_PACK_BUFFER_SIZE;
131 RtsFlags.GranFlags.proc = MAX_PROC;
132 RtsFlags.GranFlags.max_fishes = MAX_FISHES;
133 RtsFlags.GranFlags.time_slice = GRAN_TIME_SLICE;
134 RtsFlags.GranFlags.Light = rtsFalse;
136 RtsFlags.GranFlags.gran_latency = LATENCY;
137 RtsFlags.GranFlags.gran_additional_latency = ADDITIONAL_LATENCY;
138 RtsFlags.GranFlags.gran_fetchtime = FETCHTIME;
139 RtsFlags.GranFlags.gran_lunblocktime = LOCALUNBLOCKTIME;
140 RtsFlags.GranFlags.gran_gunblocktime = GLOBALUNBLOCKTIME;
141 RtsFlags.GranFlags.gran_mpacktime = MSGPACKTIME;
142 RtsFlags.GranFlags.gran_munpacktime = MSGUNPACKTIME;
143 RtsFlags.GranFlags.gran_mtidytime = MSGTIDYTIME;
145 RtsFlags.GranFlags.gran_threadcreatetime = THREADCREATETIME;
146 RtsFlags.GranFlags.gran_threadqueuetime = THREADQUEUETIME;
147 RtsFlags.GranFlags.gran_threaddescheduletime = THREADDESCHEDULETIME;
148 RtsFlags.GranFlags.gran_threadscheduletime = THREADSCHEDULETIME;
149 RtsFlags.GranFlags.gran_threadcontextswitchtime = THREADCONTEXTSWITCHTIME;
151 RtsFlags.GranFlags.gran_arith_cost = ARITH_COST;
152 RtsFlags.GranFlags.gran_branch_cost = BRANCH_COST;
153 RtsFlags.GranFlags.gran_load_cost = LOAD_COST;
154 RtsFlags.GranFlags.gran_store_cost = STORE_COST;
155 RtsFlags.GranFlags.gran_float_cost = FLOAT_COST;
157 RtsFlags.GranFlags.gran_heapalloc_cost = HEAPALLOC_COST;
159 RtsFlags.GranFlags.gran_pri_spark_overhead = PRI_SPARK_OVERHEAD;
160 RtsFlags.GranFlags.gran_pri_sched_overhead = PRI_SCHED_OVERHEAD;
162 RtsFlags.GranFlags.DoFairSchedule = rtsFalse;
163 RtsFlags.GranFlags.DoReScheduleOnFetch = rtsFalse;
164 RtsFlags.GranFlags.DoStealThreadsFirst = rtsFalse;
165 RtsFlags.GranFlags.SimplifiedFetch = rtsFalse;
166 RtsFlags.GranFlags.DoAlwaysCreateThreads = rtsFalse;
167 RtsFlags.GranFlags.DoGUMMFetching = rtsFalse;
168 RtsFlags.GranFlags.DoThreadMigration = rtsFalse;
169 RtsFlags.GranFlags.FetchStrategy = 2;
170 RtsFlags.GranFlags.PreferSparksOfLocalNodes = rtsFalse;
171 RtsFlags.GranFlags.DoPrioritySparking = rtsFalse;
172 RtsFlags.GranFlags.DoPriorityScheduling = rtsFalse;
173 RtsFlags.GranFlags.SparkPriority = 0;
174 RtsFlags.GranFlags.SparkPriority2 = 0;
175 RtsFlags.GranFlags.RandomPriorities = rtsFalse;
176 RtsFlags.GranFlags.InversePriorities = rtsFalse;
177 RtsFlags.GranFlags.IgnorePriorities = rtsFalse;
178 RtsFlags.GranFlags.ThunksToPack = 0;
179 RtsFlags.GranFlags.RandomSteal = rtsTrue;
180 RtsFlags.GranFlags.NoForward = rtsFalse;
181 RtsFlags.GranFlags.PrintFetchMisses = rtsFalse;
183 RtsFlags.GranFlags.debug = 0x0;
184 RtsFlags.GranFlags.event_trace = rtsFalse;
185 RtsFlags.GranFlags.event_trace_all = rtsFalse;
189 RtsFlags.TickyFlags.showTickyStats = rtsFalse;
190 RtsFlags.TickyFlags.tickyFile = NULL;
192 AllFlags.doUpdEntryCounts = rtsTrue; /*ToDo:move? */
199 "Usage: <prog> <args> [+RTS <rtsopts> | -RTS <args>] ... --RTS <args>",
201 " +RTS Indicates run time system options follow",
202 " -RTS Indicates program arguments follow",
203 " --RTS Indicates that ALL subsequent arguments will be given to the",
204 " program (including any of these RTS flags)",
206 "The following run time system options are available:",
208 " -? -f Prints this message and exits; the program is not executed",
210 " -K<size> Sets the maximum stack size (default 1M) Egs: -K32k -K512k",
211 " -k<size> Sets the initial thread stack size (default 1k) Egs: -K4k -K2m",
213 " -A<size> Sets the minimum allocation area size (default 256k) Egs: -A1m -A10k",
214 " -M<size> Sets the maximum heap size (default 64M) Egs: -H256k -H1G",
215 " -m<n>% Minimum % of heap which must be available (default 3%)",
216 " -s<file> Summary GC statistics (default file: <program>.stat)",
217 " -S<file> Detailed GC statistics (with -Sstderr going to stderr)",
220 " -Z Don't squeeze out update frames on stack overflow",
221 " -B Sound the bell at the start of each garbage collection",
222 #if defined(PROFILING) || defined(PAR)
224 " -p<sort> Produce cost centre time profile (output file <program>.prof)",
225 " sort: T = time (default), A = alloc, C = cost centre label",
226 " -P<sort> Produce serial time profile (output file <program>.time)",
227 " and a -p profile with detailed tick/alloc info",
228 # if defined(PROFILING)
230 " -h<break-down> Heap residency profile (output file <program>.hp)",
231 " break-down: C = cost centre (default), M = module, G = group",
232 " D = closure description, Y = type description",
233 " T<ints>,<start> = time closure created",
234 " ints: no. of interval bands plotted (default 18)",
235 " start: seconds after which intervals start (default 0.0)",
236 " A subset of closures may be selected by the attached cost centre using:",
237 " -c{mod:lab,mod:lab...}, specific module:label cost centre(s)",
238 " -m{mod,mod...} all cost centres from the specified modules(s)",
239 " -g{grp,grp...} all cost centres from the specified group(s)",
240 " Selections can also be made by description, type, kind and age:",
241 " -d{des,des...} closures with specified closure descriptions",
242 " -y{typ,typ...} closures with specified type descriptions",
243 " -k{knd,knd...} closures of the specified kinds",
244 " -a<age> closures which survived <age> complete intervals",
245 " The selection logic used is summarised as follows:",
246 " ([-c] or [-m] or [-g]) and ([-d] or [-y] or [-k]) and [-a]",
247 " where an option is true if not specified",
250 " -z<tbl><size> set hash table <size> for <tbl> (C, M, G, D or Y)",
252 " -i<secs> Number of seconds in a profiling interval (default 1.0):",
253 " heap profile (-h) and/or serial time profile (-P) frequency",
254 #endif /* PROFILING or PAR */
255 #if !defined(PROFILING) && defined(DEBUG)
257 " -h<break-down> Debugging Heap residency profile",
258 " (output file <program>.hp)",
259 " break-down: L = closure label (default)",
260 " T = closure type (constructor, thunk etc.)",
263 #if defined(TICKY_TICKY)
264 " -r<file> Produce reduction profiling statistics (with -rstderr for stderr)",
267 " -T<level> Trace garbage collection execution (debugging)",
270 " -N<n> Use <n> PVMish processors in parallel (default: 2)",
271 /* NB: the -N<n> is implemented by the driver!! */
273 " -C<secs> Context-switch interval in seconds",
274 " (0 or no argument means switch as often as possible)",
275 " the default is .01 sec; resolution is .01 sec",
276 " -e<size> Size of spark pools (default 100)",
278 " -q Enable activity profile (output files in ~/<program>*.gr)",
279 " -qb Enable binary activity profile (output file /tmp/<program>.gb)",
280 " -Q<size> Set pack-buffer size (default: 1024)",
282 " -q[v] Enable quasi-parallel profile (output file <program>.qp)",
284 " -t<num> Set maximum number of advisory threads per PE (default 32)",
285 " -o<num> Set stack chunk size (default 1024)",
287 " -d Turn on PVM-ish debugging",
288 " -O Disable output for performance measurement",
290 # ifdef GRAN /* ToDo: fill in decent Docu here */
291 " -b... All GranSim options start with -b; see GranSim User's Guide for details",
294 "Other RTS options may be available for programs compiled a different way.",
295 "The GHC User's Guide has full details.",
300 static __inline__ rtsBool
301 strequal(const char *a, const char * b)
303 return(strcmp(a, b) == 0);
307 setupRtsFlags(int *argc, char *argv[], int *rts_argc, char *rts_argv[])
309 rtsBool error = rtsFalse;
314 /* Remove directory from argv[0] -- default files in current directory */
316 if ((last_slash = (char *) strrchr(argv[0], '/')) != NULL)
317 strcpy(argv[0], last_slash+1);
319 /* Split arguments (argv) into PGM (argv) and RTS (rts_argv) parts */
320 /* argv[0] must be PGM argument -- leave in argv */
328 for (mode = PGM; arg < total_arg && ! strequal("--RTS", argv[arg]); arg++) {
329 if (strequal("+RTS", argv[arg])) {
332 else if (strequal("-RTS", argv[arg])) {
335 else if (mode == RTS && *rts_argc < MAX_RTS_ARGS-1) {
336 rts_argv[(*rts_argc)++] = argv[arg];
338 else if (mode == PGM) {
339 argv[(*argc)++] = argv[arg];
342 barf("too many RTS arguments (max %d)", MAX_RTS_ARGS-1);
345 if (arg < total_arg) {
346 /* arg must be --RTS; process remaining program arguments */
347 while (++arg < total_arg) {
348 argv[(*argc)++] = argv[arg];
351 argv[*argc] = (char *) 0;
352 rts_argv[*rts_argc] = (char *) 0;
354 /* Process RTS (rts_argv) part: mainly to determine statsfile */
356 for (arg = 0; arg < *rts_argc; arg++) {
357 if (rts_argv[arg][0] != '-') {
359 fprintf(stderr, "setupRtsFlags: Unexpected RTS argument: %s\n",
364 switch(rts_argv[arg][1]) {
366 /* process: general args, then PROFILING-only ones,
367 then CONCURRENT-only, PARallel-only, GRAN-only,
368 TICKY-only (same order as defined in RtsFlags.lh);
369 within those groups, mostly in case-insensitive
374 # define TICKY_BUILD_ONLY(x) x
376 # define TICKY_BUILD_ONLY(x) \
377 fprintf(stderr, "setupRtsFlags: GHC not built for: ticky-ticky stats\n"); \
381 #if defined(PROFILING)
382 # define COST_CENTRE_USING_BUILD_ONLY(x) x
384 # define COST_CENTRE_USING_BUILD_ONLY(x) \
385 fprintf(stderr, "setupRtsFlags: GHC not built for: -prof or -parallel\n"); \
390 # define PROFILING_BUILD_ONLY(x) x
392 # define PROFILING_BUILD_ONLY(x) \
393 fprintf(stderr, "setupRtsFlags: GHC not built for: -prof\n"); \
398 # define PAR_BUILD_ONLY(x) x
400 # define PAR_BUILD_ONLY(x) \
401 fprintf(stderr, "setupRtsFlags: GHC not built for: -parallel\n"); \
406 # define GRAN_BUILD_ONLY(x) x
408 # define GRAN_BUILD_ONLY(x) \
409 fprintf(stderr, "setupRtsFlags: GHC not built for: -gransim\n"); \
413 /* =========== GENERAL ========================== */
420 RtsFlags.GcFlags.minAllocAreaSize
421 = decode(rts_argv[arg]+2) / BLOCK_SIZE;
422 if (RtsFlags.GcFlags.minAllocAreaSize <= 0) {
423 bad_option(rts_argv[arg]);
428 RtsFlags.GcFlags.ringBell = rtsTrue;
433 /* hack warning: interpret the flags as a binary number */
434 *(int*)(&RtsFlags.DebugFlags) = decode(rts_argv[arg]+2);
439 if (strequal(rts_argv[arg]+2, "2s")) {
440 RtsFlags.GcFlags.force2s = rtsTrue;
442 bad_option( rts_argv[arg] );
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 /* ignore for compatibility with older versions */
484 case 'j': /* force GC option */
485 RtsFlags.GcFlags.forceGC = rtsTrue;
486 if (rts_argv[arg][2]) {
487 RtsFlags.GcFlags.forcingInterval
488 = decode(rts_argv[arg]+2) / sizeof(W_);
492 case 'S': /* NB: no difference at present ! */
494 RtsFlags.GcFlags.giveStats ++; /* will be VERBOSE_GC_STATS */
496 /* Opening all those files would almost certainly fail... */
497 RtsFlags.ParFlags.parallelStats = rtsTrue;
498 RtsFlags.GcFlags.statsFile = stderr; /* temporary; ToDo: rm */
500 RtsFlags.GcFlags.statsFile
501 = open_stats_file(arg, *argc, argv,
502 *rts_argc, rts_argv, STAT_FILENAME_FMT);
504 if (RtsFlags.GcFlags.statsFile == NULL) error = rtsTrue;
509 RtsFlags.GcFlags.squeezeUpdFrames = rtsFalse;
512 /* =========== PROFILING ========================== */
514 case 'P': /* detailed cost centre profiling (time/alloc) */
515 COST_CENTRE_USING_BUILD_ONLY(
516 RtsFlags.CcFlags.doCostCentres++;
518 case 'p': /* cost centre profiling (time/alloc) */
519 COST_CENTRE_USING_BUILD_ONLY(
520 RtsFlags.CcFlags.doCostCentres++;
522 switch (rts_argv[arg][2]) {
526 RtsFlags.CcFlags.sortBy = rts_argv[arg][2];
529 RtsFlags.CcFlags.sortBy = SORTCC_TIME;
534 case 'i': /* serial profiling -- initial timer interval */
535 COST_CENTRE_USING_BUILD_ONLY(
536 interval_ticks = (I_) ((atof(rts_argv[arg]+2) * TICK_FREQUENCY));
537 if (interval_ticks <= 0)
541 case 'h': /* serial heap profile */
542 #if !defined(PROFILING) && defined(DEBUG)
543 switch (rts_argv[arg][2]) {
546 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_INFOPTR;
549 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_CLOSURE_TYPE;
552 fprintf(stderr, "Invalid heap profile option: %s\n",
557 PROFILING_BUILD_ONLY(
558 switch (rts_argv[arg][2]) {
561 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_CC;
564 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_MOD;
567 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_GRP;
570 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_DESCR;
573 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_TYPE;
576 RtsFlags.ProfFlags.doHeapProfile = HEAP_BY_TIME;
577 if (rts_argv[arg][3]) {
578 char *start_str = strchr(rts_argv[arg]+3, ',');
580 if (start_str) *start_str = '\0';
582 if ((intervals = decode(rts_argv[arg]+3)) != 0) {
583 time_intervals = (hash_t) intervals;
584 /* ToDo: and what if it *is* zero intervals??? */
587 earlier_ticks = (I_)((atof(start_str + 1) * TICK_FREQUENCY));
592 fprintf(stderr, "Invalid heap profile option: %s\n",
600 case 'z': /* size of index tables */
601 PROFILING_BUILD_ONLY(
602 switch (rts_argv[arg][2]) {
604 max_cc_no = (hash_t) decode(rts_argv[arg]+3);
605 if (max_cc_no == 0) {
606 fprintf(stderr, "Bad number of cost centres %s\n", rts_argv[arg]);
611 max_mod_no = (hash_t) decode(rts_argv[arg]+3);
612 if (max_mod_no == 0) {
613 fprintf(stderr, "Bad number of modules %s\n", rts_argv[arg]);
618 max_grp_no = (hash_t) decode(rts_argv[arg]+3);
619 if (max_grp_no == 0) {
620 fprintf(stderr, "Bad number of groups %s\n", rts_argv[arg]);
625 max_descr_no = (hash_t) decode(rts_argv[arg]+3);
626 if (max_descr_no == 0) {
627 fprintf(stderr, "Bad number of closure descriptions %s\n", rts_argv[arg]);
632 max_type_no = (hash_t) decode(rts_argv[arg]+3);
633 if (max_type_no == 0) {
634 fprintf(stderr, "Bad number of type descriptions %s\n", rts_argv[arg]);
639 fprintf(stderr, "Invalid index table size option: %s\n",
645 case 'c': /* cost centre label select */
646 case 'g': /* cost centre group select */
647 case 'd': /* closure descr select */
648 case 'y': /* closure type select */
649 PROFILING_BUILD_ONLY(
650 {char *left = strchr(rts_argv[arg], '{');
651 char *right = strrchr(rts_argv[arg], '}');
653 if (! left || ! right ||
654 strrchr(rts_argv[arg], '{') != left ||
655 strchr(rts_argv[arg], '}') != right) {
656 fprintf(stderr, "Invalid heap profiling selection bracketing\n %s\n", rts_argv[arg]);
660 switch (rts_argv[arg][1]) {
661 case 'c': /* cost centre label select */
662 RtsFlags.ProfFlags.ccSelector = left + 1;
664 case 'm': /* cost centre module select */
665 RtsFlags.ProfFlags.modSelector = left + 1;
667 case 'g': /* cost centre group select */
668 RtsFlags.ProfFlags.grpSelector = left + 1;
670 case 'd': /* closure descr select */
671 RtsFlags.ProfFlags.descrSelector = left + 1;
673 case 'y': /* closure type select */
674 RtsFlags.ProfFlags.typeSelector = left + 1;
676 case 'k': /* closure kind select */
677 RtsFlags.ProfFlags.kindSelector = left + 1;
683 /* =========== CONCURRENT ========================= */
684 case 'C': /* context switch interval */
685 if (rts_argv[arg][2] == '\0')
686 RtsFlags.ConcFlags.ctxtSwitchTime = 0;
690 /* Convert to milliseconds */
691 cst = (I_) ((atof(rts_argv[arg]+2) * 1000));
692 cst = (cst / CS_MIN_MILLISECS) * CS_MIN_MILLISECS;
693 if (cst < CS_MIN_MILLISECS)
694 cst = CS_MIN_MILLISECS;
696 RtsFlags.ConcFlags.ctxtSwitchTime = cst;
701 if (rts_argv[arg][2] != '\0') {
702 RtsFlags.ConcFlags.maxThreads
703 = strtol(rts_argv[arg]+2, (char **) NULL, 10);
705 fprintf(stderr, "setupRtsFlags: missing size for -t\n");
710 /* =========== PARALLEL =========================== */
713 if (rts_argv[arg][2] != '\0') { /* otherwise, stick w/ the default */
715 RtsFlags.ParFlags.maxLocalSparks
716 = strtol(rts_argv[arg]+2, (char **) NULL, 10);
718 if (RtsFlags.ParFlags.maxLocalSparks <= 0) {
719 fprintf(stderr, "setupRtsFlags: bad value for -e\n");
727 RtsFlags.ParFlags.outputDisabled = rtsTrue;
730 case 'q': /* activity profile option */
732 if (rts_argv[arg][2] == 'b')
733 RtsFlags.ParFlags.granSimStats_Binary = rtsTrue;
735 RtsFlags.ParFlags.granSimStats = rtsTrue;
739 case 'q': /* quasi-parallel profile option */
741 if (rts_argv[arg][2] == 'v')
748 case 'Q': /* Set pack buffer size */
750 if (rts_argv[arg][2] != '\0') {
751 RtsFlags.ParFlags.packBufferSize = decode(rts_argv[arg]+2);
753 fprintf(stderr, "setupRtsFlags: missing size of PackBuffer (for -Q)\n");
758 /* =========== GRAN =============================== */
762 process_gran_option(arg, rts_argc, rts_argv, &error);
765 /* =========== TICKY ============================== */
767 case 'r': /* Basic profiling stats */
770 RtsFlags.TickyFlags.showTickyStats = rtsTrue;
771 RtsFlags.TickyFlags.tickyFile
772 = open_stats_file(arg, *argc, argv,
773 *rts_argc, rts_argv, TICKY_FILENAME_FMT);
775 if (RtsFlags.TickyFlags.tickyFile == NULL) error = rtsTrue;
778 /* =========== OH DEAR ============================ */
780 fprintf(stderr, "setupRtsFlags: Unknown RTS option: %s\n",rts_argv[arg]);
790 for (p = usage_text; *p; p++)
791 fprintf(stderr, "%s\n", *p);
792 stg_exit(EXIT_FAILURE);
797 static FILE * /* return NULL on error */
800 int argc, char *argv[],
801 int rts_argc, char *rts_argv[],
802 const char *FILENAME_FMT)
806 if (strequal(rts_argv[arg]+2, "stderr")) /* use real stderr */
808 else if (rts_argv[arg][2] != '\0') /* stats file specified */
809 f = fopen(rts_argv[arg]+2,"w");
811 char stats_filename[STATS_FILENAME_MAXLEN]; /* default <program>.<ext> */
812 sprintf(stats_filename, FILENAME_FMT, argv[0]);
813 f = fopen(stats_filename,"w");
816 fprintf(stderr, "Can't open stats file %s\n", rts_argv[arg]+2);
818 /* Write argv and rtsv into start of stats file */
820 for(count = 0; count < argc; count++)
821 fprintf(f, "%s ", argv[count]);
823 for(count = 0; count < rts_argc; count++)
824 fprintf(f, "%s ", rts_argv[count]);
832 decode(const char *s)
843 if (c == 'g' || c == 'G')
844 m *= 1000*1000*1000; /* UNchecked! */
845 else if (c == 'm' || c == 'M')
846 m *= 1000*1000; /* We do not use powers of 2 (1024) */
847 else if (c == 'k' || c == 'K') /* to avoid possible bad effects on */
848 m *= 1000; /* a direct-mapped cache. */
849 else if (c == 'w' || c == 'W')
856 bad_option(const char *s)
859 fprintf(stderr, "initSM: Bad RTS option: %s\n", s);
860 stg_exit(EXIT_FAILURE);