diff --git a/CMakeLists.txt b/CMakeLists.txt index 742034c6e97a2ba5e32bf7587a19dfd74534da0e..410a58195909424e1586914e424ddf4d2b2c0447 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,12 @@ if (POLICY CMP0048) endif (POLICY CMP0048) set(PROJECT_TOP_DIR ${CMAKE_CURRENT_LIST_DIR}) project(libkprof) -set(CMAKE_INSTALL_PREFIX "${PROJECT_TOP_DIR}/output/" CACHE PATH "Installation directory" FORCE) +if(NOT DEFINED CMAKE_INSTALL_PREFIX OR CMAKE_INSTALL_PREFIX STREQUAL "") + set(CMAKE_INSTALL_PREFIX "${PROJECT_TOP_DIR}/output/" CACHE PATH "Installation directory" FORCE) +endif() +if (NOT DEFINED CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE STREQUAL "") + set(CMAKE_BUILD_TYPE Release) +endif() cmake_minimum_required (VERSION 3.12.0) set(CMAKE_CXX_STANDARD 11) @@ -27,9 +32,6 @@ set(CMAKE_C_STANDARD 11) if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8.5) message(FATAL_ERROR "GCC 4.8.5 or newer required") endif() -if (NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE Release) -endif() set(TOP_DIR ${PROJECT_SOURCE_DIR}) diff --git a/README.en.md b/README.en.md index f9ee1221ea603e00d31e92195a9e1cc442f75182..84e8380d76062f643e7a4cfdffcc65a4f5dbd6ac 100644 --- a/README.en.md +++ b/README.en.md @@ -16,9 +16,9 @@ Symbol resolve module is developed on elfin-parser, a library for parsing elf an Run bash script: ```sh -sh build.sh +sh build.sh installPath=/home/libkperf ``` -Headers and libraries will be installed to ./output directory. +As mentioned above, the header and library will be installed in the/home/libkperf output directory, and installPath is an optional parameter. If not set, it will be installed in the output directory under libkperf by default. #### Instructions All pmu functions are accomplished by the following interfaces: diff --git a/README.md b/README.md index 2c4d72ecd25eaa89cba3537bbdc8943b0597e2d7..e2af003da430a58173d3f955df05dbb01dee29c6 100644 --- a/README.md +++ b/README.md @@ -19,10 +19,10 @@ Pmu收集模块是在syscall perf_event_open上开发的,用于启用内核pmu 运行bash脚本: ``` -sh build.sh +sh build.sh installPath=/home/libkperf ``` -标头和库将安装到。/输出目录。 +如上,标头和库将安装到/home/libkperf输出目录,installPath是可选参数,若没有设置,则默认安装到libkperf下的output目录。 #### 指令 diff --git a/build.sh b/build.sh index 511c3e305eac71d3d747114a81ea83e8fe0691ff..fe428c2468541dd51c0244d8109544b5b555df7a 100644 --- a/build.sh +++ b/build.sh @@ -19,10 +19,15 @@ PROJECT_DIR=$(realpath "${CURRENT_DIR}") BUILD_DIR=${PROJECT_DIR}/_build THIRD_PARTY=${PROJECT_DIR}/third_party/ +INSTALL_PATH=${PROJECT_DIR}/output/ +BUILD_TYPE=Release +# Test cases are not compiled by default. +INCLUDE_TEST=false + source ${PROJECT_DIR}/build/common.sh creat_dir "${BUILD_DIR}" -# 指定所有依赖使用的gcc +# Specifies the gcc used by all dependencies. export CC=gcc export CXX=g++ if [ -d "${THIRD_PARTY}/local" ];then @@ -32,15 +37,19 @@ else creat_dir ${THIRD_PARTY}/local fi -# 默认情况下不编译测试用例 -INCLUDE_TEST=OFF -echo "$1" - -# 如果第一个参数是 "test",则设置 INCLUDE_TEST 为 ON -if [[ "$1" == "test" ]]; then - build_googletest $THIRD_PARTY - INCLUDE_TEST=ON -fi +for arg in "$@"; do + case "$arg" in + test=*) + INCLUDE_TEST="${arg#*=}" + ;; + installPath=*) + INSTALL_PATH="${arg#*=}" + ;; + build_type=*) + BUILD_TYPE="${arg#*=}" + ;; + esac +done # build libprof.so libraries including libprocfs.so libprocfs.a libpmu.so libpmu.a libtrace.so libtrace.so function build_elfin() { @@ -72,15 +81,15 @@ function build_elfin() { build_libprof() { cd $BUILD_DIR - cmake -DINCLUDE_TEST=$INCLUDE_TEST .. + cmake -DINCLUDE_TEST=${INCLUDE_TEST} -DCMAKE_INSTALL_PREFIX=${INSTALL_PATH} -DCMAKE_BUILD_TYPE=${BUILD_TYPE} .. make -j ${cpu_core_num} make install - echo "build_libprof success" + echo "build_libkperf success" } function build_test() { - if [ "$INCLUDE_TEST" = "ON" ]; then + if [ "$INCLUDE_TEST" = "true" ]; then execute_binary "$PROJECT_DIR" fi } @@ -91,6 +100,6 @@ main() { build_test } -# bash build.sh test来获取UT +# bash build.sh test=true installPath=/home/ build_type=Release .The last three settings are optional. main $@ diff --git a/pmu/pmu_list.cpp b/pmu/pmu_list.cpp index e79b854f034f304b392f0b4758307a85867609fe..a3b14995ab1dc8371dcb95a45b1527209cad5bb2 100644 --- a/pmu/pmu_list.cpp +++ b/pmu/pmu_list.cpp @@ -76,7 +76,7 @@ namespace KUNPENG_PMU { if (err != SUCCESS) { return err; } - fdNum += cpuTopoList.size() + procTopoList.size(); + fdNum += cpuTopoList.size() * procTopoList.size(); std::shared_ptr evtList = std::make_shared(GetSymbolMode(pd), cpuTopoList, procTopoList, pmuTaskAttrHead->pmuEvt); InsertEvtList(pd, evtList); diff --git a/test/test_perf/CMakeLists.txt b/test/test_perf/CMakeLists.txt index 74f71021538bc56c72c0513c1cfba0ebe67a80bd..eda080896c47983abba50ae609c7d6dc444a46ae 100644 --- a/test/test_perf/CMakeLists.txt +++ b/test/test_perf/CMakeLists.txt @@ -9,6 +9,5 @@ set(CMAKE_CXX_STANDARD 14) aux_source_directory(. SOURCE_SRC) add_executable(test_perf ${SOURCE_SRC} ${CMAKE_CURRENT_LIST_DIR}/../../util/pcerr.cpp) target_link_libraries(test_perf sym kperf gtest m gtest_main elf_static dwarf_static pthread -g) -install(TARGETS test_perf DESTINATION ${CMAKE_INSTALL_PREFIX}/ COMPONENT test) add_subdirectory(case) diff --git a/test/test_symbol/CMakeLists.txt b/test/test_symbol/CMakeLists.txt index 303c01f897bae84d2c02de5bd6fe3689fd3e8e54..80b52048a636b684021722d93acd9d5db0c76ef8 100644 --- a/test/test_symbol/CMakeLists.txt +++ b/test/test_symbol/CMakeLists.txt @@ -5,6 +5,5 @@ set(CMAKE_CXX_STANDARD 14) aux_source_directory(. SOURCE_SRC) add_executable(test_symbol ${SOURCE_SRC} ${CMAKE_CURRENT_LIST_DIR}/../../util/pcerr.cpp) target_link_libraries(test_symbol sym gtest m gmock gtest_main elf_static dwarf_static pthread) -install(TARGETS test_symbol DESTINATION ${CMAKE_INSTALL_PREFIX}/ COMPONENT test) add_subdirectory(case) \ No newline at end of file