From 2561a007b8d8999a4750046d0cfb3b1ad5af50ac Mon Sep 17 00:00:00 2001 From: zhangmeng <775834166@qq.com> Date: 星期二, 09 四月 2024 15:29:32 +0800 Subject: [PATCH] test for perf --- src/bh_api.cpp | 58 +++++++++++++++++++++++++++++++++++++++++++++------------- 1 files changed, 45 insertions(+), 13 deletions(-) diff --git a/src/bh_api.cpp b/src/bh_api.cpp index c74c80d..c450bc2 100644 --- a/src/bh_api.cpp +++ b/src/bh_api.cpp @@ -3,6 +3,7 @@ #include "bus_server_socket_wrapper.h" #include "shm_mm_wrapper.h" #include "proc_def.h" +#include "mm.h" #include "usg_common.h" #include "bh_api.h" #include <pthread.h> @@ -17,6 +18,7 @@ static Logger *logger = LoggerFactory::getLogger(); static int gRun_stat = 0; +static int gRun_flag = true; static void *gNetmod_socket = NULL; static pthread_mutex_t mutex; @@ -39,21 +41,22 @@ nsec = 0; sprintf(buf, "%s", STR_EXEC); data = net_mod_socket_int_get(gNetmod_socket); - while(true) { + while(gRun_flag == true) { rv = net_mod_socket_recvfrom(gNetmod_socket, &buf_temp, &size, &key, SVR_STR, data); if (rv == 0) { - BHFree(buf_temp, size); + if (strncmp((char *)buf_temp, STR_RET, strlen(STR_RET)) != 0) { - if ((gNetmod_socket != NULL) && (gRun_stat != 0)) { rv = net_mod_socket_sendto_timeout(gNetmod_socket, buf, strlen(buf), key, sec, nsec, SVR_STR, data); if (rv != 0) { logger->error("the process check response failed with error: %s!\n", bus_strerror(rv)); } } else { - break; + gRun_flag = false; } + + BHFree(buf_temp, size); } else { @@ -234,6 +237,7 @@ #endif if (rv == 0) { + gRun_flag = true; pthread_create(&gTids, NULL, client_run_check, NULL); return true; @@ -246,8 +250,11 @@ { int rv; int min; + int data; + int diff; void *buf = NULL; char *errString = NULL; + struct timeval start, end; #if defined(PRO_DE_SERIALIZE) struct _ProcInfo_proto @@ -295,7 +302,23 @@ if (rv == 0) { rv = net_mod_socket_reg(gNetmod_socket, NULL, 0, NULL, 0, timeout_ms, PROC_UNREG); if (rv == 0) { - + gettimeofday(&start, NULL); + data = net_mod_socket_int_get(gNetmod_socket); + rv = net_mod_socket_sendto_timeout(gNetmod_socket, STR_RET, strlen(STR_RET), data, 3, 0); + if (rv != 0) { + logger->error("the process check response failed with error: %s!\n", bus_strerror(rv)); + } + + while(gRun_flag == true) { + sleep(1); + + gettimeofday(&end, NULL); + + diff = end.tv_sec - start.tv_sec; + if (diff >= TIME_DUR) + break; + }; + net_mod_socket_close(gNetmod_socket); gNetmod_socket = NULL; @@ -1221,7 +1244,8 @@ char data_buf[MAX_STR_LEN] = { 0x00 }; char buf_temp[MAX_STR_LEN] = { 0x00 }; char *topics_buf = NULL; - + hashtable_t *hashtable = mm_get_hashtable(); + #if defined(PRO_DE_SERIALIZE) struct _BHAddress { @@ -1278,14 +1302,19 @@ #else strncpy(buf_temp, (char *)request, (sizeof(buf_temp) - 1) > strlen((char *)request) ? strlen((char *)request) : (sizeof(buf_temp) - 1)); #endif - + str = buf_temp; val = net_mod_socket_buf_data_get(gNetmod_socket, str); - if(val > 0) { - + if ((val > 0) && (hashtable_get(hashtable, val) != NULL)) { + rv = 0; } else { + + if ((val > 0) && (hashtable_get(hashtable, val) == NULL)) { + net_mod_socket_buf_data_del(gNetmod_socket, str); + } + rv = net_mod_socket_reg(gNetmod_socket, buf_temp, strlen(buf_temp), &buf, &size, timeout_ms, PROC_QUE_STCS); if (rv == 0) { @@ -1397,7 +1426,8 @@ char *errString = NULL; char buf_temp[MAX_STR_LEN] = { 0x00 }; char *topics_buf = NULL; - + hashtable_t *hashtable = mm_get_hashtable(); + struct _RequestReply { std::string proc_id; @@ -1464,11 +1494,13 @@ str = buf_temp; val = net_mod_socket_buf_data_get(gNetmod_socket, str); - if(val > 0) { - + if ((val > 0) && (hashtable_get(hashtable, val) != NULL)) { rv = 0; - } else { + if ((val > 0) && (hashtable_get(hashtable, val) == NULL)) { + net_mod_socket_buf_data_del(gNetmod_socket, str); + } + rv = net_mod_socket_reg(gNetmod_socket, buf_temp, strlen(buf_temp), &buf, &size, timeout_ms, PROC_QUE_STCS); if (rv == 0) { -- Gitblit v1.8.0