Exemplo n.º 1
0
def print_results(raw_information, configuration, date, cfg, verbose=True):
    working_methods = METHODS[:]

    all_data = {
        # method : {
        #      protocol : {
        #          max:  (x,y),
        #          min:  (x,y),
        #          mean: (x,y)
        #      },
        # }
    }

    LINES = ('std', 'max', 'min', 'avg')

    protocols = set()

    for method in METHODS:
        method_data = {}
        all_data[method] = method_data

        for line in LINES:

            def func_on_results(results):
                return getattr(results, line + '_call_times')[method]

            data = {}
            data['protocols'] = raw_information.keys()
            for protocol in data['protocols']:
                try:
                    x, y = raw_information[protocol]
                    y = map(func_on_results, y)
                except KeyError:
                    continue
                except:
                    import traceback
                    traceback.print_exc()
                    continue
                else:
                    protocols.add(protocol)
                    if not protocol in method_data:
                        method_data[protocol] = {}
                    protocol_data = method_data[protocol]
                    protocol_data[line] = x, y

    for method in METHODS:
        if len(all_data[method]) == 0:
            working_methods.remove(method)

    # START PRINTING THIS PART

    CODE = """#!/usr/bin/env python
import os
import math
import matplotlib
if %(backend)r != '':
    matplotlib.use(%(backend)r)
import matplotlib.pyplot as plt

%(get_figure_filename)s

def print_figures():
    
    date            = %(date)r
    working_methods = %(working_methods)r
    all_data        = %(all_data)s

    sorter = lambda (x1, y1), (x2, y2): cmp(x1, x2)

    for method in working_methods:
        method_data = all_data[method]

        max_ys = []
        for protocol in method_data:
            protocol_data = method_data[protocol]
            _,  max_y  = zip(*sorted(zip(*protocol_data['max']), sorter))
            max_ys.append(max(max_y))

        ylim = (0, math.ceil(max(max_ys) + 0.1))

        for protocol in method_data:
            for with_bounds in True, False:
                protocol_data = method_data[protocol]
                fig = plt.figure()
                ax = fig.add_subplot(111)
                ax.set_xlabel("Users")
                ax.set_ylabel("Time (sec)")


                max_x,  max_y  = zip(*sorted(zip(*protocol_data['max']), sorter))
                mean_x, mean_y = zip(*sorted(zip(*protocol_data['avg']), sorter))
                std_x,  std_y  = zip(*sorted(zip(*protocol_data['std']), sorter))
                min_x,  min_y  = zip(*sorted(zip(*protocol_data['min']), sorter))

                ax.plot(max_x, max_y, 'r-')
                ax.errorbar(mean_x, mean_y, yerr=std_y, fmt='g-')
                ax.plot(min_x, min_y, 'b-')

                fname = get_figure_filename(protocol, method, date)
                if with_bounds:
                    ax.set_ybound(*ylim)
                else:
                    current_bounds = list(ax.get_ybound())
                    current_bounds[0] = 0
                    ax.set_ybound(*current_bounds)
                    fname = os.path.dirname(fname) + os.sep + "without_bounds_" + os.path.basename(fname)

                plt.savefig(fname)

if __name__ == '__main__':
    print_figures()
    """ % {
        'backend': cfg.MATPLOTLIB_BACKEND,
        'get_figure_filename': GET_FIGURE_FILENAME_CODE,
        'working_methods': working_methods,
        'all_data': json.dumps(all_data, indent=4),
        'date': date
    }

    generate_figures_script = "figures%sgenerate_figures_%s.py" % (os.sep,
                                                                   date)
    open(generate_figures_script, 'w').write(CODE)

    print("Executing %s..." % generate_figures_script, )
    os.system("%s %s" % (sys.executable, generate_figures_script))
    print("[done]")

    html = generate_html(protocols, configuration, working_methods, date,
                         cfg.SYSTEM, cfg.RUNNING_CONFIGURATION)
    html_filename = 'botclient_%s.html' % date
    open(html_filename, 'w').write(html)

    # END PRINTING THIS PART

    if verbose:
        print("HTML file available in", html_filename)
        print("Finished plotting; %s" % show_time())
        flush()
Exemplo n.º 2
0
def get_raw_information(date, verbose = True):
    file_name = FILE_NAME_TEMPLATE % (date, '%s')
    raw_information_filename = 'raw_information_%s.dump' % date
    if os.path.exists(raw_information_filename):
        if verbose:
            print "Retrieving cache", show_time()
            flush()
        raw_information = pickle.load(open(raw_information_filename))
        if verbose:
            print "Retrieved cached raw_information", show_time()
            flush()
        return raw_information

    if verbose:
        print "Generating new raw_information", show_time()
        flush()
    # else generate this information file
    def calculate_positions(initial):
        data = {}
        for r in RANGES:
            for i in r():
                data[i] = str(initial).zfill(FILL_NUMBER)
                initial += 1
        return data, initial

    def calculate_protocols():
        # returns 
        # { "JSON" : { 1 : "01", 2 : "02", 5 : "03" ... } ...}
        # being each "01", "02" the name of the file for 
        # that protocol and for that number of users
        protocols = {
                "JSON"   : {},
            }

        protocols = {}
        data, initial = calculate_positions(0)
        protocols["JSON"] = data
        return protocols

    protocols = calculate_protocols()

    def get_results(protocol, number):
        # 
        # Given a protocol and a number of users (1,2,3,4,5,10,15...),
        # it returns the results stored in that scenario
        #
        found_resources = sorted(glob.glob(file_name % "*"), lambda x,y: len(x) - len(y))
        if len(found_resources) == 0:
            raise Exception("No similar file found: %s" % file_name)

        regular_length = len(found_resources[len(found_resources)/2]) # Take the one in the middle
        number_length  = regular_length - len(file_name % '')

        filename = file_name % str(int(protocols[protocol][number])).zfill(number_length)
        results = pickle.load(open(filename))
        return results

    def generate_data(protocol):
        # Given a protocol, it returns the following tuple
        # 
        # x = [1,2,3,4,5,10,15,20,25]
        # y = [results_of_1, results_of_2 ...]
        # 
        x = []
        y = []
        for r in RANGES:
            for n in r():
                x.append(n)
                results = get_results(protocol, n)
                y.append(results)
        return x,y

    raw_information = {}
    for protocol in protocols.keys():
        x, y = generate_data(protocol)
        raw_information[protocol] = (x,y)

    # raw_information stores:
    # { "JSON" : ([1,2,3,4,5,10...], [results_of_1, results_of_2, results_of_3 ...]) }

    # Save as a cache
    pickle.dump(raw_information, open(raw_information_filename,'w'))

    if verbose:
        print "Raw_information generated", show_time()
        flush()

    return raw_information
Exemplo n.º 3
0
def print_results(raw_information, configuration, date, cfg, verbose = True):
    working_methods = METHODS[:]

    all_data = {
        # method : {
        #      protocol : {
        #          max:  (x,y),
        #          min:  (x,y),
        #          mean: (x,y)
        #      },
        # }
    }

    LINES = ('std','max','min','avg')

    protocols = set()

    for method in METHODS:
        method_data = {}
        all_data[method] = method_data

        for line in LINES:
            def func_on_results(results):
                return getattr(results, line + '_call_times')[method]

            data = {}
            data['protocols'] = raw_information.keys()
            for protocol in data['protocols']:
                try:
                    x, y = raw_information[protocol]
                    y = map(func_on_results, y)
                except KeyError:
                    continue
                except: 
                    import traceback
                    traceback.print_exc()
                    continue
                else:
                    protocols.add(protocol)
                    if not protocol in method_data:
                        method_data[protocol] = {}
                    protocol_data = method_data[protocol]
                    protocol_data[line] = x,y

    for method in METHODS:
        if len(all_data[method]) == 0:
            working_methods.remove(method)
    
    # START PRINTING THIS PART

    CODE="""#!/usr/bin/env python
import os
import math
import matplotlib
if %(backend)r != '':
    matplotlib.use(%(backend)r)
import matplotlib.pyplot as plt

%(get_figure_filename)s

def print_figures():
    
    date            = %(date)r
    working_methods = %(working_methods)r
    all_data        = %(all_data)s

    sorter = lambda (x1, y1), (x2, y2): cmp(x1, x2)

    for method in working_methods:
        method_data = all_data[method]

        max_ys = []
        for protocol in method_data:
            protocol_data = method_data[protocol]
            _,  max_y  = zip(*sorted(zip(*protocol_data['max']), sorter))
            max_ys.append(max(max_y))

        ylim = (0, math.ceil(max(max_ys) + 0.1))

        for protocol in method_data:
            for with_bounds in True, False:
                protocol_data = method_data[protocol]
                fig = plt.figure()
                ax = fig.add_subplot(111)
                ax.set_xlabel("Users")
                ax.set_ylabel("Time (sec)")


                max_x,  max_y  = zip(*sorted(zip(*protocol_data['max']), sorter))
                mean_x, mean_y = zip(*sorted(zip(*protocol_data['avg']), sorter))
                std_x,  std_y  = zip(*sorted(zip(*protocol_data['std']), sorter))
                min_x,  min_y  = zip(*sorted(zip(*protocol_data['min']), sorter))

                ax.plot(max_x, max_y, 'r-')
                ax.errorbar(mean_x, mean_y, yerr=std_y, fmt='g-')
                ax.plot(min_x, min_y, 'b-')

                fname = get_figure_filename(protocol, method, date)
                if with_bounds:
                    ax.set_ybound(*ylim)
                else:
                    current_bounds = list(ax.get_ybound())
                    current_bounds[0] = 0
                    ax.set_ybound(*current_bounds)
                    fname = os.path.dirname(fname) + os.sep + "without_bounds_" + os.path.basename(fname)

                plt.savefig(fname)

if __name__ == '__main__':
    print_figures()
    """ % {
        'backend'             : cfg.MATPLOTLIB_BACKEND,
        'get_figure_filename' : GET_FIGURE_FILENAME_CODE,
        'working_methods'     : working_methods,
        'all_data'            : json.dumps(all_data, indent=4),
        'date'                : date
    }

    generate_figures_script = "figures%sgenerate_figures_%s.py" % (os.sep, date)
    open(generate_figures_script,'w').write(CODE)

    print "Executing %s..." % generate_figures_script,
    os.system("%s %s" % (sys.executable, generate_figures_script))
    print "[done]"


    html = generate_html(protocols, configuration, working_methods, date, cfg.SYSTEM, cfg.RUNNING_CONFIGURATION)
    html_filename = 'botclient_%s.html' % date
    open(html_filename, 'w').write(html)

    # END PRINTING THIS PART

    if verbose:
        print "HTML file available in",html_filename
        print "Finished plotting; %s" % show_time()
        flush()
Exemplo n.º 4
0
def get_raw_information(date, verbose = True):
    file_name = FILE_NAME_TEMPLATE % (date, '%s')
    raw_information_filename = 'raw_information_%s.dump' % date
    if os.path.exists(raw_information_filename):
        if verbose:
            print "Retrieving cache", show_time()
            flush()
        raw_information = pickle.load(open(raw_information_filename))
        if verbose:
            print "Retrieved cached raw_information", show_time()
            flush()
        return raw_information

    if verbose:
        print "Generating new raw_information", show_time()
        flush()
    # else generate this information file
    def calculate_positions(initial):
        data = {}
        for r in RANGES:
            for i in r():
                data[i] = str(initial).zfill(FILL_NUMBER)
                initial += 1
        return data, initial

    def calculate_protocols():
        # returns 
        # { "JSON" : { 1 : "01", 2 : "02", 5 : "03" ... } ...}
        # being each "01", "02" the name of the file for 
        # that protocol and for that number of users
        protocols = {
                "JSON"   : {},
                "SOAP"   : {},
                "XMLRPC" : {}
            }

        protocols = {}
        data, initial = calculate_positions(0)
        protocols["JSON"] = data
        data, initial = calculate_positions(initial)
        protocols["SOAP"] = data
        data, _       = calculate_positions(initial)
        protocols["XMLRPC"] = data
        return protocols

    protocols = calculate_protocols()

    def get_results(protocol, number):
        # 
        # Given a protocol and a number of users (1,2,3,4,5,10,15...),
        # it returns the results stored in that scenario
        #
        found_resources = sorted(glob.glob(file_name % "*"), lambda x,y: len(x) - len(y))
        if len(found_resources) == 0:
            raise Exception("No similar file found: %s" % file_name)

        regular_length = len(found_resources[len(found_resources)/2]) # Take the one in the middle
        number_length  = regular_length - len(file_name % '')

        filename = file_name % str(int(protocols[protocol][number])).zfill(number_length)
        results = pickle.load(open(filename))
        return results

    def generate_data(protocol):
        # Given a protocol, it returns the following tuple
        # 
        # x = [1,2,3,4,5,10,15,20,25]
        # y = [results_of_1, results_of_2 ...]
        # 
        x = []
        y = []
        for r in RANGES:
            for n in r():
                x.append(n)
                results = get_results(protocol, n)
                y.append(results)
        return x,y

    raw_information = {}
    for protocol in protocols.keys():
        x, y = generate_data(protocol)
        raw_information[protocol] = (x,y)

    # raw_information stores:
    # { "JSON" : ([1,2,3,4,5,10...], [results_of_1, results_of_2, results_of_3 ...]) }

    # Save as a cache
    pickle.dump(raw_information, open(raw_information_filename,'w'))

    if verbose:
        print "Raw_information generated", show_time()
        flush()

    return raw_information