X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/18438ade0ea0213b9990e78db27915c9cfee58f3..051812e67ee3e1d24c8fad3f03b91627ba2821f7:/src/kernel/actor/CommObserver.cpp diff --git a/src/kernel/actor/CommObserver.cpp b/src/kernel/actor/CommObserver.cpp index 98e0af8381..bb2d4bf47c 100644 --- a/src/kernel/actor/CommObserver.cpp +++ b/src/kernel/actor/CommObserver.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2019-2022. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2019-2023. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -16,8 +16,9 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(obs_comm, mc_observer, "Logging specific to the namespace simgrid::kernel::actor { -ActivityTestanySimcall::ActivityTestanySimcall(ActorImpl* actor, const std::vector& activities) - : ResultingSimcall(actor, -1), activities_(activities) +ActivityTestanySimcall::ActivityTestanySimcall(ActorImpl* actor, const std::vector& activities, + std::string fun_call) + : ResultingSimcall(actor, -1), activities_(activities), fun_call_(fun_call) { indexes_.clear(); // list all the activities that are ready @@ -40,9 +41,9 @@ void ActivityTestanySimcall::prepare(int times_considered) } static void serialize_activity_test(const activity::ActivityImpl* act, std::stringstream& stream) { - if (auto* comm = dynamic_cast(act)) { + if (const auto* comm = dynamic_cast(act)) { stream << " " << (short)mc::Transition::Type::COMM_TEST; - stream << ' ' << (uintptr_t)comm; + stream << ' ' << comm->get_id(); stream << ' ' << (comm->src_actor_ != nullptr ? comm->src_actor_->get_pid() : -1); stream << ' ' << (comm->dst_actor_ != nullptr ? comm->dst_actor_->get_pid() : -1); stream << ' ' << comm->get_mailbox_id(); @@ -51,21 +52,16 @@ static void serialize_activity_test(const activity::ActivityImpl* act, std::stri stream << (short)mc::Transition::Type::UNKNOWN; } } -template static std::string ptr_to_id(A* ptr) -{ - static std::unordered_map map; - if (map.find(ptr) == map.end()) - map.insert(std::make_pair(ptr, std::to_string(map.size() + 1))); - return map[ptr]; -} static std::string to_string_activity_test(const activity::ActivityImpl* act) { - if (auto* comm = dynamic_cast(act)) { - return std::string("CommTest(comm_id:") + ptr_to_id(comm) + + if (const auto* comm = dynamic_cast(act)) { + const std::string src_buff_id = ptr_to_id(comm->src_buff_); + const std::string dst_buff_id = ptr_to_id(comm->dst_buff_); + return "CommTest(comm_id:" + std::to_string(comm->get_id()) + " src:" + std::to_string(comm->src_actor_ != nullptr ? comm->src_actor_->get_pid() : -1) + " dst:" + std::to_string(comm->dst_actor_ != nullptr ? comm->dst_actor_->get_pid() : -1) + - " mbox:" + std::to_string(comm->get_mailbox_id()) + " srcbuf:" + ptr_to_id(comm->src_buff_) + - " dstbuf:" + ptr_to_id(comm->dst_buff_) + " bufsize:" + std::to_string(comm->src_buff_size_); + " mbox:" + std::to_string(comm->get_mailbox_id()) + " srcbuf:" + src_buff_id + " dstbuf:" + dst_buff_id + + " bufsize:" + std::to_string(comm->src_buff_size_); } else { return "TestUnknownType()"; } @@ -73,15 +69,16 @@ static std::string to_string_activity_test(const activity::ActivityImpl* act) void ActivityTestanySimcall::serialize(std::stringstream& stream) const { stream << (short)mc::Transition::Type::TESTANY << ' ' << activities_.size() << ' '; - for (auto const& act : activities_) { + for (auto const* act : activities_) { serialize_activity_test(act, stream); stream << ' '; } + stream << fun_call_; } std::string ActivityTestanySimcall::to_string() const { std::stringstream buffer("TestAny("); - for (auto const& act : activities_) { + for (auto const* act : activities_) { buffer << to_string_activity_test(act); } return buffer.str(); @@ -90,6 +87,7 @@ std::string ActivityTestanySimcall::to_string() const void ActivityTestSimcall::serialize(std::stringstream& stream) const { serialize_activity_test(activity_, stream); + stream << ' ' << fun_call_; } std::string ActivityTestSimcall::to_string() const { @@ -97,9 +95,9 @@ std::string ActivityTestSimcall::to_string() const } static void serialize_activity_wait(const activity::ActivityImpl* act, bool timeout, std::stringstream& stream) { - if (auto* comm = dynamic_cast(act)) { + if (const auto* comm = dynamic_cast(act)) { stream << (short)mc::Transition::Type::COMM_WAIT << ' '; - stream << timeout << ' ' << (uintptr_t)comm; + stream << timeout << ' ' << comm->get_id(); stream << ' ' << (comm->src_actor_ != nullptr ? comm->src_actor_->get_pid() : -1); stream << ' ' << (comm->dst_actor_ != nullptr ? comm->dst_actor_->get_pid() : -1); @@ -111,13 +109,15 @@ static void serialize_activity_wait(const activity::ActivityImpl* act, bool time } static std::string to_string_activity_wait(const activity::ActivityImpl* act) { - if (auto* comm = dynamic_cast(act)) { - return std::string("CommWait(comm_id:") + ptr_to_id(comm) + + if (const auto* comm = dynamic_cast(act)) { + const std::string src_buff_id = ptr_to_id(comm->src_buff_); + const std::string dst_buff_id = ptr_to_id(comm->dst_buff_); + return "CommWait(comm_id:" + std::to_string(comm->get_id()) + " src:" + std::to_string(comm->src_actor_ != nullptr ? comm->src_actor_->get_pid() : -1) + " dst:" + std::to_string(comm->dst_actor_ != nullptr ? comm->dst_actor_->get_pid() : -1) + - " mbox:" + std::to_string(comm->get_mailbox_id()) + " srcbuf:" + ptr_to_id(comm->src_buff_) + - " dstbuf:" + ptr_to_id(comm->dst_buff_) + " bufsize:" + std::to_string(comm->src_buff_size_) + - ")"; + " mbox:" + (comm->get_mailbox() == nullptr ? "-" : comm->get_mailbox()->get_name()) + + "(id:" + std::to_string(comm->get_mailbox_id()) + ") srcbuf:" + src_buff_id + " dstbuf:" + dst_buff_id + + " bufsize:" + std::to_string(comm->src_buff_size_) + ")"; } else { return "WaitUnknownType()"; } @@ -126,14 +126,16 @@ static std::string to_string_activity_wait(const activity::ActivityImpl* act) void ActivityWaitSimcall::serialize(std::stringstream& stream) const { serialize_activity_wait(activity_, timeout_ > 0, stream); + stream << ' ' << fun_call_; } void ActivityWaitanySimcall::serialize(std::stringstream& stream) const { stream << (short)mc::Transition::Type::WAITANY << ' ' << activities_.size() << ' '; - for (auto const& act : activities_) { + for (auto const* act : activities_) { serialize_activity_wait(act, timeout_ > 0, stream); stream << ' '; } + stream << fun_call_; } std::string ActivityWaitSimcall::to_string() const { @@ -142,14 +144,14 @@ std::string ActivityWaitSimcall::to_string() const std::string ActivityWaitanySimcall::to_string() const { std::stringstream buffer("WaitAny("); - for (auto const& act : activities_) { + for (auto const* act : activities_) { buffer << to_string_activity_wait(act); } return buffer.str(); } ActivityWaitanySimcall::ActivityWaitanySimcall(ActorImpl* actor, const std::vector& activities, - double timeout) - : ResultingSimcall(actor, -1), activities_(activities), timeout_(timeout) + double timeout, std::string fun_call) + : ResultingSimcall(actor, -1), activities_(activities), timeout_(timeout), fun_call_(fun_call) { // list all the activities that are ready indexes_.clear(); @@ -200,30 +202,33 @@ void ActivityWaitanySimcall::prepare(int times_considered) void CommIsendSimcall::serialize(std::stringstream& stream) const { + /* Note that the comm_ is 0 until after the execution of the simcall */ stream << (short)mc::Transition::Type::COMM_ASYNC_SEND << ' '; - stream << (uintptr_t)comm_ << ' ' << mbox_->get_id() << ' ' << (uintptr_t)src_buff_ << ' ' << src_buff_size_ << ' ' - << tag_; + stream << (comm_ ? comm_->get_id() : 0) << ' ' << mbox_->get_id() << ' ' << (uintptr_t)src_buff_ << ' ' + << src_buff_size_ << ' ' << tag_; XBT_DEBUG("SendObserver comm:%p mbox:%u buff:%p size:%zu tag:%d", comm_, mbox_->get_id(), src_buff_, src_buff_size_, tag_); + stream << ' ' << fun_call_; } std::string CommIsendSimcall::to_string() const { - return std::string("CommAsyncSend(comm_id: ") + std::to_string((uintptr_t)comm_) + - " mbox:" + std::to_string(mbox_->get_id()) + " srcbuf:" + ptr_to_id(src_buff_) + - " bufsize:" + std::to_string(src_buff_size_) + " tag: " + std::to_string(tag_) + ")"; + return "CommAsyncSend(comm_id: " + std::to_string(comm_->get_id()) + " mbox:" + std::to_string(mbox_->get_id()) + + " srcbuf:" + ptr_to_id(src_buff_) + " bufsize:" + std::to_string(src_buff_size_) + + " tag: " + std::to_string(tag_) + ")"; } void CommIrecvSimcall::serialize(std::stringstream& stream) const { + /* Note that the comm_ is 0 until after the execution of the simcall */ stream << (short)mc::Transition::Type::COMM_ASYNC_RECV << ' '; - stream << (uintptr_t)comm_ << ' ' << mbox_->get_id() << ' ' << (uintptr_t)dst_buff_ << ' ' << tag_; + stream << (comm_ ? comm_->get_id() : 0) << ' ' << mbox_->get_id() << ' ' << (uintptr_t)dst_buff_ << ' ' << tag_; XBT_DEBUG("RecvObserver comm:%p mbox:%u buff:%p tag:%d", comm_, mbox_->get_id(), dst_buff_, tag_); + stream << ' ' << fun_call_; } std::string CommIrecvSimcall::to_string() const { - return std::string("CommAsyncRecv(comm_id: ") + ptr_to_id(comm_) + - " mbox:" + std::to_string(mbox_->get_id()) + " dstbuf:" + ptr_to_id(dst_buff_) + - " tag: " + std::to_string(tag_) + ")"; + return "CommAsyncRecv(comm_id: " + std::to_string(comm_->get_id()) + " mbox:" + std::to_string(mbox_->get_id()) + + " dstbuf:" + ptr_to_id(dst_buff_) + " tag: " + std::to_string(tag_) + ")"; } } // namespace simgrid::kernel::actor