diff --git a/src/backends/extrae/extrae_type_stack.cpp b/src/backends/extrae/extrae_type_stack.cpp index 23c5b4f917ec74a58fda020b84cff14a7bfdbe0d..831b8d1b2190f2a7e4df3b73bd2883c9f6607e19 100644 --- a/src/backends/extrae/extrae_type_stack.cpp +++ b/src/backends/extrae/extrae_type_stack.cpp @@ -1,28 +1,25 @@ #include "extrae_type_stack.hpp" -#include -#include -#include -#include #include -#include +#include #include +#include #include +#include +#include +#include extern "C" { #include } -ExtraeTypeStackStrategy::ExtraeTypeStackStrategy(){ - parallelism_descriptor_={ - .mpi_descriptor_ = MPIDescriptor::Aware, - .thread_descriptor_ = ThreadDescriptor::Supported // i guess no test currently for this +ExtraeTypeStackStrategy::ExtraeTypeStackStrategy() { + parallelism_descriptor_ = { + .mpi_descriptor_ = MPIDescriptor::Aware, + .thread_descriptor_ = + ThreadDescriptor::Supported // i guess no test currently for this }; } - - - - const std::string ExtraeTypeStackStrategy::paraverConfigHead = R"( #ParaverCFG ConfigFile.Version: 3.4 @@ -32,7 +29,6 @@ Configuration to visualize the annotation done by neSmiK in Paraver ConfigFile.EndDescription )"; - const std::string ExtraeTypeStackStrategy::paraverConfigOverviewWindow = R"( ################################################################################ < NEW DISPLAYING WINDOW neSmiK Annotation Overview > @@ -42,7 +38,7 @@ window_type single window_width 600 window_height 114 window_comm_lines_enabled false -window_flags_enabled true +window_flags_enabled false window_noncolor_mode true window_custom_color_enabled false window_semantic_scale_min_at_zero false @@ -70,7 +66,6 @@ window_compose_functions { 9, { {compose_cpu, As Is}, {compose_appl, As Is}, {co window_filter_module evt_type NESMIK_REPLACE_NUM_LEVELS NESMIK_REPLACE_LEVELS )"; - const std::string ExtraeTypeStackStrategy::paraverConfigLevelWindow = R"( ################################################################################ < NEW DISPLAYING WINDOW NESMIK_REPLACE_WINDOW_NAME > @@ -80,7 +75,7 @@ window_type single window_width 600 window_height 114 window_comm_lines_enabled false -window_flags_enabled true +window_flags_enabled false window_noncolor_mode true window_custom_color_enabled false window_semantic_scale_min_at_zero false @@ -108,8 +103,7 @@ window_compose_functions { 9, { {compose_cpu, As Is}, {compose_appl, As Is}, {co window_filter_module evt_type 1 NESMIK_REPLACE_EVENT_TYPE )"; - -void ExtraeTypeStackStrategy::Init() noexcept { +void ExtraeTypeStackStrategy::Init() noexcept { auto isInitializedVal = Extrae_is_initialized(); if (isInitializedVal == 0) { @@ -118,35 +112,17 @@ void ExtraeTypeStackStrategy::Init() noexcept { Extrae_init(); didInitialize = true; } - - // Check if we wanna write a configuration file - const auto ENV_NESMIK_EXTRAE_WRITE_CONFIG_FILE = std::getenv("NESMIK_EXTRAE_WRITE_CONFIG_FILE"); - const auto ENV_NESMIK_EXTRAE_CONFIG_FILE_PATH = std::getenv("NESMIK_EXTRAE_CONFIG_FILE_PATH"); - if(ENV_NESMIK_EXTRAE_WRITE_CONFIG_FILE != nullptr){ - const auto configFileString= std::string(ENV_NESMIK_EXTRAE_WRITE_CONFIG_FILE); - if(configFileString.compare("1") == 0 || configFileString.compare("ON") == 0){ - EXTRAE_WRITE_CONFIG_FILE = true; - } - } - - if(ENV_NESMIK_EXTRAE_CONFIG_FILE_PATH != nullptr){ - EXTRAE_CONFIG_FILE_PATH = std::string(ENV_NESMIK_EXTRAE_CONFIG_FILE_PATH); - } - - - //} } extrae_value ExtraeTypeStackStrategy::get_value_by_region_name(const std::string &name) { - // maybe insert + // maybe insert if (regionMapData.regionNameToValue.count(name) > 0) { return regionMapData.regionNameToValue[name]; - } - else + } else // if not allocate new entry { - const auto newValue= regionMapData.regionNameToValue.size()+1; + const auto newValue = regionMapData.regionNameToValue.size() + 1; regionMapData.regionNameToValue[name] = newValue; return newValue; } @@ -160,7 +136,8 @@ void ExtraeTypeStackStrategy::RegionStart( auto typeOffset = regionStackData.regionNameStack.size(); regionStackData.regionNameStack.push(regionName); - regionStackData.historicMaxStackSize = std::max(typeOffset, regionStackData.historicMaxStackSize); + regionStackData.historicMaxStackSize = + std::max(typeOffset, regionStackData.historicMaxStackSize); auto value = get_value_by_region_name(regionName); @@ -173,7 +150,8 @@ void ExtraeTypeStackStrategy::RegionStopLast( if (regionStackData.regionNameStack.empty()) { // whoops - std::cout << "imbalanced region stop REASON: Emtpy stack " << region.name << std::endl; + std::cout << "imbalanced region stop REASON: Emtpy stack " << region.name + << std::endl; return; } @@ -193,8 +171,8 @@ void ExtraeTypeStackStrategy::RegionStopLast( void ExtraeTypeStackStrategy::Finalize() noexcept { - - unsigned int numberOfRegionsRegistered = regionMapData.regionNameToValue.size(); + unsigned int numberOfRegionsRegistered = + regionMapData.regionNameToValue.size(); std::vector values{}; std::vector routine_names{}; @@ -207,22 +185,22 @@ void ExtraeTypeStackStrategy::Finalize() noexcept { // 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++) { + for (unsigned int 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; + for (unsigned int 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); + &numberOfRegionsRegistered, values.data(), + routine_c_names); } - - if(EXTRAE_WRITE_CONFIG_FILE){ - std::string fileName = EXTRAE_CONFIG_FILE_PATH + "NESMIK_Annotations.cfg"; + if (write_config_file_.getValue().value_or(write_config_file_default_)) { + std::string fileName = "NESMIK_Annotations.cfg"; std::ofstream outputFile; outputFile.open(fileName); @@ -230,43 +208,48 @@ void ExtraeTypeStackStrategy::Finalize() noexcept { outputFile << paraverConfigHead; // compute overview - auto numberOfEventTypes = regionStackData.historicMaxStackSize + 1 ; // 0 based so plus 1 + 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 .. + 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) + " "; + std::string allTypesString = ""; + for (const auto &type : allTypes) { + allTypesString += std::to_string(type) + " "; } - auto overviewReplacedNumLevels = std::regex_replace(paraverConfigOverviewWindow, std::regex("NESMIK_REPLACE_NUM_LEVELS"), std::to_string(numberOfEventTypes)); - auto overviewReplacedAllTypes= std::regex_replace(overviewReplacedNumLevels, std::regex("NESMIK_REPLACE_LEVELS"), allTypesString); + auto overviewReplacedNumLevels = std::regex_replace( + paraverConfigOverviewWindow, std::regex("NESMIK_REPLACE_NUM_LEVELS"), + std::to_string(numberOfEventTypes)); + auto overviewReplacedAllTypes = + std::regex_replace(overviewReplacedNumLevels, + std::regex("NESMIK_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 = "NESMIK Instrumentation Level: " + std::to_string(level); - - auto replacedEventType = std::regex_replace(paraverConfigLevelWindow, std::regex("NESMIK_REPLACE_EVENT_TYPE"), std::to_string(baseType+level)); - auto replacedWindowName = std::regex_replace(replacedEventType, std::regex("NESMIK_REPLACE_WINDOW_NAME"), windowName); - + for (unsigned int level = 0; level <= regionStackData.historicMaxStackSize; + level++) { + std::string windowName = + "NESMIK Instrumentation Level: " + std::to_string(level); + + auto replacedEventType = std::regex_replace( + paraverConfigLevelWindow, std::regex("NESMIK_REPLACE_EVENT_TYPE"), + std::to_string(baseType + level)); + auto replacedWindowName = std::regex_replace( + replacedEventType, std::regex("NESMIK_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 diff --git a/src/backends/extrae/extrae_type_stack.hpp b/src/backends/extrae/extrae_type_stack.hpp index c74ab9fa64bd5583b5c5854cc38f4dbe8baaa067..4c9956601fe103fccb91baff8ddff393cfa00d02 100644 --- a/src/backends/extrae/extrae_type_stack.hpp +++ b/src/backends/extrae/extrae_type_stack.hpp @@ -2,40 +2,47 @@ #include #include #include +#include // #include typedef unsigned long extrae_value; typedef unsigned long extrae_type; -struct RegionStackData{ +struct RegionStackData { std::stack regionNameStack; std::size_t historicMaxStackSize; }; -struct RegionMapData{ +struct RegionMapData { std::unordered_map regionNameToValue; }; - class ExtraeTypeStackStrategy : public ProperlyNestedAnnotationStrategy { private: - inline static bool EXTRAE_WRITE_CONFIG_FILE=false; - inline static std::string EXTRAE_CONFIG_FILE_PATH ="./"; + const bool write_config_file_default_{true}; + const unsigned long baseType{81000}; 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; + + EnvironmentVariable write_config_file_ = EnvironmentVariable( + "EXTRAE_WRITE_CONFIG_FILE", + "Write corresponding Paraver .cfg file if set to True", false); + + inline static bool didInitialize{false}; + + inline static thread_local RegionStackData regionStackData; inline static thread_local RegionMapData regionMapData; - static extrae_value get_value_by_region_name(const std::string &name); + extrae_value get_value_by_region_name(const std::string &name); public: ExtraeTypeStackStrategy(); inline static const std::string_view name = "Extrae::TypeStack"; - virtual void RegionStart(const ProperlyNestedRegionInformation ®ion) noexcept override; - virtual void RegionStopLast(const ProperlyNestedRegionInformation ®ion) noexcept override; - virtual void Init() noexcept; - virtual void Finalize() noexcept; + virtual void + RegionStart(const ProperlyNestedRegionInformation ®ion) noexcept override; + virtual void RegionStopLast( + const ProperlyNestedRegionInformation ®ion) noexcept override; + virtual void Init() noexcept override; + virtual void Finalize() noexcept override; };