From 48cc5e2163281db23640fa87321b22cadcd69aa0 Mon Sep 17 00:00:00 2001 From: fly_1997 Date: Mon, 23 Dec 2024 18:46:18 +0800 Subject: [PATCH 2/7] update compilation options --- CMakeLists.txt | 20 +++++++++- build.sh | 40 +++++++++++++++---- install.sh | 4 +- src/client/CMakeLists.txt | 8 ++-- src/common/CMakeLists.txt | 11 ++--- src/plugin/CMakeLists.txt | 7 ++-- src/plugin/collect/docker/CMakeLists.txt | 7 ++-- src/plugin/collect/pmu/CMakeLists.txt | 15 ++----- src/plugin/collect/system/CMakeLists.txt | 9 +++-- src/plugin/scenario/analysis/CMakeLists.txt | 9 ++--- .../scenario/thread_aware/CMakeLists.txt | 8 +++- src/plugin/tune/docker/CMakeLists.txt | 17 +++----- src/plugin/tune/system/CMakeLists.txt | 11 ++--- .../system/cpu/stealtask_tune/CMakeLists.txt | 7 ---- .../system/network/smc_tune/CMakeLists.txt | 8 ---- .../network/smc_tune/kprobe/CMakeLists.txt | 2 - .../system/power/seep_tune/CMakeLists.txt | 8 ---- src/plugin/tune/system/xcall/CMakeLists.txt | 8 ---- src/plugin/tune/unixbench/CMakeLists.txt | 13 +++--- src/plugin_mgr/CMakeLists.txt | 12 +++--- src/sdk/CMakeLists.txt | 7 +++- tests/CMakeLists.txt | 4 +- 22 files changed, 114 insertions(+), 121 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c6a435e..162ff58 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,15 +2,33 @@ cmake_minimum_required(VERSION 3.16) project(oeAware-manager) +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_FLAGS "-rdynamic -std=c++14 -g -Wl,-z,relro,-z,now -Wall -Wextra -fPIC") set(SDK_OUTPUT_LIBRARY_DIRECTORY ${CMAKE_BINARY_DIR}/output/sdk) set(SDK_INC_PATH ${CMAKE_CURRENT_LIST_DIR}/src/sdk) +if (WITH_ASAN) + message(STATUS "enable asan") + function(enable_asan target) + add_compile_options(-fsanitize=address) + target_link_libraries(${target} asan) + endfunction() +endif() + +if (WITH_OPTIMIZATION) + message(STATUS "add_compile_options(-O2)") + add_compile_options(-O2) +endif() + +message(STATUS "C Flags: ${CMAKE_C_FLAGS}") +message(STATUS "CXX Flags: ${CMAKE_CXX_FLAGS}") + add_subdirectory(src/common) add_subdirectory(src/plugin) add_subdirectory(src/plugin_mgr) add_subdirectory(src/client) add_subdirectory(src/sdk) -if (BUILD_TEST) +if (WITH_TEST) add_subdirectory(tests) endif() diff --git a/build.sh b/build.sh index c405645..bd99758 100644 --- a/build.sh +++ b/build.sh @@ -7,18 +7,25 @@ os_arch=$(uname -m) libkperf_version="v1.2.1" # only for build_kperf_by_src=ON build_kperf_by_src="ON" build_test="OFF" - +with_debug="OFF" +with_asan="OFF" +with_optimization="OFF" +params="kperfrpm,help,test,with_asan,with_optimization,debug,release" function usage() { echo "" echo "usage: build.sh [OPTIONS] [ARGS]" echo "" echo "The most commonly used build.sh options are:" - echo " -k |--kperfrpm not build with libkperf by source code" - echo " -t |--test build tests case" - echo " -h |--help show usage" + echo " -k |--kperfrpm not build with libkperf by source code" + echo " -t |--test build tests case" + echo " --with_asan open AddressSanitizer compilation option" + echo " --with_optimization open optimization compilation option" + echo " --debug compile the debug version" + echo " --release compile the release version" + echo " -h |--help show usage" } -options=$(getopt -o kht --long kperfrpm,help,test -- "$@") +options=$(getopt -o kht --long ${params} -- "$@") eval set -- "$options" while true; do case "$1" in @@ -27,7 +34,25 @@ while true; do shift ;; -t|--test) - build_test="ON" + with_test="ON" + shift + ;; + --debug) + with_test="ON" + with_debug="ON" + with_optimization="OFF" + shift + ;; + --release) + with_optimization="ON" + shift + ;; + --with_asan) + with_asan="ON" + shift + ;; + --with_optimization) + with_optimization="ON" shift ;; -h|--help) @@ -69,5 +94,6 @@ fi cmake .. -DLIB_KPERF_LIBPATH=${libkperf_lib} -DLIB_KPERF_INCPATH=${script_dir}/include/oeaware/data \ - -DBUILD_TEST=${build_test} + -DWITH_TEST=${build_test} -DWITH_DEBUG=${with_debug} -DWITH_ASAN=${with_asan} \ + -DWITH_OPTIMIZATION=${with_optimization} make -j$(nproc) \ No newline at end of file diff --git a/install.sh b/install.sh index afa01f2..55cca48 100644 --- a/install.sh +++ b/install.sh @@ -1,8 +1,8 @@ mkdir -p /usr/include/oeaware cp -r build/output/include/* /usr/include/ cp -r build/output/bin/* /bin/ -mkdir -p /etc/oeaware -cp config.yaml /etc/oeaware +mkdir -p /etc/oeAware +cp config.yaml /etc/oeAware cp build/output/sdk/liboeaware-sdk.so /lib64 mkdir -p /lib64/oeAware-plugin diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt index f16bde1..72c2cce 100644 --- a/src/client/CMakeLists.txt +++ b/src/client/CMakeLists.txt @@ -1,8 +1,5 @@ -cmake_minimum_required (VERSION 3.16) project(oeAware-client) -SET(CMAKE_CXX_FLAGS "-rdynamic -std=c++14 -g -Wl,-z,relro,-z,now -O2 -Wall -Wextra") - add_subdirectory(analysis) aux_source_directory(. SOURCE) @@ -11,5 +8,10 @@ target_include_directories(oeawarectl PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/analysis ${CMAKE_CURRENT_SOURCE_DIR}/../common ) + +if (WITH_ASAN) + enable_asan(oeawarectl) +endif() + target_link_libraries(oeawarectl analysis_cli common boundscheck) set_target_properties(oeawarectl PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/output/bin") diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index d6bbd58..a1741bc 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -1,18 +1,11 @@ -cmake_minimum_required (VERSION 3.16) project(common) aux_source_directory(. SOURCE) -SET(CMAKE_CXX_FLAGS "-rdynamic -std=c++14 -g -Wl,-z,relro,-z,now -Wall -Wextra -fPIC -O2") - -include_directories(/usr/include/yaml-cpp) include_directories(/usr/include/log4cplus) include_directories(../plugin/collect/include) include_directories(../plugin/scenario/include) include_directories(${LIB_KPERF_INCPATH}) -include_directories(/usr/include/curl) - -link_directories(/usr/lib64) add_library(${PROJECT_NAME} ${SOURCE} @@ -22,6 +15,10 @@ target_link_libraries(${PROJECT_NAME} log4cplus) target_link_libraries(${PROJECT_NAME} yaml-cpp) target_link_libraries(${PROJECT_NAME} curl boundscheck) +if (WITH_ASAN) + enable_asan(${PROJECT_NAME}) +endif() + if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64") target_link_directories(${PROJECT_NAME} PUBLIC ${LIB_KPERF_LIBPATH} diff --git a/src/plugin/CMakeLists.txt b/src/plugin/CMakeLists.txt index 450c933..a4ee240 100644 --- a/src/plugin/CMakeLists.txt +++ b/src/plugin/CMakeLists.txt @@ -1,4 +1,3 @@ - include_directories( ${CMAKE_SOURCE_DIR}/include ) @@ -15,9 +14,9 @@ if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64") endif() add_subdirectory(collect/system) - if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64") - add_subdirectory(scenario/analysis) - endif() +if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64") + add_subdirectory(scenario/analysis) +endif() add_subdirectory(scenario/thread_aware) add_subdirectory(tune/system) diff --git a/src/plugin/collect/docker/CMakeLists.txt b/src/plugin/collect/docker/CMakeLists.txt index cdde00f..5e1760d 100644 --- a/src/plugin/collect/docker/CMakeLists.txt +++ b/src/plugin/collect/docker/CMakeLists.txt @@ -1,9 +1,10 @@ -cmake_minimum_required(VERSION 3.11) project(docker_collector) -add_compile_options(-O2 -fPIC -Wall -Wextra) add_library(docker_collector SHARED docker_adapt.cpp docker_collector.cpp ) +if (WITH_ASAN) + enable_asan(docker_collector) +endif() set_target_properties(docker_collector PROPERTIES - LIBRARY_OUTPUT_DIRECTORY ${PLUGIN_OUTPUT_LIBRARY_DIRECTORY}) \ No newline at end of file + LIBRARY_OUTPUT_DIRECTORY ${PLUGIN_OUTPUT_LIBRARY_DIRECTORY}) diff --git a/src/plugin/collect/pmu/CMakeLists.txt b/src/plugin/collect/pmu/CMakeLists.txt index 000e26e..cb2870b 100644 --- a/src/plugin/collect/pmu/CMakeLists.txt +++ b/src/plugin/collect/pmu/CMakeLists.txt @@ -1,16 +1,5 @@ -cmake_minimum_required(VERSION 3.15) project(pmu_plugin) -set(CMAKE_CXX_STANDARD 14) - -option(WITH_DEBUG "debug mode" OFF) - -if (WITH_DEBUG) - message("-- Note:pmu debug mode") - add_compile_options(-g) -endif() -add_compile_options(-O2 -fPIC -Wall -Wextra -g) - # libkperf message("-- libkperf library path: ${LIB_KPERF_LIBPATH}") message("-- libkperf include path: ${LIB_KPERF_INCPATH}") @@ -35,6 +24,10 @@ target_link_directories(pmu PUBLIC ${LIB_KPERF_LIBPATH} ) +if (WITH_ASAN) + enable_asan(pmu) +endif() + target_link_libraries(pmu boundscheck kperf) set_target_properties(pmu PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PLUGIN_OUTPUT_LIBRARY_DIRECTORY}) diff --git a/src/plugin/collect/system/CMakeLists.txt b/src/plugin/collect/system/CMakeLists.txt index 3ec2358..7f832e5 100644 --- a/src/plugin/collect/system/CMakeLists.txt +++ b/src/plugin/collect/system/CMakeLists.txt @@ -1,7 +1,5 @@ -cmake_minimum_required(VERSION 3.11) project(system_collector) include_directories(command) -add_compile_options(-O2 -fPIC -Wall -Wextra) add_library(system_collector SHARED thread_collector.cpp system_collector.cpp @@ -12,6 +10,11 @@ add_library(system_collector SHARED ) target_include_directories(system_collector PUBLIC ${CMAKE_SOURCE_DIR}/include) target_include_directories(system_collector PRIVATE ${CMAKE_SOURCE_DIR}/src/common) + +if (WITH_ASAN) + enable_asan(system_collector) +endif() + target_link_libraries(system_collector common) set_target_properties(system_collector PROPERTIES - LIBRARY_OUTPUT_DIRECTORY ${PLUGIN_OUTPUT_LIBRARY_DIRECTORY}) \ No newline at end of file + LIBRARY_OUTPUT_DIRECTORY ${PLUGIN_OUTPUT_LIBRARY_DIRECTORY}) diff --git a/src/plugin/scenario/analysis/CMakeLists.txt b/src/plugin/scenario/analysis/CMakeLists.txt index 4cfe525..46fff34 100644 --- a/src/plugin/scenario/analysis/CMakeLists.txt +++ b/src/plugin/scenario/analysis/CMakeLists.txt @@ -1,5 +1,3 @@ -cmake_minimum_required(VERSION 3.15) - project(analysis) message("-- libkperf library path: ${LIB_KPERF_LIBPATH}") message("-- libkperf include path: ${LIB_KPERF_INCPATH}") @@ -11,19 +9,20 @@ set(analysis_src set(oeaware_src adapt/analysis_aware.cpp) -add_compile_options(-g -fPIC -Wall -Wextra -O2) - add_library(analysis_base OBJECT ${analysis_src}) target_include_directories(analysis_base PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/analysis ${LIB_KPERF_INCPATH} ) - target_link_libraries(analysis_base numa boundscheck) add_library(analysis_oeaware SHARED ${oeaware_src}) +if (WITH_ASAN) + enable_asan(analysis_oeaware) +endif() + target_link_libraries(analysis_oeaware analysis_base) set_target_properties(analysis_oeaware PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PLUGIN_OUTPUT_LIBRARY_DIRECTORY}) \ No newline at end of file diff --git a/src/plugin/scenario/thread_aware/CMakeLists.txt b/src/plugin/scenario/thread_aware/CMakeLists.txt index 01395e5..7e91f20 100644 --- a/src/plugin/scenario/thread_aware/CMakeLists.txt +++ b/src/plugin/scenario/thread_aware/CMakeLists.txt @@ -1,10 +1,14 @@ -cmake_minimum_required(VERSION 3.11) project(thread_scenario) -add_compile_options(-O2 -fPIC -Wall -Wextra) + add_library(thread_scenario SHARED thread_aware.cpp ) target_include_directories(thread_scenario PUBLIC ${CMAKE_SOURCE_DIR}/include) + +if (WITH_ASAN) + enable_asan(thread_scenario) +endif() + set_target_properties(thread_scenario PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PLUGIN_OUTPUT_LIBRARY_DIRECTORY}) file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/thread_scenario.conf" diff --git a/src/plugin/tune/docker/CMakeLists.txt b/src/plugin/tune/docker/CMakeLists.txt index a41465a..27115dc 100644 --- a/src/plugin/tune/docker/CMakeLists.txt +++ b/src/plugin/tune/docker/CMakeLists.txt @@ -1,16 +1,5 @@ -cmake_minimum_required(VERSION 3.11) - project(docker_tune) -if (WITH_DEBUG) - add_compile_options(-g) -else() - add_compile_options(-O2) -endif() -add_compile_options(-fPIC -Wall -Wextra) - -message("-- libkperf include path: ${LIB_KPERF_INCPATH}") - add_library(docker_tune SHARED cpu_burst.cpp cpu_burst_adapt.cpp @@ -21,5 +10,9 @@ include_directories(docker_tune PUBLIC ${LIB_KPERF_INCPATH} ) +if (WITH_ASAN) + enable_asan(docker_tune) +endif() + set_target_properties(docker_tune PROPERTIES - LIBRARY_OUTPUT_DIRECTORY ${PLUGIN_OUTPUT_LIBRARY_DIRECTORY}) \ No newline at end of file + LIBRARY_OUTPUT_DIRECTORY ${PLUGIN_OUTPUT_LIBRARY_DIRECTORY}) diff --git a/src/plugin/tune/system/CMakeLists.txt b/src/plugin/tune/system/CMakeLists.txt index 8beeb4d..8f8d0a2 100644 --- a/src/plugin/tune/system/CMakeLists.txt +++ b/src/plugin/tune/system/CMakeLists.txt @@ -1,13 +1,5 @@ -cmake_minimum_required(VERSION 3.11) project(system_tune) -if (WITH_DEBUG) - add_compile_options(-g) -else() - add_compile_options(-O2) -endif() -add_compile_options(-fPIC -Wall -Wextra) - add_subdirectory(cpu/stealtask_tune) add_subdirectory(network/smc_tune) add_subdirectory(xcall) @@ -16,6 +8,9 @@ add_subdirectory(power/seep_tune) add_library(system_tune SHARED system_tune.cpp) +if (WITH_ASAN) + enable_asan(system_tune) +endif() target_link_libraries(system_tune stealtask_tune smc_tune xcall_tune seep_tune) set_target_properties(system_tune PROPERTIES diff --git a/src/plugin/tune/system/cpu/stealtask_tune/CMakeLists.txt b/src/plugin/tune/system/cpu/stealtask_tune/CMakeLists.txt index c311a01..9413716 100644 --- a/src/plugin/tune/system/cpu/stealtask_tune/CMakeLists.txt +++ b/src/plugin/tune/system/cpu/stealtask_tune/CMakeLists.txt @@ -1,13 +1,6 @@ cmake_minimum_required(VERSION 3.11) project(stealtask_tune) -if (WITH_DEBUG) - add_compile_options(-g) -else() - add_compile_options(-O2) -endif() -add_compile_options(-fPIC -Wall -Wextra) - add_library(stealtask_tune STATIC stealtask_tune.cpp ) diff --git a/src/plugin/tune/system/network/smc_tune/CMakeLists.txt b/src/plugin/tune/system/network/smc_tune/CMakeLists.txt index 29bd449..6c81aff 100644 --- a/src/plugin/tune/system/network/smc_tune/CMakeLists.txt +++ b/src/plugin/tune/system/network/smc_tune/CMakeLists.txt @@ -1,13 +1,5 @@ -cmake_minimum_required(VERSION 3.11) project(smc_tune) -if (WITH_DEBUG) - add_compile_options(-g) -else() - add_compile_options(-O2) -endif() -add_compile_options(-fPIC -Wall -Wextra -Wno-unused-value -Wno-missing-field-initializers) - include_directories(/usr/include/libnl3) add_subdirectory(kprobe) diff --git a/src/plugin/tune/system/network/smc_tune/kprobe/CMakeLists.txt b/src/plugin/tune/system/network/smc_tune/kprobe/CMakeLists.txt index 5eb787a..e737eb6 100644 --- a/src/plugin/tune/system/network/smc_tune/kprobe/CMakeLists.txt +++ b/src/plugin/tune/system/network/smc_tune/kprobe/CMakeLists.txt @@ -1,5 +1,3 @@ -cmake_minimum_required(VERSION 3.10) - # set module name project(smc_acc) diff --git a/src/plugin/tune/system/power/seep_tune/CMakeLists.txt b/src/plugin/tune/system/power/seep_tune/CMakeLists.txt index 92fb91b..080ff6a 100644 --- a/src/plugin/tune/system/power/seep_tune/CMakeLists.txt +++ b/src/plugin/tune/system/power/seep_tune/CMakeLists.txt @@ -1,13 +1,5 @@ -cmake_minimum_required(VERSION 3.11) project(seep_tune) -if (WITH_DEBUG) - add_compile_options(-g) -else() - add_compile_options(-O2) -endif() -add_compile_options(-fPIC -Wall -Wextra) - add_library(seep_tune STATIC seep_tune.cpp ) diff --git a/src/plugin/tune/system/xcall/CMakeLists.txt b/src/plugin/tune/system/xcall/CMakeLists.txt index 815a96e..d00f7c2 100644 --- a/src/plugin/tune/system/xcall/CMakeLists.txt +++ b/src/plugin/tune/system/xcall/CMakeLists.txt @@ -1,13 +1,5 @@ -cmake_minimum_required(VERSION 3.11) project(xcall_tune) -if (WITH_DEBUG) - add_compile_options(-g) -else() - add_compile_options(-O2) -endif() -add_compile_options(-fPIC -Wall -Wextra -Wno-unused-value -Wno-missing-field-initializers) - add_library(xcall_tune STATIC xcall_tune.cpp ) diff --git a/src/plugin/tune/unixbench/CMakeLists.txt b/src/plugin/tune/unixbench/CMakeLists.txt index dd6e934..55c34dd 100644 --- a/src/plugin/tune/unixbench/CMakeLists.txt +++ b/src/plugin/tune/unixbench/CMakeLists.txt @@ -1,18 +1,15 @@ -cmake_minimum_required(VERSION 3.11) project(ub_tune) -if (WITH_DEBUG) - add_compile_options(-g) -else() - add_compile_options(-O2) -endif() -add_compile_options(-fPIC -Wall -Wextra) - add_library(ub_tune SHARED ub_tune.cpp ) target_link_libraries(ub_tune numa) + +if (WITH_ASAN) + enable_asan(ub_tune) +endif() + set_target_properties(ub_tune PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PLUGIN_OUTPUT_LIBRARY_DIRECTORY}) file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/ub_tune.conf" diff --git a/src/plugin_mgr/CMakeLists.txt b/src/plugin_mgr/CMakeLists.txt index a3f9dd1..90e410b 100644 --- a/src/plugin_mgr/CMakeLists.txt +++ b/src/plugin_mgr/CMakeLists.txt @@ -1,12 +1,5 @@ -cmake_minimum_required (VERSION 3.16) project(oeAware-server) -SET(CMAKE_CXX_FLAGS "-rdynamic -std=c++14 -g -Wl,-z,relro,-z,now -Wall -Wextra -O2") - -if("${OEAWARE_DEBUG}" EQUAL 1) -add_definitions(-DOEAWARE_DEBUG) -endif() - aux_source_directory(. SOURCE) aux_source_directory(event EVENT_SOURCE) include_directories(/usr/include) @@ -20,6 +13,11 @@ add_executable (oeaware ${EVENT_SOURCE} ) target_link_libraries(oeaware common) + +if (WITH_ASAN) + enable_asan(oeaware) +endif() + if (${CMAKE_CXX_COMPILER_VERSION} LESS "10.3.1") target_link_libraries(oeaware -lpthread -ldl) endif() diff --git a/src/sdk/CMakeLists.txt b/src/sdk/CMakeLists.txt index e362a1a..a6385aa 100644 --- a/src/sdk/CMakeLists.txt +++ b/src/sdk/CMakeLists.txt @@ -1,12 +1,15 @@ -cmake_minimum_required (VERSION 3.16) project(oeaware-sdk) aux_source_directory(. SOURCE) -SET(CMAKE_CXX_FLAGS "-rdynamic -std=c++14 -g -Wl,-z,relro,-z,now -Wall -Wextra -fPIC -O2") add_library(${PROJECT_NAME} SHARED oe_client.cpp ) + +if (WITH_ASAN) + enable_asan(${PROJECT_NAME}) +endif() + target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/include) target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/src/common) target_link_libraries(${PROJECT_NAME} common) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2a6afcd..11aa06d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,7 +1,5 @@ -cmake_minimum_required(VERSION 3.16) project(test) set(SRC_DIR ../src) -SET(CMAKE_CXX_FLAGS "-rdynamic -std=c++14 -g -Wl,-z,relro,-z,now") find_package(GTest CONFIG REQUIRED) @@ -30,7 +28,7 @@ add_executable(utils_test ) add_executable(data_register_test - data_register_test + data_register_test.cpp ) target_link_libraries(serialize_test PRIVATE common GTest::gtest_main) -- 2.33.0