提交环形缓冲区相关修改
This commit is contained in:
@@ -86,26 +86,26 @@ void call_logger(int log_num, int thread_num)
|
|||||||
|
|
||||||
void *thread_logger(void *arg)
|
void *thread_logger(void *arg)
|
||||||
{
|
{
|
||||||
int thread_num = (int)(unsigned long long)arg;
|
int thread_num = (int)(unsigned long long)arg;
|
||||||
printf("thread %d created! \n", thread_num);
|
printf("thread %d created! \n", thread_num);
|
||||||
call_logger(g_log_num, thread_num);
|
call_logger(g_log_num, thread_num);
|
||||||
printf("thread %d finished! \n", thread_num);
|
printf("thread %d finished! \n", thread_num);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sig_int_handler(int sig)
|
void sig_int_handler(int sig)
|
||||||
{
|
{
|
||||||
printf("ctrl+c recviced!\n");
|
printf("ctrl+c recviced!\n");
|
||||||
MESA_destroy_runtime_log_handle(sample_handle);
|
MESA_destroy_runtime_log_handle(sample_handle);
|
||||||
MESA_destroy_runtime_log_handle(test_handle);
|
MESA_destroy_runtime_log_handle(test_handle);
|
||||||
sample_handle = NULL;
|
sample_handle = NULL;
|
||||||
test_handle = NULL;
|
test_handle = NULL;
|
||||||
if (g_mode == 2)
|
if (g_mode == 2)
|
||||||
{
|
{
|
||||||
MESA_handle_runtime_log_destruction();
|
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);
|
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);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sig_hup_handler(int sig)
|
void sig_hup_handler(int sig)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "MESA_handle_logger.h"
|
#include "MESA_handle_logger.h"
|
||||||
|
#include "MESA_shm_ring_queue.h"
|
||||||
#include "snprintf.h"
|
#include "snprintf.h"
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include "zlog.h"
|
#include "zlog.h"
|
||||||
@@ -30,6 +31,7 @@ struct MESA_pthread_private{
|
|||||||
char *cache_buf;
|
char *cache_buf;
|
||||||
int fmt_buf_len;
|
int fmt_buf_len;
|
||||||
int cache_buf_len;
|
int cache_buf_len;
|
||||||
|
struct MESA_shm_queue_head *ring_queue_head;
|
||||||
};
|
};
|
||||||
struct MESA_fmt_obj{
|
struct MESA_fmt_obj{
|
||||||
char sign;
|
char sign;
|
||||||
@@ -216,6 +218,12 @@ struct MESA_pthread_private *MESA_create_pthread_private(void *handle)
|
|||||||
if(pri->cache_buf == NULL){
|
if(pri->cache_buf == NULL){
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
pri->ring_queue_head = MESA_shm_get_ring_queue();
|
||||||
|
/*
|
||||||
|
if(pri->queue_head == NULL){
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
*/
|
||||||
return pri;
|
return pri;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
@@ -237,6 +245,9 @@ void MESA_free_pthread_private(void *arg)
|
|||||||
if(pri == NULL){
|
if(pri == NULL){
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
|
if(pri->ring_queue_head){
|
||||||
|
MESA_shm_recycle_ring_queue(pri->ring_queue_head);
|
||||||
|
}
|
||||||
if(pri->fmt_buf){
|
if(pri->fmt_buf){
|
||||||
free(pri->fmt_buf);
|
free(pri->fmt_buf);
|
||||||
}
|
}
|
||||||
@@ -252,6 +263,8 @@ void MESA_free_pthread_private(void *arg)
|
|||||||
void MESA_alloc_pthread_key()
|
void MESA_alloc_pthread_key()
|
||||||
{
|
{
|
||||||
pthread_key_create(&MESA_pthread_key, MESA_free_pthread_private);
|
pthread_key_create(&MESA_pthread_key, MESA_free_pthread_private);
|
||||||
|
MESA_shm_init_overview();
|
||||||
|
MESA_shm_init_mutex();
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -334,9 +347,10 @@ void MESA_handle_runtime_log(void *handle, int level, const char *module, const
|
|||||||
pri->cache_buf_len = n + 1;
|
pri->cache_buf_len = n + 1;
|
||||||
pri->cache_buf = p;
|
pri->cache_buf = p;
|
||||||
va_copy(ap_bk, ap);
|
va_copy(ap_bk, ap);
|
||||||
portable_vsnprintf(handle, pri->cache_buf, pri->cache_buf_len, fmt, ap_bk);
|
n = portable_vsnprintf(handle, pri->cache_buf, pri->cache_buf_len, fmt, ap_bk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
MESA_shm_copy_buf_to_ring_queue(pri->cache_buf, n, pri->ring_queue_head);
|
||||||
|
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
va_end(ap_bk);
|
va_end(ap_bk);
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ CFLAGS_+= -fsanitize=address -fno-omit-frame-pointer
|
|||||||
LIB+=-lasan
|
LIB+=-lasan
|
||||||
endif
|
endif
|
||||||
|
|
||||||
SRC=MESA_handle_logger.c
|
SRC=MESA_handle_logger.c MESA_shm_ring_queue.c
|
||||||
OBJS=$(SRC:.c=.o)
|
OBJS=$(SRC:.c=.o)
|
||||||
|
|
||||||
TARGET=libMESA_handle_logger.a libMESA_handle_logger.so
|
TARGET=libMESA_handle_logger.a libMESA_handle_logger.so
|
||||||
@@ -26,10 +26,10 @@ all:$(TARGET)
|
|||||||
cp -f $(TARGET) ../lib
|
cp -f $(TARGET) ../lib
|
||||||
|
|
||||||
libMESA_handle_logger.a:$(OBJS)
|
libMESA_handle_logger.a:$(OBJS)
|
||||||
ar cqs $@ $<
|
ar cqs $@ $^
|
||||||
|
|
||||||
libMESA_handle_logger.so:$(OBJS)
|
libMESA_handle_logger.so:$(OBJS)
|
||||||
$(CC) $(CFLAGS) $(LIB) -shared $< -o $@
|
$(CC) $(CFLAGS) $(LIB) -shared $^ -o $@
|
||||||
.c.o:
|
.c.o:
|
||||||
|
|
||||||
#$(OBJS):$(SRC)
|
#$(OBJS):$(SRC)
|
||||||
|
|||||||
Reference in New Issue
Block a user