예제 #1
0
def compute_case_score(result, category, score_way, exec_dir, target):
    tmp = category.split()
    length = len(tmp)
    if (length != 4):
        return -3

    result_flag = 1
    score_flag = 2

    if type(result) is types.StringType:
        result_fp = string.atof(result)
    elif type(result) is types.FloatType:
        result_fp = result
    elif type(result) is types.IntType:
        result_fp = result
    else:
        return -4
    #pdb.set_trace()
    # this part should be improved
    func_args = score_way.split()
    score_method = func_args[0]
    if len(func_args) < 2:
        print "The configuration of run the benchmark is wrong"
        return -5
    base = string.atof(func_args[1])
    if len(func_args) >= 3:
        index = string.atof(func_args[2])
    if score_method == "exp_score_compute":
        if result_fp == 0:
            result_score = 0
        else:
            result_score = Scores_method.exp_score_compute(
                result_fp, base, index)
            logging.info("After computing, the result is %f" % result_score)
    else:
        if score_method == "compute_speed_score":
            if result_fp == 0:
                result_score = 0
            else:
                result_score = Scores_method.compute_speed_score(
                    result_fp, base)

    #write the result and the corresponding score to files
    target_name = server_utils.get_host_name(target)
    yaml_dir = os.path.join(exec_dir, "..", "output", "yaml")
    result_yaml_name = target_name + '.yaml'
    score_yaml_name = target_name + "_score.yaml"
    result_yaml = os.path.join(yaml_dir, result_yaml_name)
    score_yaml = os.path.join(yaml_dir, score_yaml_name)

    try:
        flag1 = write_yaml(result_yaml, tmp, result_fp, result_flag)
        flag2 = write_yaml(score_yaml, tmp, result_score, score_flag)
    except BaseException:
        print "There is wrong when compute the score."
    return flag1 & flag2
예제 #2
0
def traverse_caliper_output(hosts):
    YAML_DIR = os.path.join(caliper_path.folder_ope.results_dir, 'yaml')
    host_name = server_utils.get_host_name(hosts)
    host_yaml_name = host_name + '_score.yaml'
    host_yaml_file = os.path.join(YAML_DIR, host_yaml_name)
    try:
        return_code = traverse.traverser_results(hosts, host_yaml_file)
    except Exception, e:
        logging.info(e)
        raise
예제 #3
0
def traverse_caliper_output(hosts):
    YAML_DIR = os.path.join(caliper_path.folder_ope.results_dir, 'yaml')
    host_name = server_utils.get_host_name(hosts)
    host_yaml_name = host_name + '_score.yaml'
    host_yaml_file = os.path.join(YAML_DIR, host_yaml_name)
    try:
        return_code = traverse.traverser_results(hosts, host_yaml_file)
    except Exception, e:
        logging.info(e)
        raise
예제 #4
0
def traverse_pre(target, dic_file):
    """ dic_file means sections in the yaml file which store the information
    of machine """
    if name_str not in dic_file:
        dic_file[name_str] = {}
    hostName = server_utils.get_host_name(target)
    dic_file[name_str] = hostName
    if conf_str not in dic_file:
        dic_file[conf_str] = {}
    dic_file[conf_str] = server_utils.get_host_hardware_info(target)
    return dic_file
예제 #5
0
def traverse_pre(target, dic_file):
    """ dic_file means sections in the yaml file which store the information
    of machine """
    if name_str not in dic_file:
        dic_file[name_str] = {}
    hostName = server_utils.get_host_name(target)
    dic_file[name_str] = hostName
    if conf_str not in dic_file:
        dic_file[conf_str] = {}
    dic_file[conf_str] = server_utils.get_host_hardware_info(target)
    return dic_file
예제 #6
0
def hardware_info_parser(content, outfp):
    category = {
        '[CPU]': dictionary.cpu,
        '[DISK]': dictionary.disk,
        '[NETWORK]': dictionary.network,
        '[MEMORY]': dictionary.memory,
        '[KERNEL]': dictionary.kernel,
        '[OS]': dictionary.os
    }
    dic = {}
    dic_yaml = {}
    dic_yaml['Configuration'] = {}
    dic_yaml['name'] = {}
    contents = content.split('\n\n\n')
    for key, value in category.iteritems():
        value(dic)
    os_populate(dic, contents)
    cpu_populate(dic, contents)
    memory_populate(dic, contents)
    disk_populate(dic, contents)
    kernel_populate(dic, contents)
    network_populate(dic, contents)
    update(dic, outfp)
    host = get_remote_host()
    dic_yaml['Configuration']['CPU'] = dic['Hardware_Info']['CPU']['CPU_Cores']
    dic_yaml['Configuration']['CPU_type'] = dic['Hardware_Info']['CPU'][
        'Cpu_Type']
    dic_yaml['Configuration']['Memory'] = dic['Hardware_Info']['MEMORY'][
        'Main_Memory_Size']
    dic_yaml['Configuration']['OS_Version'] = dic['Hardware_Info']['KERNEL'][
        'Version']
    dic_yaml['Configuration']['Byte_order'] = dic['Hardware_Info']['CPU'][
        'Byte_Order']
    dic_yaml['Configuration']['Hostname'] = server_utils.get_host_name(host)
    dic_yaml['Configuration']['L1d_cache'] = dic['Hardware_Info']['MEMORY'][
        'L1_D-Cache_Size']
    dic_yaml['Configuration']['L1i_cache'] = dic['Hardware_Info']['MEMORY'][
        'L1_I-Cache_Size']
    dic_yaml['Configuration']['L2_cache'] = dic['Hardware_Info']['MEMORY'][
        'L2_Cache_Size']
    dic_yaml['Configuration']['L3_cache'] = dic['Hardware_Info']['MEMORY'][
        'L3_Cache_Size']
    dic_yaml['Configuration']['Machine_arch'] = dic['Hardware_Info']['CPU'][
        'Architecture']
    dic_yaml['name'] = dic_yaml['Configuration']['Hostname']
    yaml_name = dic_yaml['Configuration']['Hostname'] + ".yaml"
    yaml_path = os.path.join(Folder.yaml_dir, yaml_name)
    with open(yaml_path, 'w') as outfp:
        outfp.write(yaml.dump(dic_yaml, default_flow_style=False))
    yaml_name_hw = dic_yaml['Configuration']['Hostname'] + "_hw_info.yaml"
    yaml_path_hw = os.path.join(Folder.yaml_dir, yaml_name_hw)
    with open(yaml_path_hw, 'w') as outfp:
        outfp.write(yaml.dump(dic, default_flow_style=False))
    return dic
예제 #7
0
def traverse_caliper_output(hosts):

    YAML_DIR = os.path.join(OUT_DIR, 'yaml')

    host_name = server_utils.get_host_name(hosts)
    host_yaml_name = host_name + '_score.yaml'
    host_yaml_file = os.path.join(YAML_DIR, host_yaml_name)
    try:
        return_code = traverse.traverser_perf(hosts, host_yaml_file)
    except Exception, e:
        logging.info(e.args[0], e.args[1])
        raise
예제 #8
0
def traverse_pre(target, dic_file):
    """ dic_file means sections in the yaml file which store the information of machine """
    if 'name' not in dic_file:
        dic_file['name'] = {}
    hostName = server_utils.get_host_name(target)
    dic_file['name'] = hostName

    if 'Configuration' not in dic_file:
        dic_file['Configuration'] = {}

    dic_file['Configuration'] = server_utils.get_host_hardware_info(target)

    return dic_file
예제 #9
0
def compute_case_score(result, category, score_way, target):
    tmp = category.split()
    length = len(tmp)
    # write the result and the corresponding score to files
    target_name = server_utils.get_host_name(target)
    yaml_dir = os.path.join(Folder.results_dir, 'yaml')
    result_yaml_name = target_name + '.yaml'
    score_yaml_name = target_name + '_score.yaml'
    result_yaml = os.path.join(yaml_dir, result_yaml_name)
    score_yaml = os.path.join(yaml_dir, score_yaml_name)
    if (length == 4 and tmp[0] == 'Functional'):
        return compute_func(result, tmp, score_way, result_yaml, score_yaml)
    elif ((length != 0 and length <= 4) and tmp[0] == 'Performance'):
        return compute_perf(result, tmp, score_way, result_yaml, score_yaml)
    else:
        return -4
예제 #10
0
def hardware_info_parser(content,outfp):
    category = {
        '[CPU]' : dictionary.cpu,
        '[DISK]' : dictionary.disk,
        '[NETWORK]' : dictionary.network,
        '[MEMORY]' : dictionary.memory,
        '[KERNEL]' : dictionary.kernel,
        '[OS]' : dictionary.os
    }
    dic = {}
    dic_yaml = {}
    dic_yaml['Configuration'] = {}
    dic_yaml['name'] = {}
    contents = content.split('\n\n\n')
    for key,value in category.iteritems():
        value(dic)
    os_populate(dic,contents)
    cpu_populate(dic,contents)
    memory_populate(dic,contents)
    disk_populate(dic,contents)
    kernel_populate(dic,contents)
    network_populate(dic,contents)
    update(dic,outfp)
    host = get_remote_host()
    dic_yaml['Configuration']['CPU'] = dic['Hardware_Info']['CPU']['CPU_Cores']
    dic_yaml['Configuration']['CPU_type'] = dic['Hardware_Info']['CPU']['Cpu_Type']
    dic_yaml['Configuration']['Memory'] = dic['Hardware_Info']['MEMORY']['Main_Memory_Size']
    dic_yaml['Configuration']['OS_Version'] = dic['Hardware_Info']['KERNEL']['Version']
    dic_yaml['Configuration']['Byte_order'] = dic['Hardware_Info']['CPU']['Byte_Order']
    dic_yaml['Configuration']['Hostname'] = server_utils.get_host_name(host)
    dic_yaml['Configuration']['L1d_cache'] = dic['Hardware_Info']['MEMORY']['L1_D-Cache_Size']
    dic_yaml['Configuration']['L1i_cache'] = dic['Hardware_Info']['MEMORY']['L1_I-Cache_Size']
    dic_yaml['Configuration']['L2_cache'] = dic['Hardware_Info']['MEMORY']['L2_Cache_Size']
    dic_yaml['Configuration']['L3_cache'] = dic['Hardware_Info']['MEMORY']['L3_Cache_Size']
    dic_yaml['Configuration']['Machine_arch'] = dic['Hardware_Info']['CPU']['Architecture']
    dic_yaml['name'] = dic_yaml['Configuration']['Hostname']
    yaml_name = dic_yaml['Configuration']['Hostname'] + ".yaml"
    yaml_path = os.path.join(Folder.yaml_dir,yaml_name)
    with open(yaml_path,'w') as outfp:
        outfp.write(yaml.dump(dic_yaml,default_flow_style = False))
    yaml_name_hw = dic_yaml['Configuration']['Hostname'] + "_hw_info.yaml"
    yaml_path_hw = os.path.join(Folder.yaml_dir,yaml_name_hw)
    with open(yaml_path_hw,'w') as outfp:
        outfp.write(yaml.dump(dic,default_flow_style = False))
    return dic
예제 #11
0
def compute_case_score(result, category, score_way, target, flag):
    tmp = category.split()
    length = len(tmp)
    # write the result and the corresponding score to files
    target_name = server_utils.get_host_name(target)
    yaml_dir = os.path.join(Folder.results_dir, 'yaml')
    result_yaml_name = target_name + '.yaml'
    score_yaml_name = target_name + '_score.yaml'
    if flag == 1:
        result_yaml = os.path.join(yaml_dir, result_yaml_name)
    else :
        result_yaml = os.path.join(yaml_dir, score_yaml_name)
    if (length == 4 and tmp[0] == 'Functional'):
        return compute_func(result, tmp, score_way, result_yaml, flag)
    elif ((length != 0 and length <= 4) and tmp[0] == 'Performance'):
        return compute_perf(result, tmp, score_way, result_yaml, flag)
    else:
        return -4
예제 #12
0
def run_caliper_tests(target, f_option):
    #f_option =1 if -f is used
    if f_option == 1:
        if not os.path.exists(Folder.exec_dir):
            os.mkdir(Folder.exec_dir)
    else:
        if os.path.exists(Folder.exec_dir):
            shutil.rmtree(Folder.exec_dir)
        os.mkdir(Folder.exec_dir)
    if not os.path.exists(Folder.results_dir):
        os.mkdir(Folder.results_dir)
    if not os.path.exists(Folder.yaml_dir):
        os.mkdir(Folder.yaml_dir)
    if not os.path.exists(Folder.html_dir):
        os.mkdir(Folder.html_dir)

    flag = 0
    target_execution_dir = server_utils.get_target_exec_dir(target)
    if not os.path.exists(target_execution_dir):
        flag = 1
    try:
        logging.debug("beginnig to run the test cases")
        test_result = caliper_run(target_execution_dir, target)
        if intermediate == 1:
            target_name = server_utils.get_host_name(target)
            yaml_dir = os.path.join(Folder.results_dir, 'yaml')
            result_yaml_name = target_name + '.yaml'
            result_yaml = os.path.join(yaml_dir, result_yaml_name)
            dic = {}
            dic = traverse.traverse_pre(target, dic)
            with open(result_yaml, 'w') as fp:
                fp.write(yaml.dump(dic, default_flow_style=False))

    except error.CmdError:
        logging.info("There is wrong in running benchmarks")
        flag = 1
    else:
        if test_result:
            flag = test_result
    return flag
예제 #13
0
def run_caliper_tests(target,f_option):
    #f_option =1 if -f is used
    if f_option == 1:
        if not os.path.exists(Folder.exec_dir):
            os.mkdir(Folder.exec_dir)
    else:
        if os.path.exists(Folder.exec_dir):
            shutil.rmtree(Folder.exec_dir)
        os.mkdir(Folder.exec_dir)
    if not os.path.exists(Folder.results_dir):
        os.mkdir(Folder.results_dir)
    if not os.path.exists(Folder.yaml_dir):
        os.mkdir(Folder.yaml_dir)
    if not os.path.exists(Folder.html_dir):
        os.mkdir(Folder.html_dir)

    flag = 0
    target_execution_dir = server_utils.get_target_exec_dir(target)
    if not os.path.exists(target_execution_dir):
        flag = 1
    try:
        logging.debug("beginnig to run the test cases")
        test_result = caliper_run(target_execution_dir, target)
        if intermediate == 1:
            target_name = server_utils.get_host_name(target)
            yaml_dir = os.path.join(Folder.results_dir, 'yaml')
            result_yaml_name = target_name + '.yaml'
            result_yaml = os.path.join(yaml_dir, result_yaml_name)
            dic = {}
            dic = traverse.traverse_pre(target, dic)
            with open(result_yaml,'w') as fp:
                fp.write(yaml.dump(dic, default_flow_style=False))

    except error.CmdError:
        logging.info("There is wrong in running benchmarks")
        flag = 1
    else:
        if test_result:
            flag = test_result
    return flag