diff --git a/Platform/common/rpc/rpc_common.h b/Platform/common/rpc/rpc_common.h index fc80b4df5..c4f101fac 100755 --- a/Platform/common/rpc/rpc_common.h +++ b/Platform/common/rpc/rpc_common.h @@ -16,6 +16,7 @@ #define BUFFER_SIZE 2048 #define RPC_VERSION "RPC/1.0" #define TIMEOUT 120 +#define TIMEWARN 200 typedef enum { /* RPC ret code */ diff --git a/Platform/common/rpc/rpc_util.h b/Platform/common/rpc/rpc_util.h index cb6600462..bb9027841 100755 --- a/Platform/common/rpc/rpc_util.h +++ b/Platform/common/rpc/rpc_util.h @@ -118,4 +118,6 @@ void rpc_sleep(int ms); void rpc_set_non_block(int fd); +long rpc_time_msec(void); + #endif /* RPC_UTIL_H_ */ diff --git a/Platform/user/rpc/rpc_client.c b/Platform/user/rpc/rpc_client.c index 8adecb60b..23c9224d0 100755 --- a/Platform/user/rpc/rpc_client.c +++ b/Platform/user/rpc/rpc_client.c @@ -11,6 +11,7 @@ #include "rpc_thread.h" #include "rpc_module.h" #include "rpc_conn.h" +#include "rpc_util.h" #include #include @@ -22,6 +23,7 @@ #include #include #include +#include //server: one thread multiply connection. a connection would block a thread //client: one thread one connection @@ -137,9 +139,11 @@ ret_code rpc_client_call(rpc_client* client, char* service_name, int* output_len) { int n_fd = eventfd(0, 0); rpc_response rsp; - + long time_diff; + assert(client!=NULL); rsp.data = (INT_TO_POINTER(n_fd)); + time_diff = rpc_time_msec(); rpc_client_call_async(client, service_name, method_name, input, input_len, cb_call_ex, &rsp); @@ -154,6 +158,13 @@ ret_code rpc_client_call(rpc_client* client, char* service_name, int rt = select(n_fd + 1, &r_set, NULL, NULL, &tm); close(n_fd); + + time_diff = rpc_time_msec()-time_diff; + if(time_diff > TIMEWARN) + { + rpc_log_warn("call %s@%s cost %ld\n",service_name, method_name, time_diff); + } + if (rt == -1) { return RET_UNKNOWN; } else if (rt == 0) { diff --git a/Platform/user/rpc/rpc_util.c b/Platform/user/rpc/rpc_util.c index bc6191675..d40b631a4 100755 --- a/Platform/user/rpc/rpc_util.c +++ b/Platform/user/rpc/rpc_util.c @@ -62,4 +62,13 @@ uint rpc_str_hash(constpointer v) { return h; } +long rpc_time_msec(void) +{ + struct timespec tp = {0}; + + clock_gettime (CLOCK_MONOTONIC, &tp); + + return(tp.tv_sec * 1000 + tp.tv_nsec / (1000 *1000)); +} +