From 07aa3824a94cab5b02401dce6eebea74c55e7410 Mon Sep 17 00:00:00 2001 From: ubuntu201711081 <201711081@jbnu.ac.kr> Date: Mon, 7 Dec 2020 10:05:19 +0000 Subject: [PATCH] add TRACE p-server --- .vscode/settings.json | 3 ++- p-server.c | 25 +++++++++++++++++++++++++ server.c | 2 +- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 25131cc..aa9a253 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,6 +4,7 @@ ], "files.associations": { "socket_wrapper.h": "c", - "stdalign.h": "c" + "stdalign.h": "c", + "timerhelper.h": "c" } } \ No newline at end of file diff --git a/p-server.c b/p-server.c index 5d61b64..5ef1710 100644 --- a/p-server.c +++ b/p-server.c @@ -13,6 +13,7 @@ #include #include #include + #include "socket_wrapper.h" #ifndef DEFAULT_MAX_LISTEN_SOCKET @@ -51,6 +52,15 @@ static const int RESPONSE_REQUEST = 3; static const int RESPONSE_REQUEST = DEFAULT_RESPONSE_REQUEST; #endif +#define USE_TRACE + +#include +#include +#include "timerhelper.h" +enum{ + Trace_Timer_ID = CLOCK_REALTIME +}; + /*======== *Operation *========*/ @@ -276,15 +286,22 @@ int main(int argc, const char *argv[]){ char ip_buf[INET_ADDRSTRLEN]; const char * msg; int retval = 0; + struct timespec ts,tsmiddle,tsend; if((csock = accept(sock, (struct sockaddr *)&client_addr,&client_addr_len)) < 0){ free(buf); perror("accept error"); return 1; } msg = inet_ntop(AF_INET,&client_addr.sin_addr,ip_buf,sizeof(ip_buf)); + #ifdef USE_TRACE + clock_gettime(Trace_Timer_ID,&ts); + #endif fprintf(stderr,"Connected on : %s:%d\n",msg == NULL ? "(null)" : msg , ntohs(client_addr.sin_port)); pid = fork(); if(pid == 0){ + #ifdef USE_TRACE + clock_gettime(Trace_Timer_ID,&tsmiddle); + #endif if((fd = read_request(csock,buf,bufsize)) > 0){ retval = send_response(csock,fd,buf,bufsize); close(fd); @@ -292,6 +309,14 @@ int main(int argc, const char *argv[]){ else retval = fd; if(close(csock) < 0) perror("csock close error"); + #ifdef USE_TRACE + clock_gettime(Trace_Timer_ID,&tsend); + struct timespec tophalf = timespec_sub(tsmiddle,ts); + struct timespec bottomhelf = timespec_sub(tsend,tsmiddle); + struct timespec resolution; + clock_getres(Trace_Timer_ID,&resolution); + fprintf(stderr,"top: %ld ns, bottom: %ld ns, res: %ld\n",tophalf.tv_nsec,bottomhelf.tv_nsec,resolution.tv_nsec); + #endif free(buf); return retval; } diff --git a/server.c b/server.c index d74fde3..1ec080e 100644 --- a/server.c +++ b/server.c @@ -237,7 +237,7 @@ int parse_args(int argc,const char * argv[] , in_port_t * port){ //============ #ifdef USE_TRACE enum{ - Trace_Timer_ID = CLOCK_PROCESS_CPUTIME_ID + Trace_Timer_ID = CLOCK_REALTIME }; #endif