From c3aba869402fd6e57bd6c70dde801e6995037d99 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Sat, 19 Mar 2022 20:12:48 +0100 Subject: [PATCH] Give users a way to debug their barriers --- include/simgrid/s4u/Barrier.hpp | 2 ++ src/kernel/activity/BarrierImpl.hpp | 5 +++++ src/s4u/s4u_Barrier.cpp | 5 +++++ 3 files changed, 12 insertions(+) diff --git a/include/simgrid/s4u/Barrier.hpp b/include/simgrid/s4u/Barrier.hpp index 1e5e589f75..547f5d82d4 100644 --- a/include/simgrid/s4u/Barrier.hpp +++ b/include/simgrid/s4u/Barrier.hpp @@ -34,6 +34,8 @@ public: static BarrierPtr create(unsigned int expected_actors); /** Blocks into the barrier. Every waiting actors will be unlocked once the expected amount of actors reaches the barrier */ int wait(); + /** Returns some debug information about the barrier */ + std::string to_string(); #ifndef DOXYGEN /* refcounting */ diff --git a/src/kernel/activity/BarrierImpl.hpp b/src/kernel/activity/BarrierImpl.hpp index e34ba73ac6..b214e5f161 100644 --- a/src/kernel/activity/BarrierImpl.hpp +++ b/src/kernel/activity/BarrierImpl.hpp @@ -74,6 +74,11 @@ public: } s4u::Barrier& get_iface() { return piface_; } + + std::string to_string() + { + return xbt::string_printf("Barrier %d: %zu of %u", id_, ongoing_acquisitions_.size(), expected_actors_); + } }; } // namespace activity } // namespace kernel diff --git a/src/s4u/s4u_Barrier.cpp b/src/s4u/s4u_Barrier.cpp index 8aa46d2392..297109e115 100644 --- a/src/s4u/s4u_Barrier.cpp +++ b/src/s4u/s4u_Barrier.cpp @@ -53,6 +53,11 @@ int Barrier::wait() } } +std::string Barrier::to_string() +{ + return pimpl_->to_string(); +} + void intrusive_ptr_add_ref(Barrier* barrier) { intrusive_ptr_add_ref(barrier->pimpl_); -- 2.20.1