-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollect.py
74 lines (62 loc) · 2.22 KB
/
collect.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import csv, subprocess, logging, itertools, re, os
from io import TextIOWrapper
from enum import Enum, IntEnum
from typing import Any, Dict, List, Tuple, Union
from collections import namedtuple, ChainMap
SIFT_TRACES_DIRECTORY = "sift-traces"
SIFT_FILE_EXTENSION = ".sift"
def getTraceNames() -> List[str]:
return list(map(lambda file: f"{SIFT_TRACES_DIRECTORY}/{file.strip(SIFT_FILE_EXTENSION)}", os.listdir(SIFT_TRACES_DIRECTORY)))
TRACES = getTraceNames()
def executeProcess(command: Union[List[str], str]) -> subprocess.CompletedProcess:
return subprocess.run(
command.split(" ") if type(command) == str else command,
capture_output=True,
text=True
)
def runTrace(predictor: str, trace: str):
command = [
"./run-sniper",
"-c", "gainestown",
"-c", "rob",
"-c", predictor,
"-d", "result_directory",
f"--traces={trace}"
]
result = executeProcess(command)
if (result.returncode != 0):
raise RuntimeError(f"Trace failed to execute: {result.stderr}")
BRANCH_PREDICTOR_HIT_COUNT_REGEX = re.compile("branch_predictor\.num\-correct\s=\s[0-9]+")
BRANCH_PREDICTOR_MISS_COUNT_REGEX = re.compile("branch_predictor\.num\-incorrect\s=\s[0-9]+")
def filterBranchResults(stdout: str) -> Tuple[str, str]:
hits = BRANCH_PREDICTOR_HIT_COUNT_REGEX.findall(stdout)[0]
misses = BRANCH_PREDICTOR_MISS_COUNT_REGEX.findall(stdout)[0]
return hits, misses
def getResults() -> str:
command = [
"./tools/dumpstats.py",
"-d", "~/comp3710-uarch-assignment-2/result_directory"
]
result = executeProcess(command)
if (result.returncode != 0):
raise RuntimeError(f"Unable to retrieve stats for trace results: {result.stderr}")
return filterBranchResults(result.stdout)
PREDICTORS = [
"one_bit",
"pentium_m",
"gshare",
# "bi_mode",
# "perceptron"
]print(TRACES)
def main():
results = {}
for predictor in PREDICTORS:
for trace in TRACES:
runTrace(predictor, trace)
result = getResults()
if (predictor not in results):
results[predictor] = {}
results[predictor][trace] = result
print(results)
if __name__ == "__main__":
main()