From 662dd2ab7807111642cf77c57edc8a622ed67e28 Mon Sep 17 00:00:00 2001 From: JOAN VINYALS YLLA CATALA Date: Mon, 17 Jun 2024 18:35:20 +0200 Subject: [PATCH 1/9] Add JSON and ASCII Serializer to TALP-Tree --- src/backends/dlb/dlb_talp_tree/CMakeLists.txt | 2 +- .../dlb/dlb_talp_tree/dlb_talp_tree.cpp | 144 +++--------------- .../dlb/dlb_talp_tree/dlb_talp_tree.hpp | 4 +- .../dlb_talp_tree_ascii_serializer.cpp | 117 ++++++++++++++ .../dlb_talp_tree_ascii_serializer.hpp | 24 +++ .../dlb_talp_tree_json_serializer.cpp | 49 ++++++ .../dlb_talp_tree_json_serializer.hpp | 19 +++ 7 files changed, 238 insertions(+), 121 deletions(-) create mode 100644 src/backends/dlb/dlb_talp_tree/dlb_talp_tree_ascii_serializer.cpp create mode 100644 src/backends/dlb/dlb_talp_tree/dlb_talp_tree_ascii_serializer.hpp create mode 100644 src/backends/dlb/dlb_talp_tree/dlb_talp_tree_json_serializer.cpp create mode 100644 src/backends/dlb/dlb_talp_tree/dlb_talp_tree_json_serializer.hpp diff --git a/src/backends/dlb/dlb_talp_tree/CMakeLists.txt b/src/backends/dlb/dlb_talp_tree/CMakeLists.txt index 160cc50..fc44ff5 100644 --- a/src/backends/dlb/dlb_talp_tree/CMakeLists.txt +++ b/src/backends/dlb/dlb_talp_tree/CMakeLists.txt @@ -1 +1 @@ -target_sources(nesmik PRIVATE dlb_talp_tree.cpp) +target_sources(nesmik PRIVATE dlb_talp_tree.cpp dlb_talp_tree_json_serializer.cpp dlb_talp_tree_ascii_serializer.cpp) diff --git a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp index 62c3e2d..842c0d1 100644 --- a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp +++ b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp @@ -1,4 +1,6 @@ #include "dlb_talp_tree.hpp" +#include "dlb_talp_tree_json_serializer.hpp" +#include "dlb_talp_tree_ascii_serializer.hpp" #include "dlb.h" #include "dlb_talp.h" #include @@ -7,6 +9,7 @@ #include #include #include +#include #ifdef WITH_MPI #include @@ -15,6 +18,8 @@ #include +using json = nlohmann::json; + DLBTalpTreeStrategy::DLBTalpTreeStrategy():mpi_helper_{}{ parallelism_descriptor_={ .mpi_descriptor_ = MPIDescriptor::Aware, @@ -22,8 +27,6 @@ DLBTalpTreeStrategy::DLBTalpTreeStrategy():mpi_helper_{}{ }; } - - void DLBTalpTreeStrategy::RegionStart( const ProperlyNestedRegionInformation ®ion) noexcept { @@ -43,9 +46,9 @@ void DLBTalpTreeStrategy::RegionStart( // Add the new region in the map this->regions[region_hash] = { /* .name */ std::string(region.name), - /* .tree_lines */ "", /* .parent */ this->current_region, - /* .childs */ std::vector() + /* .childs */ {}, + /* .pop_metrics*/ {} }; } @@ -88,144 +91,47 @@ void DLBTalpTreeStrategy::Init() noexcept { this->current_region = std::hash{}(this->top_region); this->regions[this->current_region] = { /* .name */ this->top_region, - /* .tree_lines */ "", /* .parent */ 0, /* .childs */ {}, + /* .pop_metrics*/ {} }; this->talp_profiling_strategy.Init(); } void DLBTalpTreeStrategy::Finalize() noexcept { + // Stop the top region which was automatically started by TALP. this->talp_profiling_strategy.RegionStop({.name = this->top_region}); - std::size_t max_width = 0; - - // First pass to format the names with the appropiate tree lines and to determine paddings. - { - std::size_t top_region = std::hash{}(this->top_region); - - std::stack regions_stack; - regions_stack.push(top_region); - - std::stack regions_level; - regions_level.push(0); - - std::stack regions_tree_lines; - regions_tree_lines.push(""); - - while (!regions_stack.empty()) { - auto ¤t_region = this->regions[regions_stack.top()]; - //TalpRegionNode ¤t_region = this->regions[regions_stack.top()]; - int level = regions_level.top(); - std::string tree_lines = regions_tree_lines.top(); - - regions_stack.pop(); - regions_level.pop(); - regions_tree_lines.pop(); - - // I am the last child either if the stack is empty or if the level of the following element - // in the stack is lower than mine. - bool last_child = regions_level.empty() || regions_level.top() < level; - - std::string next_tree_lines = " │ "; // By default I get the continuation line. - if (level == 0) next_tree_lines = ""; // If I am the root region I don't need line. - else if (last_child) next_tree_lines = " "; // If I am the last child I add space. - - for (auto region : current_region.childs) { - regions_stack.push(region); - regions_level.push(level+1); - regions_tree_lines.push(tree_lines + next_tree_lines); - } - - if (level == 0) tree_lines += ""; // If I am the root I don't have lines - else if (last_child) tree_lines += " └─ "; // If I am the last child I close the line - else tree_lines += " ├─ "; // Otherwise i continue the line. - - current_region.tree_lines = tree_lines; - max_width = std::max(max_width, current_region.name.length() + - current_region.tree_lines.length()); - } - } - - std::size_t top_region = std::hash{}(this->top_region); - - std::stack regions_stack; - regions_stack.push(top_region); - - std::stringstream region_stream_stdout; - std::stringstream region_stream_csv; - - while (!regions_stack.empty()) { - std::size_t current_region_hash = regions_stack.top(); - auto current_region = this->regions[current_region_hash]; - regions_stack.pop(); - - for (auto region : current_region.childs) { - regions_stack.push(region); - } - - std::string name = std::to_string((unsigned int)current_region_hash); - if (current_region.name.compare(this->top_region) == 0) { + // Collect the POP metrics from all the regions + for (auto ®ion : this->regions) { + std::string name = std::to_string((unsigned int) region.first); + if (region.second.name.compare(this->top_region) == 0) { name = this->top_region; } auto handle = DLB_MonitoringRegionRegister(name.c_str()); + int dlb_error = DLB_TALP_CollectPOPMetrics(handle, ®ion.second.pop_metrics); - dlb_pop_metrics_t pop_metrics; - int error = DLB_TALP_CollectPOPMetrics(handle, &pop_metrics); - - if (error != DLB_SUCCESS) { - + if (dlb_error != DLB_SUCCESS) { + // Warn about the error trying to close region name with hash } - - std::string name_with_tree_lines = current_region.tree_lines + current_region.name; - - region_stream_stdout << std::setw(max_width+3) << std::left << name_with_tree_lines; - region_stream_stdout << std::fixed << std::setprecision(2); - region_stream_stdout << std::setw(15) << std::right << 100 * pop_metrics.elapsed_time/1000000000 << "s"; - region_stream_stdout << std::setw(8) << std::right << 100 * pop_metrics.parallel_efficiency; - region_stream_stdout << std::setw(8) << std::right << 100 * pop_metrics.mpi_parallel_efficiency; - region_stream_stdout << std::setw(8) << std::right << 100 * pop_metrics.mpi_communication_efficiency; - region_stream_stdout << std::setw(8) << std::right << 100 * pop_metrics.mpi_load_balance; - region_stream_stdout << std::setw(8) << std::right << 100 * pop_metrics.mpi_load_balance_in; - region_stream_stdout << std::setw(8) << std::right << 100 * pop_metrics.mpi_load_balance_out; - - region_stream_stdout << std::setw(8) << std::right << 100 * pop_metrics.omp_parallel_efficiency; - region_stream_stdout << std::setw(8) << std::right << 100 * pop_metrics.omp_load_balance; - region_stream_stdout << std::setw(8) << std::right << 100 * pop_metrics.omp_scheduling_efficiency; - region_stream_stdout << std::setw(8) << std::right << 100 * pop_metrics.omp_serialization_efficiency; - region_stream_stdout << std::endl; - - region_stream_csv << name_with_tree_lines; - region_stream_csv << std::fixed << std::setprecision(4); - region_stream_csv << "," << pop_metrics.elapsed_time/1000000000 << "s"; - region_stream_csv << "," << 100 * pop_metrics.parallel_efficiency; - region_stream_csv << "," << 100 * pop_metrics.mpi_parallel_efficiency; - region_stream_csv << "," << 100 * pop_metrics.mpi_communication_efficiency; - region_stream_csv << "," << 100 * pop_metrics.mpi_load_balance; - region_stream_csv << "," << 100 * pop_metrics.mpi_load_balance_in; - region_stream_csv << "," << 100 * pop_metrics.mpi_load_balance_out; - - region_stream_csv << "," << 100 * pop_metrics.omp_parallel_efficiency; - region_stream_csv << "," << 100 * pop_metrics.omp_load_balance; - region_stream_csv << "," << 100 * pop_metrics.omp_scheduling_efficiency; - region_stream_csv << "," << 100 * pop_metrics.omp_serialization_efficiency; - region_stream_csv << std::endl; } + std::size_t top = std::hash{}(this->top_region); if(mpi_helper_.IsRankNumber(0)){ - std::cout << region_stream_stdout.str() << std::endl; + // Print the regions metrics in JSON format + DLBTalpTreeJSONSerializer json_printer(top, this->regions); + std::cout << json_printer.dump() << std::endl; } - if(mpi_helper_.IsRankNumber(0)){ - std::ofstream csv_stream; - csv_stream.open("nesmik_talp_tree.csv", std::ios::trunc); - csv_stream << region_stream_csv.str() << std::endl; + // Print the regions metrics in ASCII format + DLBTalpTreeASCIISerializer ascii_printer(top, this->regions); + std::cout << ascii_printer.dump() << std::endl; } - - + // Stop TALP this->talp_profiling_strategy.Finalize(); + } diff --git a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp index 83e51f7..fe78356 100644 --- a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp +++ b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp @@ -1,6 +1,8 @@ #ifndef SIT_DLB_TALP_TREE_H #define SIT_DLB_TALP_TREE_H +#include "dlb.h" +#include "dlb_talp.h" #include "../dlb/dlb.hpp" #include "strategies.hpp" #include @@ -12,9 +14,9 @@ struct TalpRegionNode { std::string name; - std::string tree_lines; std::size_t parent; std::vector childs; + dlb_pop_metrics_t pop_metrics; }; class DLBTalpTreeStrategy : public ProperlyNestedAnnotationStrategy { diff --git a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree_ascii_serializer.cpp b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree_ascii_serializer.cpp new file mode 100644 index 0000000..b1ee852 --- /dev/null +++ b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree_ascii_serializer.cpp @@ -0,0 +1,117 @@ + +#include +#include +#include +#include + +#include "dlb_talp_tree_ascii_serializer.hpp" + +using json = nlohmann::json; + +DLBTalpTreeASCIISerializer::DLBTalpTreeASCIISerializer(std::size_t top_region, std::map const& regions) + : top_region(top_region) + , regions(regions) + , tree_lines{} + {} + +struct RegionStackEntry { + std::size_t hash; + std::size_t level; + std::string tree_lines; +}; + +std::size_t DLBTalpTreeASCIISerializer::compute_tree_lines() { + + std::stack regions_stack; + regions_stack.push({ + .hash = this->top_region, + .level = 0, + .tree_lines = "" + }); + + std::size_t max_width = 0; + + while (!regions_stack.empty()) { + + RegionStackEntry current_region = regions_stack.top(); + regions_stack.pop(); + + // I am the last child either if the stack is empty or if the level of the following element + // in the stack is lower than mine. + bool last_child = regions_stack.empty() || regions_stack.top().level < current_region.level; + + std::string next_tree_lines = " │ "; // By default I get the continuation line. + if (current_region.level == 0) // If I am the root region I don't need line. + next_tree_lines = ""; + else if (last_child) // If I am the last child I add space. + next_tree_lines = " "; + + for (auto region : this->regions.at(current_region.hash).childs) { + regions_stack.push({ + .hash = region, + .level = current_region.level + 1, + .tree_lines = current_region.tree_lines + next_tree_lines + }); + } + + std::size_t level = current_region.level; + std::string tree_lines = current_region.tree_lines; + if (level == 0) tree_lines += ""; // If I am the root I don't have lines + else if (last_child) tree_lines += " └─ "; // If I am the last child I close the line + else tree_lines += " ├─ "; // Otherwise i continue the line. + + this->tree_lines[current_region.hash] = tree_lines; + + max_width = std::max(max_width, + this->regions.at(current_region.hash).name.length() + tree_lines.length()); + } + +} + +std::string DLBTalpTreeASCIISerializer::generate_tree_view(int name_width) { + + std::stack regions_stack; + regions_stack.push(this->top_region); + + std::stringstream region_stream; + + while (!regions_stack.empty()) { + + std::size_t current_region_hash = regions_stack.top(); + regions_stack.pop(); + + for (std::size_t child_hash : this->regions.at(current_region_hash).childs) { + regions_stack.push(child_hash); + } + + TalpRegionNode current_region = this->regions.at(current_region_hash); + dlb_pop_metrics_t &pop_metrics = current_region.pop_metrics; + + std::string name_with_tree_lines = this->tree_lines[current_region_hash] + current_region.name; + + region_stream << std::setw(name_width+3) << std::left << name_with_tree_lines; + region_stream << std::fixed << std::setprecision(2); + region_stream << std::setw(15) << std::right << 100 * pop_metrics.elapsed_time/1000000000 << "s"; + region_stream << std::setw(8) << std::right << 100 * pop_metrics.parallel_efficiency; + region_stream << std::setw(8) << std::right << 100 * pop_metrics.mpi_parallel_efficiency; + region_stream << std::setw(8) << std::right << 100 * pop_metrics.mpi_communication_efficiency; + region_stream << std::setw(8) << std::right << 100 * pop_metrics.mpi_load_balance; + region_stream << std::setw(8) << std::right << 100 * pop_metrics.mpi_load_balance_in; + region_stream << std::setw(8) << std::right << 100 * pop_metrics.mpi_load_balance_out; + + region_stream << std::setw(8) << std::right << 100 * pop_metrics.omp_parallel_efficiency; + region_stream << std::setw(8) << std::right << 100 * pop_metrics.omp_load_balance; + region_stream << std::setw(8) << std::right << 100 * pop_metrics.omp_scheduling_efficiency; + region_stream << std::setw(8) << std::right << 100 * pop_metrics.omp_serialization_efficiency; + region_stream << std::endl; + + } + + return region_stream.str(); +} + +std::string DLBTalpTreeASCIISerializer::dump() { + std::size_t max_width = compute_tree_lines(); + std::string tree_view = generate_tree_view(max_width); + return tree_view; +} diff --git a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree_ascii_serializer.hpp b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree_ascii_serializer.hpp new file mode 100644 index 0000000..14e210a --- /dev/null +++ b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree_ascii_serializer.hpp @@ -0,0 +1,24 @@ +#ifndef NESMIK_DLB_TALP_TREE_ASCII_SERIALIZER_H +#define NESMIK_DLB_TALP_TREE_ASCII_SERIALIZER_H + +#include + +#include "dlb_talp_tree.hpp" + +class DLBTalpTreeASCIISerializer { + +private: + std::size_t top_region; + std::map const& regions; + std::map tree_lines; + +public: + DLBTalpTreeASCIISerializer(std::size_t top_region, const std::map ®ions); + std::string dump(); + +private: + std::size_t compute_tree_lines(); + std::string generate_tree_view(int name_width); +}; + +#endif // NESMIK_DLB_TALP_TREE_ASCII_SERIALIZER_H diff --git a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree_json_serializer.cpp b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree_json_serializer.cpp new file mode 100644 index 0000000..3212561 --- /dev/null +++ b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree_json_serializer.cpp @@ -0,0 +1,49 @@ + +#include +#include + + +#include "dlb_talp_tree_json_serializer.hpp" + +using json = nlohmann::json; + +DLBTalpTreeJSONSerializer::DLBTalpTreeJSONSerializer(std::size_t top_region, std::map const& regions) + : top_region(top_region) + , regions(regions) + {} + +void treeToJSON(const TalpRegionNode &node, json &talp_json, + std::map const& regions) { + + talp_json["regionName"] = node.name; + talp_json["metrics"] = { + {"elapsedTime", node.pop_metrics.elapsed_time}, + + {"parallelEfficiency", node.pop_metrics.parallel_efficiency}, + + {"mpiParallelEfficiency", node.pop_metrics.mpi_parallel_efficiency}, + {"mpiCommunicationEfficiency", node.pop_metrics.mpi_communication_efficiency}, + {"mpiLoadBalance", node.pop_metrics.mpi_load_balance}, + {"mpiLoadBalanceIn", node.pop_metrics.mpi_load_balance_in}, + {"mpiLoadBalanceOut", node.pop_metrics.mpi_load_balance_out}, + + {"ompParallelEfficiency", node.pop_metrics.omp_parallel_efficiency}, + {"ompLoadBalance", node.pop_metrics.omp_load_balance}, + {"ompSchedulingEfficiency", node.pop_metrics.omp_scheduling_efficiency}, + {"ompSerializationEfficiency", node.pop_metrics.omp_serialization_efficiency} + }; + + talp_json["subregions"] = json::array(); + for (std::size_t child : node.childs) { + json childJSON; + treeToJSON(regions.at(child), childJSON, regions); + talp_json["subregions"].push_back(childJSON); + } + +} + +std::string DLBTalpTreeJSONSerializer::dump() { + json talp_tree; + treeToJSON(this->regions.at(this->top_region), talp_tree, this->regions); + return talp_tree.dump(); +} diff --git a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree_json_serializer.hpp b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree_json_serializer.hpp new file mode 100644 index 0000000..4e279f4 --- /dev/null +++ b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree_json_serializer.hpp @@ -0,0 +1,19 @@ +#ifndef NESMIK_DLB_TALP_TREE_JSON_SERIALIZER_H +#define NESMIK_DLB_TALP_TREE_JSON_SERIALIZER_H + +#include + +#include "dlb_talp_tree.hpp" + +class DLBTalpTreeJSONSerializer { + +private: + std::size_t top_region; + std::map const& regions; + +public: + DLBTalpTreeJSONSerializer(std::size_t top_region, const std::map ®ions); + std::string dump(); +}; + +#endif // NESMIK_DLB_TALP_TREE_JSON_SERIALIZER_H -- GitLab From 83ab6c493f379248a7333d656af6c76f660accee Mon Sep 17 00:00:00 2001 From: JOAN VINYALS YLLA CATALA Date: Mon, 17 Jun 2024 18:37:08 +0200 Subject: [PATCH 2/9] Fix ascii serializer elapsed_time --- .../dlb/dlb_talp_tree/dlb_talp_tree_ascii_serializer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree_ascii_serializer.cpp b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree_ascii_serializer.cpp index b1ee852..7873f3f 100644 --- a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree_ascii_serializer.cpp +++ b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree_ascii_serializer.cpp @@ -91,7 +91,7 @@ std::string DLBTalpTreeASCIISerializer::generate_tree_view(int name_width) { region_stream << std::setw(name_width+3) << std::left << name_with_tree_lines; region_stream << std::fixed << std::setprecision(2); - region_stream << std::setw(15) << std::right << 100 * pop_metrics.elapsed_time/1000000000 << "s"; + region_stream << std::setw(15) << std::right << pop_metrics.elapsed_time/1000000000 << "s"; region_stream << std::setw(8) << std::right << 100 * pop_metrics.parallel_efficiency; region_stream << std::setw(8) << std::right << 100 * pop_metrics.mpi_parallel_efficiency; region_stream << std::setw(8) << std::right << 100 * pop_metrics.mpi_communication_efficiency; -- GitLab From 8901a9ea8780d82247ba5f3b1ab311ae06029048 Mon Sep 17 00:00:00 2001 From: JOAN VINYALS YLLA CATALA Date: Fri, 21 Jun 2024 12:57:55 +0200 Subject: [PATCH 3/9] Make json dump pretty and to a file --- src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp | 5 ++++- .../dlb/dlb_talp_tree/dlb_talp_tree_json_serializer.cpp | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp index 842c0d1..78b2f78 100644 --- a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp +++ b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp @@ -122,7 +122,10 @@ void DLBTalpTreeStrategy::Finalize() noexcept { if(mpi_helper_.IsRankNumber(0)){ // Print the regions metrics in JSON format DLBTalpTreeJSONSerializer json_printer(top, this->regions); - std::cout << json_printer.dump() << std::endl; + + std::ofstream json_stream; + json_stream.open("nesmik_talp_tree.json", std::ios::trunc); + json_stream << json_printer.dump() << std::endl; } if(mpi_helper_.IsRankNumber(0)){ diff --git a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree_json_serializer.cpp b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree_json_serializer.cpp index 3212561..558e6a2 100644 --- a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree_json_serializer.cpp +++ b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree_json_serializer.cpp @@ -45,5 +45,5 @@ void treeToJSON(const TalpRegionNode &node, json &talp_json, std::string DLBTalpTreeJSONSerializer::dump() { json talp_tree; treeToJSON(this->regions.at(this->top_region), talp_tree, this->regions); - return talp_tree.dump(); + return talp_tree.dump(2); } -- GitLab From d8ecde3b3ae7c0a8a2bf71cdec27eb57e4ccc554 Mon Sep 17 00:00:00 2001 From: JOAN VINYALS YLLA CATALA Date: Wed, 26 Jun 2024 15:14:31 +0200 Subject: [PATCH 4/9] Make dlb_talp_tree match coding style --- .../dlb/dlb_talp_tree/dlb_talp_tree.cpp | 54 +++++++++---------- .../dlb/dlb_talp_tree/dlb_talp_tree.hpp | 10 ++-- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp index 78b2f78..5eaf83f 100644 --- a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp +++ b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp @@ -32,36 +32,36 @@ void DLBTalpTreeStrategy::RegionStart( // Construct the opening region hash by joining the name of the region with // the current region (i.e. the parent) hash. - std::string region_name = std::string(region.name) + std::to_string((unsigned int) this->current_region); - if (region.name.compare(this->top_region) == 0) { - region_name = this->top_region; + std::string region_name = std::string(region.name) + std::to_string((unsigned int) this->current_region_); + if (region.name.compare(this->top_region_) == 0) { + region_name = this->top_region_; } std::size_t region_hash = std::hash{}(region_name); - if (this->regions.count(region_hash) == 0) { + if (this->regions_.count(region_hash) == 0) { // Add the new region as a child to the current region - this->regions[this->current_region].childs.push_back(region_hash); + this->regions_[this->current_region_].childs.push_back(region_hash); // Add the new region in the map - this->regions[region_hash] = { + this->regions_[region_hash] = { /* .name */ std::string(region.name), - /* .parent */ this->current_region, + /* .parent */ this->current_region_, /* .childs */ {}, /* .pop_metrics*/ {} }; } - this->current_region = region_hash; + this->current_region_ = region_hash; std::string name = std::to_string((unsigned int) region_hash); - this->talp_profiling_strategy.RegionStart({name}); + this->talp_profiling_strategy_.RegionStart({name}); } void DLBTalpTreeStrategy::RegionStopLast( const ProperlyNestedRegionInformation ®ion) noexcept { - auto current_region = this->regions[this->current_region]; + auto current_region = this->regions_[this->current_region_]; if (region.name.compare(current_region.name) != 0) { std::stringstream error; @@ -74,40 +74,40 @@ void DLBTalpTreeStrategy::RegionStopLast( std::cerr << error.str(); } - std::string name = std::to_string((unsigned int)this->current_region); - if (current_region.name.compare(this->top_region) == 0) { - name = this->top_region; + std::string name = std::to_string((unsigned int)this->current_region_); + if (current_region.name.compare(this->top_region_) == 0) { + name = this->top_region_; } - this->current_region = current_region.parent; + this->current_region_ = current_region.parent; - this->talp_profiling_strategy.RegionStop({name}); + this->talp_profiling_strategy_.RegionStop({name}); } void DLBTalpTreeStrategy::Init() noexcept { - this->current_region = std::hash{}(this->top_region); - this->regions[this->current_region] = { - /* .name */ this->top_region, + this->current_region_ = std::hash{}(this->top_region_); + this->regions_[this->current_region_] = { + /* .name */ this->top_region_, /* .parent */ 0, /* .childs */ {}, /* .pop_metrics*/ {} }; - this->talp_profiling_strategy.Init(); + this->talp_profiling_strategy_.Init(); } void DLBTalpTreeStrategy::Finalize() noexcept { // Stop the top region which was automatically started by TALP. - this->talp_profiling_strategy.RegionStop({.name = this->top_region}); + this->talp_profiling_strategy_.RegionStop({.name = this->top_region_}); // Collect the POP metrics from all the regions - for (auto ®ion : this->regions) { + for (auto ®ion : this->regions_) { std::string name = std::to_string((unsigned int) region.first); - if (region.second.name.compare(this->top_region) == 0) { - name = this->top_region; + if (region.second.name.compare(this->top_region_) == 0) { + name = this->top_region_; } auto handle = DLB_MonitoringRegionRegister(name.c_str()); @@ -118,10 +118,10 @@ void DLBTalpTreeStrategy::Finalize() noexcept { } } - std::size_t top = std::hash{}(this->top_region); + std::size_t top = std::hash{}(this->top_region_); if(mpi_helper_.IsRankNumber(0)){ // Print the regions metrics in JSON format - DLBTalpTreeJSONSerializer json_printer(top, this->regions); + DLBTalpTreeJSONSerializer json_printer(top, this->regions_); std::ofstream json_stream; json_stream.open("nesmik_talp_tree.json", std::ios::trunc); @@ -130,11 +130,11 @@ void DLBTalpTreeStrategy::Finalize() noexcept { if(mpi_helper_.IsRankNumber(0)){ // Print the regions metrics in ASCII format - DLBTalpTreeASCIISerializer ascii_printer(top, this->regions); + DLBTalpTreeASCIISerializer ascii_printer(top, this->regions_); std::cout << ascii_printer.dump() << std::endl; } // Stop TALP - this->talp_profiling_strategy.Finalize(); + this->talp_profiling_strategy_.Finalize(); } diff --git a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp index fe78356..bb32eae 100644 --- a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp +++ b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp @@ -22,18 +22,18 @@ struct TalpRegionNode { class DLBTalpTreeStrategy : public ProperlyNestedAnnotationStrategy { private: - DLBTalpStrategy talp_profiling_strategy; + DLBTalpStrategy talp_profiling_strategy_; - inline static const std::string top_region = "Application"; - std::size_t current_region; - std::map regions; + inline static const std::string top_region_ = "Application"; + std::size_t current_region_; + std::map regions_; // Mpi aware stuff MPIHelper mpi_helper_; public: DLBTalpTreeStrategy(); - inline static const std::string_view name = "TALP-Tree"; + inline static const std::string_view name = "TALP::Tree"; void RegionStart(const ProperlyNestedRegionInformation ®ion) noexcept override; void RegionStopLast(const ProperlyNestedRegionInformation ®ion) noexcept override; virtual void Init() noexcept; -- GitLab From 831c247e79bd320a59ace26d303e6f76368956e4 Mon Sep 17 00:00:00 2001 From: JOAN VINYALS YLLA CATALA Date: Wed, 26 Jun 2024 16:20:32 +0200 Subject: [PATCH 5/9] TALP Tree use of env vars and more style --- .../dlb/dlb_talp_tree/dlb_talp_tree.cpp | 68 ++++++++++--------- .../dlb/dlb_talp_tree/dlb_talp_tree.hpp | 23 +++++++ src/utils/environment_variable.cpp | 6 +- src/utils/environment_variable.hpp | 3 +- 4 files changed, 67 insertions(+), 33 deletions(-) diff --git a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp index 5eaf83f..94c10d0 100644 --- a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp +++ b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp @@ -32,36 +32,36 @@ void DLBTalpTreeStrategy::RegionStart( // Construct the opening region hash by joining the name of the region with // the current region (i.e. the parent) hash. - std::string region_name = std::string(region.name) + std::to_string((unsigned int) this->current_region_); - if (region.name.compare(this->top_region_) == 0) { - region_name = this->top_region_; + std::string region_name = std::string(region.name) + std::to_string((unsigned int) current_region_); + if (region.name.compare(top_region_) == 0) { + region_name = top_region_; } std::size_t region_hash = std::hash{}(region_name); - if (this->regions_.count(region_hash) == 0) { + if (regions_.count(region_hash) == 0) { // Add the new region as a child to the current region - this->regions_[this->current_region_].childs.push_back(region_hash); + regions_[current_region_].childs.push_back(region_hash); // Add the new region in the map - this->regions_[region_hash] = { + regions_[region_hash] = { /* .name */ std::string(region.name), - /* .parent */ this->current_region_, + /* .parent */ current_region_, /* .childs */ {}, /* .pop_metrics*/ {} }; } - this->current_region_ = region_hash; + current_region_ = region_hash; std::string name = std::to_string((unsigned int) region_hash); - this->talp_profiling_strategy_.RegionStart({name}); + talp_profiling_strategy_.RegionStart({name}); } void DLBTalpTreeStrategy::RegionStopLast( const ProperlyNestedRegionInformation ®ion) noexcept { - auto current_region = this->regions_[this->current_region_]; + auto current_region = regions_[current_region_]; if (region.name.compare(current_region.name) != 0) { std::stringstream error; @@ -74,40 +74,40 @@ void DLBTalpTreeStrategy::RegionStopLast( std::cerr << error.str(); } - std::string name = std::to_string((unsigned int)this->current_region_); - if (current_region.name.compare(this->top_region_) == 0) { - name = this->top_region_; + std::string name = std::to_string((unsigned int)current_region_); + if (current_region.name.compare(top_region_) == 0) { + name = top_region_; } - this->current_region_ = current_region.parent; + current_region_ = current_region.parent; - this->talp_profiling_strategy_.RegionStop({name}); + talp_profiling_strategy_.RegionStop({name}); } void DLBTalpTreeStrategy::Init() noexcept { - this->current_region_ = std::hash{}(this->top_region_); - this->regions_[this->current_region_] = { - /* .name */ this->top_region_, + current_region_ = std::hash{}(top_region_); + regions_[current_region_] = { + /* .name */ top_region_, /* .parent */ 0, /* .childs */ {}, /* .pop_metrics*/ {} }; - this->talp_profiling_strategy_.Init(); + talp_profiling_strategy_.Init(); } void DLBTalpTreeStrategy::Finalize() noexcept { // Stop the top region which was automatically started by TALP. - this->talp_profiling_strategy_.RegionStop({.name = this->top_region_}); + talp_profiling_strategy_.RegionStop({.name = top_region_}); // Collect the POP metrics from all the regions - for (auto ®ion : this->regions_) { + for (auto ®ion : regions_) { std::string name = std::to_string((unsigned int) region.first); - if (region.second.name.compare(this->top_region_) == 0) { - name = this->top_region_; + if (region.second.name.compare(top_region_) == 0) { + name = top_region_; } auto handle = DLB_MonitoringRegionRegister(name.c_str()); @@ -118,23 +118,29 @@ void DLBTalpTreeStrategy::Finalize() noexcept { } } - std::size_t top = std::hash{}(this->top_region_); - if(mpi_helper_.IsRankNumber(0)){ + std::size_t top = std::hash{}(top_region_); + + bool enable_json_output = env_enable_json_.getValue().value_or(def_enable_json_); + if (mpi_helper_.IsRankNumber(0) && enable_json_output) { // Print the regions metrics in JSON format - DLBTalpTreeJSONSerializer json_printer(top, this->regions_); + DLBTalpTreeJSONSerializer json_printer(top, regions_); + + std::string json_name = + env_json_file_name_.getValue().value_or(def_json_file_name_); std::ofstream json_stream; - json_stream.open("nesmik_talp_tree.json", std::ios::trunc); + json_stream.open(json_name, std::ios::trunc); json_stream << json_printer.dump() << std::endl; } - if(mpi_helper_.IsRankNumber(0)){ + bool enable_ascii_output = env_enable_ascii_.getValue().value_or(def_enable_ascii_); + if (mpi_helper_.IsRankNumber(0) && enable_ascii_output) { // Print the regions metrics in ASCII format - DLBTalpTreeASCIISerializer ascii_printer(top, this->regions_); - std::cout << ascii_printer.dump() << std::endl; + DLBTalpTreeASCIISerializer ascii_serializer(top, regions_); + std::cout << ascii_serializer.dump() << std::endl; } // Stop TALP - this->talp_profiling_strategy_.Finalize(); + talp_profiling_strategy_.Finalize(); } diff --git a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp index bb32eae..d788a61 100644 --- a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp +++ b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp @@ -11,6 +11,7 @@ #include #include +#include struct TalpRegionNode { std::string name; @@ -31,6 +32,28 @@ private: // Mpi aware stuff MPIHelper mpi_helper_; + // Configuration variables + inline static const std::string def_json_file_name_ = "nesmik_talp_tree.json"; + EnvironmentVariable env_json_file_name_ = + EnvironmentVariable( + "JSON_FILE", + "Set the name of the output JSON file. (default: nesmik_talp_tree.json)", + false); + + inline static const bool def_enable_json_ = true; + EnvironmentVariable env_enable_json_ = + EnvironmentVariable( + "JSON_OUTPUT", + "Enables output to a JSON file.", + false); + + inline static const bool def_enable_ascii_ = false; + EnvironmentVariable env_enable_ascii_ = + EnvironmentVariable( + "ASCII_OUTPUT", + "Enables human readable output to standard output. (default: off)", + false); + public: DLBTalpTreeStrategy(); inline static const std::string_view name = "TALP::Tree"; diff --git a/src/utils/environment_variable.cpp b/src/utils/environment_variable.cpp index 5472e51..589d53d 100644 --- a/src/utils/environment_variable.cpp +++ b/src/utils/environment_variable.cpp @@ -28,4 +28,8 @@ template <> std::optional fromEnvString(const std::string &env_string) { } else { return std::nullopt; } -} \ No newline at end of file +} + +template <> std::optional fromEnvString(const std::string &env_string) { + return std::optional{env_string}; +} diff --git a/src/utils/environment_variable.hpp b/src/utils/environment_variable.hpp index 2e87a74..d4543b0 100644 --- a/src/utils/environment_variable.hpp +++ b/src/utils/environment_variable.hpp @@ -17,6 +17,7 @@ template std::optional fromEnvString(const std::string &env_string) = delete; template <> std::optional fromEnvString(const std::string &env_string); +template <> std::optional fromEnvString(const std::string &env_string); template class EnvironmentVariable { inline static std::string PREFIX = "NESMIK_"; @@ -52,4 +53,4 @@ public: bool isSet() const { return value_.has_value(); } }; -#endif // NESMIK_ENVIROMENT_VARIABLE_HPP \ No newline at end of file +#endif // NESMIK_ENVIROMENT_VARIABLE_HPP -- GitLab From 64d3747dde64e1fe713e37b789f436c850dbb1d7 Mon Sep 17 00:00:00 2001 From: JOAN VINYALS YLLA CATALA Date: Wed, 26 Jun 2024 16:40:18 +0200 Subject: [PATCH 6/9] Formated TALP Tree main files. --- .../dlb/dlb_talp_tree/dlb_talp_tree.cpp | 100 +++++++++--------- .../dlb/dlb_talp_tree/dlb_talp_tree.hpp | 58 +++++----- 2 files changed, 76 insertions(+), 82 deletions(-) diff --git a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp index 94c10d0..5421133 100644 --- a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp +++ b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp @@ -1,38 +1,37 @@ #include "dlb_talp_tree.hpp" -#include "dlb_talp_tree_json_serializer.hpp" -#include "dlb_talp_tree_ascii_serializer.hpp" #include "dlb.h" #include "dlb_talp.h" -#include +#include "dlb_talp_tree_ascii_serializer.hpp" +#include "dlb_talp_tree_json_serializer.hpp" +#include +#include #include +#include +#include #include -#include #include -#include -#include #ifdef WITH_MPI - #include -#endif - +#include +#endif #include using json = nlohmann::json; -DLBTalpTreeStrategy::DLBTalpTreeStrategy():mpi_helper_{}{ - parallelism_descriptor_={ - .mpi_descriptor_ = MPIDescriptor::Aware, - .thread_descriptor_ = ThreadDescriptor::Unsupported - }; +DLBTalpTreeStrategy::DLBTalpTreeStrategy() : mpi_helper_{} { + parallelism_descriptor_ = {.mpi_descriptor_ = MPIDescriptor::Aware, + .thread_descriptor_ = + ThreadDescriptor::Unsupported}; } void DLBTalpTreeStrategy::RegionStart( - const ProperlyNestedRegionInformation ®ion) noexcept { + const ProperlyNestedRegionInformation ®ion) noexcept { // Construct the opening region hash by joining the name of the region with // the current region (i.e. the parent) hash. - std::string region_name = std::string(region.name) + std::to_string((unsigned int) current_region_); + std::string region_name = + std::string(region.name) + std::to_string((unsigned int)current_region_); if (region.name.compare(top_region_) == 0) { region_name = top_region_; } @@ -44,22 +43,20 @@ void DLBTalpTreeStrategy::RegionStart( regions_[current_region_].childs.push_back(region_hash); // Add the new region in the map - regions_[region_hash] = { - /* .name */ std::string(region.name), - /* .parent */ current_region_, - /* .childs */ {}, - /* .pop_metrics*/ {} - }; + regions_[region_hash] = {/* .name */ std::string(region.name), + /* .parent */ current_region_, + /* .childs */ {}, + /* .pop_metrics*/ {}}; } current_region_ = region_hash; - std::string name = std::to_string((unsigned int) region_hash); + std::string name = std::to_string((unsigned int)region_hash); talp_profiling_strategy_.RegionStart({name}); } void DLBTalpTreeStrategy::RegionStopLast( - const ProperlyNestedRegionInformation ®ion) noexcept { + const ProperlyNestedRegionInformation ®ion) noexcept { auto current_region = regions_[current_region_]; @@ -69,7 +66,8 @@ void DLBTalpTreeStrategy::RegionStopLast( error << "neSmiK:: Closing " << region.name << " would make "; error << current_region.name << "not nested." << std::endl; - error << "neSmiK:: Closing " << current_region.name << " instead." << std::endl; + error << "neSmiK:: Closing " << current_region.name << " instead." + << std::endl; std::cerr << error.str(); } @@ -84,63 +82,61 @@ void DLBTalpTreeStrategy::RegionStopLast( talp_profiling_strategy_.RegionStop({name}); } +void DLBTalpTreeStrategy::Init() noexcept { - -void DLBTalpTreeStrategy::Init() noexcept { - - current_region_ = std::hash{}(top_region_); - regions_[current_region_] = { - /* .name */ top_region_, - /* .parent */ 0, - /* .childs */ {}, - /* .pop_metrics*/ {} - }; + current_region_ = std::hash{}(top_region_); + regions_[current_region_] = {/* .name */ top_region_, + /* .parent */ 0, + /* .childs */ {}, + /* .pop_metrics*/ {}}; talp_profiling_strategy_.Init(); } -void DLBTalpTreeStrategy::Finalize() noexcept { +void DLBTalpTreeStrategy::Finalize() noexcept { // Stop the top region which was automatically started by TALP. talp_profiling_strategy_.RegionStop({.name = top_region_}); // Collect the POP metrics from all the regions for (auto ®ion : regions_) { - std::string name = std::to_string((unsigned int) region.first); + std::string name = std::to_string((unsigned int)region.first); if (region.second.name.compare(top_region_) == 0) { name = top_region_; } auto handle = DLB_MonitoringRegionRegister(name.c_str()); - int dlb_error = DLB_TALP_CollectPOPMetrics(handle, ®ion.second.pop_metrics); + int dlb_error = + DLB_TALP_CollectPOPMetrics(handle, ®ion.second.pop_metrics); if (dlb_error != DLB_SUCCESS) { // Warn about the error trying to close region name with hash } } - std::size_t top = std::hash{}(top_region_); + std::size_t top = std::hash{}(top_region_); - bool enable_json_output = env_enable_json_.getValue().value_or(def_enable_json_); + bool enable_json_output = + env_enable_json_.getValue().value_or(def_enable_json_); if (mpi_helper_.IsRankNumber(0) && enable_json_output) { - // Print the regions metrics in JSON format - DLBTalpTreeJSONSerializer json_printer(top, regions_); + // Print the regions metrics in JSON format + DLBTalpTreeJSONSerializer json_printer(top, regions_); - std::string json_name = - env_json_file_name_.getValue().value_or(def_json_file_name_); + std::string json_name = + env_json_file_name_.getValue().value_or(def_json_file_name_); - std::ofstream json_stream; - json_stream.open(json_name, std::ios::trunc); - json_stream << json_printer.dump() << std::endl; + std::ofstream json_stream; + json_stream.open(json_name, std::ios::trunc); + json_stream << json_printer.dump() << std::endl; } - bool enable_ascii_output = env_enable_ascii_.getValue().value_or(def_enable_ascii_); + bool enable_ascii_output = + env_enable_ascii_.getValue().value_or(def_enable_ascii_); if (mpi_helper_.IsRankNumber(0) && enable_ascii_output) { - // Print the regions metrics in ASCII format - DLBTalpTreeASCIISerializer ascii_serializer(top, regions_); - std::cout << ascii_serializer.dump() << std::endl; + // Print the regions metrics in ASCII format + DLBTalpTreeASCIISerializer ascii_serializer(top, regions_); + std::cout << ascii_serializer.dump() << std::endl; } // Stop TALP talp_profiling_strategy_.Finalize(); - } diff --git a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp index d788a61..029ec82 100644 --- a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp +++ b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp @@ -1,23 +1,23 @@ #ifndef SIT_DLB_TALP_TREE_H #define SIT_DLB_TALP_TREE_H +#include "../dlb/dlb.hpp" #include "dlb.h" #include "dlb_talp.h" -#include "../dlb/dlb.hpp" #include "strategies.hpp" #include -#include -#include #include +#include +#include -#include #include +#include struct TalpRegionNode { - std::string name; - std::size_t parent; - std::vector childs; - dlb_pop_metrics_t pop_metrics; + std::string name; + std::size_t parent; + std::vector childs; + dlb_pop_metrics_t pop_metrics; }; class DLBTalpTreeStrategy : public ProperlyNestedAnnotationStrategy { @@ -33,34 +33,32 @@ private: MPIHelper mpi_helper_; // Configuration variables - inline static const std::string def_json_file_name_ = "nesmik_talp_tree.json"; - EnvironmentVariable env_json_file_name_ = - EnvironmentVariable( - "JSON_FILE", - "Set the name of the output JSON file. (default: nesmik_talp_tree.json)", - false); + inline static const std::string def_json_file_name_ = "nesmik_talp_tree.json"; + EnvironmentVariable env_json_file_name_ = EnvironmentVariable< + std::string>( + "JSON_FILE", + "Set the name of the output JSON file. (default: nesmik_talp_tree.json)", + false); - inline static const bool def_enable_json_ = true; - EnvironmentVariable env_enable_json_ = - EnvironmentVariable( - "JSON_OUTPUT", - "Enables output to a JSON file.", - false); + inline static const bool def_enable_json_ = true; + EnvironmentVariable env_enable_json_ = EnvironmentVariable( + "JSON_OUTPUT", "Enables output to a JSON file.", false); - inline static const bool def_enable_ascii_ = false; - EnvironmentVariable env_enable_ascii_ = - EnvironmentVariable( - "ASCII_OUTPUT", - "Enables human readable output to standard output. (default: off)", - false); + inline static const bool def_enable_ascii_ = false; + EnvironmentVariable env_enable_ascii_ = EnvironmentVariable( + "ASCII_OUTPUT", + "Enables human readable output to standard output. (default: off)", + false); public: DLBTalpTreeStrategy(); inline static const std::string_view name = "TALP::Tree"; - void RegionStart(const ProperlyNestedRegionInformation ®ion) noexcept override; - void RegionStopLast(const ProperlyNestedRegionInformation ®ion) noexcept override; - virtual void Init() noexcept; - virtual void Finalize() noexcept; + void + RegionStart(const ProperlyNestedRegionInformation ®ion) noexcept override; + void RegionStopLast( + const ProperlyNestedRegionInformation ®ion) noexcept override; + virtual void Init() noexcept; + virtual void Finalize() noexcept; }; #endif // DLB_TALP_TREE_H -- GitLab From 44fd5050dda2ab19011c0648b02a6f397e4d64b3 Mon Sep 17 00:00:00 2001 From: JOAN VINYALS YLLA CATALA Date: Fri, 28 Jun 2024 17:40:33 +0200 Subject: [PATCH 7/9] TALP::Tree make c-cast conversion more readable --- src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp index 5421133..1e6227f 100644 --- a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp +++ b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp @@ -25,13 +25,19 @@ DLBTalpTreeStrategy::DLBTalpTreeStrategy() : mpi_helper_{} { ThreadDescriptor::Unsupported}; } +std::string region_hash_to_string(std::size_t region_hash) { + // We need to cast the std::size_t before conversion to get + // decimal representation in the string. + return std::to_string((unsigned int) region_hash); +} + void DLBTalpTreeStrategy::RegionStart( const ProperlyNestedRegionInformation ®ion) noexcept { // Construct the opening region hash by joining the name of the region with // the current region (i.e. the parent) hash. std::string region_name = - std::string(region.name) + std::to_string((unsigned int)current_region_); + std::string(region.name) + region_hash_to_string(current_region_); if (region.name.compare(top_region_) == 0) { region_name = top_region_; } @@ -51,7 +57,7 @@ void DLBTalpTreeStrategy::RegionStart( current_region_ = region_hash; - std::string name = std::to_string((unsigned int)region_hash); + std::string name = region_hash_to_string(region_hash); talp_profiling_strategy_.RegionStart({name}); } @@ -72,7 +78,7 @@ void DLBTalpTreeStrategy::RegionStopLast( std::cerr << error.str(); } - std::string name = std::to_string((unsigned int)current_region_); + std::string name = region_hash_to_string(current_region_); if (current_region.name.compare(top_region_) == 0) { name = top_region_; } @@ -99,7 +105,7 @@ void DLBTalpTreeStrategy::Finalize() noexcept { // Collect the POP metrics from all the regions for (auto ®ion : regions_) { - std::string name = std::to_string((unsigned int)region.first); + std::string name = region_hash_to_string(region.first); if (region.second.name.compare(top_region_) == 0) { name = top_region_; } -- GitLab From 6491a42ca948bea7eb118b4463685a777350d43d Mon Sep 17 00:00:00 2001 From: JOAN VINYALS YLLA CATALA Date: Fri, 28 Jun 2024 17:41:15 +0200 Subject: [PATCH 8/9] TALP::Tree JSON serializer comment pretty setting --- .../dlb/dlb_talp_tree/dlb_talp_tree_json_serializer.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree_json_serializer.cpp b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree_json_serializer.cpp index 558e6a2..fd44ae4 100644 --- a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree_json_serializer.cpp +++ b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree_json_serializer.cpp @@ -45,5 +45,7 @@ void treeToJSON(const TalpRegionNode &node, json &talp_json, std::string DLBTalpTreeJSONSerializer::dump() { json talp_tree; treeToJSON(this->regions.at(this->top_region), talp_tree, this->regions); - return talp_tree.dump(2); + + // Activate pretty printing by giving an ammount of spaces bigger than 0. + return talp_tree.dump(/* ammount of spaces for indentation */ 2); } -- GitLab From ab7b9cd1eff451b721169a794efa517c456862d8 Mon Sep 17 00:00:00 2001 From: VALENTIN SEITZ Date: Fri, 28 Jun 2024 18:06:47 +0200 Subject: [PATCH 9/9] Apply 1 suggestion(s) to 1 file(s) --- src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp index 1e6227f..3bd604a 100644 --- a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp +++ b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp @@ -28,7 +28,7 @@ DLBTalpTreeStrategy::DLBTalpTreeStrategy() : mpi_helper_{} { std::string region_hash_to_string(std::size_t region_hash) { // We need to cast the std::size_t before conversion to get // decimal representation in the string. - return std::to_string((unsigned int) region_hash); + return std::to_string(static_cast(region_hash)); } void DLBTalpTreeStrategy::RegionStart( -- GitLab