1 /* Copyright (c) 2015-2022. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #ifndef SIMGRID_MC_TRANSITION_HPP
8 #define SIMGRID_MC_TRANSITION_HPP
10 #include "simgrid/forward.h" // aid_t
11 #include "xbt/utility.hpp" // XBT_DECLARE_ENUM_CLASS
19 /** An element in the recorded path
21 * At each decision point, we need to record which process transition
22 * is triggered and potentially which value is associated with this
23 * transition. The value is used to find which communication is triggered
24 * in things like waitany and for associating a given value of MC_random()
28 /* Textual representation of the transition, to display backtraces */
29 static unsigned long executed_transitions_;
30 static unsigned long replayed_transitions_;
32 friend State; // FIXME remove this once we have a proper class to handle the statistics
35 XBT_DECLARE_ENUM_CLASS(Type, UNKNOWN, RANDOM, COMM_RECV, COMM_SEND, COMM_TEST, COMM_WAIT, TESTANY);
36 Type type_ = Type::UNKNOWN;
40 /* Which transition was executed for this simcall
42 * Some simcalls can lead to different transitions:
44 * * waitany/testany can trigger on different messages;
46 * * random can produce different values.
48 int times_considered_ = 0;
50 Transition() = default;
51 Transition(Type type, aid_t issuer, int times_considered)
52 : type_(type), aid_(issuer), times_considered_(times_considered)
55 virtual ~Transition();
57 virtual std::string to_string(bool verbose = false) const;
58 virtual std::string dot_label() const;
60 /* Moves the application toward a path that was already explored, but don't change the current transition */
63 virtual bool depends(const Transition* other) const { return true; }
65 /* Returns the total amount of transitions executed so far (for statistics) */
66 static unsigned long get_executed_transitions() { return executed_transitions_; }
67 /* Returns the total amount of transitions replayed so far while backtracing (for statistics) */
68 static unsigned long get_replayed_transitions() { return replayed_transitions_; }
71 class RandomTransition : public Transition {
76 std::string to_string(bool verbose) const override;
77 std::string dot_label() const override;
78 RandomTransition(aid_t issuer, int times_considered, std::stringstream& stream);
79 bool depends(const Transition* other) const override { return false; } // Independent with any other transition
83 } // namespace simgrid