Commit ·
10de591
1
Parent(s): f0abe0a
Update multi_threaded_processed.py
Browse files35 unmodified lines36373839394041422 unmodified lines4546474848495050515253545556575859606162631 unmodified line65666764686970714 unmodified lines76777879808182838485868788899 unmodified lines99100101949510210310410510610 unmodified lines1171181191121131201211221231244 unmodified lines1291301311241251321331341351361371301381391401331411421431361441451461471481411491501511526 unmodified lines1591601611541621631641651 unmodified line16716816916217017117216517317417517617717817918018118217417518318418518635 unmodified lines # If it requires authentication if completed.returncode != 0: #print("ERRORC1", completed) return ("", "") return ("", "", completed.returncode, completed.stderr.decode(errors='ignore')) # Optionally do git diff at the same time (Saving code needs to be added) # git_diff = run_in_shell(f"git diff {commit}^ {commit}", cwd=cwd).stdout.decode(errors='ignore') completed = run_in_shell("git checkout FETCH_HEAD -- " + new_file, cwd=cwd)2 unmodified lines # If there's only a new file, but no old file if completed.returncode != 0: #print("ERRORC2", completed) return (new_contents, "") return (new_contents, "", completed.returncode, completed.stderr.decode(errors='ignore')) old_contents = run_in_shell("cat " + old_file, cwd=cwd).stdout.decode(errors='ignore') return (new_contents, old_contents) return (new_contents, old_contents, completed.returncode, completed.stderr.decode(errors='ignore'))
def get_diff(ex): commit_id = ex["commit"] repos = list(set(ex["repos"].split(","))) old_file = ex["old_file"] new_file = ex["new_file"] # Initialize returncode = 0 stderr = "unknown"
for i, repo in enumerate(repos): repo = "https://xxx:xxx@github.com/" + repo + ".git" # Create a random directory to store the repo1 unmodified line # Can take very long when running many processes run_in_shell("mkdir " + random_dir, timeout=300) try: new_contents, old_contents = get_file_contents(commit_id, old_file, new_file, repo, cwd=random_dir) new_contents, old_contents, returncode, stderr = get_file_contents(commit_id, old_file, new_file, repo, cwd=random_dir) except Exception as e: #print("ERROR", commit_id, old_file, new_file, repo, str(random_dir), e) # Break in case of many repos that all lead us nowhere4 unmodified lines run_in_shell("rm -rf " + random_dir) # clean up again ex["new_contents"] = new_contents ex["old_contents"] = old_contents ex["returncode"] = returncode ex["stderr"] = stderr return ex # If no repo worked ex["new_contents"] = "" ex["old_contents"] = "" ex["returncode"] = returncode ex["stderr"] = stderr return ex
def get_diff_multi_threaded_processed(batch):9 unmodified lines
### OPTIONAL FILTERING ### #""" java = tuple([".java"]) javascript = tuple([ java = [".java"] javascript = [ ".js", "._js", ".bones",10 unmodified lines ".ssjs", ".xsjs", ".xsjslib" ]) python = tuple([ ] python = [ ".py", ".bzl", ".gyp",4 unmodified lines ".pyw", ".tac", ".wsgi", ".xpy", ]) ".xpy" ]
import json with open("programming-languages.json", "r") as f: extensions = json.load(f) suffices = tuple([suffix for suffices in extensions.values() for suffix in suffices] ) suffices = tuple([suffix for suffices in extensions.values() for suffix in suffices]) def filter_extension(ex): return ex["new_file"].endswith(suffices)
def filter_extension_python(ex): return ex["new_file"].endswith(python)
def filter_update(ex): return ex["message"] != "Update " + ex["old_file"]
filter_msg = ["initial commit", "please\n", "please", "lalala"]
def filter_misc(ex): return ex["message"] not in filter_msg
6 unmodified lines #ds = ds.filter(filter_extension_python, num_proc=NUM_PROC) #print("After Python filter", len(ds)) ds = ds.filter(filter_misc, num_proc=NUM_PROC) print("After Misc filter", len(ds)) print("After Misc filter", len(ds)) #ds = ds.select(range(DEBUG_SIZE)) START = 0 # Modify for each instance (0 - 7) samples_per_instance = 64 * 64 * 64 * 32 # 8_388_6081 unmodified line select_end = START * samples_per_instance + samples_per_instance ds = ds.select(range(select_start, select_end)) print(f"Going from {select_start} till {select_end}")
#""" ### END FILTERING ###
def run_multi_processing_threading(): ds.map(get_diff_multi_threaded_processed, num_proc=NUM_PROC, batch_size=NUM_THREADS, batched=True).to_json(f"diffs_{select_start}_{select_end}.jsonl", num_proc=NUM_PROC)
# Benchmarking #NUM_TRIALS = 1 #print(f"Timing multithreading + multiprocessing using {NUM_THREADS} threads and {NUM_PROC} processes") #time = timeit.timeit(stmt=run_multi_processing_threading, number=NUM_TRIALS) #print("Time:", time) #with open("mpt.txt", "w") as f: # f.write(str(time)) run_multi_processing_threading() # f.write(str(time))
# Running run_multi_processing_threading()multi_threaded_processed.py+30-19