<jupyter_start><jupyter_text>Results Analysis for Benchmark Script<jupyter_code>%matplotlib inline 
import os 
import re
import csv 
import glob

import numpy as np
import pandas as pd
import seaborn as sns 
import matplotlib.pyplot as plt 

from datetime import datetime 
from collections import defaultdict
sns.set_style('whitegrid')
sns.set_context('notebook')
sns.set_palette('muted')
DTFMT = "%Y%m%d%H%M"
FIXTURES = os.path.join(os.getcwd(), "..", "fixtures")

def get_latest_results(path=FIXTURES):
    results = None 
    latest  = None
    
    for name in glob.glob(os.path.join(path, "results-*.csv")):
        base = os.path.basename(name)
        fname, ext = os.path.splitext(base)
        rdate = datetime.strptime(fname.split("-")[1], DTFMT)
    
        if latest is None or rdate > latest:
            latest  = rdate 
            results = name 
    
    if results is None:
        raise ValueError("could not find results file")
    
    return pd.read_csv(name), latest 
        
        
results, rdate = get_latest_results()    
results.head()
results.rename(columns={'test path': 'file system'}, inplace=True)
sns.barplot(x='test name', y='clone time', hue='file system', data=results)
plt.xlabel('workload')
plt.ylabel('clone time (seconds)')
plt.title('Git Clone Latency for {} Results'.format(rdate.strftime('%b %d, %Y')))
plt.savefig('{}-clone-time.png'.format(rdate.strftime('%Y-%m-%d')))
sns.barplot(x='test name', y='build time', hue='file system', data=results)
plt.xlabel('workload')
plt.ylabel('build time (seconds)')
plt.title('Compile (Build) Latency for {} Results'.format(rdate.strftime('%b %d, %Y')))
plt.savefig('{}-build-time.png'.format(rdate.strftime('%Y-%m-%d')))
MPROF_FIXTURES = os.path.join(FIXTURES, "mprof")

cmdre = re.compile(r"^CMDLINE\s+(.+)$")
memre = re.compile(r"^MEM\s+([\d\.e]+)\s+([\d\.e]+)$")


def get_mprofile_results(path=MPROF_FIXTURES):
    series = defaultdict(list)
    
    for name in glob.glob(os.path.join(path, 'mprofile_*.dat')):
        base = os.path.basename(name)
        fname, ext = os.path.splitext(base) 
        test = fname.split('_')[1]
        
        with open(name, 'r') as f:
            for line in f:
                match = memre.match(line)
                if match:
                    series[test].append(tuple(map(float, match.groups())))
        
        stime = series[test][0][1]
        for idx in range(len(series[test])):
            series[test][idx] = (series[test][idx][0], series[test][idx][1] - stime)
        
    return series 
        

def get_mprofile_baseline(path=MPROF_FIXTURES):
    base = {}
    with open(os.path.join(path, 'baseline.csv')) as f:
        reader = csv.DictReader(f) 
        for row in reader:
            base[row['test name']] = float(row['build bytes']) / 1048576.0 
    
    return base 
        
        
mprof = get_mprofile_results()
baseline = get_mprofile_baseline()
baseline
fig = plt.figure(figsize=(14,6))
axe = fig.add_axes([0.1, 0.1, 0.6, 0.75])
axe.set_xlabel("percent complete")
axe.set_ylabel("memory used (in MiB)")
axe.set_title("MemFS Memory Usage During Clone and Build")

colors = {
    'python': "#34495e",
    'apache': "#2ecc71",
    'ruby': "#e74c3c", 
    'redis': "#9b59b6", 
    'nginx': "#3498db", 
    'postgres': "#f4d03f", 
}

for name, data in mprof.items():
    ts = np.asarray([item[1] for item in data])
    ts = ts / ts.max() * 100.0
    mem = np.asarray([item[0] for item in data])
    plt.plot(ts, mem, "+-", c=colors[name], label=name)

for name, maxval in baseline.items():
    plt.plot([0, 100], [maxval, maxval], "--", c=colors[name])

legend = axe.legend(loc='center left', bbox_to_anchor=(1, 0.5))
legend.get_frame().set_alpha(0.5)

plt.savefig('{}-mprof-memfs.png'.format(rdate.strftime('%Y-%m-%d')))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1721332983468906, 'fraction_numerical': 0.016531094200997114, 'mean_word_length': 3.2639821029082774, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '648608', 'license': 'MIT', 'n_tokens_mistral': 1469, 'n_tokens_neox': 1386, 'n_words': 287, 'path': 'notebooks/results-analysis.ipynb', 'repo_name': 'bbengfort/compile-workload', 'size': '3811'}