-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
165 lines (125 loc) · 4.38 KB
/
main.cpp
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
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<list>
#include"2cache.h"
using namespace std;
int main(int argc, char*argv[])
{
list<cache*> cachelist;
// page size, number of victim buffer, number of stream buffer
//cache *cache11 = new cache(512, 4, 1);
//cachelist.push_back(cache11);
//cache *cache12 = new cache(512, 4, 2);
//cachelist.push_back(cache12);
cache *cache13 = new cache(512, 4, 4);
cachelist.push_back(cache13);
//cache *cache14 = new cache(512, 8, 1);
//cachelist.push_back(cache14);
//cache *cache15 = new cache(512, 8, 2);//y
//cachelist.push_back(cache15);
//cache *cache16 = new cache(512, 8, 4);//j
//cachelist.push_back(cache16);
//cache *cache17 = new cache(512, 16, 1);
//cachelist.push_back(cache17);
//cache *cache18 = new cache(512, 16, 2);
//cachelist.push_back(cache18);
//cache *cache19 = new cache(512, 16, 4);
//cachelist.push_back(cache19);
printf("read the trace file...\n");
FILE *trace;
//fopen_s(&trace, "trace-redis2.txt", "rt");
fopen_s(&trace, "6t-final.txt", "rt");
//fopen_s(&trace, "1t.txt", "rt");
//fopen_s(&trace, "bzip2", "rt");
if (!trace)
{
printf("Can't open the trace file!\n");
return 0;
}
list<cache*> ::iterator it = cachelist.begin();
for (; it != cachelist.end(); it++)
{
if (!(*it)->initcache())
return 0;
}
unsigned int type, addr;
while (fscanf_s(trace, "%d %x\n", &type, &addr) != EOF)
{
it = cachelist.begin();
if ((*it)->getaccessnum()%1000000==0)//till 51
printf("%d\n", (*it)->getaccessnum());
switch (type)
{
case 0:
for (; it != cachelist.end(); it++)
if (!(*it)->cacheread(addr))
return 0;
break;
case 1:
for (; it != cachelist.end(); it++)
if (!(*it)->cachewrite(addr))
return 0;
break;
case 2:
for (; it != cachelist.end(); it++)
if (!(*it)->instread(addr))
return 0;
break;
case 3:
for (; it != cachelist.end(); it++)
if (!(*it)->cachewrite(addr))
return 0;
break;
default:
perror("invalid type\n");
printf("%d", type);
break;
}
}
FILE *file;
fopen_s(&file, "result5.csv", "wt");
if (!file)
{
printf("Can't create the result1 file!\n");
return 0;
}
fprintf(
file,
"\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\"\n",
"victimBuffer", "streamBuffer",
"victimBufferWrite", "victimBufferRead", "victimBufferHit",
"streamBufferWrite", "streamBufferRead", "streamBufferHit",
"L1-Access", "L1-Read", "L1-Write","L1-Hit", "L1-Miss", "L1-MissRate",
"L2-Access", "L2-Read", "L2-Write", "L2-Hit", "L2-Miss", "L2-MissRate",
"DRAM-Access", "DRAM-Read", "DRAM-Write", "DRAM-Hit", "DRAM-Miss", "DRAM-MissRate",
"SSD-Access", "SSD-Read", "SSD-Write", "SSD-Hit", "SSD-Miss", "SSD-MissRate",
"TotalAccessTime","AMAT");
printf("11");
list<cache*>::iterator itt = cachelist.begin();
for (; itt != cachelist.end(); itt++)
{
fprintf(
file,
"\"%d\",\"%d\",\"%d\",\"%d\",\"%d\",\"%d\",\"%d\",\"%d\",\"%d\",\"%d\",\"%d\",\"%d\",\"%d\",\"%lf\",\"%d\",\"%d\",\"%d\",\"%d\",\"%d\",\"%lf\",\"%d\",\"%d\",\"%d\",\"%d\",\"%d\",\"%lf\",\"%d\",\"%d\",\"%d\",\"%d\",\"%d\",\"%lf\",\"%lf\",\"%lf\"\n",
(*itt)->getvbuffernum(), (*itt)->getsbuffernum(),
(*itt)->getvwritenum(), (*itt)->getvreadnum(), (*itt)->getvhitmnum(),
(*itt)->getswritenum(), (*itt)->getsreadnum(), (*itt)->getshitmnum(),
(*itt)->getaccessnum(), (*itt)->getreadnum(), (*itt)->getwritenum(),
(*itt)->gethitnum(), (*itt)->getmissnum(),(*itt)->getmissrate(),
(*itt)->getaccessnum2(), (*itt)->getreadnum2(), (*itt)->getwritenum2(),
(*itt)->gethitnum2(), (*itt)->getmissnum2(), (*itt)->getmissrate2(),
(*itt)->getaccessnumd(), (*itt)->getreadnumd(), (*itt)->getwritenumd(),
(*itt)->gethitnumd(), (*itt)->getmissnumd(), (*itt)->getmissrated(),
(*itt)->getaccessnums(), (*itt)->getreadnums(), (*itt)->getwritenums(),
(*itt)->gethitnums(), (*itt)->getmissnums(), (*itt)->getmissrates(),
(*itt)->totalaccesstime(), (*itt)->amat()
);
}
printf("22");
fclose(trace);
printf("close the trace file!\n");
fclose(file);
printf("Done!\n");
return 0;
}