{
return get_issuer() == other->get_issuer();
}
-void RandomSimcall::serialize(Simcall& type, char* buffer)
+void RandomSimcall::serialize(Simcall& type, std::stringstream& stream)
{
type = Simcall::RANDOM;
- std::stringstream stream;
-
stream << min_ << ' ' << max_;
- xbt_assert(stream.str().size() < SIMCALL_SERIALIZATION_BUFFER_SIZE,
- "The serialized simcall is too large for the buffer. Please fix the code.");
- strncpy(buffer, stream.str().c_str(), SIMCALL_SERIALIZATION_BUFFER_SIZE);
}
bool MutexSimcall::depends(SimcallObserver* other)
return true;
}
-void ActivityWaitSimcall::serialize(Simcall& type, char* buffer)
+void ActivityWaitSimcall::serialize(Simcall& type, std::stringstream& stream)
{
- std::stringstream stream;
if (auto* comm = dynamic_cast<activity::CommImpl*>(activity_)) {
type = Simcall::COMM_WAIT;
stream << (timeout_ > 0) << ' ' << comm;
stream << ' ' << (comm->dst_actor_ != nullptr ? comm->dst_actor_->get_pid() : -1);
stream << ' ' << comm->get_mailbox_id();
stream << ' ' << (void*)comm->src_buff_ << ' ' << (void*)comm->dst_buff_ << ' ' << comm->src_buff_size_;
- xbt_assert(stream.str().size() < SIMCALL_SERIALIZATION_BUFFER_SIZE,
- "The serialized simcall is too large for the buffer. Please fix the code.");
- strncpy(buffer, stream.str().c_str(), SIMCALL_SERIALIZATION_BUFFER_SIZE);
} else {
type = Simcall::UNKNOWN;
- buffer[0] = '\0';
}
}
next_value_ = times_considered;
}
-void CommIsendSimcall::serialize(Simcall& type, char* buffer)
+void CommIsendSimcall::serialize(Simcall& type, std::stringstream& stream)
{
type = Simcall::ISEND;
- std::stringstream stream;
stream << mbox_->get_id() << ' ' << (void*)src_buff_ << ' ' << src_buff_size_;
- xbt_assert(stream.str().size() < SIMCALL_SERIALIZATION_BUFFER_SIZE,
- "The serialized simcall is too large for the buffer. Please fix the code.");
- strncpy(buffer, stream.str().c_str(), SIMCALL_SERIALIZATION_BUFFER_SIZE);
XBT_DEBUG("SendObserver mbox:%u buff:%p size:%zu", mbox_->get_id(), src_buff_, src_buff_size_);
}
-void CommIrecvSimcall::serialize(Simcall& type, char* buffer)
+void CommIrecvSimcall::serialize(Simcall& type, std::stringstream& stream)
{
type = Simcall::IRECV;
- std::stringstream stream;
stream << mbox_->get_id() << dst_buff_;
- xbt_assert(stream.str().size() < SIMCALL_SERIALIZATION_BUFFER_SIZE,
- "The serialized simcall is too large for the buffer. Please fix the code.");
- strncpy(buffer, stream.str().c_str(), SIMCALL_SERIALIZATION_BUFFER_SIZE);
-}
-
-
-/*
-std::string CommIrecvSimcall::to_string(int times_considered) const
-{
- std::string res = SimcallObserver::to_string(times_considered) + "iRecv(";
- res += xbt::string_printf("dst=(%ld)%s (%s)", get_issuer()->get_pid(), get_issuer()->get_host()->get_cname(),
- get_issuer()->get_cname());
- res += ", buff=" + (XBT_LOG_ISENABLED(mc_observer, xbt_log_priority_verbose) ? xbt::string_printf("%p", dst_buff_)
- : "(verbose only)");
- res += ", size=" + (XBT_LOG_ISENABLED(mc_observer, xbt_log_priority_verbose) ? std::to_string(*dst_buff_size_)
- : "(verbose only)");
- res += ")";
- return res;
}
-*/
} // namespace actor
} // namespace kernel
#include <string>
-#define SIMCALL_SERIALIZATION_BUFFER_SIZE 2048
-
namespace simgrid {
namespace kernel {
namespace actor {
/** Computes the dependency relation */
virtual bool depends(SimcallObserver* other);
- /** Serialize to the given buffer */
- virtual void serialize(Simcall& type, char* buffer) { type = Simcall::UNKNOWN; }
+ /** Serialize to the given string buffer */
+ virtual void serialize(Simcall& type, std::stringstream& stream) { type = Simcall::UNKNOWN; }
/** Some simcalls may only be observable under some conditions.
* Most simcalls are not visible from the MC because they don't have an observer at all. */
res->next_value_ = next_value_;
return res;
}
- void serialize(Simcall& type, char* buffer) override;
+ void serialize(Simcall& type, std::stringstream& stream) override;
int get_max_consider() const override;
void prepare(int times_considered) override;
std::string dot_label(int times_considered) const override;
{
}
SimcallObserver* clone() override { return new ActivityWaitSimcall(get_issuer(), activity_, timeout_); }
- void serialize(Simcall& type, char* buffer) override;
+ void serialize(Simcall& type, std::stringstream& stream) override;
bool is_visible() const override { return true; }
bool is_enabled() const override;
std::string dot_label(int times_considered) const override;
, copy_data_fun_(copy_data_fun)
{
}
- void serialize(Simcall& type, char* buffer) override;
+ void serialize(Simcall& type, std::stringstream& stream) override;
CommIsendSimcall* clone() override
{
return new CommIsendSimcall(get_issuer(), mbox_, payload_size_, rate_, src_buff_, src_buff_size_, match_fun_,
return new CommIrecvSimcall(get_issuer(), mbox_, dst_buff_, dst_buff_size_, match_fun_, copy_data_fun_, payload_,
rate_);
}
- void serialize(Simcall& type, char* buffer) override;
+ void serialize(Simcall& type, std::stringstream& stream) override;
bool is_visible() const override { return true; }
std::string dot_label(int times_considered) const override
{
s_mc_message_simcall_execute_answer_t answer;
memset(&answer, 0, sizeof(answer));
answer.type = MessageType::SIMCALL_EXECUTE_ANSWER;
- if (actor->simcall_.observer_ != nullptr)
- actor->simcall_.observer_->serialize(answer.simcall, answer.buffer);
+ if (actor->simcall_.observer_ != nullptr) {
+ std::stringstream stream;
+ actor->simcall_.observer_->serialize(answer.simcall, stream);
+ xbt_assert(stream.str().size() < sizeof(answer.buffer),
+ "The serialized simcall is too large for the buffer. Please fix the code.");
+ strncpy(answer.buffer, stream.str().c_str(), SIMCALL_SERIALIZATION_BUFFER_SIZE);
+ } else {
+ answer.simcall = kernel::actor::SimcallObserver::Simcall::UNKNOWN;
+ }
+
XBT_DEBUG("send SIMCALL_EXECUTE_ANSWER(%s) ~> %s '%s'", actor->get_cname(),
simgrid::kernel::actor::SimcallObserver::to_c_str(answer.simcall), answer.buffer);
xbt_assert(channel_.send(answer) == 0, "Could not send response");
SIMCALL_EXECUTE_ANSWER, SIMCALL_IS_VISIBLE, SIMCALL_IS_VISIBLE_ANSWER, SIMCALL_DOT_LABEL,
SIMCALL_DOT_LABEL_ANSWER, ASSERTION_FAILED, ACTOR_ENABLED, ACTOR_ENABLED_REPLY, FINALIZE);
+#define SIMCALL_SERIALIZATION_BUFFER_SIZE 2048
+
} // namespace mc
} // namespace simgrid