Repository navigation
Expand file tree
/
Copy pathview.py
More file actions
92 lines (76 loc) · 2.69 KB
/
Copy pathview.py
File metadata and controls
92 lines (76 loc) · 2.69 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
from pathlib import Path
from time import ctime
from core import CONFIG, load
from tui import show_result, show_benchmark, C_CYAN
history = {}
for record in (Path(CONFIG["paths.storage"]) / CONFIG["paths.names.history"]).glob("*.txt"):
timestamp = int(record.stem[:-1])
if timestamp not in history:
history[timestamp] = {}
record_type = record.stem[-1]
if record_type == "0":
history[timestamp]["O0"] = record
if record_type == "1":
history[timestamp]["O1"] = record
if record_type == "2":
history[timestamp]["benchmark"] = record
if record_type == "-":
history[timestamp]["argv"] = record
history_keys = sorted(history.keys(), reverse=True)
def show_hint(page: int = 0):
start = page * 8
end = min(page * 8 + 7, len(history_keys) - 1)
if start >= len(history_keys):
print("--- no more ---")
return
for i in range(start, end + 1):
if "benchmark" in history[history_keys[i]] and "O0" in history[history_keys[i]]:
s = "Benchmark with Self"
elif "benchmark" in history[history_keys[i]] and "O0" not in history[history_keys[i]]:
s = "Benchmark with Clang"
elif "O1" in history[history_keys[i]]:
s = "Optimal enabled"
else:
s = "Optimal disabled"
print(f"{i + 1}: {ctime(history_keys[i])} ({s})")
if "argv" in history[history_keys[i]]:
s = " ".join(load(history[history_keys[i]]["argv"].read_text()))
print(f" - Run Args: `{C_CYAN(s)}`")
def show_record(index: int):
key = history_keys[index - 1]
if "O0" in history[key]:
print("====== Optimal Disabled ======")
show_result(*load(history[key]["O0"].read_text()).values())
if "O1" in history[key]:
print("====== Optimal Enabled ======")
show_result(*load(history[key]["O1"].read_text()).values())
if "benchmark" in history[key]:
print("====== Benchmark ======")
show_benchmark(
load(history[key]["benchmark"].read_text()), "CompilerX-O1",
"CompilerX-O0" if "O0" in history[key] else "Clang-O2"
)
page = 0
def interact():
print("Enter a number to view the results. Press ENTER to view more records.")
s = input("> ")
if s == "":
global page
page += 1
show_hint(page)
else:
index = int(s)
show_record(index)
if __name__ == "__main__":
show_hint()
while True:
try:
interact()
except KeyboardInterrupt:
print("Bye ~")
break
except EOFError:
print("Bye ~")
break
except Exception as e:
print("What happened?", repr(e))