-
Notifications
You must be signed in to change notification settings - Fork 3
/
generateResults.py
255 lines (185 loc) · 7.7 KB
/
generateResults.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
import sys
import os
import subprocess
import shutil
import matplotlib.pyplot as plt
plt.rcParams['figure.figsize'] = [16, 9]
plt.rcParams.update({'font.size': 18})
plt.style.use('dark_background')
from tkinter import *
from tkinter.ttk import Progressbar
totalProgress = 0
CONTR_PROCESS = 7
CONTR_PLOT = 3
def generateStatistics_Plot1():
global pageFaults, PATH_TO_PROCESS_LIST, PATH_TO_PROCESS_TRACE, REPLACEMENT, PAGING
global totalProgress
pageSizeList = ['1', '2', '4', '8', '16', '32']
pageFaultList = []
for i, pageSize in enumerate(pageSizeList):
if pageSize == PAGE_SIZE:
pageFaultList.append(pageFaults)
pageIndex = i
else:
processInfo = ['./a.out', PATH_TO_PROCESS_LIST, PATH_TO_PROCESS_TRACE, REPLACEMENT, PAGING, pageSize, '0']
process = subprocess.Popen(processInfo, stdout=subprocess.PIPE)
dataBytes = process.communicate()[0]
dataStr = dataBytes.decode('utf-8')
data = list(map(int,dataStr.split(' ')))
pageFaultList.append(data[2])
totalProgress += CONTR_PROCESS
updateProgressBar()
return pageSizeList, pageFaultList, pageIndex
def generateStatistics_Plot2():
global pageFaults, PATH_TO_PROCESS_LIST, PATH_TO_PROCESS_TRACE, PAGE_SIZE
global totalProgress
simCombinations = [['DEMAND', 'FIFO'], ['DEMAND', 'LRU'], ['DEMAND', 'CLOCK'], ['PRE', 'FIFO'], ['PRE', 'LRU'], ['PRE', 'CLOCK']]
for i, combination in enumerate(simCombinations):
if combination[0] == PAGING and combination[1] == REPLACEMENT:
simCombinations[i].append(pageFaults)
mainIndex = i
else:
processInfo = ['./a.out', PATH_TO_PROCESS_LIST, PATH_TO_PROCESS_TRACE, combination[1], combination[0], PAGE_SIZE, '0']
process = subprocess.Popen(processInfo, stdout=subprocess.PIPE)
dataBytes = process.communicate()[0]
dataStr = dataBytes.decode('utf-8')
data = list(map(int,dataStr.split(' ')))
simCombinations[i].append(data[2])
totalProgress += CONTR_PROCESS
updateProgressBar()
combinationList = [combination[0] + ' + ' + combination[1] for combination in simCombinations]
pageFaultList = [combination[2] for combination in simCombinations]
return combinationList, pageFaultList, mainIndex
def createPlot1():
global totalProgress
pageSizeList, pageFaultList, pageIndex = generateStatistics_Plot1()
# Figure Size
_, ax = plt.subplots(figsize =(16, 9))
# Horizontal Bar Plot
bars = plt.barh(pageSizeList, pageFaultList)
bars[pageIndex].set_color('r')
ax.spines['right'].set_color('black')
ax.spines['top'].set_color('black')
ax.xaxis.set_tick_params(pad = 5)
ax.yaxis.set_tick_params(pad = 10)
ax.grid(b = True, color ='grey', linestyle ='-.', linewidth = 0.5, alpha = 0.2)
ax.invert_yaxis()
# Add annotation to bars
for i in ax.patches:
plt.text(i.get_width()+0.2, i.get_y()+0.45, str(round((i.get_width()), 2)), color ='white')
# plt.title('Number of pagefaults VS Page size', fontweight ="bold")
plt.ylabel('Page size')
plt.xlabel('Number of page faults')
plt.tight_layout()
# Save figure
plt.savefig('./Plots/plot1.png')
totalProgress += CONTR_PLOT
updateProgressBar()
def createPlot2():
global totalProgress
combinationList, pageFaultList, mainIndex = generateStatistics_Plot2()
# Figure Size
_, ax = plt.subplots(figsize =(16, 9))
# Horizontal Bar Plot
bars = plt.barh(combinationList, pageFaultList)
bars[mainIndex].set_color('r')
ax.spines['right'].set_color('black')
ax.spines['top'].set_color('black')
ax.xaxis.set_tick_params(pad = 5)
ax.yaxis.set_tick_params(pad = 10)
ax.grid(b = True, color ='grey', linestyle ='-.', linewidth = 0.5, alpha = 0.2)
ax.invert_yaxis()
# Add annotation to bars
for i in ax.patches:
plt.text(i.get_width()+0.2, i.get_y()+0.45, str(round((i.get_width()), 2)), color ='white')
# plt.title('Number of pagefaults for different paging and replacement methods', fontweight ="bold")
plt.ylabel('Different combinations of paging and replacement methods')
plt.xlabel('Number of pagefaults')
plt.tight_layout()
# Save figure
plt.savefig('./Plots/plot2.png')
totalProgress += CONTR_PLOT
updateProgressBar()
def executeMainRequest():
global totalProgress, CONTR_PROCESS
os.system('g++ -I ./ simulator.cpp')
processInfo = ['./a.out', PATH_TO_PROCESS_LIST, PATH_TO_PROCESS_TRACE, REPLACEMENT, PAGING, PAGE_SIZE, '1']
backend = subprocess.Popen(processInfo, stdout=subprocess.PIPE)
dataBytes = backend.communicate()[0]
dataStr = dataBytes.decode('utf-8')
data = list(map(int,dataStr.split(' ')))
global processCount
global memoryRequestCount
global pageFaults
global pageFaultTracker
processCount = data[0]
memoryRequestCount = data[1]
pageFaults = data[2]
pageFaultTracker = data[3:]
totalProgress += CONTR_PROCESS
updateProgressBar()
def printData():
global REPLACEMENT, PAGING, PAGE_SIZE
global processCount, memoryRequestCount, pageFaults
print(processCount, memoryRequestCount, PAGING, REPLACEMENT, PAGE_SIZE, pageFaults, end='')
def updateProgressBar():
global progress, totalProgress
progress['value']=totalProgress
ProgressWin.update_idletasks()
def destroyProgressBar():
global ProgressWin
ProgressWin.destroy()
def main():
updateProgressBar()
# Arguments
argData = sys.argv
global PAGING, REPLACEMENT, PATH_TO_PROCESS_LIST, PATH_TO_PROCESS_TRACE, PAGE_SIZE, progress, totalProgress
PAGING = argData[1]
REPLACEMENT = argData[2]
PATH_TO_PROCESS_LIST = argData[3]
PATH_TO_PROCESS_TRACE = argData[4]
PAGE_SIZE = argData[5]
# Creating directory to store plots
dir = './Plots'
if os.path.exists(dir):
shutil.rmtree(dir)
os.makedirs(dir)
# Executing all functions
executeMainRequest()
createPlot1()
createPlot2()
totalProgress += 3
updateProgressBar()
printData()
ProgressWin.destroy()
if __name__ == '__main__':
# creating tkinter window
ProgressWin = Tk()
ProgressWin.title('Virtual memory management simulator- Processing')
ProgressWin.config(bg = 'black')
# Defining attributes of root window
ProgressWin.resizable(False, False) # This code helps to disable windows from resizing
window_height = 150
window_width = 500
screen_width = ProgressWin.winfo_screenwidth()
screen_height = ProgressWin.winfo_screenheight()
x_cordinate = int((screen_width/2) - (window_width/2))
y_cordinate = int((screen_height/2) - (window_height/2))
ProgressWin.geometry("{}x{}+{}+{}".format(window_width, window_height, x_cordinate, y_cordinate))
# Creating a main frame inside the root window
main_frame=Frame(ProgressWin,relief=GROOVE, bg = 'black')
main_frame.place(x=10,y=10) # Placing the frame at (10, 10)
# Creating sub- frames
frame1 = Frame(main_frame, padx=3, pady=3, bg = 'black')
frame2 = Frame(main_frame, bg='white', pady=5, padx = 5)
frame1.grid(row = 1, column = 1, padx = 5, pady = 5)
frame2.grid(row = 2, column = 1, padx = 5, pady = (30,10))
# Title label in sub_frame1
label = Label(master=frame1, text="Running simulations! Please wait...", fg = '#23ff0f', font = "Verdana 15 bold", bg = 'black')
label.pack() # Put the label into the window
# Progress bar widget
progress = Progressbar(frame2, orient = HORIZONTAL, length = 450, mode = 'determinate')
progress.pack()
main()
# Run the GUI
ProgressWin.mainloop()