Exemple #1
0
    def ValidDriver(self, path):
        """
        Is this a path to a kit with a valid pinplay driver?

        @param path Path to kit to be validated

        @return True if valid drivers found, otherwise exit with an error msg
        """

        # See if the 64-bit driver exists
        #
        # import pdb;  pdb.set_trace()
        arch = 'intel64'
        if os.path.isfile(os.path.join(path, self.driver_intel64)):

            # See if the 32-bit driver exists
            #
            arch = 'ia32'
            if os.path.isfile(os.path.join(path, self.driver_ia32)):
                return True

        # There is a valid 'pinbin' binary, or this method wouldn't get called, but
        # there isn't a valid pinplay-driver.
        #
        msg.PrintMsg('ERROR: The required PinTool \'' + self.pintool +
                     '\' for arch \'' + arch + '\' was not found.')
        msg.PrintMsg('Perhaps the PinPlay kit installation was incomplete. Check to make sure\n' \
            'there weren\'t any errors during the install.')
        sys.exit(1)
Exemple #2
0
    def InitKit(self):
        """
        Get the path to a valid kit, the appropriate tool name and add a path
        to the environment variable PATH required to find the binaries.
        """

        # Get the paths to config directory.
        #
        # import pdb;  pdb.set_trace()
        self.sim_path = self.GetDefaultDir(self.default_sim_dir, config.simhome)

        # Check to see if it points to a valid kit.
        #
        if not self.ValidKit(self.sim_path):
            msg.PrintMsg(
                'ERROR: Path to the ' + self.binary + ' kit was not found.')
            msg.PrintMsg('Default kit location is: ' + \
                os.path.realpath(os.path.join(os.path.expanduser("~"), self.default_sim_dir)))
            msg.PrintMsg('Use option \'--simhome\' to define kit location.')
            sys.exit(1)

        # Add the binary's directory in the kit to the environment variable PATH.
        #
        # import pdb;  pdb.set_trace()
        os.environ["PATH"] += os.pathsep + self.sim_path
Exemple #3
0
    def ValidDriver(self, path):
        """
        For SDE, make sure the 'simpoint' binary is in the kit instead of
        verifying the drivers are valid.

        No need to verify drivers for SDE, as the SDE tool doesn't use a
        pinplay driver any more.  (There is a unified controller.)

        @param path Path to kit to be validated

        @return True if Simpoint found, otherwise exit with an error msg
        """

        # Chose the appropriate Pin binary/tool for this platform.
        #
        platform = util.Platform()
        if platform == config.WIN_NATIVE or platform == config.WIN_CYGWIN:
            path = os.path.join(path, self.simpoint_path, 'simpoint.exe')
        else:
            path = os.path.join(path, self.simpoint_path, 'simpoint')
        if not os.path.isfile(path):
            msg.PrintMsg(
                'ERROR: The required binary \'simpoint\' was not found.')
            msg.PrintMsg('   ' + path)
            msg.PrintMsg('Perhaps the SDE kit installation was incomplete. Check to make sure\n' \
                'there weren\'t any errors during the install.')
            sys.exit(1)

        return True
Exemple #4
0
    def InitKit(self, script_path):
        """
        Get the path to a valid kit, the appropriate tool name and add several paths
        to the environment variable PATH required to find script/utilities.

        @param script_path Path to scripts directory in a kit

        @return No return value
        """

        self.path = self.GetKitLocation(script_path)

        # Check to see if it's a valid kit. If not, exit with an error.
        #
        if not self.ValidKit(self.path):
            msg.PrintMsg('ERROR: Path to the ' + self.type +
                         ' kit was not found.')
            msg.PrintMsg('Default kit location is: ' + \
                os.path.realpath(os.path.join(os.path.expanduser("~"), self.default_dir)))
            sys.exit(1)

        # Add several directories in the PinPlay kit to the environment variable PATH.
        #
        os.environ["PATH"] += os.pathsep + os.path.join(
            self.path, self.script_path)
        if self.simpoint_path != self.script_path:
            os.environ["PATH"] += os.pathsep + os.path.join(
                self.path, self.simpoint_path)
Exemple #5
0
def FinalizeNoGDB(kit_script_path, options):
    """
    Execute the final section of the program.  This version is for
    the scripts which don't use GDB.   If user gave option '--pid'
    then wait until the process exits.  Otherwise, just return.

    @param kit_script_path Explicit path to location in kit where scripts are located
    @param options Options given on cmd line

    @return no return
    """

    # If attaching to a process, spin here until the process has finished
    # running.
    #
    if (hasattr(options, 'pid') and options.pid):
        msg.PrintMsg('Waiting for process to exit, PID: ' + str(options.pid))
        while util.CheckPID(options.pid):
            if (hasattr(options, 'verbose') and options.verbose):
                msg.PrintMsgNoCR('.')
            time.sleep(5)
        if (hasattr(options, 'verbose') and options.verbose):
            msg.PrintMsg('\nProcess has exited')
        else:
            msg.PrintMsg('Process has exited')

    if (hasattr(options, 'verbose') and options.verbose):
        if hasattr(options, 'log_file') and options.log_file:
            msg.PrintMsg('Output pinball: ' + options.log_file)
        else:
            msg.PrintMsg('Output pinball: default file name (pinball/log)')

    return
Exemple #6
0
    def GetLastMetric(self, sim_file, tid, options):
        """
        Get the last metric in a simulator output file.  This is the value
        for running the entire pinball.

        @param sim_file File with simulator results to process
        @param options TID of results to be processed
        @param options Options given on cmd line

        @return metric
        """

        # Get a file pointer to the simulator data file.
        #
        f = util.OpenCompressFile(sim_file)
        if f == None:
            # Error opening file, return an error.
            #
            return -1.0

        # This is the code which needs to be modified in order to use a
        # different metric of interest for a new simulator.  The existing code
        # uses the metric MPI (misses per thousand instruction).
        #
        # Current code assume the default Branch Predictor simulator is used. Get the
        # number of instructions and misses for this thread in the last line of
        # the output.
        #
        # import pdb ; pdb.set_trace()
        instr = misses = 0
        for line in f.readlines():
            pos = line.find('Icount: ')
            if pos != -1:
                last = line
        # import pdb ; pdb.set_trace()
        lst = last.split()
        instr = int(lst[1])
        misses = int(lst[3])

        # Check to make sure there really is valid data.  If not, the print a
        # warning.  No need to exit with an error, because it's possible for
        # MPI_MT_MODE applications to have a different number of threads in
        # each process.  This means some processes may have a thread 'tid',
        # while this process may not.
        #
        if instr > 1:
            metric = misses / (float(instr) / 1000)
        else:
            msg.PrintMsgPlus('WARNING: There were no instructions in simulator output for thread ' + \
                                   str(tid) + ' in file:\n         ' + sim_file)
            msg.PrintMsg('Prediction error for this process may be suspect.')
            if options.mode == config.MPI_MT_MODE:
                msg.PrintMsg(
                    'Since tracing mode is \'mpi_mt\', this may be OK.')
            metric = -1.0  # Error indication

        return metric
Exemple #7
0
    def Replay(self, param, dirname, filename):
        """
        Run the Simulator on a single LIT file given the command line options and the name of
        the file to run. It formats the appropriate command line options,
        saves global variables in a pickle file & calls the Sim run script.
        """

        # import pdb ; pdb.set_trace()
        if 'options' in param:
            options = param['options']
        else:
            msg.PrintAndExit(
                'method replay_dir.Replay() failed to get param \'options\'')
        basename_file = os.path.join(dirname, filename)
        if config.verbose:
            msg.PrintMsg("-> Replaying pinball \"" + basename + "\"")

        cmd = self.replayer_cmd + ' ' + basename_file

        # Check to see if need to add options passed to the Sim run script.
        # These are NOT parameters, so they don't get passed in the global
        # variables.
        #
        if options.sim_options:
            cmd += ' --sim_options ' + options.sim_options
        if options.verify:
            cmd += ' --verify'

        # Add the configuration file, if one exists and print the cmd if just
        # debugging.
        #
        # import pdb ; pdb.set_trace()
        cmd += util.AddCfgFile(options)
        if options.debug:
            msg.PrintMsg(cmd)

        result = 0
        if not options.debug:

            # Dump the global data to a unique file name.  Need to add the
            # option --global_file with this unique file name to options when
            # calling a script.
            #
            gv = config.GlobalVar()
            cmd += util.AddGlobalFile(gv.DumpGlobalVars(), options)

            # import pdb ; pdb.set_trace()
            if not options.list:
                result = util.RunCmd(
                    cmd, options, filename,
                    concurrent=True)  # Run concurrent jobs here
            else:
                msg.PrintMsg(cmd)

        return result
Exemple #8
0
    def NormWeightLDV(self, options):
        """
        Normalize and apply weights to LRU stack distance vector files.

        @param options Options given on cmd line

        @return result of command to generate file
        """

        # Ensure there's an LDV file to process.
        #
        if not os.path.isfile(self.generic_ldv_name):
            msg.PrintMsg('ERROR: Can\'t open LDV vector file.\n '
                         '   ' + self.generic_ldv_name)
            return -1

        # Use options for the Python script to process the LDV file.
        #
        # import pdb;  pdb.set_trace()
        output_file = 'normalize_weight.out'
        try:
            fp_error = open(output_file, 'w')
        except IOError:
            msg.PrintMsg(
                'ERROR: Failed to open normalize weights error file:\n'
                '   ' + output_file)
            return -1
        try:
            fp_out = open(self.weight_ldv_file, 'w')
        except IOError:
            msg.PrintMsg(
                'ERROR: Failed to open normalize weights output file:\n'
                '   ' + self.weight_ldv_file)
            fp_error.close()
            return -1

        cmd = self.csv_bin
        cmd += ' --weight_ldv '
        cmd += ' --ldv_file ' + self.generic_ldv_name
        cmd += ' --dimensions 16'

        # msg.PrintMsg('')
        # print 'cmd: ' + cmd
        # import pdb;  pdb.set_trace()
        result = util.RunCmd(cmd, options, '', concurrent=False, f_stdout=fp_out, \
                             f_stderr=fp_error)
        msg.PrintMsg('   Output file: %s' % (self.weight_ldv_file))
        msg.PrintMsg('   Stderr file: %s\n' % (output_file))
        fp_out.close()
        fp_error.close()

        return result
Exemple #9
0
    def NormProjectBBV(self, options):
        """
        Normalize and project the basic block vector file instead of doing this in Simpoint.

        This is required so we can combine BBV and LDV files as frequency vector file given
        to Simpoint.

        @param options Options given on cmd line

        @return result of command to generate projected file
        """

        # Format the command and run it.
        #
        # import pdb;  pdb.set_trace()

        # Use options for the Python script to generate the CSV file.
        #
        output_file = 'normalize_project.out'
        try:
            fp_error = open(output_file, 'w')
        except IOError:
            msg.PrintMsg(
                'ERROR: Failed to open normalize/project error file:\n'
                '   ' + output_file)
            return -1
        try:
            fp_out = open(self.proj_bbv_file, 'w')
        except IOError:
            msg.PrintMsg(
                'ERROR: Failed to open normalize/project output file:\n'
                '   ' + self.proj_bbv_file)
            fp_error.close()
            return -1

        cmd = self.csv_bin
        cmd += ' --project_bbv'
        cmd += ' --bbv_file'
        cmd += ' ' + self.generic_bbv_name
        cmd += ' --dimensions 16'

        # msg.PrintMsg('')
        # print 'cmd: ' + cmd
        # import pdb;  pdb.set_trace()
        result = util.RunCmd(cmd, options, '', concurrent=False, f_stdout=fp_out, \
                             f_stderr=fp_error)
        msg.PrintMsg('   Output file: %s' % (self.proj_bbv_file))
        msg.PrintMsg('   Stderr file: %s\n' % (output_file))
        fp_out.close()
        fp_error.close()

        return result
Exemple #10
0
    def RunSimpoint(self, options):
        """
        Format and execute the command to run Simpoint.

        @param options Options given on cmd line

        @return result of running Simpoint
        """

        import subprocess

        # Output file for simpoint
        #
        output_file = 'simpoint.out'
        try:
            fp_out = open(output_file, 'w')
        except IOError:
            msg.PrintMsg('ERROR: Failed to open simpoint error file:\n'
                         '   ' + output_file)
            return -1

        # Format the Simpoint command and run it.
        #
        # import pdb;  pdb.set_trace()
        cmd = self.simpoint_bin
        if options.ldv:
            cmd += ' -fixedLength on -loadVectorsTxtFmt ' + self.freq_vect_file
        else:
            cmd += ' -loadFVFile ' + self.generic_bbv_name

        # Add either the default options used to configure Simpoints or the
        # Simpoint options from the user.
        #
        if options.simpoint_options == '':
            cmd += ' -coveragePct ' + str(options.cutoff)
            cmd += ' -maxK ' + str(options.maxk)
        else:
            cmd += ' ' + options.simpoint_options

        cmd += ' -saveSimpoints ./t.simpoints -saveSimpointWeights ./t.weights -saveLabels t.labels'
        result = util.RunCmd(cmd,
                             options,
                             '',
                             concurrent=False,
                             f_stdout=fp_out,
                             f_stderr=subprocess.STDOUT)
        msg.PrintMsg('   Output file: %s' % (output_file))
        msg.PrintMsg('   Stderr file: %s' % (output_file))
        fp_out.close()

        return result
def CheckRegions(simp_dict, weight_dict):
    """
    Check to make sure the simpoint and weight files contain the same regions.

    @return no return value
    """

    if len(simp_dict) != len(weight_dict) or \
       simp_dict.keys() != weight_dict.keys():
            msg.PrintMsg('ERROR: Regions in these two files are not identical')
            msg.PrintMsg('   Simpoint regions: ' + str(simp_dict.keys()))
            msg.PrintMsg('   Weight regions:   ' + str(weight_dict.keys()))
            cleanup()
            sys.exit(-1)
Exemple #12
0
    def VerifyLITFiles(self, sim_run_cmd, options):
        """
        Use a simulator to verify all the LIT files for the tracing instance are valid.
        """

        # Verify the LIT files for each directory.
        #
        # import pdb;  pdb.set_trace()
        result = 0
        for lit_dir in util.GetLitDir():
            if not options.list:
                msg.PrintMsgPlus('Verifying files in dir: ' + lit_dir)

            # import pdb;  pdb.set_trace()
            cmd = sim_run_cmd + ' --replay_dir ' + lit_dir
            if options.sim_options:
                cmd += ' --sim_options ' + options.sim_options
            cmd += ' --verify'
            cmd += util.AddGlobalFile(self.gv.DumpGlobalVars(), options)
            cmd += util.AddCfgFile(options)
            result = util.RunCmd(cmd, options, '',
                                 concurrent=True)  # Run jobs concurrently

            if result != 0:
                msg.PrintMsg('Error found during LIT file verification')
                return result

        # Wait for all the verification jobs to finish.
        #
        result = util.WaitJobs(options)

        return result
Exemple #13
0
    def get_cpi(dir):
        try:
            r = sniper_lib.get_results(0, dir)
        except ValueError:
            msg.PrintMsg('\nERROR: Can\'t get sniper results for:\n       ' +
                         dir)
            return 0.0
        stats = r['results']
        if stats['ncores'] != 1:
            msg.PrintMsgPlus(
                'Warning: Sniper only supports single-threaded SimPoints')

        # This code works with both Sniper/SniperLite
        #
        instrs = stats['core.instructions']
        fs_to_cycles = stats['fs_to_cycles_cores']
        fs = stats['barrier.global_time']
        for i, d in enumerate(instrs):
            cpi = (float(fs[0]) * fs_to_cycles[i]) / instrs[i]

        if sum(instrs) <= 0:
            msg.PrintMsgPlus(
                '\nERROR: No cycles found in Sniper output for pinball:\n      '
                + dir)
            cpi = 0.0

        return cpi
Exemple #14
0
    def ReplayAllFile(self, options):
        """Replays all pinballs based on a partial file name.

        @param options Options given on cmd line

        @return exit code from replaying all pinballs
        """

        if config.debug:
            print('Replaying all pinballs matching patern.')

        import glob

        # If the user has given the "--all_file" option, then try to find all files
        # with this string. Replay all the pinballs in these directories.
        #
        result = 0
        if options.all_file:
            param = {'options': options}
            for path in glob.glob('*' + options.all_file + '*'):
                pos = path.find(".address")
                if pos != -1:
                    basename_file = path[0:pos]
                    self.Replay(param, '', basename_file)

            # Wait until all the jobs complete.
            #
            if options.verbose:
                msg.PrintMsg(
                    'Calling WaitJobs() from replay_dir.py, ReplayAllFile()')
            result = util.WaitJobs(options)

        return result
Exemple #15
0
    def CombineFreqVectFiles(self, options):
        """
        Combine the BBV and LDV files, applying a scaling factor to allow
        different contributions from each file.

        @param options Options given on cmd line

        @return result of command to generate file
        """

        # Format the command and run it.
        #
        # import pdb;  pdb.set_trace()

        # Use options for the Python script to generate the CSV file.
        #
        output_file = 'scaled_combined.out'
        try:
            fp_error = open(output_file, 'w')
        except IOError:
            msg.PrintMsg('ERROR: Failed to open combined scale error file:\n'
                         '   ' + output_file)
            return -1
        try:
            fp_out = open(self.freq_vect_file, 'w')
        except IOError:
            msg.PrintMsg('ERROR: Failed to open combined scale output file:\n'
                         '   ' + self.freq_vect_file)
            fp_error.close()
            return -1

        cmd = self.csv_bin
        cmd += ' --combine ' + str(options.combine)
        string = 'Combining BBV and LDV files with scaling factors: BBV: %.3f, LDV: %.3f\n' % \
            (options.combine, 1 - options.combine)
        msg.PrintMsgPlus(string)
        fp_error.write(string)
        cmd += ' --normal_bbv ' + self.proj_bbv_file
        cmd += ' --normal_ldv ' + self.weight_ldv_file
        result = util.RunCmd(cmd, options, '', concurrent=False, f_stdout=fp_out, \
                             f_stderr=fp_error)
        msg.PrintMsg('   Output file: %s' % (self.freq_vect_file))
        msg.PrintMsg('   Stderr file: %s\n' % (output_file))
        fp_out.close()
        fp_error.close()

        return result
Exemple #16
0
        def copy_file(f, d):

            try:
                shutil.copy(f, d)
                return 0
            except IOError:
                msg.PrintMsg('\nError found in dir:\n'
                             '    %s\nUnable to copy file:\n    %s to %s' %
                             (os.getcwd(), f, d))
                return -1
Exemple #17
0
        def FinalizeWPDir(wp_dir, string):
            """
            Set the filtered WP pinball directory to be the new default WP dir
            and print out the number of instructions in the newly filtered
            pinballs.
            """

            config.relog_dir = wp_dir
            if not options.debug and not options.list:
                # Only save this parameter if not just debugging or
                # listing the commands to be run.
                #
                self.Config.SaveCfgParameter('relog_dir', wp_dir)
            if not options.list and os.path.isdir(wp_dir):
                msg.PrintMsg('')
                msg.PrintMsg(string)
                util.PrintInstrCount(wp_dir, options)

            return
Exemple #18
0
    def PrintHome(self, options):
        """
        Print the directories where the Pin kit and Sniper are located.

        @return No return value
        """

        super(SniperPinPoints,
              self).PrintHome(options)  # Call base class method PrintHome()
        if options.sniper_root:
            msg.PrintMsg('Sniper_root:               ' +
                         os.path.realpath(options.sniper_root))
        else:
            msg.PrintMsgPlus('WARNING: Sniper root not defined.\n')
        if options.sniper_options:
            msg.PrintMsg('Sniper options:            ' +
                         options.sniper_options)
        if options.no_sniperlite or options.sniper_options:
            msg.PrintMsg('Sniper type:               Full Sniper simulator')
        else:
            msg.PrintMsg('Sniper type:               Sniperlite')
    def ReplayOne(self, options):
        """
        Replays one set of pinballs. Calls Replay() with the pinball name.

        @return exit code from replaying pinball
        """

        param = {'options': options}
        self.Replay(param, '', options.replay_file)
        if options.verbose:
            msg.PrintMsg('Calling WaitJobs() from replay_dir.py, ReplayOne()')
        result = util.WaitJobs(options)
        return result
Exemple #20
0
def CheckRegions(simp_dict, weight_dict):
    """
    Check to make sure the simpoint and weight files contain the same regions.

    @return no return value
    """

    # if weight regions dictionary is smaller then simpoints regions
    # then add missing values with weight 0
    if len(simp_dict) > len(weight_dict):
        for simp_key in list(simp_dict.keys()):
            if simp_key not in list(weight_dict.keys()):
                weight_dict[simp_key] = 0

    if len(simp_dict) != len(weight_dict) or \
       sorted(simp_dict.keys()) != sorted(weight_dict.keys()):
        msg.PrintMsg(
            'ERROR: ICount Regions in these two files are not identical')
        msg.PrintMsg('   Simpoint regions: ' + str(sorted(simp_dict.keys())))
        msg.PrintMsg('   Weight regions:   ' + str(sorted(weight_dict.keys())))
        cleanup()
        sys.exit(-1)
Exemple #21
0
    def PrintHome(self, options):
        """
        Print the directory where the PinPlay kit is located.

        @return No return value
        """

        # If this variable is a symbolic link, then print the real directory name.
        #
        if os.path.islink(self.path):
            path = os.path.realpath(self.path)
        else:
            path = self.path
        msg.PrintMsg('Pinplayhome:               ' + path)
Exemple #22
0
    def RunSimulator(self, dirname, sim_replay_cmd, options):
        """
        Run Branch Predictor simulator on all the pinballs in a set of
        directories given by 'dirname'.


        Return: error code from running the simulator
        """

        # Don't do anything if running in debug mode.
        #
        if options.debug:
            return 0

        gv = config.GlobalVar()

        # Need to let script 'sim_replay_cmd' know type of kit is calling it.
        #
        config.sim_kit_type = self.kit_type

        # Run on all the pinballs in 'dirname'.
        #
        cmd = 'pwd;' + sim_replay_cmd + ' --replay_dir ' + dirname
        cmd += ' --log_options'

        # SiNUCA options
        cmd += ' "'
        cmd += ' -output ' + str(options.sinuca_tracer_output)
        cmd += ' -threads ' + str(options.sinuca_tracer_threads)
        cmd += ' -parallel_start ' + str(options.sinuca_tracer_parallel_start)
        cmd += ' -parallel_end ' + str(options.sinuca_tracer_parallel_end)
        cmd += ' "'

        cmd += ' --sim_add_filename'  # This causes simulator output file name to be added to cmd.
        cmd += util.AddCfgFile(options)
        cmd += util.AddGlobalFile(gv.DumpGlobalVars(), options)

        msg.PrintMsg('DEBUG>> ' + cmd + '\n')

        end_str = ''  # Don't want to print anything when this cmd finishes.
        # import pdb;  pdb.set_trace()
        result = util.RunCmd(cmd, options, end_str, False)

        return result
Exemple #23
0
    def GetSimCfgFile(self, options):
        """
        Get the path to the processor configuration file for this simulator.
        """

        # import pdb;  pdb.set_trace()
        cfg_file = os.path.join(self.sim_path, self.config_dir,
                                options.processor)
        if not os.path.isfile(cfg_file):
            # Try addding the configuration file extension.
            #
            cfg_file = cfg_file + config.config_ext
            if not os.path.isfile(cfg_file):
                msg.PrintMsg('ERROR: Processor config file not found:\n     ' +  \
                    cfg_file + '\n' \
                    'Please make sure the processor TLA is correct and the simulators are installed correctly.')
                return ''

        return (cfg_file)
Exemple #24
0
    def RunMPDelete(self, kit, log_key, options):
        """
        Delete mp_pool when logging MPI apps.

        @param kit     Kit instance for these scripts
        @param log_key  Key to mp_pool to delete
        @param options Options given on cmd line

        @return No return value
        """

        # Start command with pin and pintool.
        #
        # import pdb;  pdb.set_trace()
        cmd = os.path.join(kit.path, kit.pin)
        cmd += kit.GetPinToolKnob()

        # Remove the string '-log:mode_attach' because it's only
        # used for logging.
        #
        pos = log_key.find('-log:mode_attach')
        if pos != -1:
            log_key = log_key[0:pos]

        # Logging mp_pool deletion knobs.
        #
        cmd += ' -log '
        cmd += log_key
        cmd += ' -log:mp_delete_pool '
        cmd += ' -- echo'

        # Execute the cmd
        #
        if (not hasattr(options, 'no_print_cmd') or not options.no_print_cmd) or\
            hasattr(options, 'verbose') and options.verbose:
            msg.PrintMsgPlus('Deleting mp_pools for MPI tracing')
            msg.PrintMsg(cmd)
        if not config.debug:
            p = subprocess.Popen(cmd, shell=True)
            p.communicate()
            del p

        return
Exemple #25
0
    def RunMPCreate(self, kit, options):
        """
        Create mp_pool when logging MPI apps.

        @param kit     Kit instance for these scripts
        @param options Options given on cmd line

        @return String with MP key and a knob required for mp_pools, or null string
        """

        # Start command with pin and pintool.
        #
        # import pdb;  pdb.set_trace()
        cmd = os.path.join(kit.path, kit.pin)
        cmd += kit.GetPinToolKnob()

        # Logging mp_pool creation knobs.
        #
        log_key = ' -log:mp_key ' + str(random.randint(0, 32728))
        cmd += ' -log '
        cmd += log_key
        cmd += ' -log:mp_create_pool '
        cmd += ' -- echo'

        # Execute the cmd
        #
        if (not hasattr(options, 'no_print_cmd') or not options.no_print_cmd) or\
            hasattr(options, 'verbose') and options.verbose:
            msg.PrintMsgPlus('Creating mp_pools for MPI tracing')
            msg.PrintMsg(cmd)
        if not config.debug:
            p = subprocess.Popen(cmd, shell=True)
            p.communicate()
            del p

        # Return the key to the memory pool just created.
        #
        return log_key
def GetOptions():
    """Get users command line options."""

    version = '$Revision: 1.20 $'
    version = version.replace(' ', '')
    ver = version.replace(' $', '')
    us = '%prog [options] app_version compiler_version input_name platform program_name'
    desc = \
    'Renames tracing files generated by PinPlay tools to conform to the GTR requirements.  ' \
    'There are 5 arguments required to run the script.  Details are given below in the ' \
    'section \'Required arguments\'.'

    # Print arguments passed to the script.
    #
    # import pdb;  pdb.set_trace()
    msg.PrintMsgNoCR('Script args: '),
    for string in sys.argv[1:]:
        msg.PrintMsgNoCR(string + ' '),
    msg.PrintMsg('')
    msg.PrintMsg('')

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

    # Command line options to control the scripts behavior.
    #
    # import pdb;  pdb.set_trace()
    cmd_options.config_file(parser)
    cmd_options.debug(parser)
    cmd_options.date(parser, '')
    cmd_options.processor(parser, '')
    cmd_options.verbose(parser)

    # Define a separate option group for the require arguments.
    #
    required_opts = cmd_options.RenameRequiredOpts(parser)

    cmd_options.app_version(parser, required_opts)
    cmd_options.compiler_version(parser, required_opts)
    cmd_options.input_name(parser, required_opts)
    cmd_options.platform(parser, required_opts)
    cmd_options.program_name(parser, required_opts)

    parser.add_option_group(required_opts)

    (options, args) = parser.parse_args()

    # Read in the configuration file.
    #
    Config.GetCfgGlobals(options, True)  # 2 required parameters are needed

    # Ensure the required variables are defined.
    #
    CheckRequiredVariables(options)

    # If the user didn't give a date, use the current date.
    #
    if options.date == '':
        today = datetime.date.today()
        options.date = today.strftime('%y%m')
    CheckField(options.date)

    # If user didn't give a separate processor name, get it from the platform info.
    #
    if options.processor == '':
        # Use the first 3 char as the processor type
        options.processor = options.platform[:3]
    CheckField(options.processor)

    return options
    return options


############################################################################

# Host is always 'pin'.
# OS is Linux64.  May need to change this to be an option for Windows.
#
host = 'pin'
operating_sys = 'linux64'

options = GetOptions()

# Define a lambda function to print an error message.
#
err_msg = lambda string: msg.PrintMsg(
    'ERROR: util.ParseFileName() failed to get field: ' + string)

# import pdb;  pdb.set_trace()

# For each LIT directory, create a link to each file which is formatted properly
# to be submitted to the GTR.
#
dirs = util.GetLitDir()
dirs.sort()
for lit_dir in dirs:

    # Make sure the LIT directory exists, then go there.
    #
    # import pdb;  pdb.set_trace()
    old_dir = os.getcwd()
    if os.path.isdir(lit_dir):
Exemple #28
0
    def Run(self):
        """
        Get the user's options, read config file and execute the phases desired by the user.

        @return Exit code from last phase executed
        """

        # Catch signals in order to do an orderly shutdown of the script.
        #
        self.InstallSigHandler()

        # import pdb;  pdb.set_trace()
        options = self.ParseCommandLine()

        # Print out the version numbers for all python modules in this directory.
        #
        if config.debug:
            util.PrintModuleVersions()

        # If logging, ensure the user has entered a mode.
        #
        if options.log and config.mode == '':
            msg.PrintHelpAndExit(
                'Must enter mode of application using: --mode "st|mt|mpi|mpi_mt"')

        # Set the defaults for a set of variables which are needed, but not in the list
        # of required options in the tracing configuration file.
        #
        self.SetDefaults(options)

        # Create an new status file and zero out the file if it already exists.
        # If user sets parameter 'append_status', the old file is not deleted.
        #
        util.NewStatusFile(options)

        # Add 1500 to the warmup length in order to deal with problems that
        # occur when the start of a warmup region and the end of the previous
        # region are in the same basic block.
        #
        if not config.global_regions:
          config.warmup_length += 1500

        # Get variables used in many phases.
        #
        # import pdb;  pdb.set_trace()
        wp_pb_dir = util.GetWPDir()
        log_file_name = util.GetLogFile()

        # Print out the tracing configuration parameters.
        #
        if not options.list:
            self.phases.PrintTracingInfo(options, wp_pb_dir, log_file_name,
                                         self.PrintHome)

        #########################################################################
        #
        # Several phases which clean up tracing instances.
        #
        #########################################################################

        result = 0
        if options.delete or options.delete_wp:
            self.phases.DeleteTracingFileDir(options)
            util.CheckResult(result, options, 'Deleting tracing instance files')

            # Since just deleted all files/dirs for the tracing instance, need
            # to set the whole program directory to the default value.  Do NOT
            # use util.GetWPDir() here because this may return the name of a
            # relogged WP directory (which we, of course, just deleted.)
            #
            wp_pb_dir = util.GetBaseWPDir()

        if options.delete_all:
            self.phases.DeleteAllTracingFileDir(options)
            util.CheckResult(result, options, 'Deleting all tracing files')

            # Again, since just deleted all files/dirs, need to set the whole
            # program directory to the default value.  
            #
            wp_pb_dir = util.GetBaseWPDir()

        # If the user has given the name of the whole program pinball
        # directory, then save it. This must be done after the two delete
        # phases because these phases delete this configuration file.
        # Also, need to get default WP directory name in 'wp_pb_dir'.
        #
        # import pdb ; pdb.set_trace()
        if hasattr(options, 'whole_pgm_dir') and options.whole_pgm_dir:
            config.whole_pgm_dir = options.whole_pgm_dir
            self.Config.SaveCfgParameter('whole_pgm_dir', options.whole_pgm_dir)
            wp_pb_dir = util.GetWPDir()

        #########################################################################
        #
        # Run the phases of the script. They are in a specific order to ensure
        # all prerequisite phases are completed before a given phase is run.
        #
        #########################################################################

        # Run the application without pin/pintools.
        #
        if options.native_pure:
            util.PhaseBegin(options)
            result = self.phases.NativePure(options)
            util.CheckResult(
                result, options,
                'Pure native run %s' % config.PhaseStr(config.native_pure))

        # Run the application using pin, but no pintools.
        #
        if options.native_pin:
            util.PhaseBegin(options)
            result = self.phases.NativePin(self.logger_cmd, wp_pb_dir, log_file_name, \
                options)
            util.CheckResult(result, options, 'Native run with pin only %s' % \
                config.PhaseStr(config.native_pin))

        # Logging phase to generate initial whole program pinballs.
        #
        # import pdb;  pdb.set_trace()
        if options.log or options.default_phases:
            util.PhaseBegin(options)
            result = self.phases.Logger(self.logger_cmd, wp_pb_dir, log_file_name, \
                options)
            util.CheckResult(result, options, 'Whole program pinball generation %s' % \
                config.PhaseStr(config.log_whole))

        # All phases after this require the whole program pinball directory.  Exit with an
        # error if it does not exist.
        #
        # import pdb;  pdb.set_trace()
        if not os.path.isdir(wp_pb_dir) and not options.list and not options.debug and\
                not options.delete and not options.delete_all and not options.delete_wp and \
                not options.native_pure and not options.native_pin:
            string = '\nERROR: Can\'t proceed because the whole program pinball directory does not exist:\n' + \
                '      ' + wp_pb_dir + \
                '\nMust select at least one phase to run.  Try using option \'--default_phases\'.' + \
                '\nUse \'-h\' for help on selecting phases to run.'
            msg.PrintMsg(string)
            # Use -1 to force check to fail
            util.CheckResult(-1, options,
                             'Initial check to see if WP pinballs exist')

        # Print out the number of instructions in the whole program pinballs.
        #
        if not options.list and os.path.isdir(wp_pb_dir):
            msg.PrintMsg('')
            msg.PrintMsg('Initial whole program pinball(s)')
            util.PrintInstrCount(wp_pb_dir, options)

        #########################################################################
        #
        # Phases which relog whole program pinballs using a filter to remove
        # certain type of instructions (such as initialization or MPI spin).
        #
        # The relogging phases must be executed before the basic block vector
        # generation phase. This must be done in case one, or more, relogging
        # phases are executed.  If so then, the BB vector phase needs to use
        # the final relogged WP pinballs generated here.
        #
        #########################################################################

        # If the user gives one, or more, of the use_relog_* options, they want
        # to explictly define which filtered WP pinballs to use.  As a result,
        # unset the parameter 'relog_dir' just read from the per instance
        # tracing configuration file and from the config object.  This removes
        # the previous "sticky" value for the filtered WP pinballs.  Then use
        # the WP pinball directory before any filters have been applied.
        #
        # import pdb;  pdb.set_trace()
        if cmd_options.UseRelogOptionsSet(options):
            Config = config.ConfigClass()
            Config.ClearCfgParameter('relog_dir')
            config.relog_dir = ''
            wp_pb_dir = util.GetBaseWPDir()

        def FinalizeWPDir(wp_dir, string):
            """
            Set the filtered WP pinball directory to be the new default WP dir
            and print out the number of instructions in the newly filtered
            pinballs.
            """

            config.relog_dir = wp_dir
            if not options.debug and not options.list:
                # Only save this parameter if not just debugging or
                # listing the commands to be run.
                #
                self.Config.SaveCfgParameter('relog_dir', wp_dir)
            if not options.list and os.path.isdir(wp_dir):
                msg.PrintMsg('')
                msg.PrintMsg(string)
                util.PrintInstrCount(wp_dir, options)

            return

        # The format of the code for each relogging (filtering) phase contains
        # 3 components:
        #
        #   1) If going to use relogged WP pinballs for the phase (indicated by
        #      either 'relog_*' or 'use_relog_*' options), then get the
        #      appropriate WP directory name for this phase.  Need to always do
        #      this, even when not relogging, because a previous run generated
        #      relogged WP pinballs.
        #
        #   2) If going to filter with relogging (indicated by a 'relog_*'
        #      option), then run the relogging phase.
        #
        #   3) Set the name of the default whole program pinball directory to
        #      the directory with the relogged WP pinballs.

        # Relog with a user defined name for the relogged directory, and hopefully a set of
        # knobs to define what action to take when relogging.
        #
        # import pdb;  pdb.set_trace()
        if options.use_relog_name != '' or options.relog_name:
            relog_wp_dir = util.GetRelogPhaseDir(wp_pb_dir, config.RELOG_NAME,
                                                 options)
            if options.relog_name:
                if not options.list:
                    msg.PrintMsgDate('Filtering whole program pinballs with user defined name: %s %s' % \
                        (options.relog_name, config.PhaseStr(config.filter_user_defn)))
                util.PhaseBegin(options)
                result = self.phases.RelogWholeName(self.replay_cmd, wp_pb_dir,
                                                    relog_wp_dir, options)
                if not options.list:
                    msg.PrintMsgDate('Finished filtering whole program pinballs with user defined name: %s %s' % \
                        (options.relog_name, config.PhaseStr(config.filter_user_defn)))
                util.CheckResult(result, options, 'Filtering WP pinballs with user defined name: %s %s' % \
                    (options.relog_name, config.PhaseStr(config.filter_user_defn)))

            # No errors, commit to using the new pinballs.
            #
            wp_pb_dir = relog_wp_dir
            FinalizeWPDir(
                relog_wp_dir,
                'Whole program pinball(s) filtered with user defined name: ' +
                options.relog_name)

        # Relog with a focus thread.
        #
        if options.use_relog_focus or options.relog_focus:
            relog_wp_dir = util.GetRelogPhaseDir(wp_pb_dir, config.RELOG_FOCUS,
                                                 options)
            if options.relog_focus:
                if not options.list:
                    msg.PrintMsgDate('Filtering whole program pinballs with a focus thread %s' % \
                        config.PhaseStr(config.filter_focus_thread))
                # import pdb;  pdb.set_trace()
                util.PhaseBegin(options)
                result = self.phases.RelogWholeFocus(self.replay_cmd,
                                                     wp_pb_dir, relog_wp_dir,
                                                     options)
                if not options.list:
                    msg.PrintMsgDate('Finished filtering whole program pinballs with a focus thread %s' % \
                        config.PhaseStr(config.filter_focus_thread))
                util.CheckResult(result, options, 'Filtering WP pinballs with focus thread %s' % \
                    config.PhaseStr(config.filter_focus_thread))

            # No errors, commit to using the new pinballs.
            #
            wp_pb_dir = relog_wp_dir
            FinalizeWPDir(
                relog_wp_dir,
                'Whole program pinball(s) filtered with a focus thread')

            # If pinballs were relogged with a focus thread, then in the
            # remaining phases the focus thread must be 0.  Relogging generates
            # per thread whole program pinballs (which only have thread 0).  To
            # enforce this, we change the focus_thread in the config object to
            # be 0.
            #
            config.focus_thread = 0

            # Also need to set options.use_relog_focus = True because we are will be using
            # WP pinballs which have been relogged with a focus thread.
            #
            options.use_relog_focus = True

        # Relog to remove initialization instructions.  Do this before removing cleanup or
        # MPI spin instructions.
        #
        # import pdb;  pdb.set_trace()
        if options.use_relog_no_init or options.relog_no_init:
            relog_wp_dir = util.GetRelogPhaseDir(wp_pb_dir,
                                                 config.RELOG_NO_INIT, options)
            if options.relog_no_init:
                if not options.list:
                    msg.PrintMsgDate('Filtering whole program pinballs to remove initialization instructions %s' % \
                        config.PhaseStr(config.filter_init))
                util.PhaseBegin(options)
                result = self.phases.RelogWholeRemoveInit(self.replay_cmd,
                                                          wp_pb_dir,
                                                          relog_wp_dir, options)
                if not options.list:
                    msg.PrintMsgDate('Finished filtering whole program pinballs to remove initialization instructions %s' % \
                        config.PhaseStr(config.filter_init))
                util.CheckResult(result, options, 'Filtering WP pinballs to remove init instructions %s' % \
                    config.PhaseStr(config.filter_init))

            # No errors, commit to using the new pinballs.
            #
            wp_pb_dir = relog_wp_dir
            FinalizeWPDir(
                relog_wp_dir,
                'Whole program pinball(s) filtered to remove initialization instructions')

        # Relog to remove cleanup instructions.  Do this before removing MPI spin
        # instructions.
        #
        # import pdb;  pdb.set_trace()
        if options.use_relog_no_cleanup or options.relog_no_cleanup:
            relog_wp_dir = util.GetRelogPhaseDir(wp_pb_dir,
                                                 config.RELOG_NO_CLEANUP,
                                                 options)
            if options.relog_no_cleanup:
                if not options.list:
                    msg.PrintMsgDate('Filtering whole program pinballs to remove cleanup instructions %s' % \
                        config.PhaseStr(config.filter_cleanup))
                util.PhaseBegin(options)
                result = self.phases.RelogWholeRemoveCleanup(
                    self.replay_cmd, wp_pb_dir, relog_wp_dir, options)
                if not options.list:
                    msg.PrintMsgDate('Finished filtering whole program pinballs to remove cleanup instructions %s' % \
                        config.PhaseStr(config.filter_cleanup))
                util.CheckResult(result, options, 'Filtering WP pinballs to remove cleanup instructions %s' % \
                    config.PhaseStr(config.filter_cleanup))

            # No errors, commit to using the new pinballs.
            #
            wp_pb_dir = relog_wp_dir
            FinalizeWPDir(
                relog_wp_dir,
                'Whole program pinball(s) filtered to remove cleanup instructions')

        # Relog to exclude code (instructions) between two addresses. Do this
        # before removing MPI spin instructions.
        #
        # import pdb;  pdb.set_trace()
        if options.use_relog_code_exclude != '' or options.relog_code_exclude:
            relog_wp_dir = util.GetRelogPhaseDir(wp_pb_dir,
                                                 config.RELOG_CODE_EXCLUDE,
                                                 options)
            if options.relog_code_exclude:
                if not options.list:
                    msg.PrintMsgDate('Filtering whole program pinballs with code exclusion %s' % \
                        config.PhaseStr(config.filter_code_exclude))
                util.PhaseBegin(options)
                result = self.phases.RelogWholeCodeExclude(
                    self.replay_cmd, wp_pb_dir, relog_wp_dir, options)
                if not options.list:
                    msg.PrintMsgDate('Finished filtering whole program pinballs with code exclusion %s' % \
                        config.PhaseStr(config.filter_code_exclude))
                util.CheckResult(result, options, 'Filtering WP pinballs with code exclusion %s' % \
                    config.PhaseStr(config.filter_code_exclude))

            # No errors, commit to using the new pinballs.
            #
            wp_pb_dir = relog_wp_dir
            FinalizeWPDir(
                relog_wp_dir,
                'Whole program pinball(s) filtered with code exclusion')

        # Relog to remove OpenMP spin instructions.
        #
        # import pdb;  pdb.set_trace()
        if options.use_relog_no_omp_spin or options.relog_no_omp_spin:
            relog_wp_dir = util.GetRelogPhaseDir(wp_pb_dir,
                                                 config.RELOG_NO_OMP_SPIN,
                                                 options)
            if options.relog_no_omp_spin:
                if not options.list:
                    msg.PrintMsgDate('Filtering whole program pinballs to remove OpenMP spin instructions %s' % \
                        config.PhaseStr(config.filter_OMP_spin))
                util.PhaseBegin(options)
                result = self.phases.RelogWholeRemoveOMPSpin(
                    self.replay_cmd, wp_pb_dir, relog_wp_dir, options)
                if not options.list:
                    msg.PrintMsgDate('Finished filtering whole program pinballs to remove OpenMP spin instructions %s' % \
                        config.PhaseStr(config.filter_OMP_spin))
                util.CheckResult(result, options, 'Filtering WP pinballs to remove OpenMP spin instructions %s' % \
                    config.PhaseStr(config.filter_OMP_spin))

            # No errors, commit to using the new pinballs.
            #
            wp_pb_dir = relog_wp_dir
            FinalizeWPDir(
                relog_wp_dir,
                'Whole program pinball(s) filtered to remove OpenMP spin instructions')

        # Relog to remove MPI spin instructions.
        #
        # import pdb;  pdb.set_trace()
        if options.use_relog_no_mpi_spin or options.relog_no_mpi_spin:
            relog_wp_dir = util.GetRelogPhaseDir(wp_pb_dir,
                                                 config.RELOG_NO_MPI_SPIN,
                                                 options)
            if options.relog_no_mpi_spin:
                if not options.list:
                    msg.PrintMsgDate('Filtering whole program pinballs to remove MPI spin instructions %s' % \
                        config.PhaseStr(config.filter_MPI_spin))
                util.PhaseBegin(options)
                result = self.phases.RelogWholeRemoveMPISpin(
                    self.replay_cmd, wp_pb_dir, relog_wp_dir, options)
                if not options.list:
                    msg.PrintMsgDate('Finished filtering whole program pinballs to remove MPI spin instructions %s' % \
                        config.PhaseStr(config.filter_MPI_spin))
                util.CheckResult(result, options, 'Filtering WP pinballs to remove MPI spin instructions %s' % \
                    config.PhaseStr(config.filter_MPI_spin))

            # No errors, commit to using the new pinballs.
            #
            wp_pb_dir = relog_wp_dir
            FinalizeWPDir(
                relog_wp_dir,
                'Whole program pinball(s) filtered to remove MPI spin instructions')

        if not options.list:
            msg.PrintMsgPlus(
                'Using whole program pinballs in dir: ' + wp_pb_dir)
            if (cmd_options.UseRelogOptionsSet(options) or \
               cmd_options.RelogOptionsSet(options)) and \
               os.path.isdir(wp_pb_dir):
                msg.PrintMsg('')
                util.PrintInstrCount(wp_pb_dir, options)

        #########################################################################
        #
        # These phases are run with the whole progam pinballs defined/generated
        # in the previous phases.
        #
        #########################################################################

        # Make sure any relogged whole program pinball directory exist.  Exit with an
        # error if it does not exist.
        #
        # import pdb;  pdb.set_trace()
        if not os.path.isdir(wp_pb_dir) and not options.list and not options.debug and\
                not options.delete and not options.delete_all and not options.delete_wp and \
                not options.native_pure and not options.native_pin:
            string = 'ERROR: Can\'t proceed because the whole program pinball directory does not exist:\n' + \
                '      ' + wp_pb_dir
            msg.PrintMsg(string)
            # Use -1 to force check to fail
            util.CheckResult(-1, options,
                             'Second check to see if WP pinballs exist')

        # Do not run replay whole program pinballs as one of the default
        # phases.  The user must explicitly include this option.  This is to
        # save time during the tracing process.
        #
        if options.replay:
            if not options.list:
                msg.PrintMsgDate('Replaying all whole program pinballs %s' % \
                    config.PhaseStr(config.replay_whole))
            util.PhaseBegin(options)
            result = self.phases.Replay(self.replay_cmd, wp_pb_dir, options)
            if not options.list:
                msg.PrintMsgDate('Finished replaying all whole program pinballs %s' % \
                    config.PhaseStr(config.replay_whole))
            util.CheckResult(result, options, 'Replay of whole program pinballs %s' % \
                config.PhaseStr(config.replay_whole))

        # Generate basic block vectors.
        #
        if options.basic_block_vector or options.default_phases:
            if not options.list:
                msg.PrintMsgDate('Generating basic block vectors %s' % \
                    config.PhaseStr(config.gen_BBV))
            util.PhaseBegin(options)
            result = self.phases.BasicBlockVector(self.replay_cmd, wp_pb_dir,
                                                  options)
            if result == 0:
                result = util.WaitJobs(options)
            if not options.list:
                msg.PrintMsgDate('Finished basic block vector generation %s' % \
                    config.PhaseStr(config.gen_BBV))
            util.CheckResult(result, options, 'Basic block vector generation %s' % \
                config.PhaseStr(config.gen_BBV))

        # Run Simpoints to genenerate representative regions.
        #
        if options.simpoint or options.default_phases:
            if not options.list:
                msg.PrintMsgDate('Running Simpoint on all processes %s' % \
                    config.PhaseStr(config.Simpoint))
            # Setup dictionary of parameters for method RunAllDir()
            #
            msg.PrintMsg('fbm was in pinpoints')
            param = {'options': options}
            util.PhaseBegin(options)
            result = util.RunAllDir(wp_pb_dir, self.phases.RunSimPoint, True,
                                    param)
            if not options.list:
                msg.PrintMsgDate('Finished running Simpoint for all processes %s' % \
                    config.PhaseStr(config.Simpoint))
            util.CheckResult(result, options, 'Simpoints generation %s' % \
                config.PhaseStr(config.Simpoint))

        # Relog to generate representative region pinballs.
        #
        if options.region_pinball or options.default_phases:
            if not options.list:
                msg.PrintMsgDate('Generating region pinballs %s' % \
                    config.PhaseStr(config.relog_regions))
            util.PhaseBegin(options)
            result = self.phases.MultiIterGenRegionPinballs(wp_pb_dir,
                                                            self.replayer_cmd,
                                                            options)
            if result == 0:
                if not options.list:
                    msg.PrintMsgPlus(
                        'Waiting on final concurrent region pinball generation')
                result = util.WaitJobs(options)
            if not options.list:
                msg.PrintMsgDate('Finished generating region pinballs %s' % \
                    config.PhaseStr(config.relog_regions))
            util.CheckResult(result, options, 'Region pinball generation %s' %\
                config.PhaseStr(config.relog_regions))

        # Do not run replay region pinballs as one of the default phases.  The
        # user must explicitly include this option.  This is to save time
        # during the tracing process.
        #
        if options.replay_region:
            result = 0
            if not options.list:
                msg.PrintMsgDate('Replaying all region pinballs %s' % \
                    config.PhaseStr(config.replay_regions))
            # import pdb;  pdb.set_trace()
            util.PhaseBegin(options)
            for pp_dir in util.GetRegionPinballDir():
                # Accumulate any errors which occur, but don't check for errors
                # until all the pinballs have been replayed.
                #
                r = self.phases.Replay(self.replay_cmd, pp_dir, options)
                result = result or r
            if not options.list:
                msg.PrintMsgDate('Finished replaying all region pinballs %s' % \
                    config.PhaseStr(config.replay_regions))
            util.CheckResult(result, options, 'Replay of region pinballs %s' % \
                config.PhaseStr(config.replay_regions))
            result = 0  # Remove the return values from replaying region pinballs

        # If there are any additional phases, then run them.
        #
        self.RunAdditionalPhases(wp_pb_dir, self.sim_replay_cmd, options)

        # Cleanup and print out a string to indicate the tracing has completed.
        #
        # import pdb;  pdb.set_trace()
        util.CleanupTraceEnd(options)
        util.PrintTraceEnd(options)

        return result
Exemple #29
0
    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
Exemple #30
0
    def RunAdditionalPhases(self, wp_pb_dir, sim_replay_cmd, options):
        """
        Run the additional phases for the simulator which are not run as
        part of the usual PinPlay phases.
        """

        phases_obj = phases.Phases()
        self.sim_kit = self.GetSimKit()

        msg.PrintMsg('sinuca_tracer_output:         ' +
                     config.sinuca_tracer_output)
        msg.PrintMsg('sinuca_tracer_threads:        ' +
                     str(config.sinuca_tracer_threads))
        msg.PrintMsg('sinuca_tracer_parallel_start: ' +
                     str(config.sinuca_tracer_parallel_start))
        msg.PrintMsg('sinuca_tracer_parallel_end:   ' +
                     str(config.sinuca_tracer_parallel_end))

        if not options.sinuca_tracer_output:
            msg.PrintMsgPlus('ERROR: Please set sinuca_tracer_output.')
            util.CheckResult(
                -1, options,
                'Could not find the sinuca_tracer_output parameter.'
            )  # Force error with -1
# ~ # ~
        if not options.sinuca_tracer_threads:
            msg.PrintMsgPlus('ERROR: Please set sinuca_tracer_threads.')
            util.CheckResult(
                -1, options,
                'Could not find the sinuca_tracer_threads parameter.'
            )  # Force error with -1
# ~ # ~
        if not options.sinuca_tracer_parallel_start:
            msg.PrintMsgPlus('ERROR: Please set sinuca_tracer_parallel_start.')
            util.CheckResult(
                -1, options,
                'Could not find the sinuca_tracer_parallel_start parameter.'
            )  # Force error with -1


# ~ # ~
        if not options.sinuca_tracer_parallel_end:
            msg.PrintMsgPlus('ERROR: Please set sinuca_tracer_parallel_end.')
            util.CheckResult(
                -1, options,
                'Could not find the sinuca_tracer_parallel_end parameter.'
            )  # Force error with -1

        # Run branch predictor simulator on region pinballs.
        #
        if options.region_sim or options.default_phases:
            # Print out simulator results every warmup_length instructions.
            #
            for pp_dir in util.GetRegionPinballDir():
                phase_length = options.warmup_length
                if phase_length == 0:
                    phase_length = options.slice_size
                if not options.list:
                    msg.PrintMsgDate('Running simulator on region pinballs: %s' % \
                        config.PhaseStr(config.sim_regions))
                util.PhaseBegin(options)
                result = self.sim_kit.RunSimulator(pp_dir, sim_replay_cmd,
                                                   options)
                if not options.list:
                    msg.PrintMsgDate('Finished running simulator on region pinballs: %s' % \
                        config.PhaseStr(config.sim_regions))
                util.CheckResult(result, options, 'simulator on region pinballs: %s' % \
                    config.PhaseStr(config.sim_regions))

        # Run branch predictor simulator on whole program pinballs.
        #
        if options.whole_sim or options.default_phases:
            # Set phase_length to print out simulator results every slice_size instructions.
            #
            phase_length = options.slice_size

            if not options.list:
                msg.PrintMsgDate('Running simulator on whole program pinballs: %s' % \
                    config.PhaseStr(config.sim_whole))
            util.PhaseBegin(options)
            result = self.sim_kit.RunSimulator(wp_pb_dir, sim_replay_cmd,
                                               options)
            if not options.list:
                msg.PrintMsgDate('Finished running simulator on whole program pinballs: %s' % \
                    config.PhaseStr(config.sim_whole))
            util.CheckResult(result, options, 'simulator on whole program pinballs: %s' % \
                config.PhaseStr(config.sim_whole))

        return 0