diff --git a/CMakeLists.txt b/CMakeLists.txt index fefaff5543624bce21429b4367b16ed5f65f5ba2..02d1b5c4810177982185d849be727b9138afca3a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,10 +9,11 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) list (APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") -option(ENABLE_EXTRAE "Enable Extrae" OFF) -option(ENABLE_DLB "Enable DLB" OFF) +option(BACKEND_EXTRAE "Enable Extrae" OFF) +option(BACKEND_DLB "Enable DLB" OFF) option(BUILD_C_FORTRAN "Enable C and Fortran Interfaces" ON) option(GEN_BINDINGS "Use Shroud to Generate C/Fortran interface" OFF) + add_library(sit SHARED) set(SIT_PUBLIC_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include) @@ -25,8 +26,6 @@ target_include_directories(sit PUBLIC ) -#set_target_properties(sit PROPERTIES PUBLIC_HEADER "${SIT_PUBLIC_HEADERS}") - if(BUILD_C_FORTRAN) enable_language(Fortran) set(CMAKE_Fortran_FORMAT FREE) diff --git a/cmake/FindExtrae.cmake b/cmake/FindExtrae.cmake index 051810a4fbd08854044448b033a3a3cfc5e919ec..6fe5ebc791c0a7f220f28c997e9cab13b50d274a 100644 --- a/cmake/FindExtrae.cmake +++ b/cmake/FindExtrae.cmake @@ -15,13 +15,13 @@ Result Variables This will define the following variables: -``EXTRAE_FOUND`` +``Extrae_FOUND`` True if the system has the Extrae library. -``EXTRAE_DIR`` +``Extrae_DIR`` The root directory of the Extrae library. -``EXTRAE_INCLUDE_DIRS`` +``Extrae_INCLUDE_DIRS`` Include directories needed to use Extrae. -``EXTRAE_LIBRARIES`` +``Extrae_LIBRARIES`` Libraries needed to link to Extrae. Cache Variables @@ -29,59 +29,59 @@ Cache Variables The following cache variables may also be set: -``EXTRAE_DIR`` +``Extrae_DIR`` The Extrae installation directory (prefix). #]=======================================================================] -if(NOT EXTRAE_DIR) - if(DEFINED ENV{EXTRAE_HOME}) - message(STATUS "Find Extrae: No EXTRAE_DIR provided: Falling back on $ENV{EXTRAE_HOME}") - set(EXTRAE_DIR $ENV{EXTRAE_HOME} ) +if(NOT Extrae_DIR) + if(DEFINED ENV{Extrae_HOME}) + message(STATUS "Find Extrae: No Extrae_DIR provided: Falling back on $ENV{Extrae_HOME}") + set(Extrae_DIR $ENV{Extrae_HOME} ) else() - message(FATAL_ERROR "Find Extrae: Couldn't get from $EXTRAE_HOME, please specify installation location with -DEXTRAE_DIR") + message(STATUS "Find Extrae: Trying to find Extrae in the normal system paths as $Extrae_HOME is not specified") endif() endif() -if(DEFINED EXTRAE_LIB) - find_library(EXTRAE_LIBRARY - NAMES ${EXTRAE_LIB} - HINTS ${EXTRAE_DIR} +if(DEFINED Extrae_LIB) + find_library(Extrae_LIBRARY + NAMES ${Extrae_LIB} + HINTS ${Extrae_DIR} PATH_SUFFIXES lib lib64) else() - find_library(EXTRAE_LIBRARY + find_library(Extrae_LIBRARY NAMES seqtrace - HINTS ${EXTRAE_DIR} + HINTS ${Extrae_DIR} PATH_SUFFIXES lib lib64) endif() -find_path(EXTRAE_INCLUDE_DIR +find_path(Extrae_INCLUDE_DIR NAMES extrae.h - PATHS ${EXTRAE_DIR} + PATHS ${Extrae_DIR} PATH_SUFFIXES include ) include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(EXTRAE +find_package_handle_standard_args(Extrae REQUIRED_VARS - EXTRAE_LIBRARY - EXTRAE_INCLUDE_DIR + Extrae_LIBRARY + Extrae_INCLUDE_DIR ) -if(EXTRAE_FOUND) - set(EXTRAE_LIBRARIES ${EXTRAE_LIBRARY}) - set(EXTRAE_INCLUDE_DIRS ${EXTRAE_INCLUDE_DIR}) +if(Extrae_FOUND) + set(Extrae_LIBRARIES ${Extrae_LIBRARY}) + set(Extrae_INCLUDE_DIRS ${Extrae_INCLUDE_DIR}) endif() -if(NOT EXTRAE_FOUND) +if(NOT Extrae_FOUND) message(FATAL_ERROR "Did not find required library Extrae") else() - message(STATUS "Using Extrae in installation: ${EXTRAE_DIR}") + message(STATUS "Using Extrae in installation: ${Extrae_DIR}") endif() -mark_as_advanced(EXTRAE_DIR) +mark_as_advanced(Extrae_DIR) diff --git a/src/backends/default/default.cpp b/src/backends/default/default.cpp index 85a189d62eaf84b104307a5e1741ad31a2fd55f4..34f199d8ecdb568c6ed95c589b4c729d957a957d 100644 --- a/src/backends/default/default.cpp +++ b/src/backends/default/default.cpp @@ -4,18 +4,18 @@ #include "default.hpp" void DefaultStrategy::region_start( - const SITRegionInformation ®ion) const noexcept { + const SITRegionInformation ®ion) noexcept { std::cout << "Region start: " << region.name << std::endl; } void DefaultStrategy::region_stop( - const SITRegionInformation ®ion) const noexcept { + const SITRegionInformation ®ion) noexcept { std::cout << "Region stop: " << region.name << std::endl; } -void DefaultStrategy::init() const noexcept { +void DefaultStrategy::init() noexcept { std::cout << "SIT_init() Backend: Default " << std::endl; } -void DefaultStrategy::finalize() const noexcept { +void DefaultStrategy::finalize() noexcept { std::cout << "SIT_finalize() Backend: Default " << std::endl; } diff --git a/src/backends/default/default.hpp b/src/backends/default/default.hpp index 1cb6060526f5b53aa2c5ffa4921e2d35801ce6af..1d7b57e2cc2cd29628a5e52e72afaaadf071349e 100644 --- a/src/backends/default/default.hpp +++ b/src/backends/default/default.hpp @@ -5,8 +5,8 @@ class DefaultStrategy : public SITProfilingStrategy { public: inline static const std::string_view name = "Default"; - void region_start(const SITRegionInformation ®ion) const noexcept override; - void region_stop(const SITRegionInformation ®ion) const noexcept override; - virtual void init() const noexcept; - virtual void finalize() const noexcept; + void region_start(const SITRegionInformation ®ion) noexcept override; + void region_stop(const SITRegionInformation ®ion) noexcept override; + virtual void init() noexcept; + virtual void finalize() noexcept; }; diff --git a/src/backends/dlb/dlb.cpp b/src/backends/dlb/dlb.cpp index 4b34700af71a7fa96b708f97594a498439b7c5b4..c474dad7ce300a9762766ead2a72bd878854c862 100644 --- a/src/backends/dlb/dlb.cpp +++ b/src/backends/dlb/dlb.cpp @@ -4,7 +4,7 @@ #include void DLBTalpStrategy::region_start( - const SITRegionInformation ®ion) const noexcept { + const SITRegionInformation ®ion) noexcept { // we have to create a small std::string thing because we cannot assume that // the string_view passed is properly null terminated auto handle = DLB_MonitoringRegionRegister(std::string(region.name).c_str()); @@ -12,17 +12,17 @@ void DLBTalpStrategy::region_start( } void DLBTalpStrategy::region_stop( - const SITRegionInformation ®ion) const noexcept { + const SITRegionInformation ®ion) noexcept { auto handle = DLB_MonitoringRegionRegister(std::string(region.name).c_str()); DLB_MonitoringRegionStop(handle); } -void DLBTalpStrategy::init() const noexcept { +void DLBTalpStrategy::init() noexcept { DLB_Init(0, NULL, "--talp"); std::cout << "SIT::" << name << " init()" << std::endl; } -void DLBTalpStrategy::finalize() const noexcept { +void DLBTalpStrategy::finalize() noexcept { DLB_Finalize(); std::cout << "SIT::" << name << " finalize()" << std::endl; } diff --git a/src/backends/dlb/dlb.hpp b/src/backends/dlb/dlb.hpp index 1e48b41ac6e09396259d279f325af21e011c97f6..99eef7814778f7401c32ba5a8b12f31fefc24985 100644 --- a/src/backends/dlb/dlb.hpp +++ b/src/backends/dlb/dlb.hpp @@ -4,8 +4,8 @@ class DLBTalpStrategy : public SITProfilingStrategy { public: inline static const std::string_view name = "DLB"; - void region_start(const SITRegionInformation ®ion) const noexcept override; - void region_stop(const SITRegionInformation ®ion) const noexcept override; - virtual void init() const noexcept; - virtual void finalize() const noexcept; + void region_start(const SITRegionInformation ®ion) noexcept override; + void region_stop(const SITRegionInformation ®ion) noexcept override; + virtual void init() noexcept; + virtual void finalize() noexcept; }; diff --git a/src/backends/extrae/CMakeLists.txt b/src/backends/extrae/CMakeLists.txt index 670a7047344e129dd1352fcdc90cb93f434b0b88..d35754d6c2e883092113e3f34ca556f341883659 100644 --- a/src/backends/extrae/CMakeLists.txt +++ b/src/backends/extrae/CMakeLists.txt @@ -1,2 +1,9 @@ -#find_package(Extrae REQUIRED) -target_sources(sit PRIVATE extrae_type_stack.cpp extrae_value_stack.cpp) \ No newline at end of file +find_package(Extrae REQUIRED) +target_sources(sit PRIVATE extrae_type_stack.cpp) +if(Extrae_FOUND) +target_include_directories(sit + PRIVATE ${Extrae_INCLUDE_DIRS}) +target_link_libraries(sit PUBLIC ${Extrae_LIBRARIES}) +target_compile_definitions(sit PRIVATE "ENABLE_EXTRAE") +endif() + diff --git a/src/backends/extrae/extrae_type_stack.cpp b/src/backends/extrae/extrae_type_stack.cpp index 6360abff914cea6b5e596c7904cb7a75f0456d83..21fb90a40abab01cd7cc32d5b77875b3b64cd3f0 100644 --- a/src/backends/extrae/extrae_type_stack.cpp +++ b/src/backends/extrae/extrae_type_stack.cpp @@ -1,17 +1,266 @@ -#include "sit_strategy.hpp" +#include "extrae_type_stack.hpp" +#include #include +#include +#include +#include +#include +#include +#include -class ExtraeTypeStackStrategy : public SITProfilingStrategy { +extern "C" { +#include +} -public: - inline static const std::string_view name = "Extrae::TypeStack"; - void - region_start(const SITRegionInformation ®ion) const noexcept override {} - void region_stop(const SITRegionInformation ®ion) const noexcept override { +const std::string ExtraeTypeStackStrategy::paraverConfigHead = R"( +#ParaverCFG +ConfigFile.Version: 3.4 +ConfigFile.NumWindows: 2 +ConfigFile.BeginDescription +Configuration to visualize the annotation done by SIT in Paraver +ConfigFile.EndDescription +)"; + + +const std::string ExtraeTypeStackStrategy::paraverConfigOverviewWindow = R"( +################################################################################ +< NEW DISPLAYING WINDOW SIT Annotation Overview > +################################################################################ +window_name SIT Annotation Overview +window_type single +window_width 600 +window_height 114 +window_comm_lines_enabled false +window_flags_enabled true +window_noncolor_mode true +window_custom_color_enabled false +window_semantic_scale_min_at_zero false +window_logical_filtered true +window_physical_filtered false +window_intracomms_enabled true +window_intercomms_enabled true +window_comm_fromto true +window_comm_tagsize true +window_comm_typeval true +window_compute_y_max false +window_level thread +window_scale_relative 1.000000000000 +window_end_time_relative 1.000000000000 +window_object appl { 1, { All } } +window_begin_time_relative 0.000000000000 +window_open true +window_drawmode draw_maximum +window_drawmode_rows draw_maximum +window_pixel_size 1 +window_labels_to_draw 1 +window_object_axis_position 0 +window_selected_functions { 14, { {cpu, Active Thd}, {appl, Adding}, {task, Adding}, {thread, Last Evt Val}, {node, Adding}, {system, Adding}, {workload, Adding}, {from_obj, All}, {to_obj, All}, {tag_msg, All}, {size_msg, All}, {bw_msg, All}, {evt_type, =}, {evt_value, All} } } +window_compose_functions { 9, { {compose_cpu, As Is}, {compose_appl, As Is}, {compose_task, As Is}, {compose_thread, Stacked Val}, {compose_node, As Is}, {compose_system, As Is}, {compose_workload, As Is}, {topcompose1, As Is}, {topcompose2, As Is} } } +window_filter_module evt_type SIT_REPLACE_NUM_LEVELS SIT_REPLACE_LEVELS +)"; + + +const std::string ExtraeTypeStackStrategy::paraverConfigLevelWindow = R"( +################################################################################ +< NEW DISPLAYING WINDOW SIT_REPLACE_WINDOW_NAME > +################################################################################ +window_name SIT_REPLACE_WINDOW_NAME +window_type single +window_width 600 +window_height 114 +window_comm_lines_enabled false +window_flags_enabled true +window_noncolor_mode true +window_custom_color_enabled false +window_semantic_scale_min_at_zero false +window_logical_filtered true +window_physical_filtered false +window_intracomms_enabled true +window_intercomms_enabled true +window_comm_fromto true +window_comm_tagsize true +window_comm_typeval true +window_compute_y_max false +window_level thread +window_scale_relative 1.000000000000 +window_end_time_relative 1.000000000000 +window_object appl { 1, { All } } +window_begin_time_relative 0.000000000000 +window_open true +window_drawmode draw_maximum +window_drawmode_rows draw_maximum +window_pixel_size 1 +window_labels_to_draw 1 +window_object_axis_position 0 +window_selected_functions { 14, { {cpu, Active Thd}, {appl, Adding}, {task, Adding}, {thread, Last Evt Val}, {node, Adding}, {system, Adding}, {workload, Adding}, {from_obj, All}, {to_obj, All}, {tag_msg, All}, {size_msg, All}, {bw_msg, All}, {evt_type, =}, {evt_value, All} } } +window_compose_functions { 9, { {compose_cpu, As Is}, {compose_appl, As Is}, {compose_task, As Is}, {compose_thread, As Is}, {compose_node, As Is}, {compose_system, As Is}, {compose_workload, As Is}, {topcompose1, As Is}, {topcompose2, As Is} } } +window_filter_module evt_type 1 SIT_REPLACE_EVENT_TYPE +)"; + + +void ExtraeTypeStackStrategy::init() noexcept { + + auto isInitializedVal = Extrae_is_initialized(); + if (isInitializedVal == 0) { + // Extrae is not initialized yet see + // https://github.com/bsc-performance-tools/extrae/blob/daee11a2f98e301eb146608f51df0c844e1ff381/include/extrae_types.h#L33 + Extrae_init(); + didInitialize = true; + } + + // Check if we wanna write a configuration file + const auto ENV_SIT_EXTRAE_WRITE_CONFIG_FILE = std::getenv("SIT_EXTRAE_WRITE_CONFIG_FILE"); + const auto ENV_SIT_EXTRAE_CONFIG_FILE_PATH = std::getenv("SIT_EXTRAE_CONFIG_FILE_PATH"); + if(ENV_SIT_EXTRAE_WRITE_CONFIG_FILE != nullptr){ + const auto configFileString= std::string(ENV_SIT_EXTRAE_WRITE_CONFIG_FILE); + if(configFileString.compare("1") == 0 || configFileString.compare("ON") == 0){ + EXTRAE_WRITE_CONFIG_FILE = true; + } + } + + if(ENV_SIT_EXTRAE_CONFIG_FILE_PATH != nullptr){ + EXTRAE_CONFIG_FILE_PATH = std::string(ENV_SIT_EXTRAE_CONFIG_FILE_PATH); + } + + + //} +} + +extrae_value +ExtraeTypeStackStrategy::get_value_by_region_name(const std::string &name) { + // maybe insert + if (regionMapData.regionNameToValue.count(name) > 0) { + return regionMapData.regionNameToValue[name]; + } + else + // if not allocate new entry + { + const auto newValue= regionMapData.regionNameToValue.size()+1; + regionMapData.regionNameToValue[name] = newValue; + return newValue; + } +} + +void ExtraeTypeStackStrategy::region_start( + const SITRegionInformation ®ion) noexcept { + + // First push to stack + const auto regionName = std::string(region.name); + auto typeOffset = regionStackData.regionNameStack.size(); + regionStackData.regionNameStack.push(regionName); + + regionStackData.historicMaxStackSize = std::max(typeOffset, regionStackData.historicMaxStackSize); + + auto value = get_value_by_region_name(regionName); + + auto type = baseType + typeOffset; + + Extrae_eventandcounters(type, value); +} +void ExtraeTypeStackStrategy::region_stop( + const SITRegionInformation ®ion) noexcept { + + if (regionStackData.regionNameStack.empty()) { + // whoops + std::cout << "imbalanced region stop REASON: Emtpy stack " << region.name << std::endl; + return; } - virtual void init() const noexcept {} - virtual void finalize() const noexcept {} -}; + const auto &lastRegionName = regionStackData.regionNameStack.top(); + + if (lastRegionName.compare(region.name) == 0) { + // its the same -> we pop it and end that stack level with a 0 + regionStackData.regionNameStack.pop(); + auto typeOffset = regionStackData.regionNameStack.size(); + auto type = baseType + typeOffset; + Extrae_eventandcounters(type, 0); + return; + } else { + std::cout << "imbalanced region stop " << region.name << std::endl; + } +} + +void ExtraeTypeStackStrategy::finalize() noexcept { + + + unsigned int numberOfRegionsRegistered = regionMapData.regionNameToValue.size(); + std::vector values{}; + std::vector routine_names{}; + + for (const auto &item : regionMapData.regionNameToValue) { + const auto &routine_name = item.first; + const auto &value = item.second; + routine_names.push_back(routine_name); + values.push_back(value); + } + // leaking memory a bit, but c vs c++ strings are not worth making it not + // leaky? + char **routine_c_names = new char *[numberOfRegionsRegistered]; + for (auto i = 0; i < numberOfRegionsRegistered; i++) { + routine_c_names[i] = new char[routine_names[i].size() + 1]; + std::strcpy(routine_c_names[i], routine_names[i].c_str()); + } + + + for (auto level = 0; level <= regionStackData.historicMaxStackSize; level++) { + extrae_type_t type = baseType+level; + std::string description = "Level: " + std::to_string(level); + Extrae_define_event_type(&type, const_cast(description.c_str()), + &numberOfRegionsRegistered, values.data(), routine_c_names); + } + + + if(EXTRAE_WRITE_CONFIG_FILE){ + std::string fileName = EXTRAE_CONFIG_FILE_PATH + "SIT_Annotations.cfg"; + std::ofstream outputFile; + outputFile.open(fileName); + + // write header + outputFile << paraverConfigHead; + + // compute overview + auto numberOfEventTypes = regionStackData.historicMaxStackSize + 1 ; // 0 based so plus 1 + auto allTypes = std::vector(numberOfEventTypes); + std::iota(std::begin(allTypes), std::end(allTypes), baseType); // Fill with baseType baseType+1 .. + + // Build a small list of all types + std::string allTypesString =""; + for(const auto& type : allTypes){ + allTypesString+=std::to_string(type) + " "; + } + + auto overviewReplacedNumLevels = std::regex_replace(paraverConfigOverviewWindow, std::regex("SIT_REPLACE_NUM_LEVELS"), std::to_string(numberOfEventTypes)); + auto overviewReplacedAllTypes= std::regex_replace(overviewReplacedNumLevels, std::regex("SIT_REPLACE_LEVELS"), allTypesString); + + + // write Overview + outputFile << overviewReplacedAllTypes; + outputFile << std::endl; + + // write seperate windows + for (auto level = 0; level <= regionStackData.historicMaxStackSize; level++) { + auto type = baseType+level; + std::string windowName = "SIT Instrumentation Level: " + std::to_string(level); + + auto replacedEventType = std::regex_replace(paraverConfigLevelWindow, std::regex("SIT_REPLACE_EVENT_TYPE"), std::to_string(baseType+level)); + auto replacedWindowName = std::regex_replace(replacedEventType, std::regex("SIT_REPLACE_WINDOW_NAME"), windowName); + + // write Overview + outputFile << replacedWindowName; + outputFile << std::endl; + + + + } + + } + + + if (didInitialize) { + // Assumption is that if we needed to initialize the lib we also need to + // finalize it + Extrae_fini(); + } +} diff --git a/src/backends/extrae/extrae_type_stack.hpp b/src/backends/extrae/extrae_type_stack.hpp new file mode 100644 index 0000000000000000000000000000000000000000..a54fb24ff7174dddcabd68d08986f6115bfaefb0 --- /dev/null +++ b/src/backends/extrae/extrae_type_stack.hpp @@ -0,0 +1,40 @@ +#include "sit_strategy.hpp" +#include +#include +#include +// #include +typedef unsigned long extrae_value; +typedef unsigned long extrae_type; + +struct RegionStackData{ + std::stack regionNameStack; + std::size_t historicMaxStackSize; +}; + +struct RegionMapData{ + std::unordered_map regionNameToValue; +}; + + +class ExtraeTypeStackStrategy : public SITProfilingStrategy { + +private: + inline static bool EXTRAE_WRITE_CONFIG_FILE=false; + inline static std::string EXTRAE_CONFIG_FILE_PATH ="./"; + static const std::string paraverConfigHead; + static const std::string paraverConfigOverviewWindow; + static const std::string paraverConfigLevelWindow; + inline static thread_local bool didInitialize; + inline static constexpr unsigned long baseType = 81000; + inline static thread_local RegionStackData regionStackData; + inline static thread_local RegionMapData regionMapData; + static extrae_value get_value_by_region_name(const std::string &name); + +public: + inline static const std::string_view name = "Extrae::TypeStack"; + + void region_start(const SITRegionInformation ®ion) noexcept override; + void region_stop(const SITRegionInformation ®ion) noexcept override; + virtual void init() noexcept; + virtual void finalize() noexcept; +}; diff --git a/src/backends/extrae/extrae_value_stack.cpp b/src/backends/extrae/extrae_value_stack.cpp index 90cef232f2cf98e10d0378d11b16558077a1792e..2add7bc17b0f7203fdebfd7deca9ce0e19479ceb 100644 --- a/src/backends/extrae/extrae_value_stack.cpp +++ b/src/backends/extrae/extrae_value_stack.cpp @@ -1,17 +1,17 @@ #include "extrae_value_stack.hpp" void ExtraeValueStackStrategy::region_start( - const SITRegionInformation ®ion) const noexcept { + const SITRegionInformation ®ion) noexcept { // TODO } void ExtraeValueStackStrategy::region_stop( - const SITRegionInformation ®ion) const noexcept { + const SITRegionInformation ®ion) noexcept { // TODO } -void ExtraeValueStackStrategy::init() const noexcept { +void ExtraeValueStackStrategy::init() noexcept { // TODO } -void ExtraeValueStackStrategy::finalize() const noexcept { +void ExtraeValueStackStrategy::finalize() noexcept { // TODO } diff --git a/src/backends/extrae/extrae_value_stack.hpp b/src/backends/extrae/extrae_value_stack.hpp index 039c674c51dfbf7c2405703b3b14bc8357b951d3..4bde6fd90d8ea1b9e41b2f99157fee77ee9494ae 100644 --- a/src/backends/extrae/extrae_value_stack.hpp +++ b/src/backends/extrae/extrae_value_stack.hpp @@ -4,8 +4,10 @@ class ExtraeValueStackStrategy : public SITProfilingStrategy { public: inline static const std::string_view name = "Extrae::ValueStack"; - void region_start(const SITRegionInformation ®ion) const noexcept override; - void region_stop(const SITRegionInformation ®ion) const noexcept override; - virtual void init() const noexcept; - virtual void finalize() const noexcept; + virtual void + region_start(const SITRegionInformation ®ion) noexcept override; + virtual void + region_stop(const SITRegionInformation ®ion) noexcept override; + virtual void init() noexcept; + virtual void finalize() noexcept; }; diff --git a/src/backends/extrae/legacy/wrapper.cpp b/src/backends/extrae/legacy/wrapper.cpp deleted file mode 100644 index f182a704854e5e71629f667aafbb9215682cc530..0000000000000000000000000000000000000000 --- a/src/backends/extrae/legacy/wrapper.cpp +++ /dev/null @@ -1,136 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include - -extern "C" { -#include "extrae.h" -} - -class MultiLevelExtraeWrapper { -public: - static constexpr int MAX_LEVELS = 10; - -private: - static constexpr extrae_type_t BASE_EVENT = 81000; - - static std::array, MAX_LEVELS> level_stacks; - - static std::unordered_map - routine_to_value_mapper; - - static extrae_value_t _num_routines; // where the 0 is actually the no routine - - static void _maybe_add_routine_name(const std::string &routine_name) { - if (routine_to_value_mapper.count(routine_name) > 0) { - return; - } else { -#pragma omp criticial - { - _num_routines++; - routine_to_value_mapper[routine_name] = _num_routines; - } - } - } - -public: - static extrae_value_t get_routine_value(const std::string &routine_name) { - _maybe_add_routine_name(routine_name); - return routine_to_value_mapper[routine_name]; - } - static extrae_type_t get_level_event(const int level) { - return BASE_EVENT + level; - } - - static const decltype(routine_to_value_mapper) & - get_routine_to_value_mapper() { - return routine_to_value_mapper; - } - - static inline extrae_value_t pop_level_stack(const int level) { - if (level_stacks[level].empty()) { - return 0; - } - level_stacks[level].pop(); - if (level_stacks[level].empty()) { - return 0; - } - const auto value = level_stacks[level].top(); - return value; - } - - static inline void push_level_stack(const extrae_value_t value, int level) { - level_stacks[level].push(value); - } -}; - -std::unordered_map - MultiLevelExtraeWrapper::routine_to_value_mapper = - std::unordered_map(); -std::array, MultiLevelExtraeWrapper::MAX_LEVELS> - MultiLevelExtraeWrapper::level_stacks = - std::array, - MultiLevelExtraeWrapper::MAX_LEVELS>(); -extrae_value_t MultiLevelExtraeWrapper::_num_routines = 0; - -void event_start(const std::string &routineName, int level, bool withCounters) { - - extrae_type_t event = MultiLevelExtraeWrapper::get_level_event(level); - extrae_value_t value = - MultiLevelExtraeWrapper::get_routine_value(std::string(routineName)); - MultiLevelExtraeWrapper::push_level_stack(value, level); - if (withCounters) { - Extrae_eventandcounters(event, value); - } else { - Extrae_event(event, value); - } -} -void event_stop(const std::string &routineName, int level, bool withCounters) { - extrae_type_t event = MultiLevelExtraeWrapper::get_level_event(level); - extrae_value_t value = MultiLevelExtraeWrapper::pop_level_stack(level); - if (withEvents) { - Extrae_eventandcounters(event, value); - } else { - Extrae_event(event, value); - } -} - -void extrae_stop() { Extrae_shutdown(); } - -void extrae_start() { Extrae_restart(); } -void finalize() { - // now register all the routines with the different levels - unsigned n_values = - MultiLevelExtraeWrapper::get_routine_to_value_mapper().size(); - - std::vector values{}; - std::vector routine_names{}; - - for (const auto &item : - MultiLevelExtraeWrapper::get_routine_to_value_mapper()) { - const auto &routine_name = item.first; - const auto &value = item.second; - routine_names.push_back(routine_name); - values.push_back(value); - } - // leaking memory a bit, but c vs c++ strings are not worth making it not - // leaky? - char **routine_c_names = new char *[n_values]; - for (size_t i = 0; i < n_values; i++) { - routine_c_names[i] = new char[routine_names[i].size() + 1]; - std::strcpy(routine_c_names[i], routine_names[i].c_str()); - } - - for (auto level = 0; level < MultiLevelExtraeWrapper::MAX_LEVELS; level++) { - auto event = MultiLevelExtraeWrapper::get_level_event(level); - std::string description = "Level: " + std::to_string(level); - Extrae_define_event_type(&event, const_cast(description.c_str()), - &n_values, values.data(), routine_c_names); - } - - printf("\nRegistered %i regions with extrae\n", n_values); -} diff --git a/src/backends/extrae/legacy/wrapper.hpp b/src/backends/extrae/legacy/wrapper.hpp deleted file mode 100644 index e70629864f78900a23938f43a947c82ac899cdf3..0000000000000000000000000000000000000000 --- a/src/backends/extrae/legacy/wrapper.hpp +++ /dev/null @@ -1,141 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include - -extern "C" { -#include "extrae.h" -} - -Extrae_Wrapper_Init_ValueStack("Name Of Type") - Extrae_Wrapper_Init_TypeStack("Prefix Type") - - Extrae_Wrapper_Init("aklsdjföa", Type = ValueStack) - - SIMPLE INSTRUMENTATION TOOL - - enum class class MultiLevelExtraeWrapper { - public : static constexpr int MAX_LEVELS = 10; - - private : static constexpr extrae_type_t BASE_EVENT = 81000; - - static std::array, MAX_LEVELS> level_stacks; - - static std::unordered_map - routine_to_value_mapper; - - static extrae_value_t - _num_routines; // where the 0 is actually the no routine - - static void _maybe_add_routine_name(const std::string &routine_name){ - if (routine_to_value_mapper.count(routine_name) > 0){return;} -else { -#pragma omp criticial - { - _num_routines++; - routine_to_value_mapper[routine_name] = _num_routines; - } -} -} - -public: -static extrae_value_t get_routine_value(const std::string &routine_name) { - _maybe_add_routine_name(routine_name); - return routine_to_value_mapper[routine_name]; -} -static extrae_type_t get_level_event(const int level) { - return BASE_EVENT + level; -} - -static const decltype(routine_to_value_mapper) &get_routine_to_value_mapper() { - return routine_to_value_mapper; -} - -static inline extrae_value_t pop_level_stack(const int level) { - if (level_stacks[level].empty()) { - return 0; - } - level_stacks[level].pop(); - if (level_stacks[level].empty()) { - return 0; - } - const auto value = level_stacks[level].top(); - return value; -} - -static inline void push_level_stack(const extrae_value_t value, int level) { - level_stacks[level].push(value); -} -} -; - -std::unordered_map - MultiLevelExtraeWrapper::routine_to_value_mapper = - std::unordered_map(); -std::array, MultiLevelExtraeWrapper::MAX_LEVELS> - MultiLevelExtraeWrapper::level_stacks = - std::array, - MultiLevelExtraeWrapper::MAX_LEVELS>(); -extrae_value_t MultiLevelExtraeWrapper::_num_routines = 0; - -void event_start(const std::string &routineName, int level, bool withCounters) { - - extrae_type_t event = MultiLevelExtraeWrapper::get_level_event(level); - extrae_value_t value = - MultiLevelExtraeWrapper::get_routine_value(std::string(routineName)); - MultiLevelExtraeWrapper::push_level_stack(value, level); - if (withCounters) { - Extrae_eventandcounters(event, value); - } else { - Extrae_event(event, value); - } -} -void event_stop(const std::string &routineName, int level, bool withCounters) { - extrae_type_t event = MultiLevelExtraeWrapper::get_level_event(level); - extrae_value_t value = MultiLevelExtraeWrapper::pop_level_stack(level); - if (withEvents) { - Extrae_eventandcounters(event, value); - } else { - Extrae_event(event, value); - } -} - -void extrae_stop() { Extrae_shutdown(); } - -void extrae_start() { Extrae_restart(); } -void finalize() { - // now register all the routines with the different levels - unsigned n_values = - MultiLevelExtraeWrapper::get_routine_to_value_mapper().size(); - - std::vector values{}; - std::vector routine_names{}; - - for (const auto &item : - MultiLevelExtraeWrapper::get_routine_to_value_mapper()) { - const auto &routine_name = item.first; - const auto &value = item.second; - routine_names.push_back(routine_name); - values.push_back(value); - } - // leaking memory a bit, but c vs c++ strings are not worth making it not - // leaky? - char **routine_c_names = new char *[n_values]; - for (size_t i = 0; i < n_values; i++) { - routine_c_names[i] = new char[routine_names[i].size() + 1]; - std::strcpy(routine_c_names[i], routine_names[i].c_str()); - } - - for (auto level = 0; level < MultiLevelExtraeWrapper::MAX_LEVELS; level++) { - auto event = MultiLevelExtraeWrapper::get_level_event(level); - std::string description = "Level: " + std::to_string(level); - Extrae_define_event_type(&event, const_cast(description.c_str()), - &n_values, values.data(), routine_c_names); - } - - printf("\nRegistered %i regions with extrae\n", n_values); -} diff --git a/src/backends/extrae/legacy/wrapper.yaml b/src/backends/extrae/legacy/wrapper.yaml deleted file mode 100644 index 9123b2c9013aad4750be986a2aa63ef4eebf0ef7..0000000000000000000000000000000000000000 --- a/src/backends/extrae/legacy/wrapper.yaml +++ /dev/null @@ -1,8 +0,0 @@ -library: sit -cxx_header: api.hpp - -declarations: -- decl: void sit_init(std::string_view backend) -- decl: void sit_region_start(std::string_view name) -- decl: void sit_region_stop(std::string_view name) -- decl: void sit_finalize() \ No newline at end of file diff --git a/src/sit.cpp b/src/sit.cpp index 099c54295549ab32f709058a335f419747720847..d9ef341bc1a02a3637c77eff760c926f30219f48 100644 --- a/src/sit.cpp +++ b/src/sit.cpp @@ -2,8 +2,11 @@ #include "sit/sit.hpp" #include "sit_delegator.hpp" #include + +// provides a c-like way to call things with just a fuction compared to instanciate a class. namespace sit { -void init(const std::string &backend) { return SITDelegator::init(backend); } +void init(const std::string &backend) { return SITDelegator::init(backend); +} void region_start(const std::string &name) { return SITDelegator::region_start(name); } diff --git a/src/sit_delegator.cpp b/src/sit_delegator.cpp index 77b237240f8aa8e5384dcbb458f8145d97404951..b14998cd27218189d63cfb786d2803ca0ffde66f 100644 --- a/src/sit_delegator.cpp +++ b/src/sit_delegator.cpp @@ -13,7 +13,7 @@ #endif #ifdef ENABLE_EXTRAE -#include "backends/extrae/extrae_value_stack.hpp" +#include "backends/extrae/extrae_type_stack.hpp" #endif void SITDelegator::init(std::string_view backend) { @@ -23,8 +23,8 @@ void SITDelegator::init(std::string_view backend) { profiling_strategy = std::make_unique(); } #ifdef ENABLE_EXTRAE - else if (backend.compare(ExtraeValueStackStrategy::name) == 0) { - profiling_strategy = std::make_unique(); + else if (backend.compare(ExtraeTypeStackStrategy::name) == 0) { + profiling_strategy = std::make_unique(); } #endif #ifdef ENABLE_DLB diff --git a/src/sit_strategy.hpp b/src/sit_strategy.hpp index 19749c1ddf7395d1bbfe97aa3c11b131fffb8a9a..34ae59de1ca9f1041afce4321aaf7f7d7f58ae7d 100644 --- a/src/sit_strategy.hpp +++ b/src/sit_strategy.hpp @@ -15,11 +15,11 @@ class SITProfilingStrategy { public: virtual ~SITProfilingStrategy() = default; virtual void - region_start(const SITRegionInformation ®ion) const noexcept = 0; + region_start(const SITRegionInformation ®ion) noexcept = 0; virtual void - region_stop(const SITRegionInformation ®ion) const noexcept = 0; - virtual void init() const noexcept = 0; - virtual void finalize() const noexcept = 0; + region_stop(const SITRegionInformation ®ion) noexcept = 0; + virtual void init() noexcept = 0; + virtual void finalize() noexcept = 0; }; #endif // SIT_STRATEGY_HPP \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5641c326d49670c9832b3a4a41b79b6a51635971..28b6b096c809825f4920a4de3a7231fc7b2bf294 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -19,6 +19,19 @@ add_test(NAME TestCppDLB endif() +if(ENABLE_EXTRAE) +add_executable(TestCppExtraeTypeStack cpp/TestCppExtraeTypeStack.cpp) +target_link_libraries(TestCppExtraeTypeStack sit::sit) +target_include_directories(TestCppExtraeTypeStack + PRIVATE ${SIT_PUBLIC_HEADERS}) + +add_test(NAME TestCppExtraeTypeStack + COMMAND TestCppExtraeTypeStack) + + +endif() + + if(BUILD_C_FORTRAN) add_executable(TestCLink c/TestCLink.c) target_link_libraries(TestCLink sit) diff --git a/tests/cpp/TestCppExtraeTypeStack.cpp b/tests/cpp/TestCppExtraeTypeStack.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3f72c1c292d4966bb8910d30183145db88dc8e0a --- /dev/null +++ b/tests/cpp/TestCppExtraeTypeStack.cpp @@ -0,0 +1,17 @@ +#include "sit/sit.hpp" + +int main() { + sit::init("Extrae::TypeStack"); + + sit::region_start("init"); + sit::region_start("init_ts"); + sit::region_stop("init_ts"); + + sit::region_start("init_io"); + sit::region_stop("init_io"); + sit::region_stop("init"); + + sit::region_start("init_ts"); + sit::region_stop("init_ts"); + sit::finalize(); +} \ No newline at end of file