Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines.
[simgrid.git] / examples / s4u / trace-host-user-variables / s4u-trace-host-user-variables.cpp
1 /* Copyright (c) 2010-2021. 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 /* 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
8  * traces.
9  */
10
11 #include "simgrid/instr.h"
12 #include "simgrid/s4u.hpp"
13
14 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
15
16 static void trace_fun()
17 {
18   const char* hostname = simgrid::s4u::this_actor::get_host()->get_cname();
19
20   // the hostname has an empty HDD with a capacity of 100000 (bytes)
21   TRACE_host_variable_set(hostname, "HDD_capacity", 100000);
22   TRACE_host_variable_set(hostname, "HDD_utilization", 0);
23
24   for (int i = 0; i < 10; i++) {
25     // create and execute a task just to make the simulated time advance
26     simgrid::s4u::this_actor::execute(1e4);
27
28     // ADD: after the execution of this task, the HDD utilization increases by 100 (bytes)
29     TRACE_host_variable_add(hostname, "HDD_utilization", 100);
30   }
31
32   for (int i = 0; i < 10; i++) {
33     // create and execute a task just to make the simulated time advance
34     simgrid::s4u::this_actor::execute(1e4);
35
36     // SUB: after the execution of this task, the HDD utilization decreases by 100 (bytes)
37     TRACE_host_variable_sub(hostname, "HDD_utilization", 100);
38   }
39 }
40
41 int main(int argc, char* argv[])
42 {
43   simgrid::s4u::Engine e(&argc, argv);
44   xbt_assert(argc > 1, "Usage: %s platform_file\n \tExample: %s small_platform.xml\n", argv[0], argv[0]);
45
46   e.load_platform(argv[1]);
47
48   // declaring user variables
49   TRACE_host_variable_declare("HDD_capacity");
50   TRACE_host_variable_declare("HDD_utilization");
51
52   simgrid::s4u::Actor::create("master", simgrid::s4u::Host::by_name("Tremblay"), trace_fun);
53
54   e.run();
55
56   // get user declared variables
57   xbt_dynar_t host_variables = TRACE_get_host_variables();
58   if (host_variables) {
59     XBT_INFO("Declared host variables:");
60     unsigned int cursor;
61     char* variable;
62     xbt_dynar_foreach (host_variables, cursor, variable) {
63       XBT_INFO("%s", variable);
64     }
65     xbt_dynar_free(&host_variables);
66   }
67   xbt_dynar_t link_variables = TRACE_get_link_variables();
68   if (link_variables) {
69     xbt_assert(xbt_dynar_is_empty(link_variables), "Should not have any declared link variable!");
70     xbt_dynar_free(&link_variables);
71   }
72
73   return 0;
74 }