def profile_cpu_check_connectivity_ratio(datasets=None,
                                         queries=None,
                                         methods=None,
                                         feature=None,
                                         input_dir='reuse'):
    for dataset in datasets:
        for method in methods:
            print 'dataset=%s,method=%d, intersect_time/(intersect_time+condition_time)' % (
                dataset, method)
            for query in queries:
                filename = input_dir + '/' + dataset + '_a' + \
                    str(method) + '_q' + str(query) + '_' + feature + '.txt'
                t = extract_keywords_count(
                    filename, 'check_connectivity/check_constraints')
                print t
            print 'dataset=%s, intersect_time/elapsed_time' % dataset
            for query in queries:
                filename = input_dir + '/' + dataset + '_a' + \
                    str(method) + '_q' + str(query) + '_' + feature + '.txt'
                connectivity_time = extract_keywords_time(
                    filename, 'intersect_time')
                elapsed_time = extract_keywords_time(filename, 'elapsed_time')
                ratio = float(connectivity_time) / float(elapsed_time)
                # print connectivity_time + ',' + elapsed_time + ',' + str(ratio)
                print ratio
def profile_gpu_reuse(datasets=None,
                      queries=None,
                      methods=None,
                      feature=None,
                      input_dir='reuse'):
    time_keywords = [
        'process_level_time', 'check_order_non_equality_time',
        'check_connectivity_time', 'organize_batch_time',
        'reuse_overhead_time', 'predicate_time', 'intersect_time',
        'compact_time', 'iterate_gather_time', 'load_balance_search_time',
        'memory_operations_time'
    ]

    for dataset in datasets:
        for method in methods:
            print "dataset=%s,method=%d, in ms" % (dataset, method)
            for query in queries:
                filename = input_dir + '/' + dataset + '_a' + \
                    str(method) + '_q' + str(query) + '_' + feature + '.txt'
                time_collection = []
                for keyword in time_keywords:
                    t = extract_keywords_time(filename, keyword)
                    time_collection.append(t)
                ss = ''
                for i in range(len(time_collection)):
                    if i > 0:
                        ss += ','
                    ss += time_collection[i]
                print ss
def profile_gpu_set_intersect_time_ratio(datasets=None,
                                         queries=None,
                                         methods=None,
                                         feature=None,
                                         input_dir='reuse'):
    for dataset in datasets:
        for method in methods:
            print "dataset=%s,method=%d, in ms" % (dataset, method)
            for query in queries:
                filename = input_dir + '/' + dataset + '_a' + \
                    str(method) + '_q' + str(query) + '_' + feature + '.txt'
                set_intersect_time = extract_keywords_time(
                    filename, "check_constraints_time")
                total_time = extract_keywords_time(filename, "elapsed_time")
                ratio = float(set_intersect_time) / float(total_time)
                # print "%s,%s" % (set_intersect_time, total_time)
                # print set_intersect_time
                print total_time
def profile_gpu_memory_operation_overheads(datasets=None,
                                           queries=None,
                                           methods=None,
                                           feature=None,
                                           input_dir='reuse'):
    for dataset in datasets:
        for method in methods:
            print 'dataset=%s,method=%d, memory_operations_time' % (dataset,
                                                                    method)
            for query in queries:
                filename = input_dir + '/' + dataset + '_a' + \
                    str(method) + '_q' + str(query) + '_' + feature + '.txt'
                t = extract_keywords_time(filename, 'memory_operations_time')
                print t
            print 'dataset=%s, elapsed_time' % dataset
            for query in queries:
                filename = input_dir + '/' + dataset + '_a' + \
                    str(method) + '_q' + str(query) + '_' + feature + '.txt'
                t = extract_keywords_time(filename, 'elapsed_time')
                print t
def exp_effect_reuse(datasets=None,
                     queries=None,
                     methods=None,
                     feature=None,
                     input_dir='reuse'):
    for dataset in datasets:
        for method in methods:
            print 'dataset=%s,method=%d' % (dataset, method)
            for query in queries:
                filename = input_dir + '/' + dataset + \
                    '_a' + str(method) + "_q" + str(query)
                if len(feature) > 0:
                    filename += '_' + feature
                filename += '.txt'

                t = extract_keywords_time(filename, 'elapsed_time')
                num = float(t) / 1000.0
                # return the time in second
                print num
def profile_gpu_check_connectivity_ratio(datasets=None,
                                         queries=None,
                                         methods=None,
                                         feature=None,
                                         input_dir='reuse'):
    for dataset in datasets:
        for method in methods:
            print 'dataset=%s,method=%d, intersect_time/(predicate_time+condition_time)' % (
                dataset, method)
            for query in queries:
                filename = input_dir + '/' + dataset + '_a' + \
                    str(method) + '_q' + str(query) + '_' + feature + '.txt'
                intersect_time = extract_keywords_time(filename,
                                                       'intersect_time')
                predicate_time = extract_keywords_time(filename,
                                                       'predicate_time')
                condition_time = extract_keywords_time(filename,
                                                       'condition_time')
                ratio = float(intersect_time) / \
                    (float(predicate_time) + float(condition_time))
                print ratio

            print 'dataset=%s,predicate_time/(predicate_time+condition_time)' % dataset
            for query in queries:
                filename = input_dir + '/' + dataset + '_a' + \
                    str(method) + '_q' + str(query) + '_' + feature + '.txt'
                predicate_time = extract_keywords_time(filename,
                                                       'predicate_time')
                condition_time = extract_keywords_time(filename,
                                                       'condition_time')
                ratio = float(predicate_time) / \
                    (float(predicate_time) + float(condition_time))
                print ratio

            print 'dataset=%s,intersect_time/elapsed_time' % dataset
            for query in queries:
                filename = input_dir + '/' + dataset + '_a' + \
                    str(method) + '_q' + str(query) + '_' + feature + '.txt'
                intersect_time = extract_keywords_time(filename,
                                                       'intersect_time')
                elapsed_time = extract_keywords_time(filename, 'elapsed_time')
                ratio = float(intersect_time) / float(elapsed_time)
                print ratio
def profile_phases(datasets=None,
                   queries=None,
                   methods=None,
                   feature=None,
                   keywords=None,
                   input_dir='reuse'):
    print keywords

    for dataset in datasets:
        for method in methods:
            print "dataset=%s,method=%d" % (dataset, method)
            for query in queries:
                filename = input_dir + '/' + dataset + '_a' + \
                    str(method) + "_q" + str(query) + "_" + feature + ".txt"
                times = []
                for keyword in keywords:
                    t = extract_keywords_time(filename, keyword)
                    times.append(t)
                ss = ''
                for i in range(len(times)):
                    if i > 0:
                        ss += ' '
                    ss += times[i]
                print ss