From f8736bbfdc97255be20a90a26b4f504c4e69d559 Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Tue, 2 Jul 2024 08:44:33 +0200 Subject: [PATCH 1/3] fixed #17 --- src/backends/extrae/extrae_type_stack.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backends/extrae/extrae_type_stack.cpp b/src/backends/extrae/extrae_type_stack.cpp index 23c5b4f..2ab4286 100644 --- a/src/backends/extrae/extrae_type_stack.cpp +++ b/src/backends/extrae/extrae_type_stack.cpp @@ -42,7 +42,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 @@ -80,7 +80,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 -- GitLab From 53eb49d1af0e16723106bce886d73e12654e165a Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Tue, 2 Jul 2024 09:32:05 +0200 Subject: [PATCH 2/3] fix compiler warnings and move to new env variable --- src/backends/extrae/extrae_type_stack.cpp | 31 ++++------------------- src/backends/extrae/extrae_type_stack.hpp | 18 ++++++++----- 2 files changed, 16 insertions(+), 33 deletions(-) diff --git a/src/backends/extrae/extrae_type_stack.cpp b/src/backends/extrae/extrae_type_stack.cpp index 2ab4286..3048741 100644 --- a/src/backends/extrae/extrae_type_stack.cpp +++ b/src/backends/extrae/extrae_type_stack.cpp @@ -118,23 +118,6 @@ 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 @@ -207,13 +190,13 @@ 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++) { + 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()), @@ -221,8 +204,8 @@ void ExtraeTypeStackStrategy::Finalize() noexcept { } - 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); @@ -249,8 +232,7 @@ void ExtraeTypeStackStrategy::Finalize() noexcept { outputFile << std::endl; // write seperate windows - for (auto level = 0; level <= regionStackData.historicMaxStackSize; level++) { - auto type = baseType+level; + 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)); @@ -259,9 +241,6 @@ void ExtraeTypeStackStrategy::Finalize() noexcept { // write Overview outputFile << replacedWindowName; outputFile << std::endl; - - - } } diff --git a/src/backends/extrae/extrae_type_stack.hpp b/src/backends/extrae/extrae_type_stack.hpp index c74ab9f..8a4266f 100644 --- a/src/backends/extrae/extrae_type_stack.hpp +++ b/src/backends/extrae/extrae_type_stack.hpp @@ -2,6 +2,7 @@ #include #include #include +#include // #include typedef unsigned long extrae_value; typedef unsigned long extrae_type; @@ -19,16 +20,19 @@ struct RegionMapData{ 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; + + 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(); @@ -36,6 +40,6 @@ public: 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 Init() noexcept override; + virtual void Finalize() noexcept override; }; -- GitLab From 1d27a7d0aa5e8f9438c8e7fe2a0cef4bb6897d73 Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Tue, 2 Jul 2024 09:35:17 +0200 Subject: [PATCH 3/3] apply clang-format --- src/backends/extrae/extrae_type_stack.cpp | 98 ++++++++++++----------- src/backends/extrae/extrae_type_stack.hpp | 19 +++-- 2 files changed, 62 insertions(+), 55 deletions(-) diff --git a/src/backends/extrae/extrae_type_stack.cpp b/src/backends/extrae/extrae_type_stack.cpp index 3048741..831b8d1 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 > @@ -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 > @@ -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) { @@ -122,14 +116,13 @@ void ExtraeTypeStackStrategy::Init() noexcept { 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; } @@ -143,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); @@ -156,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; } @@ -176,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{}; @@ -195,16 +190,16 @@ void ExtraeTypeStackStrategy::Finalize() noexcept { std::strcpy(routine_c_names[i], routine_names[i].c_str()); } - - for (unsigned int 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(write_config_file_.getValue().value_or(write_config_file_default_)){ + if (write_config_file_.getValue().value_or(write_config_file_default_)) { std::string fileName = "NESMIK_Annotations.cfg"; std::ofstream outputFile; outputFile.open(fileName); @@ -213,39 +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 (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); - + 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 8a4266f..4c99566 100644 --- a/src/backends/extrae/extrae_type_stack.hpp +++ b/src/backends/extrae/extrae_type_stack.hpp @@ -7,16 +7,15 @@ 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: @@ -26,11 +25,13 @@ private: static const std::string paraverConfigOverviewWindow; static const std::string paraverConfigLevelWindow; - EnvironmentVariable write_config_file_ = EnvironmentVariable("EXTRAE_WRITE_CONFIG_FILE","Write corresponding Paraver .cfg file if set to True",false); + 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 RegionStackData regionStackData; inline static thread_local RegionMapData regionMapData; extrae_value get_value_by_region_name(const std::string &name); @@ -38,8 +39,10 @@ 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 + RegionStart(const ProperlyNestedRegionInformation ®ion) noexcept override; + virtual void RegionStopLast( + const ProperlyNestedRegionInformation ®ion) noexcept override; virtual void Init() noexcept override; virtual void Finalize() noexcept override; }; -- GitLab