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