Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'maximal-subset-search' into 'master'
[simgrid.git] / src / mc / explo / Exploration.cpp
1 /* Copyright (c) 2016-2023. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #include "src/mc/explo/Exploration.hpp"
7 #include "src/mc/mc_config.hpp"
8 #include "src/mc/mc_private.hpp"
9
10 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_explo, mc, "Generic exploration algorithm of the model-checker");
11
12 namespace simgrid::mc {
13
14 static simgrid::config::Flag<std::string> cfg_dot_output_file{
15     "model-check/dot-output", "Name of dot output file corresponding to graph state", ""};
16
17 Exploration::Exploration(const std::vector<char*>& args) : remote_app_(std::make_unique<RemoteApp>(args))
18 {
19   mc_model_checker->set_exploration(this);
20
21   if (not cfg_dot_output_file.get().empty()) {
22     dot_output_ = fopen(cfg_dot_output_file.get().c_str(), "w");
23     xbt_assert(dot_output_ != nullptr, "Error open dot output file: %s", strerror(errno));
24
25     fprintf(dot_output_, "digraph graphname{\n fixedsize=true; rankdir=TB; ranksep=.25; edge [fontsize=12]; node "
26                          "[fontsize=10, shape=circle,width=.5 ]; graph [resolution=20, fontsize=10];\n");
27   }
28 }
29
30 Exploration::~Exploration()
31 {
32   if (dot_output_ != nullptr)
33     fclose(dot_output_);
34 }
35
36 void Exploration::dot_output(const char* fmt, ...)
37 {
38   if (dot_output_ != nullptr) {
39     va_list ap;
40     va_start(ap, fmt);
41     vfprintf(dot_output_, fmt, ap);
42     va_end(ap);
43     fflush(dot_output_);
44   }
45 }
46
47 void Exploration::log_state()
48 {
49   if (not cfg_dot_output_file.get().empty()) {
50     dot_output("}\n");
51     fclose(dot_output_);
52   }
53   if (getenv("SIMGRID_MC_SYSTEM_STATISTICS")) {
54     int ret = system("free");
55     if (ret != 0)
56       XBT_WARN("Call to system(free) did not return 0, but %d", ret);
57   }
58 }
59
60 }; // namespace simgrid::mc