-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalyzeserver.cpp
More file actions
230 lines (207 loc) · 5.04 KB
/
analyzeserver.cpp
File metadata and controls
230 lines (207 loc) · 5.04 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
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
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <iostream.h>
#include <fstream.h>
#include <iomanip.h>
#include <string.h>
#include <sys/time.h>
#include <math.h>
//timeval_subtract and timeval_print was taken from a stackoverflow problem
/* Return 1 if the difference is negative, otherwise 0. */
int timeval_subtract(struct timeval *result, struct timeval *t2, struct timeval *t1)
{
long int diff = (t2->tv_usec + 1000000 * t2->tv_sec) - (t1->tv_usec + 1000000 * t1->tv_sec);
result->tv_sec = diff / 1000000;
result->tv_usec = diff % 1000000;
return (diff<0);
}
void timeval_print(struct timeval *tv)
{
char buffer[30];
time_t curtime;
printf("%ld.%06ld", tv->tv_sec, tv->tv_usec);
curtime = tv->tv_sec;
strftime(buffer, 30, "%m-%d-%Y %T", localtime(&curtime));
printf(" = %s.%06ld\n", buffer, tv->tv_usec);
}
double calcMean(double *list) {
int i;
double sum = 0;
for (i = 0; i < 100; i++) {
sum += list[i];
}
return sum/100;
}
double calcStd(double *list, double mean) {
int i;
double sum = 0;
for (i = 0; i < 100; i++) {
sum += pow(mean-list[i], 2);
}
return sum/99;
}
#ifndef INADDR_NONE
#define INADDR_NONE 0xffffffff /* should be in <netinet/in.h> */
#endif
int main(int argc, char *argv[]) {
int c;
int tflag = 0;
int fflag = 0;
int rflag = 0;
int cflag = 0;
char *ffile;
while ((c = getopt (argc, argv, "ctrf:")) != EOF) {
switch (c) {
case 't':
tflag++;
break;
case 'r':
rflag++;
break;
case 'f':
ffile = optarg;
fflag++;
break;
case 'c':
cflag++;
break;
}
}
if (tflag) {
int i;
struct timeval tvBegin, tvEnd, tvDiff;
gettimeofday(&tvBegin, NULL);
for (i = 0; i < 100; i++) {
system("./dsh -s cccwork2.wpi.edu -p 4444 -c \"test\"");
}
//system("./dsh -s cccwork2.wpi.edu -c \"close\"");
gettimeofday(&tvEnd, NULL);
timeval_subtract(&tvDiff, &tvEnd, &tvBegin);
FILE * pFile;
pFile = fopen ("setupData.txt","a");
if (pFile!=NULL)
{
fprintf(pFile, "%ld.%06ld\n", tvDiff.tv_sec, tvDiff.tv_usec);
fclose (pFile);
}
printf("%ld.%06ld\n", tvDiff.tv_sec, tvDiff.tv_usec);
}
else if (rflag) {
int i;
struct timeval tvBegin, tvEnd, tvDiff;
FILE * pFile;
pFile = fopen ("thruData.txt","a");
for (i = 0; i < 100; i++) {
gettimeofday(&tvBegin, NULL);
system("./dsh -s cccwork2.wpi.edu -p 4444 -c \"cat testdata.dat\"");
gettimeofday(&tvEnd, NULL);
timeval_subtract(&tvDiff, &tvEnd, &tvBegin);
fprintf(pFile, "%ld.%06ld\n", tvDiff.tv_sec, tvDiff.tv_usec);
}
//system("./dsh -s cccwork2.wpi.edu -c \"close\"");
fclose (pFile);
//printf("%ld.%06ld\n", tvDiff.tv_sec, tvDiff.tv_usec);
}
else if (fflag) {
char *filename, *pfilename;
int setup = 0;
fstream inStream;
printf("here is %s\n", ffile);
if (strcmp(ffile, "setup") == 0) {
filename = "setupData.txt";
pfilename = "fsetupData.txt";
setup++;
}
else {
filename = "thruData.txt";
pfilename = "fthruData.txt";
}
inStream.open(filename, ios :: in);
if(inStream.fail())
{
//return false;
cout << "couldn't open\n";
return 0;
}
double inNum;
FILE *pFile;
pFile = fopen(pfilename, "a");
if ( pFile != NULL)
{
double number;
char numtxt[80];
printf("here");
int i;
for (i = 0; i < 100; i++)
{
inStream >> inNum;
if (setup) inNum = inNum/100;
else inNum = inNum*100;
sprintf(numtxt,"%.8f",inNum);
puts(numtxt);
fputs ( numtxt, pFile ); /* write the line */
}
fclose(pFile);
}
inStream.close();
}
else if (cflag) {
char *thrufile, *setupfile;
double thruList[100];
double setupList[100];
double thruMean, thruStd, setupMean, setupStd, thruReal;
int setup;
fstream inStream;
thrufile = "thruData.txt";
setupfile = "fsetupData.txt";
inStream.open(thrufile, ios :: in);
if(inStream.fail())
{
//return false;
cout << "couldn't open\n";
return 0;
}
int i;
for (i = 0; i < 100; i++) {
inStream >> thruList[i];
}
inStream.close();
inStream.open(setupfile, ios :: in);
if(inStream.fail())
{
//return false;
cout << "couldn't open\n";
return 0;
}
for (i = 0; i < 100; i++) {
inStream >> setupList[i];
}
inStream.close();
setupMean = calcMean(setupList);
thruMean = calcMean(thruList);
setupStd = calcStd(setupList, setupMean);
thruStd = calcStd(thruList, thruMean);
thruReal = thruMean - setupMean;
FILE *pFile;
pFile = fopen("finalData.txt", "a");
if ( pFile == NULL)
{
printf("couldn't open file");
}
fprintf(pFile, "Setup Average: %.8f\nSetup Standard Deviation: %.8f\nThroughput Average: %.8f\nThroughput Standard Deviation: %.8f\nActual Throughput Average: %.8f (Throughput - Setup)\n\n",
setupMean, setupStd, thruMean, thruStd, thruReal);
fprintf(pFile, "Data:\nSetup | Throughput\n");
for (i = 0; i < 100; i++) {
fprintf(pFile, "%.8f|%.8f\n",setupList[i],thruList[i]);
}
fclose(pFile);
}
return 0;
}