예제 #1
0
    def ParseCommandLine(self):
        """
        Parse command line arguments and check to make sure all required options were given.

        @return List of options
        """

        # command line options for the driver
        #
        version = '$Revision: 1.14 $'
        version = version.replace(' ', '')
        ver = version.replace(' $', '')
        us = '%prog [options] --mode MODE binary args'
        desc = 'Runs binary with the logger Pintool and generates whole program '\
               'pinballs. Required arguments include:\n'\
               '   1) Binary to run and it\'s arguments.\n'\
               '   2) Mode of the binary using \'--mode MODE\'.\n'\
               'If the option \'--log_file\' is not given, the default pinball name is \'log\'.'

        util.CheckNonPrintChar(sys.argv)
        parser = optparse.OptionParser(
            usage=us,
            version=ver,
            description=desc,
            formatter=cmd_options.BlankLinesIndentedHelpFormatter())

        # Define the command line options which control the behavior of the
        # script.  Some of these methods take a 2nd argument which is the empty
        # string ''.   If the script uses option groups, then this parameter is
        # the group.  However, this script does not use option groups, so the
        # argument is empty.
        #
        cmd_options.arch(parser, '')
        cmd_options.compressed(parser, '')
        cmd_options.config_file(parser)
        cmd_options.debug(parser)
        cmd_options.global_file(parser)
        cmd_options.log_file(parser)
        cmd_options.log_options(parser)
        cmd_options.mode(parser, '')
        cmd_options.mpi_options(parser, '')
        cmd_options.msgfile_ext(parser)
        cmd_options.no_log(parser)
        cmd_options.no_print_cmd(parser)
        cmd_options.pid(parser)
        cmd_options.pinplayhome(parser, '')
        cmd_options.pintool(parser)
        cmd_options.pintool_help(parser)
        cmd_options.pin_options(parser)
        cmd_options.save_global(parser)
        cmd_options.sdehome(parser, '')
        cmd_options.verbose(parser)

        # import pdb;  pdb.set_trace()
        (options, args) = parser.parse_args()

        # Added method cbsp() to 'options' to check if running CBSP.
        #
        util.AddMethodcbsp(options)

        # Translate the 'arch' string given by the user into
        # the internal arch type used by the scripts.
        #
        util.SetArch(options)

        # If user just wants pintool_help, return
        #
        if (hasattr(options, 'pintool_help') and options.pintool_help):

            return options

        # Read in configuration files and set global variables.
        # No requirment to read in a config file, but it's OK
        # to give one.
        #
        config_obj = config.ConfigClass()
        config_obj.GetCfgGlobals(options,
                                 False)  # No, don't need required parameters

        # Make sure user gave an application mode
        #
        if options.mode:
            options.mode = util.ParseMode(options.mode)
        else:
            parser.error("Application mode was not given.\n" \
                "Need to use option --mode MODE. Choose MODE from: 'st', 'mt', 'mpi', 'mpi_mt', 'mp', 'mp_mt'")

        # Get the application command line
        #
        # import pdb;  pdb.set_trace()
        cmd_line = " ".join(args)
        if not options.pid:
            if cmd_line:
                setattr(options, 'command', cmd_line)
            else:
                parser.error('no program command line specified.\n'
                             'Need to add binary and it\'s arguments.')

        return options
예제 #2
0
파일: replay_dir.py 프로젝트: mazalves/OrCS
    def ParseCommandLine(self):
        """
        Process command line arguments and ensure they are valid.

        @return List of command line options
        """

        # import pdb ; pdb.set_trace()
        version = '$Revision: 1.78 $'
        version = version.replace('$Revision: ', '')
        ver = version.replace(' $', '')
        us = '%prog [options]\nVersion: ' + ver
        desc = 'Replays one, or more, pinball(s). Must use one of '\
               'the following options: \n'\
               '--replay_file, --all_file, --all_dir'

        util.CheckNonPrintChar(sys.argv)
        parser = optparse.OptionParser(usage=us, version=ver, description=desc)

        # Define the command line options which control the behavior of the
        # script.  Some of these methods take a 2nd argument which is the empty
        # string ''. If the script uses option groups, then this parameter is
        # the group. However, this script does not use option groups, so the
        # argument is empty.
        #
        cmd_options.debug(parser)
        cmd_options.verbose(parser)
        cmd_options.all_dir(parser)
        cmd_options.all_file(parser)
        cmd_options.config_file(parser)
        cmd_options.global_file(parser)
        cmd_options.list(parser, '')
        cmd_options.no_glob(parser)
        cmd_options.num_cores(parser, '')
        cmd_options.replay_dir(parser)
        cmd_options.replay_file(parser)
        cmd_options.replay_filter(parser)
        cmd_options.save_global(parser)

        self.AddAdditionalOptions(parser)

        # import pdb ; pdb.set_trace()
        (options, args) = parser.parse_args()

        # Added method cbsp() to 'options' to check if running CBSP.
        #
        util.AddMethodcbsp(options)

        # Read in configuration files and set global variables.
        # No need to read in a config file.
        #
        # import pdb;  pdb.set_trace()
        config_obj = config.ConfigClass()
        config_obj.GetCfgGlobals(options,
                                 False)  # Don't need to require 4 variables

        # Once the tracing configuration parameters are read, get the kit in
        # case pinplayhome was set on the command line.
        #
        self.kit_obj = self.GetKit()

        # Print out the version number
        #
        # import pdb;  pdb.set_trace()
        if config.debug:
            print(os.path.basename(sys.argv[0]) + " $Revision: 1.78 $")

        # Some error checking.
        #
        if options.replay_file == '' and options.all_dir == '' and options.all_file == '' and \
                options.replay_dir == '':
            msg.PrintAndExit(
                "Either a replay directory or replay file must be specified!")

        elif (options.all_dir != '' and options.all_file != '') or  \
             (options.all_dir != '' and options.replay_file != '') or \
             (options.all_file != '' and options.replay_file != ''):

            msg.PrintAndExit(
                "Specify either a replay directory or a replay file, not both!")

        return options
예제 #3
0
    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]'
        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.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.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)
예제 #4
0
    def ParseCommandLine(self):
        """
        Process command line arguments, get Kit, tool options, and their paths.

        @return List containing: pin_options, pintool_options, options.replay_file, kit_obj
        """

        # import pdb;  pdb.set_trace()
        version = '$Revision: 1.63 $'
        version = version.replace(' ', '')
        ver = version.replace(' $', '')
        us = '%prog [options] pinball_basename \nVersion: ' + ver
        desc = 'Replays one pinball. Use \'--replay_options\' or ' \
               '\'--log_options\' to modify the pintool behavior during replay.'
        util.CheckNonPrintChar(sys.argv)
        parser = optparse.OptionParser(usage=us, version=ver, description=desc)

        # Define the command line options which control the behavior of the
        # script.
        #
        # Some of these methods take a 2nd argument which is the empty string
        # ''.  If this script used option groups, then the 2nd parameter would
        # be the group.  However, this script does not use option groups, so
        # the argument is empty.
        #
        cmd_options.arch(parser, '')
        cmd_options.config_file(parser)
        cmd_options.cross_os(parser, '')
        cmd_options.debug(parser)
        cmd_options.global_file(parser)
        cmd_options.log_options(parser)
        cmd_options.msgfile_ext(parser)
        cmd_options.no_print_cmd(parser)
        cmd_options.pintool(parser)
        cmd_options.pintool_help(parser)
        cmd_options.pin_options(parser)
        cmd_options.pinplayhome(parser, '')
        cmd_options.playout(parser)
        cmd_options.replay_file(parser)
        cmd_options.replay_options(parser)
        cmd_options.save_global(parser)
        cmd_options.sdehome(parser, '')
        cmd_options.verbose(parser)

        # import pdb;  pdb.set_trace()
        (options, args) = parser.parse_args()

        if options.verbose:
            msg.PrintMsg('Started replayer.py')
        # Check to make sure the pinball basename has been given as an argument or
        # command line option.
        #
        # import pdb;  pdb.set_trace()
        if options.replay_file == '' and \
           not (hasattr(options, 'pintool_help') and options.pintool_help):
            if len(sys.argv) == 1 or len(args) == 0:
                msg.PrintMsg(
                    "ERROR: Must have a trace basename on the command line.\n"
                    "Usage: %s [options] pinball_basename" %
                    os.path.basename(sys.argv[0]))
                util.CheckResult(-1, options, 'Checking command line options')
            options.replay_file = args[0]

        # 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

        # Once the tracing configuration parameters are read, get the kit in
        # case pinplayhome was set on the command line.
        #
        # import pdb;  pdb.set_trace()
        kit_obj = self.GetKit()

        # If user just wants 'pintool_help' go ahead and print it, then exit
        # the script.
        #
        if hasattr(options, 'pintool_help') and options.pintool_help:
            result = util.PintoolHelpKit(kit_obj, options)
            sys.exit(result)

        # Translate the 'arch' value given by the user into
        # the internal arch type used by the scripts.
        #
        if hasattr(options, 'arch') and options.arch:
            if 'intel64' in options.arch:
                options.arch = config.ARCH_INTEL64
            elif 'ia32' in options.arch:
                options.arch = config.ARCH_IA32
            else:
                options.arch = config.ARCH_INVALID

        # Now that we know the type of the binary, set the user defined pintool,
        # if one exists.  Need to wait until now to set the tool because the
        # user may only have the tool in the architecture dependent directory
        # for this type of application.  Thus we need the binary type in order
        # to find it.
        #
        # import pdb;  pdb.set_trace()
        kit_obj.binary_type = options.arch

        pin_options = ''
        pintool_options = ''

        # Check to see if there is a pinball to replay.
        #
        if options.replay_file == "":
            msg.PrintHelpAndExit('Replay file not specified!')

        # If the user specified a pintool, replace the default pintool in the kit with
        # it.
        #
        if hasattr(options, "pintool") and options.pintool:
            kit_obj.SetPinTool(options.pintool, options.replay_file)

        platform = util.Platform()
        if platform == config.LINUX:
            pin_options = ' ' + kit_obj.prefix + ' -xyzzy '

            # If using NOT using Linux tools to work with whole program pinballs generated on Windows,
            # then need a set of  knobs for the pin binary itself.
            #
            if not options.cross_os:
                pin_options += kit_obj.prefix + ' -reserve_memory '
                pin_options += kit_obj.prefix + ' ' + options.replay_file + '.address '

        pintool_options += ' -replay:basename ' + options.replay_file
        if options.playout or '-replay:playout 1' in options.replay_options:
            # If present, need to remove the knob '-replay:playout 1' from
            # options.replay_options because it can only be given once on the
            # command line.
            #
            pintool_options += ' -replay:playout 1 '
            options.replay_options = options.replay_options.replace(
                '-replay:playout 1', '')
        else:
            pintool_options += ' -replay:playout 0 '

        # If running Windows WP pinballs on Linux, then need this knob for the replayer pintool.
        #
        if options.cross_os:
            pintool_options += ' -replay:addr_trans'

        # Add knobs for Pin and replay/logging user gave on the command line.
        #
        pin_options += ' ' + options.pin_options
        pintool_options += ' ' + options.replay_options + ' ' + options.log_options

        # If user has log options, then may need to at multi-thread knob.
        #
        if options.log_options:
            pintool_options += util.AddMt(options, options.replay_file)

        return pin_options, pintool_options, options.replay_file, kit_obj, options
예제 #5
0
    def ParseCommandLine(self):
        """
        Process command line arguments. Generate pin and tool options, and their paths.
        """

        # import pdb;  pdb.set_trace()
        version = '$Revision: 1.14 $'
        version = version.replace(' ', '')
        ver = version.replace(' $', '')
        us = '%prog [options] trace_basename \nVersion: ' + ver
        desc = 'Run a simulator on a trace.'
        util.CheckNonPrintChar(sys.argv)
        parser = optparse.OptionParser(usage=us, version=ver, description=desc)

        # Define the command line options which control the behavior of the
        # script.
        #
        # Some of these methods take a 2nd argument which is the empty string
        # ''.  If this script used option groups, then the 2nd parameter would
        # be the group.  However, this script does not use option groups, so
        # the argument is empty.
        #
        cmd_options.config_file(parser)
        cmd_options.debug(parser)
        cmd_options.global_file(parser)
        cmd_options.list(parser, '')
        cmd_options.processor(parser, '')
        cmd_options.save_global(parser)
        cmd_options.simhome(parser, '')
        cmd_options.sim_options(parser, '')
        cmd_options.trace_basename(parser)
        cmd_options.verbose(parser)
        cmd_options.verify(parser, '')

        self.AddAdditionalCmdOptions(parser)

        # import pdb;  pdb.set_trace()
        (options, args) = parser.parse_args()

        # Check to make sure the trace basename has been given as an argument.
        #
        # import pdb;  pdb.set_trace()
        if len(sys.argv) == 1 or len(args) == 0:
            msg.PrintMsg(
                "ERROR: Must have a trace basename on the command line.\n"
                "Usage: %s [options] trace_basename" %
                os.path.basename(sys.argv[0]))
            util.CheckResult(-1, options, 'Checking command line options')
        options.trace_basename = args[0]

        # Read in optional configuration files and set global variables.
        #
        config_obj = config.ConfigClass()
        config_obj.GetCfgGlobals(options,
                                 False)  # Don't need all 4 required parameters

        # Just need this parameter.
        #
        self.Config.CheckRequiredParameter('processor')

        # Initialize the kit after reading in parameters, in case the user
        # specified anything which is used to intialize the kit.
        #
        self.kit = self.GetKit()

        return options
예제 #6
0
    def ParseCommandLine(self):
        """
        Parse command line arguments and returns pin and tools options and app command line.

        @return List containing: options
        """

        # command line options for the driver
        #
        version = '$Revision: 1.81 $'
        version = version.replace('$Revision: ', '')
        ver = version.replace(' $', '')
        us = '%prog [options] --mode MODE --log_file FILE binary args'
        desc = 'Runs binary with the logger Pintool and generates whole program '\
               'pinballs. Required arguments include:\n'\
               '   1) Binary to run and it\'s arguments.\n'\
               '   2) Name for the log file (pinball) using \'--log_file FILE\'\n'\
               '         Name can include a dir as well as a file.\n' \
               '   3) Mode of the binary using \'--mode MODE\'.'

        util.CheckNonPrintChar(sys.argv)
        parser = optparse.OptionParser(
            usage=us,
            description=desc,
            version=ver,
            formatter=cmd_options.BlankLinesIndentedHelpFormatter())

        # Define the command line options which control the behavior of the
        # script.  Some of these methods take a 2nd argument which is the empty
        # string ''.   If the script uses option groups, then this parameter is
        # the group.  However, this script does not use option groups, so the
        # argument is empty.
        #

        cmd_options.compressed(parser, '')
        cmd_options.config_file(parser)
        cmd_options.debug(parser)
        cmd_options.global_file(parser)
        cmd_options.list(parser, '')
        cmd_options.log_file(parser)
        cmd_options.log_options(parser)
        cmd_options.mode(parser, '')
        cmd_options.mpi_options(parser, '')
        cmd_options.msgfile_ext(parser)
        cmd_options.no_log(parser)
        cmd_options.num_proc(parser, '')
        cmd_options.pid(parser)
        cmd_options.pinplayhome(parser, '')
        cmd_options.pintool(parser)
        cmd_options.pin_options(parser)
        cmd_options.save_global(parser)
        cmd_options.sdehome(parser, '')
        cmd_options.verbose(parser)

        # import pdb;  pdb.set_trace()
        (options, args) = parser.parse_args()

        # Read in configuration files and set global variables.
        # No need to read in a config file.
        #
        config_obj = config.ConfigClass()
        config_obj.GetCfgGlobals(options,
                                 False)  # No, don't need required parameters

        # Make sure user gave an application mode
        #
        if options.mode:
            options.mode = util.ParseMode(options.mode)
        else:
            parser.error(
                "Application mode was not given.\n"
                "Need to use option --mode MODE. Choose MODE from: 'st', 'mt', 'mpi', 'mpi_mt', 'mp', 'mp_mt',"
            )

        # Log file name must be given.
        #
        # import pdb;  pdb.set_trace()
        if options.log_file == '':
            parser.error('Log file basename was not given.\n' \
                'Must give basename with option: --log_file FILE')

        # Get the application command line
        #
        # import pdb;  pdb.set_trace()
        cmd_line = " ".join(args)
        if not options.pid:
            if cmd_line:
                setattr(options, 'command', cmd_line)
            else:
                parser.error('no program command line specified.\n'
                             'Need to add binary and it\'s arguments.')

        return options