-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_graph.py
More file actions
62 lines (48 loc) · 1.65 KB
/
create_graph.py
File metadata and controls
62 lines (48 loc) · 1.65 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
import matplotlib.pyplot as plt
def read_trace_generate_graph():
hit_rate_list = []
time_list = []
access_frame = 1000
hit_count = 0
miss_count = 0
total_access = 0
#access_list = []
file = open("results_trace.txt")
lines = file.readlines()
for line in lines:
l = line.split()
if len(l)>1 and l[1] == "access":
total_access += 1
if l[7] == "hit":
hit_count += 1
else:
miss_count += 1
if total_access%access_frame == 0:
#hit_rate is the hit rate per 1000 accesses
hit_rate = hit_count/access_frame
hit_rate_list.append(hit_rate)
time_list.append(total_access)
#hit count is needed for every 1000 accesses so after every 1000 accesses hit count is made 0
hit_count = 0
print("total access : ",total_access)
#return hit_rate_list,time_list
y_values,x_values=hit_rate_list,time_list
plt.plot(x_values, y_values, marker='o', linestyle='-')
plt.xlabel('Accesses')
plt.ylabel('Hit Rate')
plt.title('Hit Rate over the Time')
plt.grid(True) # Enable grid
plt.savefig('hit_rate_graph.pdf', format='pdf')
plt.show()
# # Sample data
# y_values,x_values = read_trace_generate_graph()
# # Plotting the line graph
# plt.plot(x_values, y_values, marker='o', linestyle='-')
# # Adding labels and title
# plt.xlabel('Accesses')
# plt.ylabel('Hit Rate')
# plt.title('Hit Rate over the Time')
# # Displaying the graph
# plt.grid(True) # Enable grid
# plt.savefig('hit_rate_graph.pdf', format='pdf')
# plt.show()