Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1dd9e1e0f2 | ||
|
|
7fa29b1a00 | ||
|
|
8680c2f4f5 | ||
|
|
c0620c8d25 | ||
|
|
4d64f0cf06 |
@@ -16,6 +16,7 @@ void *test_handle = NULL;
|
|||||||
int g_mode = 0;
|
int g_mode = 0;
|
||||||
int g_log_num = 0;
|
int g_log_num = 0;
|
||||||
int g_thread_num = 0;
|
int g_thread_num = 0;
|
||||||
|
int g_sleep_interval = 0;
|
||||||
const char *g_zlog_conf = NULL;
|
const char *g_zlog_conf = NULL;
|
||||||
volatile long g_start_time = 0;
|
volatile long g_start_time = 0;
|
||||||
volatile long g_end_time = 0;
|
volatile long g_end_time = 0;
|
||||||
@@ -44,7 +45,11 @@ void call_logger(int log_num, int thread_num)
|
|||||||
//sleep(1);
|
//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(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);
|
//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);
|
if(g_sleep_interval > 0)
|
||||||
|
{
|
||||||
|
printf("MESA_handle_runtime_log_level_enabled(%d) return %d\n", RLOG_LV_DEBUG, MESA_handle_runtime_log_level_enabled(test_handle, RLOG_LV_DEBUG));
|
||||||
|
sleep(g_sleep_interval);
|
||||||
|
}
|
||||||
//MESA_HANDLE_RUNTIME_LOG(test_handle, RLOG_LV_FATAL, "test", "test_handle RUNTIEM_LOG test, i = %d, thread_num = %d", i, thread_num);
|
//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);
|
clock_gettime(CLOCK_MONOTONIC, &end);
|
||||||
@@ -60,8 +65,9 @@ void call_logger(int log_num, int thread_num)
|
|||||||
g_end_time = end_time;
|
g_end_time = end_time;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
time_cost = (end.tv_sec - start.tv_sec) * 1000000 + (end.tv_nsec - start.tv_nsec) / 1000 ;
|
time_cost = (end.tv_sec - start.tv_sec) * 1000000 + (end.tv_nsec - start.tv_nsec) / 1000 - g_sleep_interval * 1000000 ;
|
||||||
printf("THREAD %d write %d log using %ld us, avg speed %f /s, %ld -> %ld\n", thread_num, log_num, time_cost, ((float)log_num/(float)time_cost)*1000000, start_time, end_time);
|
printf("THREAD %d write %d log using %ld us, avg speed %f /s, %ld -> %ld\n", thread_num, log_num, time_cost, ((float)log_num/(float)time_cost)*1000000, start_time, end_time);
|
||||||
|
printf("MESA_handle_runtime_log_level_enabled(%d) return %d\n", RLOG_LV_DEBUG, MESA_handle_runtime_log_level_enabled(test_handle, RLOG_LV_DEBUG));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,15 +107,16 @@ int main(int argc, char ** args)
|
|||||||
pthread_t t[MAX_THREAD_NUM];
|
pthread_t t[MAX_THREAD_NUM];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
if (argc != 5)
|
if (argc != 6)
|
||||||
{
|
{
|
||||||
printf("Usage: ./($app) $mode[1 or 2] $zlog_conf_path $thread_num $log_num \n");
|
printf("Usage: ./($app) $version_mode[1 or 2] $zlog_conf_path $thread_num $log_num $sleep_interval\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
g_mode = atoi(args[1]);
|
g_mode = atoi(args[1]);
|
||||||
g_zlog_conf = args[2];
|
g_zlog_conf = args[2];
|
||||||
g_thread_num = atoi(args[3]);
|
g_thread_num = atoi(args[3]);
|
||||||
g_log_num = atoi(args[4]);
|
g_log_num = atoi(args[4]);
|
||||||
|
g_sleep_interval = atoi(args[5]);
|
||||||
|
|
||||||
if(g_thread_num <= 0 || g_log_num <= 0)
|
if(g_thread_num <= 0 || g_log_num <= 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -27,6 +27,19 @@ void MESA_handle_runtime_log_destruction();
|
|||||||
MESA_handle_runtime_log((handle), (lv), (mod), "file %s, line %d, " fmt, \
|
MESA_handle_runtime_log((handle), (lv), (mod), "file %s, line %d, " fmt, \
|
||||||
__FILE__, __LINE__, ##args)
|
__FILE__, __LINE__, ##args)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
#define MESA_HANDLE_RUNTIME_LOG_EXPAND(handle, level, module, fmt, ...) \
|
||||||
|
{ \
|
||||||
|
if (MESA_handle_runtime_log_level_enabled(handle, level)) \
|
||||||
|
{ \
|
||||||
|
MESA_handle_runtime_log(handle, level, module, fmt, __VA_ARGS__); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
int MESA_handle_runtime_log_level_enabled(void *handle, const int level);
|
||||||
/*
|
/*
|
||||||
* name: MESA_create_runtime_log_handle
|
* name: MESA_create_runtime_log_handle
|
||||||
* functionality: get runtime_log handle;
|
* functionality: get runtime_log handle;
|
||||||
|
|||||||
@@ -14,13 +14,13 @@ static int g_zlog_conf_fp = -1;
|
|||||||
static char global_conf_filepath[MAX_HANDLE_LOG_PATH] = "";
|
static char global_conf_filepath[MAX_HANDLE_LOG_PATH] = "";
|
||||||
static char tmp_conf_filepath[MAX_HANDLE_LOG_PATH] = "";
|
static char tmp_conf_filepath[MAX_HANDLE_LOG_PATH] = "";
|
||||||
|
|
||||||
typedef struct log_handle_t
|
struct log_handle_t
|
||||||
{
|
{
|
||||||
int runtime_log_level;
|
int runtime_log_level;
|
||||||
zlog_category_t *zc;
|
zlog_category_t *zc;
|
||||||
const char *global_conf_path;
|
const char *global_conf_path;
|
||||||
char runtime_log_file[MAX_HANDLE_LOG_PATH];
|
char runtime_log_file[MAX_HANDLE_LOG_PATH];
|
||||||
} log_handle_t;
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -171,11 +171,11 @@ void *MESA_create_runtime_log_handle(const char *file_path, int level)
|
|||||||
int rc = -1;
|
int rc = -1;
|
||||||
zlog_category_t *zc = NULL;
|
zlog_category_t *zc = NULL;
|
||||||
FILE *fp = NULL;
|
FILE *fp = NULL;
|
||||||
log_handle_t *p_handle = NULL;
|
struct log_handle_t *handle = NULL;
|
||||||
|
|
||||||
char handle_name[MAX_HANDLE_LOG_PATH];
|
char handle_name[MAX_HANDLE_LOG_PATH];
|
||||||
char *p_path_end = rindex(file_path, '/');
|
char *p_path_end = rindex(file_path, '/');
|
||||||
char *p_name = p_path_end+1;
|
char *p_name;
|
||||||
|
|
||||||
strcpy(handle_name, file_path);
|
strcpy(handle_name, file_path);
|
||||||
escape_for_zlog(handle_name, strlen(handle_name));
|
escape_for_zlog(handle_name, strlen(handle_name));
|
||||||
@@ -195,11 +195,11 @@ void *MESA_create_runtime_log_handle(const char *file_path, int level)
|
|||||||
{
|
{
|
||||||
fprintf(stderr,"[MESA_create_runtime_log_handle], get zlog category (%s) in global_conf_filepath(%s) fail\n", p_name, global_conf_filepath);
|
fprintf(stderr,"[MESA_create_runtime_log_handle], get zlog category (%s) in global_conf_filepath(%s) fail\n", p_name, global_conf_filepath);
|
||||||
}
|
}
|
||||||
p_handle = (log_handle_t *)calloc(sizeof(log_handle_t), 1);
|
handle = (struct log_handle_t *)calloc(sizeof(struct log_handle_t), 1);
|
||||||
strncpy(p_handle->runtime_log_file, file_path, sizeof(p_handle->runtime_log_file) - 1);
|
strncpy(handle->runtime_log_file, file_path, sizeof(handle->runtime_log_file) - 1);
|
||||||
p_handle->runtime_log_level = level;
|
handle->runtime_log_level = level;
|
||||||
p_handle->zc = zc;
|
handle->zc = zc;
|
||||||
return (void *)p_handle;
|
return (void *)handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MESA_destroy_runtime_log_handle(void *handle)
|
void MESA_destroy_runtime_log_handle(void *handle)
|
||||||
@@ -214,19 +214,28 @@ void MESA_destroy_runtime_log_handle(void *handle)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MESA_handle_runtime_log(void *handle, int level, const char *module, const char *fmt, ...)
|
int MESA_handle_runtime_log_level_enabled(void *v_handle, const int level)
|
||||||
{
|
{
|
||||||
|
struct log_handle_t *handle = (struct log_handle_t *)v_handle;
|
||||||
|
if(handle == NULL || handle->runtime_log_file == NULL)return;
|
||||||
|
if(handle->zc == NULL) return;
|
||||||
|
return zlog_level_enabled(handle->zc, level);
|
||||||
|
}
|
||||||
|
|
||||||
log_handle_t *p_handle = (log_handle_t *)handle;
|
void MESA_handle_runtime_log(void *v_handle, int level, const char *module, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
struct log_handle_t *handle = (struct log_handle_t *)v_handle;
|
||||||
|
if(handle == NULL || handle->runtime_log_file == NULL)return;
|
||||||
|
|
||||||
if(p_handle == NULL || p_handle->runtime_log_file == NULL)return;
|
if(handle->zc == NULL)return;
|
||||||
|
|
||||||
if(p_handle->zc == NULL)return;
|
|
||||||
|
|
||||||
|
if (zlog_level_enabled(handle->zc, level))
|
||||||
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
vzlog(p_handle->zc, p_handle->runtime_log_file, strlen(p_handle->runtime_log_file), module, strlen(module), __LINE__, level, fmt, ap);
|
vzlog(handle->zc, handle->runtime_log_file, strlen(handle->runtime_log_file), module, strlen(module), __LINE__, level, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
}
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,6 +244,14 @@ int MESA_handle_runtime_log_creation(const char *conf_path)
|
|||||||
{
|
{
|
||||||
char *env = getenv("ZLOG_CONF_PATH");
|
char *env = getenv("ZLOG_CONF_PATH");
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
|
||||||
|
if(g_zlog_inited == 1)
|
||||||
|
{
|
||||||
|
rc = zlog_reload(conf_path);
|
||||||
|
zlog_profile();
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
if (conf_path == NULL || (access(conf_path, R_OK) != 0))
|
if (conf_path == NULL || (access(conf_path, R_OK) != 0))
|
||||||
{
|
{
|
||||||
fprintf(stderr,"[MESA_handle_runtime_log_creation], PATH (%s) unable to access, will output log to STDOUT or Using ZLOG_CONF_PATH (%s) !\n", conf_path, env);
|
fprintf(stderr,"[MESA_handle_runtime_log_creation], PATH (%s) unable to access, will output log to STDOUT or Using ZLOG_CONF_PATH (%s) !\n", conf_path, env);
|
||||||
@@ -327,4 +344,5 @@ void MESA_handle_runtime_log_destruction()
|
|||||||
unlink(tmp_conf_filepath);
|
unlink(tmp_conf_filepath);
|
||||||
close(g_zlog_conf_fp);
|
close(g_zlog_conf_fp);
|
||||||
}
|
}
|
||||||
|
g_zlog_inited=0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ cmake_minimum_required (VERSION 3.5)
|
|||||||
include(ExternalProject)
|
include(ExternalProject)
|
||||||
|
|
||||||
ExternalProject_Add(zlog PREFIX zlog
|
ExternalProject_Add(zlog PREFIX zlog
|
||||||
URL ${CMAKE_CURRENT_SOURCE_DIR}/zlog-1.2.15.tar.gz
|
URL ${CMAKE_CURRENT_SOURCE_DIR}/zlog-1.2.16.tar.gz
|
||||||
URL_MD5 5e79f8d08744c7fef8528dd55a3bcd2d
|
URL_MD5 4dcfe75a1acbb5c4513bbe168f935993
|
||||||
CONFIGURE_COMMAND ""
|
CONFIGURE_COMMAND ""
|
||||||
BUILD_COMMAND make
|
BUILD_COMMAND make
|
||||||
INSTALL_COMMAND ""
|
INSTALL_COMMAND ""
|
||||||
|
|||||||
Binary file not shown.
BIN
zlog/zlog-1.2.16.tar.gz
Normal file
BIN
zlog/zlog-1.2.16.tar.gz
Normal file
Binary file not shown.
Reference in New Issue
Block a user