14 Commits

10 changed files with 309 additions and 140 deletions

View File

@@ -1,145 +1,261 @@
image: "git.mesalab.cn:7443/mesa_platform/build-env:master"
variables: variables:
GIT_STRATEGY: "clone" GIT_STRATEGY: "clone"
BUILD_IMAGE_CENTOS7: "git.mesalab.cn:7443/mesa_platform/build-env:master"
BUILD_IMAGE_CENTOS8: "git.mesalab.cn:7443/mesa_platform/build-env:rockylinux"
BUILD_PADDING_PREFIX: /tmp/padding_for_CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX_PREFIX_PREFIX_PREFIX_PREFIX_PREFIX/ 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: libasan
stages: stages:
- build - build
- test
.build_by_travis: .build_before_script:
before_script: before_script:
- mkdir -p $BUILD_PADDING_PREFIX/$CI_PROJECT_NAMESPACE/ - mkdir -p $BUILD_PADDING_PREFIX/$CI_PROJECT_NAMESPACE/
- ln -s $CI_PROJECT_DIR $BUILD_PADDING_PREFIX/$CI_PROJECT_PATH - ln -s $CI_PROJECT_DIR $BUILD_PADDING_PREFIX/$CI_PROJECT_PATH
- cd $BUILD_PADDING_PREFIX/$CI_PROJECT_PATH - cd $BUILD_PADDING_PREFIX/$CI_PROJECT_PATH
- chmod +x ./ci/travis.sh - chmod +x ./ci/travis.sh
- yum makecache
- yum install -y elfutils-libelf-devel
.build_by_travis_for_centos7:
stage: build
image: $BUILD_IMAGE_CENTOS7
extends: .build_before_script
script: script:
- wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo - yum install -y libmnl-devel
- yum makecache fast - yum install -y libnfnetlink-devel
- ./ci/travis.sh - ./ci/travis.sh
- cd build - cd build
tags: tags:
- share - share
branch_build_debug: .build_by_travis_for_centos8:
stage: build stage: build
extends: .build_by_travis image: $BUILD_IMAGE_CENTOS8
extends: .build_before_script
script:
- dnf --enablerepo=powertools install -y libmnl-devel
- dnf --enablerepo=powertools install -y libnfnetlink-devel
- ./ci/travis.sh
tags:
- share
run_test_for_centos7:
stage: test
image: $BUILD_IMAGE_CENTOS7
extends: .build_by_travis_for_centos7
script:
- yum makecache
- ./ci/travis.sh
- cd build
- ctest --verbose
run_test_for_centos8:
stage: test
image: $BUILD_IMAGE_CENTOS8
extends: .build_by_travis_for_centos8
script:
- yum makecache
- ./ci/travis.sh
- cd build
- ctest --verbose
branch_build_debug_for_centos7:
stage: build
extends: .build_by_travis_for_centos7
variables: variables:
BUILD_TYPE: Debug BUILD_TYPE: Debug
except: except:
- /^develop.*$/i
- /^master.*$/i
- /^dev*.*$/i - /^dev*.*$/i
- /^rel*.*$/i - /^rel*.*$/i
- /^master.*$/i
- tags - tags
branch_build_release: branch_build_release_for_centos7:
stage: build stage: build
variables: variables:
BUILD_TYPE: RelWithDebInfo BUILD_TYPE: RelWithDebInfo
extends: .build_by_travis extends: .build_by_travis_for_centos7
except: except:
- /^develop.*$/i
- /^master.*$/i
- /^dev*.*$/i - /^dev*.*$/i
- /^rel*.*$/i - /^rel*.*$/i
- /^master.*$/i
- tags - tags
develop_build_debug: develop_build_debug_for_centos7:
stage: build stage: build
extends: .build_by_travis extends: .build_by_travis_for_centos7
variables: variables:
BUILD_TYPE: Debug BUILD_TYPE: Debug
PACKAGE: 1 PACKAGE: 1
UPLOAD_RPM: 1
ASAN_OPTION: ADDRESS
TESTING_VERSION_BUILD: 1
PULP3_REPO_NAME: framework-testing-x86_64.el7
PULP3_DIST_NAME: framework-testing-x86_64.el7
artifacts: artifacts:
name: "MESA_handle_logger-$CI_COMMIT_REF_NAME-debug" name: "MESA_handle_logger-$CI_COMMIT_REF_NAME-debug"
paths: paths:
- build/*.rpm - build/*.rpm
only: only:
- /^develop.*$/i
- /^master.*$/i
- /^dev*.*$/i - /^dev*.*$/i
- /^rel*.*$/i - /^rel*.*$/i
- /^master.*$/i
develop_build_release: develop_build_release_for_centos7:
stage: build stage: build
extends: .build_by_travis extends: .build_by_travis_for_centos7
variables: variables:
BUILD_TYPE: RelWithDebInfo BUILD_TYPE: RelWithDebInfo
PACKAGE: 1 PACKAGE: 1
UPLOAD_RPM: 1
TESTING_VERSION_BUILD: 1
PULP3_REPO_NAME: framework-testing-x86_64.el7
PULP3_DIST_NAME: framework-testing-x86_64.el7
artifacts: artifacts:
name: "MESA_handle_logger-$CI_COMMIT_REF_NAME-release" name: "MESA_handle_logger-$CI_COMMIT_REF_NAME-release"
paths: paths:
- build/*.rpm - build/*.rpm
only: only:
- /^develop.*$/i
- /^master.*$/i
- /^dev*.*$/i - /^dev*.*$/i
- /^rel*.*$/i - /^rel*.*$/i
- /^master.*$/i
release_build_debug_for_centos7:
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_for_centos7
artifacts:
name: "MESA_handle_logger-$CI_COMMIT_REF_NAME-debug"
paths:
- build/*.rpm
only:
- tags
release_build_release: release_build_release_for_centos7:
stage: build stage: build
variables: variables:
BUILD_TYPE: RelWithDebInfo BUILD_TYPE: RelWithDebInfo
PACKAGE: 1 PACKAGE: 1
UPLOAD: 1 UPLOAD_RPM: 1
UPLOAD_SYMBOL_FILES: 1
SYMBOL_TARGET: libMESA_handle_logger
PULP3_REPO_NAME: framework-stable-x86_64.el7 PULP3_REPO_NAME: framework-stable-x86_64.el7
PULP3_DIST_NAME: framework-stable-x86_64.el7 PULP3_DIST_NAME: framework-stable-x86_64.el7
extends: .build_by_travis extends: .build_by_travis_for_centos7
artifacts: artifacts:
name: "MESA_handle_logger-$CI_COMMIT_REF_NAME-release" name: "MESA_handle_logger-$CI_COMMIT_REF_NAME-release"
paths: paths:
- build/*.rpm - build/*.rpm
only: only:
- tags - tags
except:
- /^v[0-9].*-testing$/i
release_build_release_devel: branch_build_debug_for_centos8:
stage: build
extends: .build_by_travis_for_centos8
variables:
BUILD_TYPE: Debug
except:
- /^develop.*$/i
- /^master.*$/i
- /^dev*.*$/i
- /^rel*.*$/i
- tags
branch_build_release_for_centos8:
stage: build stage: build
variables: variables:
BUILD_TYPE: RelWithDebInfo BUILD_TYPE: RelWithDebInfo
ENABLE_DEVEL_SWITCH: "ON" extends: .build_by_travis_for_centos8
except:
- /^develop.*$/i
- /^master.*$/i
- /^dev*.*$/i
- /^rel*.*$/i
- tags
develop_build_debug_for_centos8:
stage: build
extends: .build_by_travis_for_centos8
variables:
BUILD_TYPE: Debug
PACKAGE: 1 PACKAGE: 1
UPLOAD: 1 UPLOAD_RPM: 1
PULP3_REPO_NAME: framework-stable-x86_64.el7 ASAN_OPTION: ADDRESS
PULP3_DIST_NAME: framework-stable-x86_64.el7 TESTING_VERSION_BUILD: 1
extends: .build_by_travis PULP3_REPO_NAME: framework-testing-x86_64.el8
PULP3_DIST_NAME: framework-testing-x86_64.el8
artifacts:
name: "MESA_handle_logger-$CI_COMMIT_REF_NAME-debug"
paths:
- build/*.rpm
only:
- /^develop.*$/i
- /^master.*$/i
- /^dev*.*$/i
- /^rel*.*$/i
develop_build_release_for_centos8:
stage: build
extends: .build_by_travis_for_centos8
variables:
BUILD_TYPE: RelWithDebInfo
PACKAGE: 1
UPLOAD_RPM: 1
TESTING_VERSION_BUILD: 1
PULP3_REPO_NAME: framework-testing-x86_64.el8
PULP3_DIST_NAME: framework-testing-x86_64.el8
artifacts:
name: "MESA_handle_logger-$CI_COMMIT_REF_NAME-release"
paths:
- build/*.rpm
only:
- /^develop.*$/i
- /^master.*$/i
- /^dev*.*$/i
- /^rel*.*$/i
release_build_debug_for_centos8:
stage: build
variables:
BUILD_TYPE: Debug
PACKAGE: 1
UPLOAD_RPM: 1
PULP3_REPO_NAME: framework-stable-x86_64.el8
PULP3_DIST_NAME: framework-stable-x86_64.el8
extends: .build_by_travis_for_centos8
artifacts:
name: "MESA_handle_logger-$CI_COMMIT_REF_NAME-debug"
paths:
- build/*.rpm
only:
- tags
release_build_release_for_centos8:
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.el8
PULP3_DIST_NAME: framework-stable-x86_64.el8
extends: .build_by_travis_for_centos8
artifacts: artifacts:
name: "MESA_handle_logger-$CI_COMMIT_REF_NAME-release" name: "MESA_handle_logger-$CI_COMMIT_REF_NAME-release"
paths: paths:
- build/*.rpm - build/*.rpm
only: only:
- tags - tags
except:
- /^v[0-9].*-testing$/i
testing_build_release:
stage: build
variables:
BUILD_TYPE: RelWithDebInfo
PACKAGE: 1
UPLOAD: 1
PULP3_REPO_NAME: framework-testing-x86_64.el7
PULP3_DIST_NAME: framework-testing-x86_64.el7
extends: .build_by_travis
artifacts:
name: "MESA_handle_logger-$CI_COMMIT_REF_NAME-release"
paths:
- build/*.rpm
only:
- /^v[0-9].*-testing$/i
testing_build_release_devel:
stage: build
variables:
BUILD_TYPE: RelWithDebInfo
ENABLE_DEVEL_SWITCH: "ON"
PACKAGE: 1
UPLOAD: 1
PULP3_REPO_NAME: framework-testing-x86_64.el7
PULP3_DIST_NAME: framework-testing-x86_64.el7
extends: .build_by_travis
artifacts:
name: "MESA_handle_logger-$CI_COMMIT_REF_NAME-release"
paths:
- build/*.rpm
only:
- /^v[0-9].*-testing$/i

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) add_executable(${lib_name}_demo demo/test_handle_logger.c)
target_link_libraries(${lib_name}_demo pthread ${lib_name}_shared) 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) include(Package)

View File

@@ -33,7 +33,14 @@ env | sort
: "${COMPILER_IS_GNUCXX:=OFF}" : "${COMPILER_IS_GNUCXX:=OFF}"
# Install dependency from YUM # Install dependency from YUM
#yum install -y mrzcpd framework numactl-devel zlib-devel librdkafka-devel systemd-devel if [ -n "${INSTALL_DEPENDENCY_LIBRARY}" ]; then
yum install -y $INSTALL_DEPENDENCY_LIBRARY
fi
if [ $ASAN_OPTION ] && [ -f "/opt/rh/devtoolset-7/enable" ] ;then
source /opt/rh/devtoolset-7/enable
fi
mkdir build || true mkdir build || true
cd build cd build
@@ -41,6 +48,8 @@ cmake3 -DCMAKE_CXX_FLAGS=$CXX_FLAGS \
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \ -DCMAKE_BUILD_TYPE=$BUILD_TYPE \
-DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX \ -DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX \
-DENABLE_DEVEL=$ENABLE_DEVEL_SWITCH \ -DENABLE_DEVEL=$ENABLE_DEVEL_SWITCH \
-DASAN_OPTION=$ASAN_OPTION \
-DVERSION_DAILY_BUILD=$TESTING_VERSION_BUILD \
.. ..
make make
@@ -49,13 +58,14 @@ if [ -n "${PACKAGE}" ]; then
make package make package
fi fi
if [ -n "${UPLOAD}" ]; then if [ -n "${UPLOAD_RPM}" ]; then
cp ~/rpm_upload_tools.py ./ cp ~/rpm_upload_tools.py ./
python3 rpm_upload_tools.py ${PULP3_REPO_NAME} ${PULP3_DIST_NAME} *.rpm python3 rpm_upload_tools.py ${PULP3_REPO_NAME} ${PULP3_DIST_NAME} *.rpm
fi fi
#if [ -n "${UPLOAD_SYMBOL_FILES}" ]; then if [ -n "${UPLOAD_SYMBOL_FILES}" ]; then
# rpm -i tfe*debuginfo*.rpm rpm -i $SYMBOL_TARGET*debuginfo*.rpm
# cp /usr/lib/debug/opt/tsg/tfe/bin/tfe.debug /tmp/tfe.debuginfo.${CI_COMMIT_SHORT_SHA} _symbol_file=`find /usr/lib/debug/ -name "$SYMBOL_TARGET*.so*.debug"`
# sentry-cli upload-dif -t elf /tmp/tfe.debuginfo.${CI_COMMIT_SHORT_SHA} cp $_symbol_file ${_symbol_file}info.${CI_COMMIT_SHORT_SHA}
#fi 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_PACKAGE_VERSION_PATCH "${VERSION_PATCH}.${VERSION_BUILD}")
set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}) set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
set(CPACK_PACKAGE_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}.${VERSION_BUILD}") 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) 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) SET(CPACK_RPM_CHANGELOG_FILE ${CMAKE_BINARY_DIR}/changelog.txt)
# RPM Build # RPM Build
set(CPACK_GENERATOR "RPM") 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_VENDOR "MESA")
set(CPACK_RPM_PACKAGE_AUTOREQPROV "yes") 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_DEBUGINFO_PACKAGE "on")
set(CPACK_RPM_PACKAGE_DEBUG 1)
set(CPACK_RPM_COMPONENT_INSTALL ON) set(CPACK_RPM_COMPONENT_INSTALL ON)
set(CPACK_COMPONENTS_IGNORE_GROUPS 1) set(CPACK_COMPONENTS_IGNORE_GROUPS 1)
set(CPACK_COMPONENTS_GROUPING ONE_PER_GROUP) set(CPACK_COMPONENTS_GROUPING ONE_PER_GROUP)
set(CPACK_COMPONENT_HEADER_DISPLAY_NAME "develop") set(CPACK_COMPONENT_HEADER_DISPLAY_NAME "develop")
set(CPACK_COMPONENT_LIBRARIES_REQUIRED TRUE) 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_COMPONENT_HEADER_REQUIRED TRUE)
set(CPACK_RPM_HEADER_PACKAGE_NAME "${MY_RPM_NAME_PREFIX}-devel") 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_COMPONENT_HEADER_GROUP "header")
set(CPACK_RPM_HEADER_PACKAGE_REQUIRES_PRE ${CPACK_RPM_LIBRARIES_PACKAGE_NAME}) set(CPACK_RPM_HEADER_PACKAGE_REQUIRES_PRE ${CPACK_RPM_LIBRARIES_PACKAGE_NAME})

View File

@@ -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;
} }
@@ -100,16 +106,18 @@ int main(int argc, char ** args)
{ {
pthread_t t[MAX_THREAD_NUM]; pthread_t t[MAX_THREAD_NUM];
int i = 0; int i = 0;
int ret =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)
{ {
@@ -129,26 +137,35 @@ int main(int argc, char ** args)
{ {
printf("get log sample_handle error\n"); printf("get log sample_handle error\n");
return -1; return -1;
} }
test_handle = MESA_create_runtime_log_handle("./log/test_log", RLOG_LV_DEBUG); 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"); printf("get log test_handle error\n");
return -1; 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)); pthread_create(&t[i], NULL, thread_logger, (void *)(unsigned long)(i));
} }
signal(SIGINT, sig_int_handler); signal(SIGINT, sig_int_handler);
signal(SIGHUP, sig_hup_handler); signal(SIGHUP, sig_hup_handler);
while(1)
; // 等待所有线程结束并回收
//MESA_destroy_runtime_log_handle(sample_handle); for (i = 0; i < g_thread_num; ++i) {
//MESA_destroy_runtime_log_handle(test_handle); ret = pthread_join(t[i], NULL);
//sample_handle = NULL; if (ret != 0) {
//test_handle = NULL; fprintf(stderr, "Failed to join thread %d\n", i);
return 0; 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

@@ -23,10 +23,17 @@ int MESA_handle_runtime_log_creation(const char *conf_path);
int MESA_handle_runtime_log_reconstruction(const char *conf_path); int MESA_handle_runtime_log_reconstruction(const char *conf_path);
void MESA_handle_runtime_log_destruction(); void MESA_handle_runtime_log_destruction();
#define MESA_HANDLE_RUNTIME_LOG(handle, lv, mod, fmt, args...) \ #define MESA_HANDLE_RUNTIME_LOG(handle, level, module, format, ...) \
MESA_handle_runtime_log((handle), (lv), (mod), "file %s, line %d, " fmt, \ do \
__FILE__, __LINE__, ##args) { \
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 * name: MESA_create_runtime_log_handle
* functionality: get runtime_log handle; * functionality: get runtime_log handle;
@@ -37,7 +44,7 @@ void MESA_handle_runtime_log_destruction();
* not NULL, if succeeded; * not NULL, if succeeded;
* NULL, if file is not absolute path, or failed to create log file; * 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 * name: MESA_handle_runtime_log

View File

@@ -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; };
@@ -156,7 +156,7 @@ static void snapshot_handle_info(const char *handle_name, const char *log_path,
if(g_zlog_inited == 0) if(g_zlog_inited == 0)
{ {
printf("[snapshot_handle_info], Nobody call MESA_handle_runtime_log_creation before, Using (%s) to init zlog, handle_name(%s), log_path(%s), log_level(%d)!!!\n", tmp_conf_filepath, handle_name, log_path, level); fprintf(stderr,"[snapshot_handle_info], Nobody call MESA_handle_runtime_log_creation before, Using (%s) to init zlog, handle_name(%s), log_path(%s), log_level(%d)!!!\n", tmp_conf_filepath, handle_name, log_path, level);
zlog_init(tmp_conf_filepath); zlog_init(tmp_conf_filepath);
zlog_reload(NULL); zlog_reload(NULL);
} }
@@ -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));
@@ -193,13 +193,13 @@ void *MESA_create_runtime_log_handle(const char *file_path, int level)
zc = zlog_get_category(p_name); zc = zlog_get_category(p_name);
if (!zc) if (!zc)
{ {
printf("[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;
log_handle_t *p_handle = (log_handle_t *)handle; if(handle == NULL || handle->runtime_log_file == NULL)return;
if(handle->zc == NULL) return;
return zlog_level_enabled(handle->zc, level);
}
if(p_handle == NULL || p_handle->runtime_log_file == NULL)return; 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->zc == NULL)return; if(handle->zc == NULL)return;
va_list ap; if (zlog_level_enabled(handle->zc, level))
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); va_list ap;
va_end(ap); va_start(ap, fmt);
vzlog(handle->zc, handle->runtime_log_file, strlen(handle->runtime_log_file), module, strlen(module), __LINE__, level, fmt, ap);
va_end(ap);
}
return ; return ;
} }
@@ -235,13 +244,21 @@ 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))
{ {
printf("[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);
rc = zlog_init(NULL); rc = zlog_init(NULL);
if (rc) if (rc)
{ {
printf("[MESA_handle_runtime_log_creation], INIT zlog by (NULL) or (%s) failed !!! \n", env); fprintf(stderr,"[MESA_handle_runtime_log_creation], INIT zlog by (NULL) or (%s) failed !!! \n", env);
return -1; return -1;
} }
else else
@@ -257,11 +274,11 @@ int MESA_handle_runtime_log_creation(const char *conf_path)
rc = zlog_init(conf_path); rc = zlog_init(conf_path);
if (rc) if (rc)
{ {
printf("[MESA_handle_runtime_log_creation], INIT zlog by (%s) failed , using [NULL] retry !\n", conf_path); fprintf(stderr,"[MESA_handle_runtime_log_creation], INIT zlog by (%s) failed , using [NULL] retry !\n", conf_path);
rc = zlog_init(NULL); rc = zlog_init(NULL);
if (rc) if (rc)
{ {
printf("[MESA_handle_runtime_log_creation], INIT zlog by (NULL) or (%s) failed \n", env); fprintf(stderr,"[MESA_handle_runtime_log_creation], INIT zlog by (NULL) or (%s) failed \n", env);
return -1; return -1;
} }
else else
@@ -279,7 +296,7 @@ int MESA_handle_runtime_log_creation(const char *conf_path)
} }
} }
printf("[MESA_handle_runtime_log_creation], INIT zlog finish, Using (%s). \n", global_conf_filepath); fprintf(stderr,"[MESA_handle_runtime_log_creation], INIT zlog finish, Using (%s). \n", global_conf_filepath);
g_zlog_inited = 1; g_zlog_inited = 1;
zlog_profile(); zlog_profile();
@@ -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;
} }

View File

@@ -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

Binary file not shown.