1 /* Copyright (c) 2019-2023. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include "src/kernel/actor/SimcallObserver.hpp"
7 #include "simgrid/s4u/Host.hpp"
8 #include "src/kernel/activity/CommImpl.hpp"
9 #include "src/kernel/activity/MailboxImpl.hpp"
10 #include "src/kernel/activity/MutexImpl.hpp"
11 #include "src/kernel/actor/ActorImpl.hpp"
12 #include "src/mc/mc_config.hpp"
16 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_observer, mc, "Logging specific to MC simcall observation");
18 namespace simgrid::kernel::actor {
20 void RandomSimcall::serialize(std::stringstream& stream) const
22 stream << (short)mc::Transition::Type::RANDOM << ' ';
23 stream << min_ << ' ' << max_;
25 std::string RandomSimcall::to_string() const
27 return "Random(min:" + std::to_string(min_) + " max:" + std::to_string(max_) + ")";
30 void RandomSimcall::prepare(int times_considered)
32 next_value_ = min_ + times_considered;
33 XBT_DEBUG("MC_RANDOM(%d, %d) will return %d after %d times", min_, max_, next_value_, times_considered);
36 int RandomSimcall::get_max_consider() const
38 return max_ - min_ + 1;
41 ActorJoinSimcall::ActorJoinSimcall(ActorImpl* actor, ActorImpl* other, double timeout)
42 : SimcallObserver(actor), other_(s4u::ActorPtr(other->get_iface())), timeout_(timeout)
45 bool ActorJoinSimcall::is_enabled()
47 return other_->get_impl()->wannadie();
49 void ActorJoinSimcall::serialize(std::stringstream& stream) const
51 stream << (short)mc::Transition::Type::ACTOR_JOIN << ' ';
52 stream << other_->get_pid() << ' ' << (timeout_ > 0);
54 std::string ActorJoinSimcall::to_string() const
56 return "ActorJoin(pid:" + std::to_string(other_->get_pid()) + ")";
58 void ActorSleepSimcall::serialize(std::stringstream& stream) const
60 stream << (short)mc::Transition::Type::ACTOR_SLEEP;
63 std::string ActorSleepSimcall::to_string() const
65 return "ActorSleep()";
68 void ObjectAccessSimcallObserver::serialize(std::stringstream& stream) const
70 stream << (short)mc::Transition::Type::OBJECT_ACCESS << ' ';
71 stream << object_ << ' ' << get_owner()->get_pid();
73 std::string ObjectAccessSimcallObserver::to_string() const
75 return "ObjectAccess(obj:" + ptr_to_id<ObjectAccessSimcallItem const>(object_) +
76 " owner:" + std::to_string(get_owner()->get_pid()) + ")";
78 bool ObjectAccessSimcallObserver::is_visible() const
80 return get_owner() != get_issuer();
82 ActorImpl* ObjectAccessSimcallObserver::get_owner() const
84 return object_->simcall_owner_;
87 } // namespace simgrid::kernel::actor