Exemple #1
0
    def Run(self):
        """
        Get all the user options and run the replayer.

        @return Exit code from the replayer pintool
        """

        # import pdb;  pdb.set_trace()
        parsed_tool_opts, parsed_pintool_opts, basename, kit_obj, options = self.ParseCommandLine(
        )

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

        # Get path to the kit tool and the appropriate pintool name
        #
        cmd = os.path.join(kit_obj.path, kit_obj.pin)

        # Print out all the parsed options
        #
        if config.debug:
            print "parsed_tool_opts:    ", parsed_tool_opts
            print "parsed_pintool_opts: ", parsed_pintool_opts
            print "basename:            ", basename
            print

        # Kit tool options
        #
        pin_options = ''
        pin_options += parsed_tool_opts

        # Pintool options, including the base logging options for all runs.
        # Also add any default knobs from the kit, if they exist.
        #
        pintool_options = ''
        pintool_options = ' -replay -xyzzy '
        pintool_options += parsed_pintool_opts
        pintool_options += util.GetMsgFileOption(basename)
        # import pdb;  pdb.set_trace()
        if kit_obj.default_knobs != '':
            pintool_options += ' ' + kit_obj.default_knobs

        # If generating instruction mix (indicated by the knobs -mix/-omix),
        # then can not use a pintool (a restriction imposed by the SDE driver).
        # Otherwise, get the appropriate pintool.
        #
        # import pdb;  pdb.set_trace()
        cmd = cmd + pin_options
        if '-mix' not in parsed_pintool_opts and '-omix' not in parsed_pintool_opts:
            cmd += kit_obj.GetPinToolKnob(basename)
        cmd += pintool_options

        # Add nullapp
        #
        cmd = cmd + ' -- ' + kit_obj.GetNullapp(basename)

        # Remove any double quotes (") which still exist in the cmd.
        #
        cmd = cmd.replace('"', '')

        # Finally execute the command line and gather stdin and stdout
        # Exit with the return code from executing the logger.
        #
        # import pdb;  pdb.set_trace()
        result = 0

        # Print out command line used for pin and pintool
        #
        # import pdb;  pdb.set_trace()
        if not (hasattr(options, 'no_print_cmd')
                and options.no_print_cmd) or options.verbose:
            if options.verbose:
                msg.PrintMsgNoCR('Starting job: %s\n' % cmd)
            else:
                msg.PrintMsg('\n%s' % cmd)

        if not config.debug:
            p = subprocess.Popen(cmd, shell=True)
            if options.verbose:
                msg.PrintMsg('Job PID: %d' % p.pid)
            (stdout, stderr) = p.communicate()
            result = p.returncode
            if options.verbose:
                msg.PrintMsg('Job finished, PID: %d' % p.pid)

        return result
Exemple #2
0
    def Run(self):
        """
        Get all the user options and run the logger.

        @return Exit code from the logger pintool
        """

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

        # Get the kit to be used for logging.
        #
        kit = self.GetKit()

        # Set the binary type in the kit.  Assume the first string in the
        # command line is the binary.  Only do this if user hasn't given 'pid'
        # or 'pintool_help'.
        #
        if not (hasattr(options, 'pid') and options.pid) and \
           not (hasattr(options, 'pintool_help') and options.pintool_help):
            binary = options.command.split()[0]
            kit.SetBinaryType(binary)
            if kit.binary_type == config.ARCH_INVALID:
                msg.PrintMsg(
                    '\nWARNING: Unable to determine binary file type.\n'
                    'Perhaps the string assumed to be the binary is incorrect.\n'
                    '   Command line:     ' + options.command + '\n'
                    '   Binary: (assumed) ' + binary + '\n'
                    'Setting binary type to \'Intel64\' as the default value.\n'
                )
        else:
            # If user has given 'pid' or wants 'pintool_help', then need to
            # explictly set the architecture of the binary in the kit.
            #
            kit.binary_type = options.arch

        # 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.
        #
        if hasattr(options, 'pintool') and options.pintool:
            kit.SetPinTool(options.pintool)

        # If user just wants 'pintool_help' go ahead and print it, then exit
        # the script.  Need to do this after we get the kit in order to print
        # the help for the correct kit.  Also needs to be after any user
        # defined pintools have been added to the kit. This ensures the
        # correct pintool help msg will be displayed.
        #
        if hasattr(options, 'pintool_help') and options.pintool_help:
            result = util.PintoolHelpKit(kit, options)

            return result

        # Get path to the kit pin binary, any user defined Pin knobs and
        # the pintool.
        #
        # import pdb;  pdb.set_trace()
        cmd = os.path.join(kit.path, kit.pin)
        if hasattr(options, 'pin_options') and options.pin_options:
            cmd += ' ' + options.pin_options
        if hasattr(options, 'pid') and options.pid:
            if kit.kit_type == config.PINPLAY:
                cmd += ' -pid ' + str(options.pid)
            elif kit.kit_type == config.SDE:
                cmd += ' -attach-pid ' + str(options.pid)

        cmd += kit.GetPinToolKnob()

        # Pintool knobs required for logging.
        #
        if not (hasattr(options, 'no_log') and options.no_log):
            cmd += ' -log'
            cmd += ' -xyzzy '

            # Add any knobs required by user options or the type of binary
            #
            if hasattr(options, 'log_file') and options.log_file:
                cmd += self.AddOptionIfNotPresent(options, '-log:basename',
                                                  options.log_file)
            cmd += util.AddMt(options)
            cmd += util.AddCompressed(options)
            cmd += util.GetMsgFileOption(options.log_file)

            # Add any user logging options given by the user
            #
            if hasattr(options, 'log_options') and options.log_options:
                cmd += options.log_options

        # Need to add shared memory knobs and create memory pools for MPI/MP apps.
        #
        create_mem_pool = False
        if options.mode == config.MPI_MODE or options.mode == config.MPI_MT_MODE or \
           options.mode == config.MP_MODE or options.mode == config.MP_MT_MODE:

            # Need to add the MPI options to the existing MT options already in
            # 'pintool_options'.
            #
            if not (hasattr(options, 'no_log') and options.no_log):
                cmd += self.MpModeOptions(options)
                create_mem_pool = True
            else:
                create_mem_pool = False

        # Format the MPI command line, if required to run the command line.
        #
        if options.mode == config.MPI_MODE or options.mode == config.MPI_MT_MODE:
            cmd = util.MPICmdLine(options) + ' ' + cmd

        # If logging enabled for multi-threaded app, generate the mp_pool.
        #
        if create_mem_pool:
            log_key = self.RunMPCreate(kit, options)
            cmd += log_key

        # Add program and arguments
        #
        if not options.pid:
            cmd += ' -- ' + options.command

        # Print out command line used for pin and pintool
        #
        if not (hasattr(options, 'no_print_cmd')
                and options.no_print_cmd) or options.verbose:
            string = '\n' + cmd
            msg.PrintMsg(string)

        # Finally execute the command line and gather stdin and stdout.
        # Exit with the return code from executing the logger.
        #
        result = 0
        # import pdb;  pdb.set_trace()
        if not config.debug:
            platform = util.Platform()
            if not (hasattr(options, 'no_print_cmd') and options.no_print_cmd):
                if platform != config.WIN_NATIVE:
                    cmd = 'time ' + cmd
            p = subprocess.Popen(cmd, shell=True)
            p.communicate()
            result = p.returncode

        # If logging enabled for multi-threaded app, delete the mp_pool.
        #
        if create_mem_pool:
            self.RunMPDelete(kit, log_key, options)

        return result
Exemple #3
0
    def GenLitFiles(self, param, dirname, file_name):
        """
        Generate either the LIT files or warmup LMAT files for one pinball based on the
        value 'flavor' passed in the param dictionary.

        The region pinball contains optional warmup instructions before the instructions
        in the actual representative regions.  If there aren't any warmup instructions for a
        pinball, then skip the step which generates LMAT files.
        """

        # Setup locale so we can print integers with commas.
        #
        import locale
        locale.setlocale(locale.LC_ALL, "")

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

        # Unpack replay_cmd, options and flavor from the dictionary param.
        # Flavor determines the type of file to generate.
        #
        if param.has_key('flavor'):
            flavor = param['flavor']
        else:
            err_msg('flavor')
            return -1
        if param.has_key('options'):
            options = param['options']
        else:
            err_msg('options')
            return -1
        if param.has_key('replay_cmd'):
            replay_cmd = param['replay_cmd']
        else:
            err_msg('replay_cmd')
            return -1

        result = 0

        # Get information from the pinball and the pinball file name.
        # Dummy variables: a, b, c, d, e, f
        #
        (icount, warmup, prolog, calc_region, epilog, tid,
         region) = util.GetRegionInfo(os.path.join(dirname, file_name), options)
        (a, b, c, file_region, d, e, f) = util.GetRegionInfo(
            os.path.join(dirname, file_name), options,
            use_file_fields=True)

        # If generating LMAT files, yet there aren't any warmup instructions for this pinball, then skip
        # this file by returning from the method.
        #
        if not options.list:
            if flavor == self.LMAT and warmup == 0:
                msg.PrintMsgPlus(
                    "NOTE: No warmup instructions.  Not generating LMAT files for trace:\n"
                    "       " + file_name)
                return 0

        # Check to make sure the TID in file name is the same as the tracing parameter 'focus_thread'.
        #
        if tid != config.focus_thread and config.focus_thread >= 0:
            msg.PrintMsg('ERROR: When generating LIT files, the TID in a pinball\n' \
                    'file name is not the same as the tracing parameter \'focus_thread\'. \n' \
                    'Focus thread is: ' + str(config.focus_thread) + ', yet the TID ' \
                    'in the file name is: ' + str(tid) + '.\n' \
                    'Please double check to make sure the focus thread parameter is \n' \
                    'correct (given with \'option -f X\' where X is the TID.)\n' \
                    '   ' + file_name + '\n')
            return -1

        # Calculate The length of all regions except the warmup
        #
        lit_len = icount - warmup

        # Get the number of threads from the result files
        #
        field = util.FindResultString(
            os.path.join(dirname, file_name + '.result'), 'static_threads')
        nthreads = field[0]
        if not nthreads:
            # Perhaps we are dealing with a pinball version > 2.4.  Look in the
            # *.global.log file for the number of threads.
            #
            field = util.FindString(
                os.path.join(dirname, file_name + '.global.log'), 'static_threads')
            nthreads = field[0]
        if nthreads:
            nthreads = int(nthreads)
        else:
            nthreads = 0

        # Check to make sure there are a significant number of instructions in the pinball.
        #
        if calc_region < 1000:
            msg.PrintMsg(
                '=============================================================')
            msg.PrintMsg(
                'WARNING: The icount for focus thread region pinball is low:')
            msg.PrintMsg('           Dir:               ' + dirname)
            msg.PrintMsg('           File:              ' + file_name)
        else:
            if not options.list:
                msg.PrintMsgPlus('File: ' + file_name)

        if not options.list:
            # Print details about the various sections in the pinball.
            #
            msg.PrintMsg('           Warmup count:        ' +
                         locale.format('%14d', warmup, True))
            msg.PrintMsg('           Prolog count:        ' +
                         locale.format('%14d', prolog, True))
            msg.PrintMsg('           Actual region count: ' + locale.format('%14d', calc_region, True) + \
                '   (from file name: ' + locale.format('%d', file_region, True) + ')')
            msg.PrintMsg('           Epilog count:        ' +
                         locale.format('%14d', epilog, True))

            msg.PrintMsg('           Total Instr count:   ' +
                         locale.format('%14d', icount, True))
            msg.PrintMsg('           Number of threads:   ' +
                         locale.format('%14d', nthreads, True))
            if config.focus_thread >= 0:
                msg.PrintMsg('           Focus thread:                     ' +
                             str(config.focus_thread))

        # Get the 'base' file name without the TID.
        #
        base_name = util.RemoveTID(file_name)

        # Get the LIT directory name from the region pinball directory name.
        #
        lit_dir = util.ChangeExtension(dirname, '.pp', '.lit')

        # Several file names, with path, for pinball and LIT files.  
        #
        # Need to remove TID for the file name given to knob '-log:basename'
        # when generating LMAT files.  This must be done is because pinLIT will
        # add the TID to the LIT file names. Hence it must be removed in the
        # 'basename'.
        #
        # import pdb;  pdb.set_trace()
        pb_path_file = os.path.join(dirname, file_name)
        lit_path_file = os.path.join(lit_dir, file_name)
        lit_path_file_no_tid = os.path.join(lit_dir, base_name)

        # msg.PrintMsg('pb_path_file:         ' + pb_path_file)
        # msg.PrintMsg('lit_path_file:        ' + lit_path_file)
        # msg.PrintMsg('lit_path_file_no_tid: ' + lit_path_file_no_tid)

        # Path & file name to the PTOV file which is generated by pinLIT.  If
        # there are no warmups for the file, then there won't be a 'warmup.ptov'
        # file for it.
        #
        #
        ptov_path_file = glob.glob(
            os.path.join(lit_dir, base_name) + '*.warmup.ptov')
        if ptov_path_file:
            ptov_path_file = ptov_path_file[0]

        # Format the initial part of the command line which is used for both LMAT and LIT files.
        #
        cmd_0 = replay_cmd
        cmd_0 += ' --replay_file ' + pb_path_file
        cmd_0 += ' --log_options '

        # Determine if all parameters should be dumped to the global file
        # (PinPlay), or just a subset (CBSP).
        #
        if options.cbsp():
            pinplay = False
        else:
            pinplay = True
        cmd_1 = util.AddGlobalFile(self.gv.DumpGlobalVars(pinplay), options)
        cmd_1 += util.AddCfgFile(options)

        # Add user defined 'lit_options' to both the LMAT and LIT command
        # lines.  May want sepatate options in the future, but right now
        # there's only one.
        #
        knobs = ''
        if hasattr(
            options,
            'replay_options') and options.replay_options:  # Add any user defined replay options
            knobs += ' ' + options.replay_options
        if hasattr(
            options,
            'lit_options') and options.lit_options:  # Add any user defined replay options
            knobs += ' ' + options.lit_options

        if flavor == self.LMAT:
            # Format the knobs required to generate LMAT files.
            #
            knobs += ' -log -xyzzy -log:LIT -log:LIT_warmup ' + self.kit_obj.knob_length + ' ' + str(
                warmup)
            knobs += ' -log:early_out'
            knobs += ' -log:basename ' + lit_path_file_no_tid
            if hasattr(options, 'compressed'):
                knobs += ' -log:compressed ' + options.compressed
            knobs += util.GetMsgFileOption(lit_path_file + '.lmat')

            if hasattr(options, 'list') and not options.list:
                msg.PrintMsgPlus('Generating LMAT files: ' + file_name)
            end_str = file_name

        else:
            if warmup > 0 and ptov_path_file:
                # Need this knob when generating LIT files if LMAT files already generated
                # for this trace.
                #
                knobs += ' -log:LIT_use_ptov ' + ptov_path_file

            # Format the knobs required to generate LIT files.
            #
            #import pdb;  pdb.set_trace()
            knobs += ' -log -log:LIT ' + self.kit_obj.knob_skip + ' ' + str(warmup)
            if lit_len < 0:
                msg.PrintMsg(
                '=============================================================')
                msg.PrintMsg(
                'WARNING: The icount for focus thread region pinball is low:')
                msg.PrintMsg('           Dir:               ' + dirname)
                msg.PrintMsg('           File:              ' + file_name)
                knobs += ' ' + self.kit_obj.knob_length + ' ' + '100'
                msg.PrintMsg('         No LIT will be generated')
            else:
                knobs += ' ' + self.kit_obj.knob_length + ' ' + str(lit_len)
            knobs += ' -log:early_out'
            knobs += ' -log:basename ' + lit_path_file_no_tid
            if hasattr(options, 'compressed'):
                knobs += ' -log:compressed ' + options.compressed
            knobs += util.GetMsgFileOption(lit_path_file + '.lit')

            if hasattr(options, 'list') and not options.list:
                msg.PrintMsgPlus('Generating LIT files:  ' + file_name)
            end_str = file_name

        # Format & execute the command.
        #
        cmd = cmd_0 + '"' + knobs + '"' + cmd_1

        # Run the command in the background in order to run concurrent jobs.
        #
        # import pdb;  pdb.set_trace()
        result = util.RunCmd(cmd, options, end_str, concurrent=True)

        return result