def ParseCommandLine(self): """ Process command line arguments and read in config file/globals. @return List of options parsed from command line """ version = '$Revision: 1.100 $' version = version.replace(' ', '') ver = version.replace(' $', '') us = '%prog phase [options] \nVersion: ' + ver desc = 'The script generates traces for an application using the PinPoints methodology '\ '(based on PinPlay: Pin-based record/replay tools). '\ 'At least one command line option must be given to chose the phases to run. ' \ 'Use option \'--default_phases\' to run all the default phases. ' \ 'See section "Phase options" for a list of phases. \n\n'\ '' \ 'The two parameters \'program_name\' and \'input_name\' must be defined in order '\ 'to run this script. If running the logging phase (-l), then two more parameters, '\ '\'command\' and \'mode\', must also be defined. '\ 'Parameters can be given either in a tracing configuration file or with command '\ 'line options. \n\n'\ '' \ 'The default configuration file is "tracing.cfg". '\ 'If it exists, the script will always read this cfg file first. '\ 'Use the option "--cfg" to select additional files. '\ 'Each cfg file on the command line is processed in order. '\ 'Command line options over-ride values read from configuration files. '\ 'All parameters listed in the three parameter '\ 'sections below can be defined in a cfg file. The long option name, '\ 'not the single letter option, must be used in the cfg files.\n\n'\ '' \ 'Example parameter configuration file:'\ ' '\ '--------------------------------------------'\ ' '\ '[Parameters]'\ ' '\ 'program_name: omnetpp'\ ' '\ 'input_name: p10000-s10'\ ' '\ 'command: ./dtlb5-lin64 -p10000 -s10'\ ' '\ 'mode: st'\ ' '\ '--------------------------------------------' util.CheckNonPrintChar(sys.argv) parser = optparse.OptionParser( usage=us, description=desc, version=ver, formatter=cmd_options.BlankLinesIndentedHelpFormatter()) # Command line options to control the tools behavior. These are not in any # of the option groups. # # import pdb; pdb.set_trace() cmd_options.add_program_wp(parser) cmd_options.append_status(parser) cmd_options.config_file(parser) cmd_options.debug(parser) cmd_options.delete(parser) cmd_options.delete_all(parser) cmd_options.delete_wp(parser) cmd_options.dir_separator(parser) cmd_options.log_options(parser) cmd_options.msgfile_ext(parser) cmd_options.no_glob(parser) cmd_options.pintool(parser) cmd_options.pin_options(parser) cmd_options.replay_options(parser) cmd_options.save_global(parser) cmd_options.verbose(parser) self.AddAdditionalOptions(parser) # Top level command line options in the default group allow the user # to choose the phases to run. # phase_group = cmd_options.PhaseGroup(parser) cmd_options.default_phases(parser, phase_group) cmd_options.native_pure(parser, phase_group) cmd_options.log(parser, phase_group) cmd_options.replay(parser, phase_group) cmd_options.basic_block_vector(parser, phase_group) cmd_options.simpoint(parser, phase_group) cmd_options.region_pinball(parser, phase_group) cmd_options.replay_region(parser, phase_group) self.AddAdditionalPhaseOptions(parser, phase_group) parser.add_option_group(phase_group) # Top level command line options in param group are used to set various # tracing parameters. # param_group = cmd_options.ParameterGroup(parser) cmd_options.command(parser, param_group) cmd_options.compressed(parser, param_group) cmd_options.focus_thread(parser, param_group) cmd_options.input_name(parser, param_group) cmd_options.mpi_options(parser, param_group) cmd_options.mode(parser, param_group) cmd_options.num_cores(parser, param_group) cmd_options.num_proc(parser, param_group) cmd_options.program_name(parser, param_group) self.KitOption(parser, param_group) parser.add_option_group(param_group) # Top level command line options which only apply to the Simpoint phase. # simpoint_phase_group = cmd_options.SimpointPhaseGroup(parser) cmd_options.combine(parser, simpoint_phase_group) cmd_options.cutoff(parser, simpoint_phase_group) cmd_options.ldv(parser, simpoint_phase_group) cmd_options.maxk(parser, simpoint_phase_group) cmd_options.slice_size(parser, simpoint_phase_group) cmd_options.warmup_factor(parser, simpoint_phase_group) cmd_options.pccount_regions(parser, simpoint_phase_group) cmd_options.global_regions(parser, simpoint_phase_group) cmd_options.simpoint_options(parser, simpoint_phase_group) parser.add_option_group(simpoint_phase_group) # Top level command line options which only apply to the region pinball generation phase. # region_pb_phase_group = cmd_options.RegionPBPhaseGroup(parser) cmd_options.epilog_length(parser, region_pb_phase_group) cmd_options.prolog_length(parser, region_pb_phase_group) cmd_options.warmup_length(parser, region_pb_phase_group) parser.add_option_group(region_pb_phase_group) # Add verify options. # self.AddVerifyOptions(parser) # Top level command line options in modify group modify the behavior of phases. # modify_group = cmd_options.ModifyGroup(parser) # These should go before the rest of the modify options. # cmd_options.coop_pinball(parser, modify_group) cmd_options.cross_os(parser, modify_group) cmd_options.list(parser, modify_group) cmd_options.native_pin(parser, modify_group) cmd_options.no_focus_thread(parser, modify_group) cmd_options.whole_pgm_dir(parser, modify_group) self.AddAdditionalModifyOptions(parser, modify_group) parser.add_option_group(modify_group) # Top level command line options in which only apply to the region pinball generation phase. # wp_filter_group = cmd_options.WPFilterGroup(parser) cmd_options.relog_name(parser, wp_filter_group) cmd_options.relog_focus(parser, wp_filter_group) cmd_options.relog_no_init(parser, wp_filter_group) cmd_options.relog_no_cleanup(parser, wp_filter_group) cmd_options.relog_code_exclude(parser, wp_filter_group) cmd_options.relog_no_omp_spin(parser, wp_filter_group) cmd_options.relog_no_mpi_spin(parser, wp_filter_group) cmd_options.use_relog_name(parser, wp_filter_group) cmd_options.use_relog_focus(parser, wp_filter_group) cmd_options.use_relog_no_cleanup(parser, wp_filter_group) cmd_options.use_relog_no_init(parser, wp_filter_group) cmd_options.use_relog_code_exclude(parser, wp_filter_group) cmd_options.use_relog_no_omp_spin(parser, wp_filter_group) cmd_options.use_relog_no_mpi_spin(parser, wp_filter_group) parser.add_option_group(wp_filter_group) # Parse the command line options. # # import pdb; pdb.set_trace() (options, args) = parser.parse_args() # Added method cbsp() to 'options' to check if running CBSP. # util.AddMethodcbsp(options) # Check to make sure there was at least one command line option given. # # import pdb; pdb.set_trace() if len(sys.argv) == 1: msg.PrintMsg( "ERROR: Must use command line options to chose at least one phase to run.\n" "Use the option '--default_phases' to run the default phases. Use '--help' for more info.") util.CheckResult(-1, options, 'Checking command line options') # If user does not just want to delete all the files, then # read in configuration files and set global variables. # # import pdb; pdb.set_trace() if not options.delete_all: self.Config.GetCfgGlobals(options, True) # Yes, need 4 required parameters # Once the tracing configuration parameters are read, get the kit # in case pinplayhome was set on the command line. Also, need to # reset the path in object 'self' and set the kit in self.phases. # # import pdb; pdb.set_trace() kit_obj = self.GetKit() self.path = kit_obj.path self.script_path = kit_obj.path self.phases.SetKit(kit_obj) # If required, check to see if there any 'forbidden' char in some of # the parameters. # # import pdb; pdb.set_trace() if self.kit_type == config.SDE and hasattr(options, 'spec') and not options.spec: self.Config.CheckForbiddenChar() # If doing code exclusion, check to make sure the file exists. # if options.relog_code_exclude: if not os.path.exists(options.relog_code_exclude): msg.PrintMsg( 'ERROR: The code exclusion file used for filtering does not exist:\n' ' ' + options.relog_code_exclude) util.CheckResult(-1, options, 'Checking command line options') # Do some 'special' things on native Windows. # util.WindowsNativeCheck(options) return options
def ParseCommandLine(self): """ Get the options from the command line and check for errors. @return tuple with parsed options and unparsed args """ # Define and get command line options. # version = '$Revision: 1.33 $' version = version.replace('$Revision: ', '') ver = version.replace(' $', '') us = '%prog --bbv_file FILE --data_dir DIR FILE --simpoint_file FILE [options] --pccount_regions --warmup_factor W' desc = 'Runs Simpoint and then generates the region CSV file. ' \ 'Input to Simpoint can be just an BBV file or a combination of BBV/LDV files. \n\n' \ 'Required options: --bbv_file, --data_dir, --simpoint_file' util.CheckNonPrintChar(sys.argv) parser = optparse.OptionParser( usage=us, version=ver, description=desc, formatter=cmd_options.BlankLinesIndentedHelpFormatter()) cmd_options.debug(parser) cmd_options.global_file(parser) cmd_options.list(parser, '') cmd_options.bbv_file(parser, '') cmd_options.data_dir(parser) cmd_options.simpoint_file(parser) cmd_options.ldv(parser, '') cmd_options.combine(parser, '') cmd_options.cutoff(parser, '') cmd_options.focus_thread(parser, '') cmd_options.maxk(parser, '') cmd_options.warmup_factor(parser, '') cmd_options.pccount_regions(parser, '') cmd_options.num_cores(parser, '') cmd_options.simpoint_options(parser, '') (options, args) = parser.parse_args() # Added method cbsp() to 'options' to check if running CBSP. # util.AddMethodcbsp(options) # Must have option '--ldv', even if using option '--combine', in order to # process BBV/LDV both. Let user know if '--combine' used w/o '--ldv'. # if not options.ldv and options.combine != -1.0: msg.PrintMsgPlus('WARNING: Option \'--combine\' detected without \'--ldv\'. Only using BBV for ' \ 'Simpoint. \n Must explicitly specify \'--ldv\' in order to use both BBV/LDV.\n') if options.ldv: msg.PrintMsgPlus( 'Using both BBV/LDV files when running Simpoint\n') # If option combine is not set, then set it to the default value. # Check to make sure combine an acceptable value. # util.SetCombineDefault(options) util.CheckCombine(options) # Read in an optional configuration files and set global variables. # config_obj = config.ConfigClass() config_obj.GetCfgGlobals(options, False) # Don't need to require 4 variables # Error check input to make sure all required options are on the command line. # if options.bbv_file == '': msg.PrintAndExit( 'Basic block vector file must be defined with option: --bbv_file FILE' ) if options.warmup_factor != 0 and not options.pccount_regions: msg.PrintAndExit( '--warmup_factor can only be specified with --pccount_regions') if options.data_dir == '': msg.PrintAndExit( 'Simpoint data directory must be defined with option: --data_dir DIR' ) if options.simpoint_file == '': msg.PrintAndExit( 'Simpoint output must be defined with option: --simpoint_file FILE' ) # The data_dir should exist and contain the BBV file. # if not os.path.isdir(options.data_dir): msg.PrintAndExit('Data directory does not exist: ' + options.data_dir) if not os.path.isfile(os.path.join(options.data_dir, options.bbv_file)): msg.PrintAndExit('Basic block vector file does not exist: ' + options.bbv_file) # Do some 'special' things on native Windows. # util.WindowsNativeCheck(options) return (options, args)