-
Notifications
You must be signed in to change notification settings - Fork 0
/
bounder.py
143 lines (107 loc) · 4.05 KB
/
bounder.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/python
import sys
import time
import matplotlib.pyplot as plt
import numpy
__author__ = "Matan Lachmish and Asaf Rokach"
__copyright__ = "Copyright 2016, Bounding TSO"
__version__ = "1.2"
__status__ = "Development"
kNumberOfTests = 10000
kNumberOfWritesPerTests = 2 ** 10
MeasureMethod = 'fine' # 'fine'/'coarse'
def main(argv):
printWelcomePrompt()
if MeasureMethod == 'fine':
# Fine Grained
print('Calculating TSO size (Fine Grained)...')
fineGrainedIntervals = calculateTSOSizeFineGrained()
saveResults(fineGrainedIntervals, 'fine')
print('Plotting Fine Grained results')
plt.plot(fineGrainedIntervals)
plt.title('Fine Grained results')
plt.ylabel('Process Time')
plt.xlabel('# Bytes Written')
plt.show()
elif MeasureMethod == 'coarse':
# Coarse Grained
print('Calculating TSO size (CoarseGrained)...')
sizeArray, meanTime = calculateTSOSizeCoarseGrained()
saveResults(meanTime, 'coarse')
print('Plotting Coarse Grained results')
plt.plot(sizeArray, meanTime)
plt.title('Coarse Grained results')
plt.ylabel('Process Time')
plt.xlabel('# Bytes Written')
plt.show()
else:
print('Unsupported MeasureMethod')
def floodTSO():
meanWriteTime = 0.0
for test in range(1, kNumberOfTests):
storage = bytearray() # New empty byte array
for byteNumber in range(1, kNumberOfWritesPerTests):
startTime = time.process_time()
storage.extend(b"x")
currentTime = time.process_time()
currentWriteTime = currentTime - startTime
if currentWriteTime >= meanWriteTime * 1.8 and byteNumber > 1: # Check if current write time pass the threshold (1.8)
print("Flooded at byte number: " + str(byteNumber))
return True
else:
meanWriteTime = ((meanWriteTime * (byteNumber - 1)) + currentWriteTime) / byteNumber
return False
def calculateTSOSizeCoarseGrained():
sizeArray = list(range(1, kNumberOfWritesPerTests))
meanTimeArray = []
for size in sizeArray:
# Flood TSO
if not floodTSO():
print("Flooding the TSO failed!")
return
startTime = time.process_time()
for k in range(1, kNumberOfTests):
storage = bytearray() # New empty byte array
for i in range(1, size):
# x = b"x" # Stub write
storage.extend(b"x")
stopTime = time.process_time()
meanTimeArray.append((stopTime - startTime) / kNumberOfTests)
return sizeArray, meanTimeArray
def calculateTSOSizeFineGrained():
loggers = []
for test in range(1, kNumberOfTests):
storage = bytearray() # New empty byte array
# Flood TSO
if not floodTSO():
print("Flooding the TSO failed!")
return
timeLogger = [time.process_time()]
for byteNumber in range(1, kNumberOfWritesPerTests):
storage.extend(b"x")
# x = b"x" # Stub write
timeLogger.append(time.process_time())
loggers.append(timeLogger)
intervals = []
for logger in loggers:
timeIntervals = []
for counter in range(1, len(logger) - 1):
timeIntervals.append(logger[counter + 1] - logger[counter])
intervals.append(timeIntervals)
avgIntervals = [float(sum(col)) / len(col) for col in zip(*intervals)]
return avgIntervals
def saveResults(results, filename):
with open(filename + "_results.csv", 'w') as myfile:
for value in results:
myfile.write(str(value)+',')
def printCurrentTime():
currentTime = time.process_time()
print('Current time is: ' + str(currentTime))
def printWelcomePrompt():
print('')
print('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
print(' ~~~ Welcome to TSO Bounder ~~~')
print('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
print('')
if __name__ == "__main__":
main(sys.argv)