From c21cdcb3f0f923e25da7d1a918218c6ef870aba9 Mon Sep 17 00:00:00 2001 From: yangwei Date: Sun, 6 Sep 2020 18:46:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0test=5Fhandle=5Flog=EF=BC=8C?= =?UTF-8?q?=E9=80=82=E9=85=8D=E6=9B=B4=E6=96=B0zlog=E5=90=8E=E7=9A=84?= =?UTF-8?q?=E4=B8=89=E4=B8=AA=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- demo/test_handle_logger.c | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/demo/test_handle_logger.c b/demo/test_handle_logger.c index 71d0a34..d4d6e2f 100644 --- a/demo/test_handle_logger.c +++ b/demo/test_handle_logger.c @@ -14,6 +14,7 @@ void *test_handle = NULL; int g_log_num = 0; int g_thread_num = 0; +const char *g_zlog_conf = NULL; volatile long g_start_time = 0; volatile long g_end_time = 0; @@ -37,11 +38,11 @@ void call_logger(int log_num, int thread_num) } for(i = 0; i < log_num; i++) { - MESA_handle_runtime_log(sample_handle, RLOG_LV_INFO, "sample", "sample_handle MESA_handle_runtime_log, i = %d, thread_num = %d", i, thread_num); + MESA_handle_runtime_log(sample_handle, RLOG_LV_DEBUG, "sample", "sample_handle MESA_handle_runtime_log, i = %d, thread_num = %d", i, thread_num); //sleep(1); MESA_handle_runtime_log(test_handle, RLOG_LV_INFO, "test", "test_handle MESA_handle_runtime_log, i = %d, thread_num = %d", i, thread_num); //MESA_HANDLE_RUNTIME_LOG(sample_handle, RLOG_LV_FATAL, "sample", "sample_handle RUNTIEM_LOG test, i = %d, thread_num = %d", i, thread_num); - ////sleep(1); + //sleep(1); //MESA_HANDLE_RUNTIME_LOG(test_handle, RLOG_LV_FATAL, "test", "test_handle RUNTIEM_LOG test, i = %d, thread_num = %d", i, thread_num); } clock_gettime(CLOCK_MONOTONIC, &end); @@ -72,35 +73,48 @@ void *thread_logger(void *arg) return NULL; } -void sig_handler(int sig) +void sig_int_handler(int sig) { printf("ctrl+c recviced!\n"); MESA_destroy_runtime_log_handle(sample_handle); MESA_destroy_runtime_log_handle(test_handle); sample_handle = NULL; test_handle = NULL; - printf("%d thread write %d log using %ld us, avg speed %f /s, %ld -> %ld\n", g_thread_num, g_thread_num*g_log_num, g_end_time-g_start_time, ((float)(g_thread_num*g_log_num)/(float)(g_end_time-g_start_time))*1000000, g_start_time, g_end_time); + MESA_handle_runtime_log_destruction(); + printf("%d thread write %d log using %ld us, avg speed %f /s, %ld -> %ld\n", g_thread_num, g_thread_num * g_log_num, g_end_time - g_start_time, ((float)(g_thread_num * g_log_num) / (float)(g_end_time - g_start_time)) * 1000000, g_start_time, g_end_time); exit(0); } +void sig_hup_handler(int sig) +{ + printf("SIGHUP recviced!\n"); + MESA_handle_runtime_log_reconstruction(g_zlog_conf); +} + int main(int argc, char ** args) { pthread_t t[MAX_THREAD_NUM]; int i = 0; - if(argc != 3) + if(argc != 4) { - printf("Usage: ./($app) $thread_num $log_num \n"); + printf("Usage: ./($app) $zlog_conf_path $thread_num $log_num \n"); return -1; } - g_thread_num = atoi(args[1]); - g_log_num = atoi(args[2]); + g_zlog_conf = args[1]; + g_thread_num = atoi(args[2]); + g_log_num = atoi(args[3]); if(g_thread_num <= 0 || g_log_num <= 0) { printf("Error, wrong parameter!\n"); return -1; } + if(0 != MESA_handle_runtime_log_creation(g_zlog_conf)) + { + printf("MESA_handle_runtime_log_creation return error\n"); + return -1; + } sample_handle = MESA_create_runtime_log_handle("./log/sample_log", RLOG_LV_DEBUG); if (sample_handle == NULL) { @@ -119,7 +133,8 @@ int main(int argc, char ** args) { pthread_create(&t[i], NULL, thread_logger, (void *)(unsigned long)(i)); } - signal(SIGINT, sig_handler); + signal(SIGINT, sig_int_handler); + signal(SIGHUP, sig_hup_handler); while(1) ; //MESA_destroy_runtime_log_handle(sample_handle);