1 /* Copyright (c) 2015-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 #ifndef SIMGRID_MC_TRANSITION_HPP
7 #define SIMGRID_MC_TRANSITION_HPP
9 #include "simgrid/forward.h" // aid_t
10 #include "xbt/utility.hpp" // XBT_DECLARE_ENUM_CLASS
15 namespace simgrid::mc {
17 /** An element in the recorded path
19 * At each decision point, we need to record which process transition
20 * is triggered and potentially which value is associated with this
21 * transition. The value is used to find which communication is triggered
22 * in things like waitany and for associating a given value of MC_random()
26 /* Textual representation of the transition, to display backtraces */
27 static unsigned long executed_transitions_;
28 static unsigned long replayed_transitions_;
30 friend State; // FIXME remove this once we have a proper class to handle the statistics
32 /* Ordering is important here. depends() implementations only consider subsequent types in this ordering */
33 XBT_DECLARE_ENUM_CLASS(Type, RANDOM, ACTOR_JOIN, /* First because indep with anybody including themselves */
34 OBJECT_ACCESS, /* high priority because indep with almost everybody */
35 TESTANY, WAITANY, /* high priority because they can rewrite themselves to *_WAIT */
36 BARRIER_ASYNC_LOCK, BARRIER_WAIT, /* BARRIER transitions sorted alphabetically */
37 COMM_ASYNC_RECV, COMM_ASYNC_SEND, COMM_TEST, COMM_WAIT, /* Alphabetical ordering of COMM_* */
38 MUTEX_ASYNC_LOCK, MUTEX_TEST, MUTEX_TRYLOCK, MUTEX_UNLOCK, MUTEX_WAIT, /* alphabetical */
39 SEM_ASYNC_LOCK, SEM_UNLOCK, SEM_WAIT, /* alphabetical ordering of SEM transitions */
40 /* UNKNOWN must be last */ UNKNOWN);
41 Type type_ = Type::UNKNOWN;
45 /** The user function call that caused this transition to exist. Format: >>filename:line:function()<< */
46 std::string call_location_ = "";
48 /* Which transition was executed for this simcall
50 * Some simcalls can lead to different transitions:
52 * * waitany/testany can trigger on different messages;
54 * * random can produce different values.
56 int times_considered_ = 0;
58 Transition() = default;
59 Transition(Type type, aid_t issuer, int times_considered)
60 : type_(type), aid_(issuer), times_considered_(times_considered)
63 virtual ~Transition();
65 /** Returns a textual representation of the transition. Pointer adresses are omitted if verbose=false */
66 virtual std::string to_string(bool verbose = false) const;
67 /** Returns something like >>label = "desc", color = c<< to describe the transition in dot format */
68 virtual std::string dot_string() const;
70 std::string get_call_location() { return call_location_; }
72 /* Moves the application toward a path that was already explored, but don't change the current transition */
73 void replay(RemoteApp& app) const;
75 virtual bool depends(const Transition* other) const { return true; }
77 /* Returns the total amount of transitions executed so far (for statistics) */
78 static unsigned long get_executed_transitions() { return executed_transitions_; }
79 /* Returns the total amount of transitions replayed so far while backtracing (for statistics) */
80 static unsigned long get_replayed_transitions() { return replayed_transitions_; }
83 /** Make a new transition from serialized description */
84 Transition* deserialize_transition(aid_t issuer, int times_considered, std::stringstream& stream);
86 } // namespace simgrid::mc