9 Commits

10 changed files with 227 additions and 277 deletions

View File

@@ -1,115 +1,177 @@
image: "git.mesalab.cn:7443/mesa_platform/build-env:master"
variables:
GIT_STRATEGY: "clone"
BUILD_IMAGE_X86_64_ROCKY8: "git.mesalab.cn:7443/mesa_platform/build-env:rockylinux"
BUILD_IMAGE_AARCH64_ROCKY9: "git.mesalab.cn:7443/mesa_platform/build-env:rocky9-aarch64"
BUILD_PADDING_PREFIX: /tmp/padding_for_CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX_PREFIX_PREFIX_PREFIX_PREFIX_PREFIX/
INSTALL_PREFIX: "/opt/MESA/lib/"
INSTALL_DEPENDENCY_LIBRARY: ""
INSTALL_DEPENDENCY_LIBRARY: libasan
stages:
- build
- test
.build_by_travis:
.build_before_script:
before_script:
- mkdir -p $BUILD_PADDING_PREFIX/$CI_PROJECT_NAMESPACE/
- ln -s $CI_PROJECT_DIR $BUILD_PADDING_PREFIX/$CI_PROJECT_PATH
- cd $BUILD_PADDING_PREFIX/$CI_PROJECT_PATH
- chmod +x ./ci/travis.sh
###############################################################################
# build on x86_64 Rocky8
###############################################################################
.build_by_travis_for_x86_64_rocky8:
stage: build
image: $BUILD_IMAGE_X86_64_ROCKY8
extends: .build_before_script
script:
- ./ci/travis.sh
tags:
- tsg-os-builder-el8
run_test_for_x86_64_rocky8:
stage: test
image: $BUILD_IMAGE_X86_64_ROCKY8
extends: .build_by_travis_for_x86_64_rocky8
script:
- wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
- yum makecache fast
- ./ci/travis.sh
- cd build
tags:
- share
- ctest --verbose
branch_build_debug:
branch_build_debug_for_x86_64_rocky8:
stage: build
extends: .build_by_travis
extends: .build_by_travis_for_x86_64_rocky8
variables:
BUILD_TYPE: Debug
except:
- /^develop.*$/i
- /^master.*$/i
- /^dev*.*$/i
- /^rel*.*$/i
- /^master.*$/i
- tags
branch_build_release:
branch_build_release_for_x86_64_rocky8:
stage: build
variables:
BUILD_TYPE: RelWithDebInfo
extends: .build_by_travis
extends: .build_by_travis_for_x86_64_rocky8
except:
- /^develop.*$/i
- /^master.*$/i
- /^dev*.*$/i
- /^rel*.*$/i
- /^master.*$/i
- tags
develop_build_debug:
release_build_debug_for_x86_64_rocky88:
stage: build
extends: .build_by_travis
variables:
BUILD_TYPE: Debug
PACKAGE: 1
UPLOAD_RPM: 1
ASAN_OPTION: ADDRESS
PULP3_REPO_NAME: framework-testing-x86_64.el7
PULP3_DIST_NAME: framework-testing-x86_64.el7
PULP3_REPO_NAME: framework-stable-x86_64.el8
PULP3_DIST_NAME: framework-stable-x86_64.el8
extends: .build_by_travis_for_x86_64_rocky8
artifacts:
name: "MESA_handle_logger-$CI_COMMIT_REF_NAME-debug"
paths:
- build/*.rpm
only:
- /^dev*.*$/i
- /^rel*.*$/i
- /^master.*$/i
- tags
develop_build_release:
release_build_release_for_x86_64_rocky8:
stage: build
extends: .build_by_travis
variables:
BUILD_TYPE: RelWithDebInfo
PACKAGE: 1
UPLOAD_RPM: 1
ASAN_OPTION: "OFF"
PULP3_REPO_NAME: framework-testing-x86_64.el7
PULP3_DIST_NAME: framework-testing-x86_64.el7
SYMBOL_TARGET: libMESA_handle_logger
PULP3_REPO_NAME: framework-stable-x86_64.el8
PULP3_DIST_NAME: framework-stable-x86_64.el8
extends: .build_by_travis_for_x86_64_rocky8
artifacts:
name: "MESA_handle_logger-$CI_COMMIT_REF_NAME-release"
paths:
- build/*.rpm
only:
- tags
###############################################################################
# build on aarch64 Rocky9
###############################################################################
.build_by_travis_for_aarch64_rocky9:
stage: build
image: $BUILD_IMAGE_AARCH64_ROCKY9
extends: .build_before_script
script:
- ./ci/travis.sh
tags:
- tsg-os-builder-aarch64
run_test_for_aarch64_rocky9:
stage: test
image: $BUILD_IMAGE_AARCH64_ROCKY9
extends: .build_by_travis_for_aarch64_rocky9
script:
- ./ci/travis.sh
- cd build
- ctest --verbose
branch_build_debug_for_aarch64_rocky9:
stage: build
extends: .build_by_travis_for_aarch64_rocky9
variables:
BUILD_TYPE: Debug
except:
- /^develop.*$/i
- /^master.*$/i
- /^dev*.*$/i
- /^rel*.*$/i
- tags
branch_build_release_for_aarch64_rocky9:
stage: build
variables:
BUILD_TYPE: RelWithDebInfo
extends: .build_by_travis_for_aarch64_rocky9
except:
- /^develop.*$/i
- /^master.*$/i
- /^dev*.*$/i
- /^rel*.*$/i
- tags
release_build_debug:
release_build_debug_for_aarch64_rocky9:
stage: build
variables:
BUILD_TYPE: Debug
PACKAGE: 1
UPLOAD_RPM: 1
PULP3_REPO_NAME: framework-stable-x86_64.el7
PULP3_DIST_NAME: framework-stable-x86_64.el7
extends: .build_by_travis
PULP3_REPO_NAME: framework-stable-aarch64.el9
PULP3_DIST_NAME: framework-stable-aarch64.el9
extends: .build_by_travis_for_aarch64_rocky9
artifacts:
name: "MESA_handle_logger-$CI_COMMIT_REF_NAME-release"
name: "MESA_handle_logger-$CI_COMMIT_REF_NAME-debug"
paths:
- build/*.rpm
only:
- tags
release_build_release:
release_build_release_for_aarch64_rocky9:
stage: build
variables:
BUILD_TYPE: RelWithDebInfo
PACKAGE: 1
UPLOAD_RPM: 1
UPLOAD_SYMBOL_FILES: 1
SYMBOL_TARGET: libMESA_handle_logger
PULP3_REPO_NAME: framework-stable-x86_64.el7
PULP3_DIST_NAME: framework-stable-x86_64.el7
extends: .build_by_travis
PULP3_REPO_NAME: framework-stable-aarch64.el9
PULP3_DIST_NAME: framework-stable-aarch64.el9
extends: .build_by_travis_for_aarch64_rocky9
artifacts:
name: "MESA_handle_logger-$CI_COMMIT_REF_NAME-release"
paths:

View File

@@ -69,4 +69,9 @@ install(FILES conf/MESA_handle_logger.conf DESTINATION /usr/lib/tmpfiles.d/ COMP
add_executable(${lib_name}_demo demo/test_handle_logger.c)
target_link_libraries(${lib_name}_demo pthread ${lib_name}_shared)
enable_testing()
add_test(NAME test_compatible_mode COMMAND MESA_handle_logger_demo 1 ./demo_zlog.conf 1 100 0)
add_test(NAME test_perf COMMAND MESA_handle_logger_demo 2 ./demo_zlog.conf 1 1000 0)
include(Package)

View File

@@ -37,10 +37,6 @@ if [ -n "${INSTALL_DEPENDENCY_LIBRARY}" ]; then
yum install -y $INSTALL_DEPENDENCY_LIBRARY
fi
if [ $ASAN_OPTION ];then
source /opt/rh/devtoolset-7/enable
fi
mkdir build || true
cd build
@@ -62,10 +58,3 @@ if [ -n "${UPLOAD_RPM}" ]; then
cp ~/rpm_upload_tools.py ./
python3 rpm_upload_tools.py ${PULP3_REPO_NAME} ${PULP3_DIST_NAME} *.rpm
fi
if [ -n "${UPLOAD_SYMBOL_FILES}" ]; then
rpm -i $SYMBOL_TARGET*debuginfo*.rpm
_symbol_file=`find /usr/lib/debug/ -name "$SYMBOL_TARGET*.so*.debug"`
cp $_symbol_file ${_symbol_file}info.${CI_COMMIT_SHORT_SHA}
sentry-cli upload-dif -t elf ${_symbol_file}info.${CI_COMMIT_SHORT_SHA}
fi

View File

@@ -12,36 +12,32 @@ set(CPACK_PACKAGE_VERSION_MINOR "${VERSION_MINOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${VERSION_PATCH}.${VERSION_BUILD}")
set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
set(CPACK_PACKAGE_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}.${VERSION_BUILD}")
execute_process(COMMAND bash -c "echo -ne \"`uname -r | awk -F'.' '{print $5\".\"$6\".\"$7}'`\"" OUTPUT_VARIABLE SYSTEM_VERSION)
execute_process(COMMAND sh changelog.sh ${CMAKE_BINARY_DIR} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/cmake)
SET(CPACK_RPM_CHANGELOG_FILE ${CMAKE_BINARY_DIR}/changelog.txt)
# RPM Build
set(CPACK_GENERATOR "RPM")
set(CPACK_RPM_AUTO_GENERATED_FILE_NAME ON)
set(CPACK_RPM_FILE_NAME "RPM-DEFAULT")
set(CPACK_RPM_PACKAGE_VENDOR "MESA")
set(CPACK_RPM_PACKAGE_AUTOREQPROV "yes")
set(CPACK_RPM_PACKAGE_RELEASE_LIBRARY "on")
set(CPACK_RPM_PACKAGE_RELEASE_DIST "on")
set(CPACK_RPM_DEBUGINFO_PACKAGE "on")
set(CPACK_RPM_PACKAGE_DEBUG 1)
set(CPACK_RPM_COMPONENT_INSTALL ON)
set(CPACK_COMPONENTS_IGNORE_GROUPS 1)
set(CPACK_COMPONENTS_GROUPING ONE_PER_GROUP)
set(CPACK_COMPONENT_HEADER_DISPLAY_NAME "develop")
set(CPACK_COMPONENT_LIBRARIES_REQUIRED TRUE)
set(CPACK_RPM_LIBRARIES_PACKAGE_NAME ${MY_RPM_NAME_PREFIX})
set(CPACK_COMPONENT_LIBRARIES_GROUP "LIBRARIES")
set(CPACK_COMPONENT_EXECUTABLE_GROUP "LIBRARIES")
set(CPACK_COMPONENT_PROFILE_GROUP "LIBRARIES")
set(CPACK_COMPONENT_HEADER_REQUIRED TRUE)
set(CPACK_RPM_HEADER_PACKAGE_NAME "${MY_RPM_NAME_PREFIX}-devel")
set(CPACK_RPM_LIBRARIES_PACKAGE_NAME ${MY_RPM_NAME_PREFIX})
set(CPACK_RPM_FILE_NAME "${CPACK_RPM_LIBRARIES_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${SYSTEM_VERSION}.rpm")
set(CPACK_RPM_LIBRARIES_DEBUGINFO_FILE_NAME "${CPACK_RPM_LIBRARIES_PACKAGE_NAME}-debuginfo-${CPACK_PACKAGE_VERSION}-${SYSTEM_VERSION}.rpm")
set(CPACK_COMPONENT_LIBRARIES_GROUP "libraries")
set(CPACK_COMPONENT_EXECUTABLE_GROUP "libraries")
set(CPACK_COMPONENT_PROFILE_GROUP "libraries")
set(CPACK_RPM_HEADER_FILE_NAME "${CPACK_RPM_HEADER_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${SYSTEM_VERSION}.rpm")
set(CPACK_RPM_HEADER_DEBUGINFO_FILE_NAME "${CPACK_RPM_HEADER_PACKAGE_NAME}-debuginfo-${CPACK_PACKAGE_VERSION}-${SYSTEM_VERSION}.rpm")
set(CPACK_COMPONENT_HEADER_GROUP "header")
set(CPACK_RPM_HEADER_PACKAGE_REQUIRES_PRE ${CPACK_RPM_LIBRARIES_PACKAGE_NAME})

View File

@@ -16,12 +16,12 @@ void *test_handle = NULL;
int g_mode = 0;
int g_log_num = 0;
int g_thread_num = 0;
int g_log_print_way = 0;
int g_sleep_interval = 0;
const char *g_zlog_conf = NULL;
volatile long g_start_time = 0;
volatile long g_end_time = 0;
void call_logger(int log_num, int thread_num, int way)
void call_logger(int log_num, int thread_num)
{
int i = 0;
struct timespec start, end;
@@ -41,25 +41,16 @@ void call_logger(int log_num, int thread_num, int way)
}
for(i = 0; i < log_num; i++)
{
switch (way)
{
case 1:
MESA_handle_runtime_log(sample_handle, RLOG_LV_DEBUG, "sample", "sample_handle RUNTIEM_LOG test, 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);
break;
case 2:
MESA_HANDLE_RUNTIME_LOG_RATELIMIT(sample_handle, RLOG_LV_DEBUG, "sample", "sample_handle RUNTIEM_LOG test, i = %d, thread_num = %d", i, thread_num);
MESA_HANDLE_RUNTIME_LOG_RATELIMIT(test_handle, RLOG_LV_INFO, "test", "test_handle RUNTIEM_LOG test, i = %d, thread_num = %d", i, thread_num);
break;
case 3:
MESA_HANDLE_RUNTIME_LOG(sample_handle, RLOG_LV_DEBUG, "sample", "sample_handle RUNTIEM_LOG test, i = %d, thread_num = %d", i, thread_num);
MESA_HANDLE_RUNTIME_LOG(test_handle, RLOG_LV_INFO, "test", "test_handle RUNTIEM_LOG test, i = %d, thread_num = %d", i, thread_num);
break;
default:
break;
//MESA_HANDLE_RUNTIME_LOG(sample_handle, RLOG_LV_FATAL, "sample", "sample_handle RUNTIEM_LOG test, i = %d, thread_num = %d", i, thread_num);
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);
}
// if (i % 10000 == 0)
// 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);
end_time = end.tv_sec*1000000 + end.tv_nsec/1000;
@@ -74,8 +65,9 @@ void call_logger(int log_num, int thread_num, int way)
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("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;
}
@@ -84,7 +76,7 @@ void *thread_logger(void *arg)
{
int thread_num = (int)(unsigned long long)arg;
printf("thread %d created! \n", thread_num);
call_logger(g_log_num, thread_num, g_log_print_way);
call_logger(g_log_num, thread_num);
printf("thread %d finished! \n", thread_num);
return NULL;
}
@@ -110,39 +102,22 @@ void sig_hup_handler(int sig)
MESA_handle_runtime_log_reconstruction(g_zlog_conf);
}
void sig_user1_handler(int sig)
{
printf("SIGUSR1 recviced! set interval:3 burst:5\n");
MESA_set_runtime_log_handle_ratelimit(sample_handle, 3, 5);
}
void sig_user2_handler(int sig)
{
printf("SIGUSR2 recviced! set interval:5 burst:3\n");
MESA_set_runtime_log_handle_ratelimit(sample_handle, 5, 3);
}
void sig_min_handler(int sig)
{
printf("SIGRTMIN recviced! unlimit\n");
MESA_set_runtime_log_handle_ratelimit(sample_handle, 0, 3);
}
int main(int argc, char ** args)
{
pthread_t t[MAX_THREAD_NUM];
int i = 0;
int ret =0;
if (argc != 6)
{
printf("Usage: ./($app) $mode[1 or 2] $zlog_conf_path $thread_num $log_num $log_print_way[1 2 3]\n");
printf("Usage: ./($app) $version_mode[1 or 2] $zlog_conf_path $thread_num $log_num $sleep_interval\n");
return -1;
}
g_mode = atoi(args[1]);
g_zlog_conf = args[2];
g_thread_num = atoi(args[3]);
g_log_num = atoi(args[4]);
g_log_print_way = atoi(args[5]);
g_sleep_interval = atoi(args[5]);
if(g_thread_num <= 0 || g_log_num <= 0)
{
@@ -165,26 +140,32 @@ int main(int argc, char ** args)
}
test_handle = MESA_create_runtime_log_handle("./log/test_log", RLOG_LV_DEBUG);
if(test_handle == NULL)
if (test_handle == NULL)
{
printf("get log test_handle error\n");
return -1;
}
for(i = 0; i < g_thread_num; i++)
for (i = 0; i < g_thread_num; i++)
{
pthread_create(&t[i], NULL, thread_logger, (void *)(unsigned long)(i));
}
signal(SIGINT, sig_int_handler);
signal(SIGHUP, sig_hup_handler);
signal(SIGUSR1, sig_user1_handler);
signal(SIGUSR2, sig_user2_handler);
signal(SIGRTMIN, sig_min_handler);
while(1)
;
//MESA_destroy_runtime_log_handle(sample_handle);
//MESA_destroy_runtime_log_handle(test_handle);
//sample_handle = NULL;
//test_handle = NULL;
// 等待所有线程结束并回收
for (i = 0; i < g_thread_num; ++i) {
ret = pthread_join(t[i], NULL);
if (ret != 0) {
fprintf(stderr, "Failed to join thread %d\n", i);
return 1;
}
}
printf("All threads finished\n");
// MESA_destroy_runtime_log_handle(sample_handle);
// MESA_destroy_runtime_log_handle(test_handle);
// sample_handle = NULL;
// test_handle = NULL;
return 0;
}

View File

@@ -14,39 +14,26 @@ extern "C"
{
#endif
#include <pthread.h>
#define RLOG_LV_DEBUG 10
#define RLOG_LV_INFO 20
#define RLOG_LV_FATAL 30
typedef struct log_ratelimit_s
{
int interval;
int burst;
int printed;
int missed;
long begin;
pthread_mutex_t mutex;
}log_ratelimit_t;
int MESA_handle_runtime_log_creation(const char *conf_path);
int MESA_handle_runtime_log_reconstruction(const char *conf_path);
void MESA_handle_runtime_log_destruction();
#define MESA_HANDLE_RUNTIME_LOG(handle, lv, mod, fmt, args...) \
MESA_handle_runtime_log((handle), (lv), (mod), "file %s, line %d, " fmt, \
__FILE__, __LINE__, ##args)
#define MESA_HANDLE_RUNTIME_LOG_RATELIMIT(handle, lv, mod, fmt, args...) \
({ \
static log_ratelimit_t _rs = { \
.mutex = PTHREAD_MUTEX_INITIALIZER, \
}; \
if (MESA_runtime_log_ratelimit((handle), (&_rs), (lv), (mod), (__func__))) \
MESA_handle_runtime_log((handle), (lv), (mod), fmt, ##args); \
})
#define MESA_HANDLE_RUNTIME_LOG(handle, level, module, format, ...) \
do \
{ \
if (MESA_handle_runtime_log_level_enabled(handle, level)) \
{ \
MESA_handle_runtime_log(handle, level, module, "file %s, line %d, " format, \
__FILE__, __LINE__, ##__VA_ARGS__); \
} \
} while (0)
int MESA_handle_runtime_log_level_enabled(void *handle, const int level);
/*
* name: MESA_create_runtime_log_handle
* functionality: get runtime_log handle;
@@ -57,7 +44,7 @@ void MESA_handle_runtime_log_destruction();
* not NULL, if succeeded;
* NULL, if file is not absolute path, or failed to create log file;
*/
void *MESA_create_runtime_log_handle(const char *file_path, int level);
void *MESA_create_runtime_log_handle(const char *file_path, int level);
/*
* name: MESA_handle_runtime_log
@@ -83,18 +70,6 @@ void MESA_handle_runtime_log(void *handle, int level, const char *module, const
*/
void MESA_destroy_runtime_log_handle(void *handle);
/*
* name: MESA_set_runtime_log_handle_ratelimit
* functionality: set not more than @burst in every @interval when appends log message
* params:
* handle: runtime log handle which is going to be released;
* interval: interval time(second). if set '0', it means unlimit.
* burst: in interval time max count
* returns:
* none;
*/
void MESA_set_runtime_log_handle_ratelimit(void *handle, int interval, int burst);
#ifdef __cplusplus
}
#endif

View File

@@ -9,24 +9,18 @@
#include <time.h>
#define MAX_HANDLE_LOG_PATH 4096
#define DEFAULT_BURST 10
#define DEFAULT_INTERVAL 5
static int g_zlog_inited = 0;
static int g_zlog_conf_fp = -1;
static char global_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 interval;
int burst;
pthread_mutex_t mutex;
int runtime_log_level;
zlog_category_t *zc;
const char *global_conf_path;
char runtime_log_file[MAX_HANDLE_LOG_PATH];
} log_handle_t;
};
@@ -53,6 +47,7 @@ static __attribute__((__used__)) const char * GIT_VERSION_UNKNOWN = NULL;
}
#endif
static int create_dir(const char *dir_path, int path_len)
{
if(dir_path == NULL)
@@ -168,60 +163,6 @@ static void snapshot_handle_info(const char *handle_name, const char *log_path,
return;
}
static void log_update_time(log_handle_t *p_handle, log_ratelimit_t *rs, int level, const char *module, const char *func)
{
struct timespec current = {0, 0};
clock_gettime(CLOCK_MONOTONIC, &current);
if (((long)(rs->begin + rs->interval - current.tv_sec)) < 0)
{
if (rs->missed)
{
zlog(p_handle->zc, p_handle->runtime_log_file, strlen(p_handle->runtime_log_file), module, strlen(module), __LINE__, level, "%s: %d callbacks suppressed\n", func, rs->missed);
rs->missed = 0;
}
rs->begin = current.tv_sec;
rs->printed = 0;
}
return ;
}
int MESA_runtime_log_ratelimit(void *handle, log_ratelimit_t *rs, int level, const char *module, const char *func)
{
int ret = 0;
struct timespec timer = {0, 0};
log_handle_t *p_handle = (log_handle_t *)handle;
if (pthread_mutex_lock(&rs->mutex) != 0)return 0;
if (!rs->begin)
{
clock_gettime(CLOCK_MONOTONIC, &timer);
rs->begin = timer.tv_sec;
}
rs->burst = p_handle->burst;
rs->interval = p_handle->interval;
if (!rs->interval)
{
pthread_mutex_unlock(&rs->mutex);
return 1;
}
log_update_time(p_handle, rs, level, module, func);
if (rs->burst && rs->burst > rs->printed)
{
rs->printed++;
ret = 1;
}
else
{
rs->missed++;
ret = 0;
}
pthread_mutex_unlock(&rs->mutex);
return ret;
}
void *MESA_create_runtime_log_handle(const char *file_path, int level)
{
if(file_path == NULL)
@@ -230,11 +171,11 @@ void *MESA_create_runtime_log_handle(const char *file_path, int level)
int rc = -1;
zlog_category_t *zc = NULL;
FILE *fp = NULL;
log_handle_t *p_handle = NULL;
struct log_handle_t *handle = NULL;
char handle_name[MAX_HANDLE_LOG_PATH];
char *p_path_end = rindex(file_path, '/');
char *p_name = p_path_end+1;
char *p_name;
strcpy(handle_name, file_path);
escape_for_zlog(handle_name, strlen(handle_name));
@@ -254,23 +195,17 @@ 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);
}
p_handle = (log_handle_t *)calloc(sizeof(log_handle_t), 1);
strncpy(p_handle->runtime_log_file, file_path, sizeof(p_handle->runtime_log_file) - 1);
p_handle->runtime_log_level = level;
p_handle->zc = zc;
p_handle->burst = DEFAULT_BURST;
p_handle->interval = DEFAULT_INTERVAL;
pthread_mutex_init(&p_handle->mutex, NULL);
return (void *)p_handle;
handle = (struct log_handle_t *)calloc(sizeof(struct log_handle_t), 1);
strncpy(handle->runtime_log_file, file_path, sizeof(handle->runtime_log_file) - 1);
handle->runtime_log_level = level;
handle->zc = zc;
return (void *)handle;
}
void MESA_destroy_runtime_log_handle(void *handle)
{
log_handle_t *p_handle = (log_handle_t *)handle;
if(handle != NULL)
{
pthread_mutex_destroy(&p_handle->mutex);
free(handle);
handle = NULL;
}
@@ -278,39 +213,45 @@ void MESA_destroy_runtime_log_handle(void *handle)
return;
}
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);
}
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(handle->zc == NULL)return;
if (zlog_level_enabled(handle->zc, level))
{
va_list ap;
log_handle_t *p_handle = (log_handle_t *)handle;
if(p_handle == NULL || p_handle->runtime_log_file == NULL)return;
if(p_handle->zc == NULL)return;
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);
}
return ;
}
void MESA_set_runtime_log_handle_ratelimit(void *handle, int interval, int burst)
{
log_handle_t *p_handle = (log_handle_t *)handle;
if ((p_handle == NULL) || (interval < 0) || (burst < 0))return;
pthread_mutex_lock(&p_handle->mutex);
p_handle->interval = interval;
p_handle->burst = burst;
pthread_mutex_unlock(&p_handle->mutex);
return;
}
int MESA_handle_runtime_log_creation(const char *conf_path)
{
char *env = getenv("ZLOG_CONF_PATH");
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))
{
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);
@@ -403,4 +344,5 @@ void MESA_handle_runtime_log_destruction()
unlink(tmp_conf_filepath);
close(g_zlog_conf_fp);
}
g_zlog_inited=0;
}

View File

@@ -3,8 +3,8 @@ cmake_minimum_required (VERSION 3.5)
include(ExternalProject)
ExternalProject_Add(zlog PREFIX zlog
URL ${CMAKE_CURRENT_SOURCE_DIR}/zlog-1.2.15.tar.gz
URL_MD5 5e79f8d08744c7fef8528dd55a3bcd2d
URL ${CMAKE_CURRENT_SOURCE_DIR}/zlog-1.2.16.tar.gz
URL_MD5 4dcfe75a1acbb5c4513bbe168f935993
CONFIGURE_COMMAND ""
BUILD_COMMAND make
INSTALL_COMMAND ""

Binary file not shown.

BIN
zlog/zlog-1.2.16.tar.gz Normal file

Binary file not shown.