forked from GarCoSim/TraceFileSim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
153 lines (131 loc) · 5.02 KB
/
main.cpp
File metadata and controls
153 lines (131 loc) · 5.02 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
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
/*
* main.cpp
*
* Created on: Sep 3, 2013
* Author: GarCoSim
*/
#include "Main/Simulator.hpp"
#include <stdio.h>
#include <stdlib.h>
#include <ctime>
#include <string.h>
#include "defines.hpp"
using namespace traceFileSimulator;
using namespace std;
//logging vars
int gLineInTrace;
int gAllocations;
FILE* gLogFile;
FILE* gDetLog;
int forceAGCAfterEveryStep = 0;
string globalFilename;
int setArgs(int argc, char *argv[], const char *option, const char *shortOption) {
int i;
for (i = 1; i < argc; i++) {
if ((!strcmp("--force", option) || !strcmp("-f", shortOption)) && (!strcmp(argv[i], option) || !strcmp(argv[i], shortOption))) {
return 1;
}
if (!strcmp(argv[i], option) || !strcmp(argv[i], shortOption)) {
if (!strcmp(option, "--collector") || !strcmp(shortOption, "-c")) {
if (!strcmp(argv[i + 1], "copying"))
return (int)copyingGC;
if (!strcmp(argv[i + 1], "markSweep"))
return (int)markSweepGC;
if (!strcmp(argv[i + 1], "traversal"))
return (int)traversalGC;
return -1;
} else if (!strcmp(option, "--traversal") || !strcmp(shortOption, "-t")) {
if (!strcmp(argv[i + 1], "breadthFirst"))
return (int)breadthFirst;
if (!strcmp(argv[i + 1], "depthFirst"))
return (int)depthFirst;
if (!strcmp(argv[i + 1], "hotness"))
return (int)hotness;
return -1;
} else if (!strcmp(option, "--allocator") || !strcmp(shortOption, "-a")) {
if (!strcmp(argv[i + 1], "real"))
return (int)realAlloc;
return -1;
} else
return atoi(argv[i + 1]); // be careful! we expect the next one to be a number, otherwise we crash instantly
}
}
return -1;
}
int main(int argc, char *argv[]) {
if(argc < 2) {
fprintf(stderr, "Usage: TraceFileSimulator traceFile [OPTIONS]\n" \
"Options:\n" \
" --watermark x, -w x uses x percent as the high watermark (default: 90)\n" \
" --heapsize x, -h x uses x bytes for the heap size (default: 200000)\n" \
" --collector x, -c x uses x as the garbage collector (valid: copying, markSweep, traversal, default: markSweep)\n" \
" --traversal x, -t x uses x as the traversal algorithm (valid: breadthFirst depthFirst hotness, default: breadthFirst)\n" \
" --allocator x, -a x uses x as the allocator (valid: real, default: real)\n" \
);
exit(1);
}
fprintf(stderr, "TraceFileSimulator v%s\n\n", VERSION);
if(WRITE_DETAILED_LOG) {
gDetLog = fopen("detailed.log","w+");
}
char *filename = argv[1];
int heapSize = setArgs(argc, argv, "--heapsize", "-h");
int highWatermark = setArgs(argc, argv, "--watermark", "-w");
int traversal = setArgs(argc, argv, "--traversal", "-t");
int collector = setArgs(argc, argv, "--collector", "-c");
int allocator = setArgs(argc, argv, "--allocator", "-a");
forceAGCAfterEveryStep = setArgs(argc, argv, "--force", "-f");
if (highWatermark == -1)
highWatermark = 90;
if (traversal == -1)
traversal = (int)breadthFirst;
if (collector == -1)
collector = (int)traversalGC;
if (allocator == -1)
allocator = (int)realAlloc;
if (heapSize == -1) {
if (collector != (int)traversalGC)
heapSize = 200000;
else
heapSize = 600000;
}
if (forceAGCAfterEveryStep == -1)
forceAGCAfterEveryStep = 0;
CREATE_GLOBAL_FILENAME((string)filename);
string logFileName;
if (forceAGCAfterEveryStep)
logFileName = globalFilename + "Forced.log";
else
logFileName = globalFilename + ".log";
//set up global logfile
gLogFile = fopen(logFileName.c_str(), "w+");
fprintf(gLogFile, "TraceFileSimulator v%s\nCollector: %s\nTraversal: %s\nAllocator: %s\nHeapsize: %d%s\nWatermark: %d\n\n",
VERSION, COLLECTOR_STRING, TRAVERSAL_STRING, ALLOCATOR_STRING, heapSize, collector == traversalGC ? " (split heap)" : "", highWatermark);
fprintf(gLogFile, "%8s | %14s | %10s | %14s "
"| %13s | %10s | %10s | %10s | %7s\n",
"Line", "GC Reason", "Total GCs", "Objects Freed", "Live Objects",
"Heap Used", "Free Heap", "Generation", "GC Time");
fprintf(stderr, "Using tracefile '%s' with a heap size of %d bytes and a high watermark of %d\n", filename, heapSize, highWatermark);
fprintf(stderr, "The collector is '%s' and the selected traversal is '%s'\n", COLLECTOR_STRING, TRAVERSAL_STRING);
fprintf(stderr, "The allocator is '%s'\n", ALLOCATOR_STRING);
if (forceAGCAfterEveryStep)
fprintf(stderr, "Forcing a GC after every step\n");
//start measuring time
clock_t start = clock();
Simulator* simulator = new Simulator(filename, heapSize, highWatermark, collector, traversal, allocator);
while(simulator->lastStepWorked() == 1) {
simulator->doNextStep();
if(WRITE_DETAILED_LOG) {
fflush(gDetLog);
}
}
simulator->printStats();
simulator->lastStats();
clock_t end = clock();
double elapsed_secs = double(end - start)/CLOCKS_PER_SEC;
//double elapsed_msecs = (double)(double)(end - start)/(CLOCKS_PER_SEC/1000);
printf("Simulation ended successfully, execution took %0.3f seconds\n", elapsed_secs);
fprintf(gLogFile,"Execution finished after %0.3f seconds\n", elapsed_secs);
fclose(gLogFile);
return EXIT_SUCCESS;
}