|
@@ -6,8 +6,12 @@
|
|
#include <unistd.h>
|
|
#include <unistd.h>
|
|
#include <arpa/inet.h>
|
|
#include <arpa/inet.h>
|
|
#include <string>
|
|
#include <string>
|
|
|
|
+#include <stdio.h>
|
|
|
|
+#include <time.h>
|
|
#include "pirserver.h"
|
|
#include "pirserver.h"
|
|
|
|
|
|
|
|
+#define PIRSERVER_LOG_FILE "pirserverlog"
|
|
|
|
+
|
|
#define PIRSERVER_HDR_SIZE 13
|
|
#define PIRSERVER_HDR_SIZE 13
|
|
|
|
|
|
#define PIRSERVER_REQUEST_PARAMS 0x01
|
|
#define PIRSERVER_REQUEST_PARAMS 0x01
|
|
@@ -49,6 +53,8 @@ write_all(const char *buf, size_t len)
|
|
void
|
|
void
|
|
PIRServer::mainloop()
|
|
PIRServer::mainloop()
|
|
{
|
|
{
|
|
|
|
+ FILE *fptr = fopen(PIRSERVER_LOG_FILE, "a");
|
|
|
|
+ clock_t start, end, cpu_time;
|
|
char header[PIRSERVER_HDR_SIZE];
|
|
char header[PIRSERVER_HDR_SIZE];
|
|
size_t bodylen = 0;
|
|
size_t bodylen = 0;
|
|
char *body = NULL;
|
|
char *body = NULL;
|
|
@@ -69,6 +75,7 @@ PIRServer::mainloop()
|
|
// We have a complete request. Dispatch it.
|
|
// We have a complete request. Dispatch it.
|
|
switch(header[8]) {
|
|
switch(header[8]) {
|
|
case PIRSERVER_REQUEST_PARAMS:
|
|
case PIRSERVER_REQUEST_PARAMS:
|
|
|
|
+ start = clock();
|
|
get_params(response);
|
|
get_params(response);
|
|
response_len = response.length();
|
|
response_len = response.length();
|
|
header[8] = PIRSERVER_RESPONSE_PARAMS;
|
|
header[8] = PIRSERVER_RESPONSE_PARAMS;
|
|
@@ -79,15 +86,21 @@ PIRServer::mainloop()
|
|
res = write_all(response.c_str(), response_len);
|
|
res = write_all(response.c_str(), response_len);
|
|
if (res <= 0) return;
|
|
if (res <= 0) return;
|
|
}
|
|
}
|
|
|
|
+ end = clock();
|
|
|
|
+ fprintf(fptr, "REQUEST_PARAMS,");
|
|
break;
|
|
break;
|
|
case PIRSERVER_REQUEST_STORE:
|
|
case PIRSERVER_REQUEST_STORE:
|
|
if (bodylen >= 32) {
|
|
if (bodylen >= 32) {
|
|
|
|
+ start = clock();
|
|
string key(body, 32);
|
|
string key(body, 32);
|
|
string value(body+32, bodylen-32);
|
|
string value(body+32, bodylen-32);
|
|
store(key, value);
|
|
store(key, value);
|
|
|
|
+ end=clock();
|
|
|
|
+ fprintf(fptr, "STORE,");
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
case PIRSERVER_REQUEST_LOOKUP:
|
|
case PIRSERVER_REQUEST_LOOKUP:
|
|
|
|
+ start = clock();
|
|
query.assign(body, bodylen);
|
|
query.assign(body, bodylen);
|
|
if (lookup(query, response)) {
|
|
if (lookup(query, response)) {
|
|
response_len = response.length();
|
|
response_len = response.length();
|
|
@@ -103,9 +116,16 @@ PIRServer::mainloop()
|
|
res = write_all(response.c_str(), response_len);
|
|
res = write_all(response.c_str(), response_len);
|
|
if (res <= 0) return;
|
|
if (res <= 0) return;
|
|
}
|
|
}
|
|
|
|
+ end = clock();
|
|
|
|
+ fprintf(fptr, "LOOKUP,");
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ cpu_time = end - start;
|
|
|
|
+ //Time logged in ms
|
|
|
|
+ fprintf(fptr,"%f\n", ((float)cpu_time/CLOCKS_PER_SEC) * 1000 );
|
|
|
|
+ fflush(fptr);
|
|
|
|
+
|
|
// Clean up for the next request.
|
|
// Clean up for the next request.
|
|
free(body);
|
|
free(body);
|
|
body = NULL;
|
|
body = NULL;
|