#
options, args = GetOptions()
base_name = args[0]

# Running in a LIT directory.
#
param = {'options': options, 'in_lit_dir': True}

# Get the cluster information from the regions CSV file.  Check to make sure we
# have parsed data for every cluster.
#
#import pdb;  pdb.set_trace()
cluster_info, not_used, total_instr = util.GetClusterInfo(base_name, param)
if cluster_info == {}:
    msg.PrintAndExit('Error reading file: ' + base_name)
cluster_list = util.ParseClusterInfo(cluster_info)
if len(cluster_info) != len(cluster_list):
    msg.PrintAndExit('traceinfo.py() did not parse enough clusters.\n' '   Num clusters:         %d\n' \
        '   Num parsed clusters:  %d' % (len(cluster_info), len(cluster_list)))

# First print some info which is independent of the specific traces in the current directory.
#
count = len(cluster_info)
util.RunCmd(FmtPrintCmd(blank_DTD), options, '',
            concurrent=False,
            print_time=False,
            print_cmd=False)
util.RunCmd(FmtPrintCmd(blank_head), options, '',
            concurrent=False,
            print_time=False,
            print_cmd=False)
Ejemplo n.º 2
0
    def GenTraceinfoFiles(self, options):
        """
        Generate traceinfo files from sysinfo files. Also do some simple error
        checking.

        One traceinfo file is generated for each directory which contains
        region pinballs.  Currently, the script 'create_traceinfo.sh' is used
        to generate the traceinfo file.  This will be replaced with a Python
        script at sometime in the future.

        The following info is printed to allow the user to determine if the
        required number of region pinballs and traces were generated:
        1) The script 'count_traces.sh' gets a count of the number of
           expected traces and the region numbers from the region CSV file.
        2) The number of actual traces generated and the trace names.
        3) The number of region pinballs generated and the pinball names.
        """

        # Check to make sure there is at least one region pinball directory for
        # this tracing instance.
        #
        all_pp_dirs = util.GetRegionPinballDir(options)
        if all_pp_dirs == [] and not options.debug:
            msg.PrintMsg(
                '\nERROR: Could not find any PinPoint \'*.pp\' directories.\n'
                'Make sure you have run the phase \'-p\'.')
            return -1

        # Get the region pinball directories for this tracing instance.
        #
        # import pdb;  pdb.set_trace()
        all_lit_dirs = util.GetLitDir()
        if all_lit_dirs == [] and not options.debug:
            msg.PrintMsg(
                '\nERROR: Could not find any LIT \'*.lit\' directories.\n'
                'Make sure you have run the phase \'-L\'.')
            return -1

        result = 0
        # import pdb;  pdb.set_trace()
        for lit_dir in all_lit_dirs:

            # Get the name of the corresponding region pinball directory
            # and make sure it exists.
            #
            pp_dir = util.ChangeExtension(lit_dir, '.lit', '.pp')
            if not os.path.isdir(pp_dir):
                if not options.list:
                    msg.PrintMsgPlus('WARNING: Generating traceinfo files, but the required \'pp\' ' \
                        'directory does not exist:\n   ' + pp_dir)

                    # If running in MPI_MT_MODE, then it's possible for one process to
                    # not have a thread corresponding to the the current focus thread.
                    # However, another process might have this thread.
                    # Thus, only return an error if not tracing a MPI_MT application.
                    #
                    if options.mode == config.MPI_MT_MODE:
                        msg.PrintMsg(
                            'Since tracing mode is \'mpi_mt\', this may be OK.')
                        continue
                    else:
                        return -1
                else:
                    # Not printing any msgs, just skip to the next directory
                    #
                    continue

            # Make sure the LIT directory exists, then go there.
            #
            old_dir = os.getcwd()
            if os.path.isdir(lit_dir):
                os.chdir(lit_dir)
            else:
                if not options.list:
                    msg.PrintMsgPlus('WARNING: Generating traceinfo files, but the LIT ' \
                        'directory does not exist:\n   ' + lit_dir)

                    # If running in MPI_MT_MODE, then it's possible for one process to
                    # not have a thread corresponding to the the current focus thread.
                    # However, another process might have this thread.
                    # Thus, only return an error if not tracing a MPI_MT application.
                    #
                    if options.mode == config.MPI_MT_MODE:
                        msg.PrintMsg(
                            'Since tracing mode is \'mpi_mt\', this may be OK.')
                        continue
                    else:
                        return -1
                else:
                    # Not printing any msgs, just skip to the next directory
                    #
                    continue

            # Copy the traceinfo 'blank' XML files from the SDE kit.
            #
            blank_path = self.kit_obj.GetTraceinfoBlank()
            for blank in config.traceinfo_blank_files:
                blank_file = os.path.join(blank_path, blank)
                try:
                    shutil.copy(blank_file, os.getcwd())
                except IOError:
                    msg.PrintMsg(
                        '\nERROR: Unable to copy traceinfo \'blank\' file:\n    '
                        + blank_file)
                    return -1

            # Run the script to generate traceinfo XML file.  Stdout from the
            # script is the XML file.  Function util.RunCMD() needs the output XML
            # file object in order to write this file.
            #
            msg.PrintMsg('')
            base_name = util.ChangeExtension(lit_dir, '.lit', '')
            tr_file = base_name + '.traceinfo.xml'
            try:
                fp_out = open(tr_file, 'w')
            except IOError:
                msg.PrintMsg('ERROR: Failed to open traceinfo output file:\n'
                             '   ' + tr_file)
                return -1
            cmd = self.traceinfo_bin + ' ' + base_name
            result = util.RunCmd(cmd, options, '',
                                 concurrent=False,
                                 f_stdout=fp_out)
            if result != 0:
                msg.PrintMsg('Error found while running script \'%s\'' %
                             self.traceinfo_bin)
                return -1

            # Print info from the CSV regions file (located in the *.Data
            # directory) about the number of expected traces.
            #
            msg.PrintMsg('')
            param = {'in_lit_dir': True}
            cluster_info, not_used, total_instr = util.GetClusterInfo(base_name, param)
            if cluster_info == {}:
                msg.PrintMsg(
                    'ERROR: Problems getting cluster info from file: %s.pinpoints.csv'
                    % (base_name))
                return -1
            cluster_list = util.ParseClusterInfo(cluster_info)
            if len(cluster_info) != len(cluster_list):
                msg.PrintMsg('ERROR: Did not parse enough clusters from CSV file: %s.pinpoints.csv\n' '   Num clusters:         %d\n' \
                    '   Num parsed clusters:  %d' % (base_name, len(cluster_info), len(cluster_list)))
                return -1

            # Print the number of expected traces from the regions CSV file.
            #
            base_tid = -1
            for cl in cluster_list:
                if (cl.has_key('tid')):
                    tid = cl['tid']
                else:
                    msg.PrintMsg(
                        'ERROR: Parsing cluster info for cluster:\n     %s' %
                        (cl))
                    return -1
                if base_tid == -1:
                    base_tid = tid
                else:
                    if tid != base_tid:
                        msg.PrintAndExit(
                            'ERROR: Expected TID %d, but found TID %d' %
                            (base_tid, tid))
                        return -1
            msg.PrintMsg('Expected trace count: %d\n' % (len(cluster_info)))

            # Print the number of actual traces in the LIT directory and the names. 
            #
            # import pdb;  pdb.set_trace()
            if not options.list:
                msg.PrintMsg(
                    'Actual trace count: ' + str(util.CountFiles('ami')))
                lit_files = glob.glob('*.ami*')
                lit_files.sort()
                for f in lit_files:
                    msg.PrintMsg('   ' + f)

            # Clean up tmp files in the LIT directory.
            #
            tmp_files = glob.glob('*blank*.xml')
            for f in tmp_files:
                os.remove(f)

            # Return to the working directory.
            #
            os.chdir(old_dir)

            # Go to the *.pp directory. Print the number of actual pinballs and the names.
            #
            os.chdir(pp_dir)
            if not options.list:
                msg.PrintMsg(
                    '\nPinball count: ' + str(util.CountFiles('address')))
                pp_files = glob.glob('*.address')
                pp_files.sort()
                for f in pp_files:
                    msg.PrintMsg('   ' + f)

                # Print a warning if the expected number of traces are not found.
                #
                if len(lit_files) != len(pp_files):
                    msg.PrintMsgPlus(
                        'WARNING: Number of traces does not match the number of region pinballs.')

            msg.PrintMsg('\nGenerated traceinfo file: ' + tr_file)

            # Return to the working directory.
            #
            os.chdir(old_dir)

        return result