<jupyter_start><jupyter_text>Prepare data<jupyter_code>task_files = glob("task*.csv")
def format_data(data):
    result = []
    for i in data:
        r = [k.strip(",") for k in i.strip("\n").strip(" ").strip(",").split(":")]
        r[1] = float(r[1])
        result.append(r)
    return result
def prepare_data(task_files):
    tasks = {t: open(t) for t in task_files}
    raw_data = {t: v.readlines() for t, v in tasks.items()}
    data_dict = [{
        "file_name": n,
        "test_name": i[1].strip("\n").strip(".").strip("Test Name:,"),
        "data": format_data(i[2:])
    } for n, i in raw_data.items()]
    data_dict = sorted(data_dict, key=lambda x: x["file_name"])
    print("Test types:\n", set([i['test_name'] for i in data_dict]))
    print("")
    print("File Names:\n", list([i['file_name'] for i in data_dict]))
    return data_dict
data_dict = prepare_data(task_files)
cols = [i[0] for i in data_dict[0]["data"]]
heat_map_data = [[j[1] for j in i["data"]] for i in data_dict]
relative_boost = [[v / heat_map_data[1][j] for j, v in enumerate(u)] for i, u in enumerate(heat_map_data)]
test_names = [i["test_name"] for i in data_dict]
file_name = [i["file_name"] for i in data_dict]
df = pd.DataFrame(heat_map_data, columns=cols)
df["test_names"] = test_names
df["file_name"] = file_name
df
absolute_df = df
df = pd.DataFrame(relative_boost, columns=cols)
df["test_names"] = test_names
df["file_name"] = file_name
df
relative_df = df
absolute_df.head(3)
absolute_df.to_csv("result-absolute.csv")
relative_df.to_csv("result-relative.csv")
intask_df = [absolute_df[absolute_df["file_name"].str.contains(f"task{i}-")] for i in range(1,5)]
crosstask_df = [absolute_df[absolute_df["file_name"].str.contains(f"-{i}.csv")] for i in range(1,5)]
a = crosstask_df[0]
b = [a[i] for i in a.columns]
x = [1,2,3,4]
a
len(b)
import re
# name = iterate_set[4].name.replace("average", "-average").replace("kbest", "-kbest")
# name.find(" -")
# re.sub("[ ]*[-](average)$", "-average", name)
# re.sub("[ ]*[-](kbest)$", "-kbest", name)
# for i, k in enumerate(iterate_set):
#     name = k.name
#     name = re.sub("[ ]*(average)$", " (average)", name)
#     name = re.sub("[ ]*(kbest)$", " (kbest)", name)
#     print(name)<jupyter_output><empty_output><jupyter_text>Produce bar plots<jupyter_code># # import math
# # iterate_set = b[:12]
# # iterate_len = len(iterate_set)
# # FIG_ROW = 3
# # FIG_COL = int(math.ceil(iterate_len/FIG_ROW))
# # for i, k in enumerate(iterate_set):
# #     ax = plt.subplot(FIG_ROW, FIG_COL, i+1)
# #     p = ax.bar(x, k)
# # #     ax.xaxis.set_label_text(k.name)
# #     ax.set_title(k.name.replace(" ", "-", 1).replace(" ", ""))

# dpi = 80
# import matplotlib as mpl
# mpl.rcParams['figure.dpi']= dpi

# import matplotlib as mpl
# mpl.rc("savefig", dpi=dpi)

# iterate_set = b
# xtick_index = [1, 2, 3, 4]
# xtick_labels = ["4.15","4.12","4.12-patch","4.12-config"]

# iterate_set = iterate_set
# for i, k in enumerate(iterate_set):
#     name = k.name
#     name = re.sub("[ ]*(average)$", " (average)", name)
#     name = re.sub("[ ]*(kbest)$", " (kbest)", name)
#     name = name.replace(" ", "-")
#     title_name = name.replace("-(average)", "").replace("-(kbest)", "")
    
#     fig = plt.figure();
#     plt.bar(x, k);
#     plt.title(title_name, fontsize=30);
#     plt.ylabel(
#         "test latency (seconds)", fontsize=15)
#     plt.xticks(
#         [1,2,3,4], xtick_labels,
#     )
#     plt.ticklabel_format(axis="y", style="sci", scilimits=(0,0))
#     fig.savefig(f"{i}-{name}.png");
#     plt.close(fig)
def get_numeric_cols(a):
    return a[[i for i in list(a.columns) if i not in ["test_names", "file_name"]]]
def get_normalized(a, normalized_idx=0):
    b = get_numeric_cols(a)
    p = b[normalized_idx:normalized_idx+1].sum()
    c = b.subtract(p).div(p).mul(100).round()
    return c
correct_column_order = [
'context siwtch          kbest',
'context siwtch        average',

'small read          kbest',
'small read        average',
'mid read          kbest',
'mid read        average',
'big read          kbest',
'big read        average',
'huge read          kbest',
'huge read        average',


'small write          kbest',
'small write        average',
'mid write          kbest',
'mid write        average',
'big write          kbest',
'big write        average',
'huge write          kbest',
'huge write        average',


'small mmap          kbest',
'small mmap        average',
'mid mmap          kbest',
'mid mmap        average',
'big mmap          kbest',
'big mmap        average',
'huge mmap          kbest',
'huge mmap        average',


'small munmap          kbest',
'small munmap        average',
'mid munmap          kbest',
'mid munmap        average',
'big munmap          kbest',
'big munmap        average',
'huge munmap          kbest',
'huge munmap        average',


'fork          kbest',
'fork       average',
'fork    Child kbest',
'fork Child average',
'big fork          kbest',
'big fork       average',
'big fork    Child kbest',
'big fork Child average',
'huge fork          kbest',
'huge fork       average',
'huge fork    Child kbest',
'huge fork Child average',

'thr create          kbest',
'thr create       average',
'thr create    Child kbest',
'thr create Child average',

'send          kbest',
'send        average',
'recv          kbest',
'recv        average',
'big send          kbest',
'big send        average',
'big recv          kbest',
'big recv        average',




'select          kbest',
'select        average',
'poll          kbest',
'poll        average',
'epoll          kbest',
'epoll        average',

'select big          kbest',
'select big        average',
'poll big          kbest',
'poll big        average',
'epoll big          kbest',
'epoll big        average',

'small page fault          kbest',
'small page fault        average',
'mid page fault          kbest',
'mid page fault        average',
'big page fault          kbest',
'big page fault        average',
'huge page fault          kbest',
'huge page fault        average',

'ref          kbest',
'ref        average',
'cpu          kbest',
'cpu        average',
'getpid          kbest',
'getpid        average',
]
a = crosstask_df[0]
b = crosstask_df[1:]
a.T.head()
normalized = get_normalized(crosstask_df[0], normalized_idx=1)
normalized = normalized[correct_column_order]
normalized.T.head()
normalized_avg = normalized[
    [i for i in normalized.columns if i.find("average") >= 0]
]
dpi = 100
import matplotlib as mpl
mpl.rcParams['figure.dpi']= dpi

import matplotlib as mpl
mpl.rc("savefig", dpi=dpi)
plt.matshow(
    normalized_avg.T, 
    interpolation='nearest',
    vmax=20, vmin=-100
)

xlabels = [str(i) for i in [
    "task1-4.15.0",
    "task2-4.12.0",
    "task3-4.12.0-patch",
    "task4-4.12.0-config"
]]

ylabels = [i.split("average")[0].strip(" ") for i in normalized_avg.columns]

plt.xticks(np.arange(len(xlabels)), xlabels, rotation='vertical')
plt.yticks(np.arange(len(ylabels)), ylabels)

plt.colorbar()

for (i, j), z in np.ndenumerate(normalized_avg.T):
    plt.text(
        j, i, '{:0.0f}'.format(z), ha='center', va='center', 
#              color='w'
            )
normalized_kbest = normalized[
    [i for i in normalized.columns if i.find("kbest") >= 0]
]
plt.matshow(
    normalized_avg.T, 
    interpolation='nearest',
    vmax=20, vmin=-100
)

xlabels = [str(i) for i in [
    "task1-4.15.0",
    "task2-4.12.0",
    "task3-4.12.0-patch",
    "task4-4.12.0-config"
]]

ylabels = [i.split("kbest")[0].strip(" ") for i in normalized_kbest.columns]

plt.xticks(np.arange(len(xlabels)), xlabels, rotation='vertical')
plt.yticks(np.arange(len(ylabels)), ylabels)

plt.colorbar()

for (i, j), z in np.ndenumerate(normalized_kbest.T):
    plt.text(
        j, i, '{:0.0f}'.format(z), ha='center', va='center', 
#              color='w'
            )<jupyter_output><empty_output><jupyter_text>Produce the OS performance<jupyter_code>a
def get_min_cmp(a):
    b = get_numeric_cols(a)
    p = b.min()
    c = b.subtract(p).div(p).mul(100).round()
    return c
dpi = 200
import matplotlib as mpl
mpl.rcParams['figure.dpi']= dpi

import matplotlib as mpl
mpl.rc("savefig", dpi=dpi)<jupyter_output><empty_output><jupyter_text>Average<jupyter_code>s = get_min_cmp(a)
s = s[[
    i for i in s.columns if i.find("average") > 0
]]
t = s.T
titles = [str(i) for i in [
    "4.15",
    "4.12",
    "4.12-patch",
    "4.12-config"
]]
xlabels = [i.split("average")[0].strip(" ") for i in s.columns]

for i, col in enumerate(t):
    fig = plt.figure(figsize=(6,10));
    plt.bar(xlabels, t[col])
    plt.ylim(0,200)
    plt.xticks(range(len(s.columns)), xlabels, rotation='vertical')
    plt.ylabel("Average slowdown compared to fastests (%)")
    title = "Relative Slowdown: " + titles[i]
    plt.title(title, fontsize=20)
    plt.savefig("")
    fig.savefig(f"slowdown-{i}-{titles[i]}.png");
    plt.close(fig)
#     break<jupyter_output><empty_output><jupyter_text>kbest<jupyter_code>s = get_min_cmp(a)
s = s[[
    i for i in s.columns if i.find("kbest") > 0
]]

titles = [str(i) for i in [
    "4.15.0",
    "4.12.0",
    "4.12.0-patch",
    "4.12.0-config"
]]

t = s.T
xlabels = [i.split("kbest")[0].strip(" ") for i in s.columns]

for i, col in enumerate(t):
    plt.bar(xlabels, t[col])
    plt.xticks(range(len(s.columns)), xlabels, rotation='vertical')
    plt.ylabel("K-best slowdown compared to fastests (%)")
    break<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1753644622860765, 'fraction_numerical': 0.01785336995563068, 'mean_word_length': 3.014843087362171, 'pattern_counts': {'":': 4, '<': 21, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '185415', 'license': 'Apache-2.0', 'n_tokens_mistral': 3694, 'n_tokens_neox': 3582, 'n_words': 815, 'path': 'outputs/Untitled.ipynb', 'repo_name': 'GindaChen/LEBench', 'size': '9466'}