def churn_info_in_commit(xml_commit, debug=False):
    # Process the stat-tag
    xml_stat = xml_commit.find('stat')
    # Debug-info
    if debug:
        logger.debug('Getting the churn from commit: %s', xml_commit.get('revision'))
        logger.debug('Stat-content: \n%s', etree.tostring(xml_stat))
    if xml_stat.text is None or xml_stat.text.strip() == '':
        #error_msg = 'Error while running churn-info-in-commit. '+
        #            'Commit-content:\n%s.'%etree.tostring(xml_commit, pretty_print=True)
        #logger.debug(error_msg)
        #raise Exception(error_msg)
        logger.warn('Commit %s has an empty stat-tag.', xml_commit.get('revision') )
        return dict_to_class({'num_files':0, 
                              'insertions':0, 
                              'deletions': 0, 
                              'churn': 0})
    stat_data = xml_stat.text.strip()
    summary_line = stat_data.splitlines()[-1] # which is the last-line
    # Debug-info
    if debug:
        logger.debug('Summary-line: %s', summary_line)
    # Get the num-files and churn
    summary_as_list = summary_line.split(',')
    if len(summary_as_list) == 3:
        raw_num_files, raw_insertions, raw_deletions = summary_as_list
    elif len(summary_as_list) == 2:
        raw_num_files, raw_ins_or_dels = summary_as_list
        if '+' in raw_ins_or_dels:
            raw_insertions = raw_ins_or_dels
            raw_deletions = ' 0 deletions(-)'
        else:
            raw_insertions = ' 0 insertions(+)'
            raw_deletions = raw_ins_or_dels
    else:
        error_msg = "Error while getting the churn in commit:\n%s"%etree.tostring(xml_commit)
        logger.debug(error_msg)
        raise Exception(error_msg)
    num_files = raw_num_files.strip().split()[0]
    insertions = raw_insertions.strip().split()[0]
    deletions = raw_deletions.strip().split()[0]
    num_files = int(num_files)
    insertions = int(insertions)
    deletions = int(deletions)
    churn = insertions + deletions
    # Debug-info
    if debug:
        logger.debug('files: %s - inserts: %s - deletes: %s - churn: %s', 
                     num_files, insertions, deletions, churn)
    # Return as an object
    return dict_to_class({'num_files':num_files, 
                          'insertions':insertions, 
                          'deletions': deletions, 
                          'churn': churn})
def get_churn_info_commits_per_bug(xml_root):
    logger.info('Getting the churn of the commits per bug')
    hash_bugs = dict()
    for xml_commit in xml_root:
        xml_identified_bugs = xml_commit.find('identified_bugs')
        churn_info = churn_info_in_commit(xml_commit, debug=False)
        if churn_info.num_files == 0:
            logger.warn('Skipping this commit')
            continue
        for xml_bug in xml_identified_bugs:
            bug_id = xml_bug.get('bug_id')
            clazz = xml_bug.get('clazz')
            if clazz == 'none':
                continue
            if bug_id not in hash_bugs:
                bug = {'bug_id': bug_id, 'clazz': clazz, 'num_commits': 0, 'num_files': 0, 'churn': 0}
                bug_obj = dict_to_class(bug)
                hash_bugs[bug_id] = bug_obj
            bug_obj = hash_bugs[bug_id]
            bug_obj.num_commits += 1
            bug_obj.num_files += churn_info.num_files
            bug_obj.churn += churn_info.churn

    # Save it as a csv
    list_bugs = list()
    for bug_obj in hash_bugs.values():
        list_bugs.append([bug_obj.bug_id, bug_obj.clazz, bug_obj.churn, 
                          bug_obj.num_files, bug_obj.num_commits])
    list_bugs = sorted(list_bugs, key=operator.itemgetter(2), reverse=True)
    header = ['bug_id', 'clazz', 'churn', 'num_files', 'num_commits']
    if len(list_bugs) == 0 :
        list_bugs = [['--', '0', -1, -1, -1]]
    bugs_churn_as_array = tabular2array(list_bugs, header)
    return bugs_churn_as_array
Ejemplo n.º 3
0
def main(args):
    """
    Plot job execution times.
    """
    with open(args.fconfig, 'rb') as fp:
        args_fconfig = utils.dict_to_class(json.load(fp))
    utils.plot(args_fconfig)
    return None
Ejemplo n.º 4
0
def main(args):
    """
    Plot job execution times.
    """
    with open(args.fconfig, 'rb') as fp:
        args_fconfig = utils.dict_to_class(json.load(fp))
    utils.plot(args_fconfig)
    return None