Example #1
0
def print_results_full(filename, format):
    for tree in read_results('%s%s' % (filename, format), format):
        for k in tree[0]:
            print(k)
        for k in tree[1]:
            print(k)
        print('')
Example #2
0
def print_results_full(filename, format):
    for tree in read_results('%s%s' % (filename, format), format):
        for k in tree[0]:
            print k
        for k in tree[1]:
            print k
        print ''
Example #3
0
def provide_result_dictionary(filename, format, goal_tuple):
    f = lambda: defaultdict(f)
    rates = defaultdict(f)
    descriptions = []

    for tree in read_results('%s%s' % (filename, format), format):
        topology_params, trace_params, synthetic_experiment_params, policy_params, strategy, cache_size = determine_parameters(
            tree)

        rates, descriptions = assign_results(goal_tuple, tree, rates,
                                             descriptions, topology_params,
                                             trace_params,
                                             synthetic_experiment_params,
                                             policy_params, strategy)

    policies = [
        'ARC', 'LRU', 'KLRU', 'SS', 'DSCA', '2DSCA', 'DSCAAWS', '2DSCAAWS',
        'DSCASW', 'DSCAFT', 'DSCAFS', 'ADSCASTK', 'ADSCAATK'
    ]
    strategies = ['LCE', 'LCD', 'CL4M', 'PROB_CACHE', 'RAND_CHOICE']

    dict_list = []

    for policy in policies:
        if policy in list(rates.keys()):
            if policy in ['ARC', 'LRU', 'SS']:
                for strategy in strategies:
                    dict_list.append(
                        put_results_if_available(
                            '%s + %s' % (policy, strategy), rates[policy],
                            strategy))
            elif policy == 'KLRU':
                segment_values = list(rates[policy].keys())
                segment_values.sort()
                for segment_value in segment_values:
                    cached_segment_values = list(
                        rates[policy][segment_value].keys())
                    cached_segment_values.sort()
                    for cached_segment_value in cached_segment_values:
                        for strategy in strategies:
                            dict_list.append(
                                put_results_if_available(
                                    'KLRU (%d,%d) + %s' %
                                    (segment_value, cached_segment_value,
                                     strategy), rates[policy][segment_value]
                                    [cached_segment_value], strategy))
            elif policy in ['DSCA', '2DSCA', 'DSCAFT']:
                window_sizes = list(rates[policy].keys())
                window_sizes.sort()
                for window_size in window_sizes:
                    for strategy in strategies:
                        dict_list.append(
                            put_results_if_available(
                                '%s %d + %s' % (policy, window_size, strategy),
                                rates[policy][window_size], strategy))
            elif policy in ['DSCAAWS', '2DSCAAWS']:
                periods = list(rates[policy].keys())
                periods.sort()
                for period in periods:
                    hypo_As = list(rates[policy][period].keys())
                    hypo_As.sort()
                    for A in hypo_As:
                        hypo_epsilons = list(rates[policy][period][A].keys())
                        hypo_epsilons.sort()
                        for epsilon in hypo_epsilons:
                            for strategy in strategies:
                                dict_list.append(
                                    put_results_if_available(
                                        '%s %d %f %f + %s' %
                                        (policy, period, A, epsilon, strategy),
                                        rates[policy][period][A][epsilon],
                                        strategy))
            elif policy == 'DSCASW':
                subwindow_sizes = list(rates[policy].keys())
                subwindow_sizes.sort()
                for subwindow_size in subwindow_sizes:
                    subwindows_values = list(
                        rates[policy][subwindow_size].keys())
                    subwindows_values.sort()
                    for subwindows in subwindows_values:
                        for strategy in strategies:
                            dict_list.append(
                                put_results_if_available(
                                    'DSCASW (%d %d) + %s' %
                                    (subwindow_size, subwindows, strategy),
                                    rates[policy][subwindow_size][subwindows],
                                    strategy))
            elif policy == 'DSCAFS':
                window_sizes = list(rates[policy].keys())
                window_sizes.sort()
                for window_size in window_sizes:
                    lru_portions = list(rates[policy][window_size].keys())
                    lru_portions.sort()
                    for lru_portion in lru_portions:
                        for strategy in strategies:
                            dict_list.append(
                                put_results_if_available(
                                    'DSCAFS (%d %f) + %s' %
                                    (window_size, lru_portion, strategy),
                                    rates[policy][window_size][lru_portion],
                                    strategy))
            elif policy in ['ADSCASTK', 'ADSCAATK']:
                window_sizes = list(rates[policy].keys())
                window_sizes.sort()
                for window_size in window_sizes:
                    for strategy in strategies:
                        dict_list.append(
                            put_results_if_available(
                                '%s %d + %s' % (policy, window_size, strategy),
                                rates[policy][window_size], strategy))

    descriptions.sort()

    return descriptions, dict_list
Example #4
0
def provide_result_dictionary(filename, format, goal_tuple):
    f = lambda: defaultdict(f)
    rates = defaultdict(f)
    descriptions = []

    for tree in read_results('%s%s' % (filename, format), format):
        topology_params, trace_params, synthetic_experiment_params, policy_params, strategy, cache_size = determine_parameters(
            tree)

        rates, descriptions = assign_results(goal_tuple, tree, rates, descriptions, topology_params, trace_params,
                                             synthetic_experiment_params, policy_params, strategy)

    policies = ['ARC', 'LRU', 'KLRU', 'SS', 'DSCA', '2DSCA', 'DSCAAWS', '2DSCAAWS', 'DSCASW', 'DSCAFT', 'DSCAFS',
                'ADSCASTK', 'ADSCAATK']
    strategies = ['LCE', 'LCD', 'CL4M', 'PROB_CACHE', 'RAND_CHOICE']

    dict_list = []

    for policy in policies:
        if policy in rates.keys():
            if policy in ['ARC', 'LRU', 'SS']:
                for strategy in strategies:
                    dict_list.append(put_results_if_available('%s + %s' % (policy, strategy), rates[policy], strategy))
            elif policy == 'KLRU':
                segment_values = rates[policy].keys()
                segment_values.sort()
                for segment_value in segment_values:
                    cached_segment_values = rates[policy][segment_value].keys()
                    cached_segment_values.sort()
                    for cached_segment_value in cached_segment_values:
                        for strategy in strategies:
                            dict_list.append(put_results_if_available(
                                'KLRU (%d,%d) + %s' % (segment_value, cached_segment_value, strategy),
                                rates[policy][segment_value][cached_segment_value], strategy))
            elif policy in ['DSCA', '2DSCA', 'DSCAFT']:
                window_sizes = rates[policy].keys()
                window_sizes.sort()
                for window_size in window_sizes:
                    for strategy in strategies:
                        dict_list.append(put_results_if_available('%s %d + %s' % (policy, window_size, strategy),
                                                                  rates[policy][window_size], strategy))
            elif policy in ['DSCAAWS', '2DSCAAWS']:
                periods = rates[policy].keys()
                periods.sort()
                for period in periods:
                    hypo_As = rates[policy][period].keys()
                    hypo_As.sort()
                    for A in hypo_As:
                        hypo_epsilons = rates[policy][period][A].keys()
                        hypo_epsilons.sort()
                        for epsilon in hypo_epsilons:
                            for strategy in strategies:
                                dict_list.append(put_results_if_available(
                                    '%s %d %f %f + %s' % (policy, period, A, epsilon, strategy),
                                    rates[policy][period][A][epsilon], strategy))
            elif policy == 'DSCASW':
                subwindow_sizes = rates[policy].keys()
                subwindow_sizes.sort()
                for subwindow_size in subwindow_sizes:
                    subwindows_values = rates[policy][subwindow_size].keys()
                    subwindows_values.sort()
                    for subwindows in subwindows_values:
                        for strategy in strategies:
                            dict_list.append(
                                put_results_if_available('DSCASW (%d %d) + %s' % (subwindow_size, subwindows, strategy),
                                                         rates[policy][subwindow_size][subwindows], strategy))
            elif policy == 'DSCAFS':
                window_sizes = rates[policy].keys()
                window_sizes.sort()
                for window_size in window_sizes:
                    lru_portions = rates[policy][window_size].keys()
                    lru_portions.sort()
                    for lru_portion in lru_portions:
                        for strategy in strategies:
                            dict_list.append(
                                put_results_if_available('DSCAFS (%d %f) + %s' % (window_size, lru_portion, strategy),
                                                         rates[policy][window_size][lru_portion], strategy))
            elif policy in ['ADSCASTK', 'ADSCAATK']:
                window_sizes = rates[policy].keys()
                window_sizes.sort()
                for window_size in window_sizes:
                    for strategy in strategies:
                        dict_list.append(put_results_if_available('%s %d + %s' % (policy, window_size, strategy),
                                                                  rates[policy][window_size], strategy))

    descriptions.sort()

    return descriptions, dict_list
Example #5
0
def draw_cache_level_proportions(plotdir, filename, format):
    from .output_results import determine_parameters

    result = read_results('%s%s' % (filename, format), format)
    for tree in result:
        trace, policy, cache_size, window_size, segments, cached_segments, subwindows, subwindow_size, lru_portion, \
           hypothesis_check_period, hypothesis_check_A, hypothesis_check_epsilon = determine_parameters(tree)
        print(trace, policy)
        param_names = [
            'window_size', 'subwindows', 'subwindow_size', 'segments',
            'cached_segments', 'lru_portion'
        ]
        params = [
            window_size, subwindows, subwindow_size, segments, cached_segments,
            lru_portion
        ]
        if policy in ['ARC', 'DSCA', 'DSCASW', 'ADSCASTK', 'ADSCAATK']:
            lru_sizes = {}
            lfu_sizes = {}
            node_name = -1
            for k in tree[1]:
                if k[0][0] == 'CACHE_LEVEL_PROPORTIONS':
                    node_name = k[0][1].split(':')[0]
                    if 'LRU' in k[0][1]:
                        lru_sizes = k[1]
                    elif 'LFU' in k[0][1]:
                        lfu_sizes = k[1]

            if node_name != -1 and lru_sizes != [] and lfu_sizes != []:

                filename = trace[10:-6] + '/' + policy + '_cache_size=' + str(
                    cache_size)
                title = 'Cache Level Proportions for %s with cache size=%i' % (
                    policy, cache_size)
                # use only policy-relevant parameters in the filename
                used_parameters = policy_parameter_usage(policy)
                for index, param in enumerate(params):
                    if used_parameters[param_names[index]]:
                        filename += '_%s=%s' % (param_names[index], str(param))
                        pretty_param_name = param_names[index].replace(
                            '_', ' ')
                        title += ', %s=%s' % (pretty_param_name, str(param))

                # include node name in filename if the method is used in a multi-cache scenario
                filename += '_' + node_name.replace(' ', '') + '.pdf'

                path = os.path.join(plotdir, filename)

                # ensure the path exists and create it if necessary
                directories = path.split('/')[1:-1]
                current_path = plotdir
                for directory in directories:
                    current_path += '/' + directory
                    if not os.path.isdir(current_path):
                        os.makedirs(current_path)

                pdf = PdfPages(path)
                fig = plt.figure()
                [lru_indices, lru_sizes] = [list(t) for t in zip(*lru_sizes)]
                [lfu_indices, lfu_sizes] = [list(t) for t in zip(*lfu_sizes)]
                p1 = plt.plot(lru_indices,
                              lru_sizes,
                              '-',
                              linewidth=2,
                              color='r')
                p2 = plt.plot(lfu_indices,
                              lfu_sizes,
                              '-',
                              linewidth=2,
                              color='b')
                plt.legend((p1[0], p2[0]), ('LRU', 'LFU'))
                plt.xlabel('incoming elements')
                plt.ylabel('cache size')
                plt.title("\n".join(wrap(title, 60)))

                pdf.savefig(fig)
                pdf.close()
                plt.close()
Example #6
0
def draw_cache_level_proportions(plotdir, filename, format):
    from output_results import determine_parameters

    result = read_results('%s%s' % (filename, format), format)
    for tree in result:
        trace, policy, cache_size, window_size, segments, cached_segments, subwindows, subwindow_size, lru_portion, \
           hypothesis_check_period, hypothesis_check_A, hypothesis_check_epsilon = determine_parameters(tree)
        print trace, policy
        param_names = ['window_size', 'subwindows', 'subwindow_size', 'segments', 'cached_segments', 'lru_portion']
        params = [window_size, subwindows, subwindow_size, segments, cached_segments, lru_portion]
        if policy in ['ARC', 'DSCA', 'DSCASW', 'ADSCASTK', 'ADSCAATK']:
            lru_sizes = {}
            lfu_sizes = {}
            node_name = -1
            for k in tree[1]:
                if k[0][0] == 'CACHE_LEVEL_PROPORTIONS':
                    node_name = k[0][1].split(':')[0]
                    if 'LRU' in k[0][1]:
                        lru_sizes = k[1]
                    elif 'LFU' in k[0][1]:
                        lfu_sizes = k[1]

            if node_name != -1 and lru_sizes != [] and lfu_sizes != []:

                filename = trace[10:-6] + '/' + policy + '_cache_size=' + str(cache_size)
                title = 'Cache Level Proportions for %s with cache size=%i' % (policy, cache_size)
                # use only policy-relevant parameters in the filename
                used_parameters = policy_parameter_usage(policy)
                for index, param in enumerate(params):
                    if used_parameters[param_names[index]]:
                        filename += '_%s=%s' % (param_names[index], str(param))
                        pretty_param_name = param_names[index].replace('_', ' ')
                        title += ', %s=%s' % (pretty_param_name, str(param))

                # include node name in filename if the method is used in a multi-cache scenario
                filename += '_' + node_name.replace(' ', '') + '.pdf'

                path = os.path.join(plotdir, filename)

                # ensure the path exists and create it if necessary
                directories = path.split('/')[1:-1]
                current_path = plotdir
                for directory in directories:
                    current_path += '/' + directory
                    if not os.path.isdir(current_path):
                        os.makedirs(current_path)

                pdf=PdfPages(path)
                fig = plt.figure()
                [lru_indices, lru_sizes] = [list(t) for t in zip(*lru_sizes)]
                [lfu_indices, lfu_sizes] = [list(t) for t in zip(*lfu_sizes)]
                p1 = plt.plot(lru_indices, lru_sizes, '-', linewidth=2, color='r')
                p2 = plt.plot(lfu_indices, lfu_sizes, '-', linewidth=2, color='b')
                plt.legend((p1[0], p2[0]), ('LRU', 'LFU'))
                plt.xlabel('incoming elements')
                plt.ylabel('cache size')
                plt.title("\n".join(wrap(title, 60)))

                pdf.savefig(fig)
                pdf.close()
                plt.close()