-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsharingProfile.py
More file actions
36 lines (30 loc) · 1.11 KB
/
sharingProfile.py
File metadata and controls
36 lines (30 loc) · 1.11 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
import sys
#validation
if(len(sys.argv) != 2):
print("invalid input")
exit(0)
else:
fileName = str(sys.argv[1])
counter = 0
#We maintain a hashmap of block vs a set of threads that have accessed it so far
AccessesSofar = {}
with open(fileName) as infile:
for line in infile:
line = line.rstrip().split(" ")
if(line[0] == "#eof"):
break
memAddr = int(line[2])
threadID = int(line[0].strip(":"))
blockNumber = memAddr >> 6
prevAccess = AccessesSofar.get(blockNumber, -1)
if prevAccess == -1:
#if accessing for the first time, add the block to the hashmap with a set of the current thread accessing it.
AccessesSofar[blockNumber] = set([threadID])
else:
#else if it already exists add the thread to the set. Sets maintain the uniqueness of their elements.
AccessesSofar[blockNumber].add(threadID)
counter += 1
blocksSharedPerThread = [0, 0, 0, 0, 0, 0, 0, 0]
for block, threadsCount in AccessesSofar.items():
blocksSharedPerThread[len(threadsCount)-1] += 1
print(blocksSharedPerThread)