-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmem_intersect.py
47 lines (40 loc) · 1.46 KB
/
mem_intersect.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
# Karim Manaouil, [email protected]
# University of Edinburgh 2023
#
# To get the trace to be passed as the argument
# run 'perf record --sample-cpu -d -a -- command args'
# then
# 'perf report -D -i perf.data | grep RECORD_SAMPLE > trace'
#
import sys
from collections import defaultdict
def round_to_4kb(address):
return address & ~(0xFFF)
if len(sys.argv) < 2:
print("Usage: python script_name.py <filename>")
sys.exit(1)
file_path = sys.argv[1]
cpu_pages = defaultdict(set)
page_access_count = defaultdict(lambda: defaultdict(int))
with open(file_path, 'r') as file:
for line in file:
parts = line.split()
if len(parts) >= 2 and "0/0" not in line and not line.endswith(" 0\n"):
cpu = parts[0]
addr_str = parts[-1]
try:
addr = int(addr_str, 16)
page = round_to_4kb(addr)
cpu_pages[cpu].add(page)
page_access_count[page][cpu] += 1
except ValueError:
pass
shared_pages = {page: counts for page, counts in page_access_count.items() if len(counts) > 1}
for page, counts in shared_pages.items():
total_accesses = sum(counts.values())
num_cpus = len(counts)
average_accesses = total_accesses / num_cpus
if average_accesses >= 100:
print(f"Page {hex(page)} accessed by multiple CPUs:")
for cpu, access_count in counts.items():
print(f" CPU {cpu} accessed {access_count} times")