X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/49b53eb334bc6f19b530603201d00bcc312bfd29..b2cda481ba83aec50577db2773702f937ea75711:/src/smpi/internals/smpi_utils.cpp diff --git a/src/smpi/internals/smpi_utils.cpp b/src/smpi/internals/smpi_utils.cpp index 784db99396..90ef1550bb 100644 --- a/src/smpi/internals/smpi_utils.cpp +++ b/src/smpi/internals/smpi_utils.cpp @@ -13,8 +13,8 @@ #include "xbt/file.hpp" #include #include "smpi_config.hpp" -#include "smpi_f2c.hpp" #include "src/simix/smx_private.hpp" +#include XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_utils, smpi, "Logging specific to SMPI (utils)"); @@ -36,6 +36,7 @@ struct MaxMalloc { std::string file; }; MaxMalloc max_malloc; +F2C* current_handle=0; std::vector parse_factor(const std::string& smpi_coef_string) { @@ -129,24 +130,44 @@ void print_time_analysis(double global_time){ } } -void print_memory_analysis(){ - if (simgrid::smpi::F2C::lookup() != nullptr && - simgrid::smpi::F2C::lookup()->size() > simgrid::smpi::F2C::get_num_default_handles()) { +void print_memory_analysis() +{ + // Put the leaked non-default handles in a vector to sort them by id + std::vector> handles; + if (simgrid::smpi::F2C::lookup() != nullptr) + std::copy_if(simgrid::smpi::F2C::lookup()->begin(), simgrid::smpi::F2C::lookup()->end(), + std::back_inserter(handles), + [](auto const& entry) { return entry.first >= simgrid::smpi::F2C::get_num_default_handles(); }); + + if (not handles.empty()) { XBT_INFO("Probable memory leaks in your code: SMPI detected %zu unfreed MPI handles : " "display types and addresses (n max) with --cfg=smpi/list-leaks:n.\n" "Running smpirun with -wrapper \"valgrind --leak-check=full\" can provide more information", - simgrid::smpi::F2C::lookup()->size() - simgrid::smpi::F2C::get_num_default_handles()); - int n = simgrid::config::get_value("smpi/list-leaks"); - for (auto const& p : *simgrid::smpi::F2C::lookup()) { - static int printed = 0; - if (printed >= n) - break; - if (p.first >= simgrid::smpi::F2C::get_num_default_handles()) { - XBT_WARN("Leak %p of type %s", p.second, boost::core::demangle(typeid(*(p.second)).name()).c_str()); - printed++; + handles.size()); + auto max = static_cast(simgrid::config::get_value("smpi/list-leaks")); + if (max > 0) { // we cannot trust F2C::lookup()->size() > F2C::get_num_default_handles() because some default + // handles are already freed at this point + std::sort(handles.begin(), handles.end(), [](auto const& a, auto const& b) { return a.first < b.first; }); + bool truncate = max < handles.size(); + if (truncate) + handles.resize(max); + bool printed_advice=false; + for (const auto& p : handles) { + if (xbt_log_no_loc || p.second->call_location().empty()) { + if (!printed_advice){ + XBT_INFO("To get more information (location of allocations), compile your code with -trace-call-location flag of smpicc/f90"); + printed_advice=true; + } + XBT_INFO("Leaked handle of type %s", p.second->name().c_str()); + } else { + XBT_INFO("Leaked handle of type %s at %s", p.second->name().c_str(), p.second->call_location().c_str()); + } } + if (truncate) + XBT_INFO("(more handle leaks hidden as you wanted to see only %lu of them)", max); } } + if (simgrid::config::get_value("smpi/display-allocs")) { if(total_malloc_size != 0) XBT_INFO("Memory Usage: Simulated application allocated %lu bytes during its lifetime through malloc/calloc calls.\n" @@ -163,6 +184,20 @@ void print_memory_analysis(){ } } +void set_current_handle(F2C* handle){ + current_handle=handle; +} + +void print_current_handle(){ + if(current_handle){ + if(current_handle->call_location().empty()) + XBT_INFO("To get handle location information, pass -trace-call-location flag to smpicc/f90 as well"); + else + XBT_INFO("Handle %s was allocated by a call at %s", current_handle->name().c_str(), + (char*)(current_handle->call_location().c_str())); + } +} + } } } // namespace simgrid