1 /* Copyright (c) 2004-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 <xbt/asserts.h>
9 #include "simgrid/sg_config.hpp"
10 #include "src/simgrid/module.hpp"
11 #include "src/surf/surf_interface.hpp"
15 XBT_LOG_NEW_CATEGORY(plugin, "Common category for the logging of all plugins");
16 XBT_LOG_EXTERNAL_CATEGORY(xbt_help);
18 using namespace simgrid;
20 void ModuleGroup::create_flag(const std::string& opt_name, const std::string& descr, const std::string& default_value,
23 std::string description = descr + ". Possible values (other compilation flags may activate more " + get_kind() +
24 "s): " + existing_values() +
25 ".\n (use 'help' as a value to see the long description of each one)";
27 simgrid::config::declare_flag<std::string>(
28 opt_name, description, default_value, [this, default_value, init_now](const std::string& value) {
29 xbt_assert(_sg_cfg_init_status < 2, "Cannot load a %s after the initialization", kind_.c_str());
31 if (value == default_value)
34 if (value == "help") {
40 by_name(value).init();
42 by_name(value); // Simply ensure that this value exists, it will be picked up later
46 ModuleGroup& ModuleGroup::add(const char* id, const char* desc, std::function<void()> init)
48 table_.emplace_back(Module(id, desc, init));
52 Module const& ModuleGroup::by_name(const std::string& name) const
54 if (auto pos = std::find_if(table_.begin(), table_.end(), [&name](const Module& item) { return item.name_ == name; });
58 xbt_die("Unable to find %s '%s'. Valid values are: %s.", kind_.c_str(), name.c_str(), existing_values().c_str());
60 /** Displays the long description of all registered models, and quit */
61 void ModuleGroup::help() const
63 XBT_HELP("Long description of the %s accepted by this simulator:", kind_.c_str());
64 for (auto const& item : table_)
65 XBT_HELP(" %s: %s", item.name_, item.description_);
67 std::string ModuleGroup::existing_values() const
71 for (auto const& item : table_) {
72 ss << sep + item.name_;
78 /* -------------------------------------------------------------------------------------------------------------- */
79 simgrid::ModuleGroup surf_optimization_mode_description("optimization mode");
81 void simgrid_create_models()
83 surf_optimization_mode_description
84 .add("Lazy", "Lazy action management (partial invalidation in lmm + heap in action remaining).", nullptr)
86 "Trace integration. Highly optimized mode when using availability traces (only available for the Cas01 CPU "
89 .add("Full", "Full update of remaining and variables. Slow but may be useful when debugging.", nullptr);