-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtrace_xcode.py
More file actions
executable file
·65 lines (53 loc) · 2.39 KB
/
Copy pathtrace_xcode.py
File metadata and controls
executable file
·65 lines (53 loc) · 2.39 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
#!python3
import os
import shutil
import subprocess
import xml.etree.ElementTree as ET
XPATH = '/trace-toc/run[@number="1"]/data/table[@schema="counters-profile"]'
EXPORT_CMD = f'xctrace export --input sim.trace --xpath \'{XPATH}\' > trace.xml'
RECORD_CMD = 'xcrun xctrace record --template counters.tracetemplate --output "sim.trace" --launch simulation'
def create_csv_header(csv):
print("category,count,columns,distribution,time,L2_TLB_MISS_DATA,L1D_CACHE_MISS_LD,L1D_CACHE_MISS_ST,L1D_TLB_MISS,BRANCH_COND_MISPRED_NONSPEC,BRANCH_MISPRED_NONSPEC", file=csv)
csv.flush()
def trace(args):
if os.path.exists('sim.trace'):
shutil.rmtree('sim.trace')
subprocess.run(RECORD_CMD + args, shell=True, capture_output=True)
def append_run(category, count, columns, distribution, csv):
subprocess.run(EXPORT_CMD, shell=True, capture_output=True)
tree = ET.parse('trace.xml')
root = tree.getroot()
for row in root[0].findall('.//row'):
pmc = row.find('pmc-events')
if not pmc.text:
continue
st = int(row.find('sample-time').text)
print(f"{category},{count},{columns},{distribution},{row.find('sample-time').text},{pmc.text.replace(' ', ',')}", file=csv)
csv.flush()
shutil.rmtree('sim.trace')
os.remove('trace.xml')
def main():
rows = 1 << 24
key_cols = 3
payload_cols = 1 << 5
configurations = [
# ('comparator', rows, key_cols, [
# 'col_all', 'col_ss', 'col_branchless', 'row_all', 'row_all_branchless', 'row_iter', 'row_norm']),
('sort', rows, key_cols, ['pdq_static', 'radix']),
# ('merge_key', rows, key_cols, ['row_all', 'row_all_branchless', 'row_norm', 'col_branch', 'col_branchless']),
# ('reorder', rows, payload_cols, ['row', 'col']),
# ('merge_payload', rows, payload_cols, ['row', 'col'])
]
distributions = ['powerlaw'] # 'random', 'uniqueN',
for sim, count, columns, categories in configurations:
for dist in distributions:
fname = f'results/xcode_output/trace_{sim}_{dist}.csv'
with open(fname, 'w+') as f:
create_csv_header(f)
for category in categories:
args = f' {sim} {category} {count} {columns} {dist}'
print(args)
trace(args)
append_run(category, count, columns, dist, f)
if __name__ == '__main__':
main()