-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
100 lines (73 loc) · 2.64 KB
/
main.cpp
File metadata and controls
100 lines (73 loc) · 2.64 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
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
#include <iostream>
#include <string>
#include "utils.h"
#include <vector>
#include "Algorithm.h"
#include "FifoAlgorithm.h"
#include "RandomAlgorithm.h"
#include "LruAlgorithm.h"
#include "SecondChanceAlgorithm.h"
#include "EnhancedSecondChanceAlgorithm.h"
#include "OptimalAlgorithm.h"
#include <fstream>
#include "MemoryReference.h"
#define FIFO_ALGO "fifo"
#define RANDOM_ALGO "random"
#define LRU_ALGO "lru"
#define SECOND_CHANCE_ALGO "second_chance"
#define ENHANCED_SECOND_CHANCE_ALGO "enhanced_second_chance"
#define OPTIMAL_ALGO "optimal"
#define DEFAULT_FILE_NAME "pinatrace.out"
#define DEFAULT_NUMBER_OF_FRAMES "10%"
#define DEFAULT_PAGE_SIZE "4k"
using namespace std;
typedef long long ll;
int main(int argc, char *argv[]) {
// if(argc < 9) {
// return -1;
// }
string algorithm_str = FIFO_ALGO; // (argv[2]);
string file_name = DEFAULT_FILE_NAME; // (argv[4]);
string num_of_frames = DEFAULT_NUMBER_OF_FRAMES; // (argv[6]);
string page_size_str = DEFAULT_PAGE_SIZE; //(argv[8]);
for(int i = 0; i < argc - 1; ++i) {
string
tmp(argv[i]),
tmp2(argv[i+1]);
if(tmp == "--algorithm")
algorithm_str = tmp2;
if(tmp == "--trace")
file_name = tmp2;
if(tmp == "--pages")
num_of_frames = tmp2;
if(tmp == "--page_size")
page_size_str = tmp2;
}
vector< MemoryReference > references;
get_memory_references(file_name, references);
int page_size = get_page_size(page_size_str);
// ifstream fin(file_name.c_str());
int number_of_pages = needed_pages(1024, references);
int number_of_frames = get_number_of_frames(number_of_pages, num_of_frames);
Algorithm *algo;
if (algorithm_str == FIFO_ALGO)
algo = new FifoAlgorithm(number_of_frames, page_size);
else if (algorithm_str == RANDOM_ALGO)
algo = new RandomAlgorithm(number_of_frames, page_size);
else if (algorithm_str == LRU_ALGO)
algo = new LruAlgorithm(number_of_frames, page_size);
else if (algorithm_str == SECOND_CHANCE_ALGO)
algo = new SecondChanceAlgorithm(number_of_frames, page_size);
else if (algorithm_str == OPTIMAL_ALGO)
algo = new OptimalAlgorithm(number_of_frames, page_size, references);
else if (algorithm_str == ENHANCED_SECOND_CHANCE_ALGO)
algo = new EnhancedSecondChanceAlgorithm(number_of_frames, page_size);
for(int i = 0; i < references.size(); ++i){
algo->access(references[i]);
// cout << "Number of page faults: " << algo->get_number_of_page_faults() << endl;
}
cout << "Total number of memory references: " << references.size() << endl;
cout << "Number of pages: " << number_of_pages << endl;
cout << "Number of frames: " << number_of_frames << endl;
cout << "Number of page faults: " << algo->get_number_of_page_faults() << endl;
}