diff --git a/ci/build_cpp.sh b/ci/build_cpp.sh index f1ddf2abdd..2c96e3dfd5 100755 --- a/ci/build_cpp.sh +++ b/ci/build_cpp.sh @@ -144,6 +144,7 @@ cmake -G "${CMAKE_GENERATOR:-Ninja}" \ -Dvt_build_extended_tests="${VT_EXTENDED_TESTS_ENABLED:-1}" \ -Dvt_zoltan_enabled="${VT_ZOLTAN_ENABLED:-0}" \ -Dvt_tv_enabled="${VT_TV_ENABLED:-0}" \ + -Dvt_perf_enabled="${VT_PERF_ENABLED:-0}" \ -Dvt_production_build_enabled="${VT_PRODUCTION_BUILD_ENABLED:-0}" \ -Dvt_unity_build_enabled="${VT_UNITY_BUILD_ENABLED:-0}" \ -Dvt_diagnostics_enabled="${VT_DIAGNOSTICS_ENABLED:-1}" \ diff --git a/cmake/configure_options.cmake b/cmake/configure_options.cmake index e3509db735..f593260af6 100644 --- a/cmake/configure_options.cmake +++ b/cmake/configure_options.cmake @@ -100,6 +100,9 @@ define_option(vt_rdma_tests_enabled "RDMA tests" "Build VT with RDMA tests enabl ON vt_feature_cmake_rdma_tests ) +define_option(vt_perf_enabled "perf task measurement" + "Build VT with Linux perf to measure low level metrics of interest" OFF vt_feature_cmake_perf +) ##################################################### #################### DIAGNOSTICS #################### diff --git a/cmake/load_packages.cmake b/cmake/load_packages.cmake index 754b62ea43..7a3a3130ab 100644 --- a/cmake/load_packages.cmake +++ b/cmake/load_packages.cmake @@ -18,5 +18,8 @@ include(cmake/load_libunwind.cmake) # Optionally link with Zoltan include(cmake/load_zoltan_package.cmake) +# If enabled, test if perf is available and works +include(cmake/load_perf.cmake) + # Tests include(cmake/test_vt.cmake) diff --git a/cmake/load_perf.cmake b/cmake/load_perf.cmake new file mode 100644 index 0000000000..1fee0328ee --- /dev/null +++ b/cmake/load_perf.cmake @@ -0,0 +1,45 @@ +set(vt_perf_found "0") + +if (vt_perf_enabled) + # check if linux + if (CMAKE_SYSTEM_NAME STREQUAL "Linux") + # check if there's the perf header we need + include(CheckIncludeFiles) + CHECK_INCLUDE_FILES("linux/perf_event.h" HAVE_PERF_EVENT_H) + if (HAVE_PERF_EVENT_H) + # check if the kernel is recent enough + string(REPLACE "." ";" VERSION_LIST ${CMAKE_SYSTEM_VERSION}) + list(GET VERSION_LIST 0 KERNEL_MAJOR_VERSION) + if (KERNEL_MAJOR_VERSION GREATER_EQUAL 4) + # check if a simple perf stat runs without issues + execute_process( + COMMAND perf stat pwd + RESULT_VARIABLE PERF_STAT_RESULT + OUTPUT_QUIET + ERROR_QUIET + ) + if (PERF_STAT_RESULT EQUAL 0) + message(STATUS "Perf measurements enabled.") + set(vt_perf_enabled "1") + set(vt_perf_found "1") + else () + message(WARNING "Perf disabled: \"perf stat\" results in non-zero error code.") + set(vt_perf_enabled "0") + set(vt_perf_found "0") + endif () + else () + message(WARNING "Perf disabled: kernel major version is less than 4.") + set(vt_perf_enabled "0") + set(vt_perf_found "0") + endif () + else () + message(WARNING "Perf disabled: could not find \"perf_event.h\".") + set(vt_perf_enabled "0") + set(vt_perf_found "0") + endif () + else () + message(WARNING "Perf disabled: system name is not Linux.") + set(vt_perf_enabled "0") + set(vt_perf_found "0") + endif () +endif () diff --git a/cmake_config.h.in b/cmake_config.h.in index 86585007df..7fd10fdfd9 100644 --- a/cmake_config.h.in +++ b/cmake_config.h.in @@ -68,6 +68,7 @@ #define vt_feature_cmake_external_fmt @vt_feature_cmake_external_fmt@ #define vt_feature_cmake_libunwind @vt_feature_cmake_libunwind@ #define vt_feature_cmake_tv @vt_feature_cmake_tv@ +#define vt_feature_cmake_perf @vt_feature_cmake_perf@ #define vt_detected_max_num_nodes @cmake_detected_max_num_nodes@ diff --git a/src/vt/configs/features/features_defines.h b/src/vt/configs/features/features_defines.h index 8186bdca24..f6451e4479 100644 --- a/src/vt/configs/features/features_defines.h +++ b/src/vt/configs/features/features_defines.h @@ -75,6 +75,7 @@ #define vt_feature_fmt_external 0 || vt_feature_cmake_external_fmt #define vt_feature_libunwind 0 || vt_feature_cmake_libunwind #define vt_feature_tv 0 || vt_feature_cmake_tv +#define vt_feature_perf 0 || vt_feature_cmake_perf #define vt_check_enabled(test_option) (vt_feature_ ## test_option != 0) diff --git a/src/vt/configs/features/features_featureswitch.h b/src/vt/configs/features/features_featureswitch.h index 6a65a249ae..10c9b71ccb 100644 --- a/src/vt/configs/features/features_featureswitch.h +++ b/src/vt/configs/features/features_featureswitch.h @@ -64,5 +64,6 @@ "debug prints disabled)" #define vt_feature_str_trace_enabled "Tracing Projections" #define vt_feature_str_zoltan "Zoltan for load balancing" +#define vt_feature_str_perf "perf for event measurement" #endif /*INCLUDED_VT_CONFIGS_FEATURES_FEATURES_FEATURESWITCH_H*/