1 /* Copyright (c) 2010-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 /* This source code simply loads the platform. This is only useful to play
7 * with the tracing module. See the tesh file to see how to generate the
11 #include "simgrid/instr.h"
12 #include "simgrid/s4u.hpp"
14 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
15 namespace sg4 = simgrid::s4u;
17 static void trace_fun()
19 const auto host = sg4::this_actor::get_host()->get_name();
21 // the hostname has an empty HDD with a capacity of 100000 (bytes)
22 simgrid::instr::set_host_variable(host, "HDD_capacity", 100000);
23 simgrid::instr::set_host_variable(host, "HDD_utilization", 0);
25 for (int i = 0; i < 10; i++) {
26 // create and execute a task just to make the simulated time advance
27 sg4::this_actor::execute(1e4);
29 // ADD: after the execution of this task, the HDD utilization increases by 100 (bytes)
30 simgrid::instr::add_host_variable(host, "HDD_utilization", 100);
33 for (int i = 0; i < 10; i++) {
34 // create and execute a task just to make the simulated time advance
35 sg4::this_actor::execute(1e4);
37 // SUB: after the execution of this task, the HDD utilization decreases by 100 (bytes)
38 simgrid::instr::sub_host_variable(host, "HDD_utilization", 100);
42 int main(int argc, char* argv[])
44 sg4::Engine e(&argc, argv);
45 xbt_assert(argc > 1, "Usage: %s platform_file\n \tExample: %s small_platform.xml\n", argv[0], argv[0]);
47 e.load_platform(argv[1]);
49 // declaring user variables
50 simgrid::instr::declare_host_variable("HDD_capacity");
51 simgrid::instr::declare_host_variable("HDD_utilization", "1 0 0"); // red color
53 sg4::Actor::create("master", e.host_by_name("Tremblay"), trace_fun);
57 // get user declared variables
58 if (const auto& host_variables = simgrid::instr::get_host_variables(); not host_variables.empty()) {
59 XBT_INFO("Declared host variables:");
60 for (const auto& var : host_variables)
61 XBT_INFO("%s", var.c_str());
63 const auto& link_variables = simgrid::instr::get_link_variables();
64 xbt_assert(link_variables.empty(), "Should not have any declared link variable!");