Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
continue the deprecation of instrumentation C interface
[simgrid.git] / src / instr / instr_interface.cpp
1 /* Copyright (c) 2010-2022. 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 <simgrid/Exception.hpp>
7 #include <simgrid/kernel/routing/NetPoint.hpp>
8 #include <simgrid/s4u/Engine.hpp>
9 #include <xbt/random.hpp>
10
11 #include "src/instr/instr_private.hpp"
12 #include "src/kernel/resource/StandardLinkImpl.hpp"
13 #include <algorithm>
14 #include <cmath>
15
16 enum class InstrUserVariable { DECLARE, SET, ADD, SUB };
17
18 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_api, instr, "API");
19
20 std::set<std::string, std::less<>> created_categories;
21 std::set<std::string, std::less<>> declared_marks;
22 std::set<std::string, std::less<>> user_host_variables;
23 std::set<std::string, std::less<>> user_vm_variables;
24 std::set<std::string, std::less<>> user_link_variables;
25
26 static void instr_user_variable(double time, const std::string& resource, const std::string& variable_name,
27                                 const std::string& parent_type, double value, InstrUserVariable what,
28                                 const std::string& color, std::set<std::string, std::less<>>* filter)
29 {
30   /* safe switches. tracing has to be activated and if platform is not traced, we don't allow user variables */
31   if (not TRACE_is_enabled() || not TRACE_needs_platform())
32     return;
33
34   // check if variable is already declared
35   auto created = filter->find(variable_name);
36   if (what == InstrUserVariable::DECLARE) {
37     if (created == filter->end()) { // not declared yet
38       filter->insert(variable_name);
39       instr_new_user_variable_type(parent_type, variable_name, color);
40     }
41   } else {
42     if (created != filter->end()) { // declared, let's work
43       simgrid::instr::VariableType* variable =
44           simgrid::instr::Container::by_name(resource)->get_variable(variable_name);
45       switch (what) {
46         case InstrUserVariable::SET:
47           variable->set_event(time, value);
48           break;
49         case InstrUserVariable::ADD:
50           variable->add_event(time, value);
51           break;
52         case InstrUserVariable::SUB:
53           variable->sub_event(time, value);
54           break;
55         default:
56           THROW_IMPOSSIBLE;
57       }
58     }
59   }
60 }
61
62 static void instr_user_srcdst_variable(double time, const std::string& src, const std::string& dst,
63                                        const std::string& variable, double value, InstrUserVariable what)
64 {
65   auto* engine        = simgrid::s4u::Engine::get_instance();
66   const auto* src_elm = engine->netpoint_by_name_or_null(src);
67   xbt_assert(src_elm, "Element '%s' not found!", src.c_str());
68
69   const auto* dst_elm = engine->netpoint_by_name_or_null(dst);
70   xbt_assert(dst_elm, "Element '%s' not found!", dst.c_str());
71
72   std::vector<simgrid::kernel::resource::StandardLinkImpl*> route;
73   simgrid::kernel::routing::NetZoneImpl::get_global_route(src_elm, dst_elm, route, nullptr);
74   for (auto const& link : route)
75     instr_user_variable(time, link->get_cname(), variable, "LINK", value, what, "", &user_link_variables);
76 }
77
78 namespace simgrid {
79 namespace instr {
80 /* for host variables */
81 /** @brief Declare a new user variable associated to hosts.
82  *
83  *  Declare a user variable that will be associated to hosts.
84  *  A user host variable can be used to trace user variables such as the number of tasks in a server, the number of
85  *  clients in an application (for hosts), and so on. The color associated to this new variable will be random if
86  *  not given as parameter.
87  */
88 void declare_host_variable(const std::string& variable, const std::string& color)
89 {
90   instr_user_variable(0, "", variable, "HOST", 0, InstrUserVariable::DECLARE, color, &user_host_variables);
91 }
92
93 void set_host_variable(const std::string& host, const std::string& variable, double value, double time)
94 {
95   instr_user_variable(time, host, variable, "HOST", value, InstrUserVariable::SET, "", &user_host_variables);
96 }
97
98 /** @brief Add a value to a variable of a host */
99 void add_host_variable(const std::string& host, const std::string& variable, double value, double time)
100 {
101   instr_user_variable(time, host, variable, "HOST", value, InstrUserVariable::ADD, "", &user_host_variables);
102 }
103
104 /** @brief Subtract a value to a variable of a host */
105 void sub_host_variable(const std::string& host, const std::string& variable, double value, double time)
106 {
107   instr_user_variable(time, host, variable, "HOST", value, InstrUserVariable::SUB, "", &user_host_variables);
108 }
109
110 /** @brief Get host variables that were already declared with #declare_host_variable. */
111 const std::set<std::string, std::less<>>& get_host_variables()
112 {
113   return user_host_variables;
114 }
115
116 /* for link variables */
117 /** @brief Declare a new user variable associated to links.
118  *
119  *  Declare a user variable that will be associated to links.
120  *  A user link variable can be used, for example, to trace user variables such as the number of messages being
121  *  transferred through network links. The color associated to this new variable will be random if not given as
122  *  parameter.
123  */
124 void declare_link_variable(const std::string& variable, const std::string& color)
125 {
126   instr_user_variable(0, "", variable, "LINK", 0, InstrUserVariable::DECLARE, color, &user_link_variables);
127 }
128
129 /** @brief Set the value of a variable of a link */
130 void set_link_variable(const std::string& link, const std::string& variable, double value, double time)
131 {
132   instr_user_variable(time, link, variable, "LINK", value, InstrUserVariable::SET, "", &user_link_variables);
133 }
134
135 void set_link_variable(const std::string& src, const std::string& dst, const std::string& variable, double value,
136                        double time)
137 {
138   instr_user_srcdst_variable(time, src, dst, variable, value, InstrUserVariable::SET);
139 }
140
141 /** @brief Add a value to a variable of a link */
142 void add_link_variable(const std::string& link, const std::string& variable, double value, double time)
143 {
144   instr_user_variable(time, link, variable, "LINK", value, InstrUserVariable::ADD, "", &user_link_variables);
145 }
146
147 /** @brief Add a value to a variable of a link */
148 void add_link_variable(const std::string& src, const std::string& dst, const std::string& variable, double value,
149                        double time)
150 {
151   instr_user_srcdst_variable(time, src, dst, variable, value, InstrUserVariable::ADD);
152 }
153
154 /** @brief Subtract a value to a variable of a link */
155 void sub_link_variable(const std::string& link, const std::string& variable, double value, double time)
156 {
157   instr_user_variable(time, link, variable, "LINK", value, InstrUserVariable::SUB, "", &user_link_variables);
158 }
159
160 /** @brief Subtract a value to a variable of a link */
161 void sub_link_variable(const std::string& src, const std::string& dst, const std::string& variable, double value,
162                        double time)
163 {
164   instr_user_srcdst_variable(time, src, dst, variable, value, InstrUserVariable::SUB);
165 }
166
167 /** @brief Get link variables that were already declared with #declare_link_variable. */
168 const std::set<std::string, std::less<>>& get_link_variables()
169 {
170   return user_link_variables;
171 }
172
173 /* for VM variables */
174 /** @brief Declare a new user variable associated to VMs.
175  *
176  *  Declare a user variable that will be associated to VMs. A user host variable can be used to trace user variables
177  *  such as the number of tasks in a VM, the number of clients in an application (for hosts), and so on. The color
178  *  associated to this new variable will be random if not given as parameter.
179  */
180 void declare_vm_variable(const std::string& variable, const std::string& color)
181 {
182   instr_user_variable(0, "", variable, "VM", 0, InstrUserVariable::DECLARE, color, &user_vm_variables);
183 }
184
185 /** @brief Set the value of a variable of a vm */
186 void set_vm_variable(const std::string& vm, const std::string& variable, double value, double time)
187 {
188   instr_user_variable(time, vm, variable, "VM", value, InstrUserVariable::SET, "", &user_vm_variables);
189 }
190
191 /** @brief Add a value to a variable of a VM */
192 void add_vm_variable(const std::string& vm, const std::string& variable, double value, double time)
193 {
194   instr_user_variable(time, vm, variable, "VM", value, InstrUserVariable::ADD, "", &user_vm_variables);
195 }
196
197 /** @brief Subtract a value from a variable of a VM */
198 void sub_vm_variable(const std::string& vm, const std::string& variable, double value, double time)
199 {
200   instr_user_variable(time, vm, variable, "VM", value, InstrUserVariable::SUB, "", &user_vm_variables);
201 }
202
203 /** @brief Get VM variables that were already declared with #declare_vm_variable. */
204 const std::set<std::string, std::less<>>& get_vm_variables()
205 {
206   return user_vm_variables;
207 }
208
209 /**@brief Declare a new type for tracing mark.
210  *
211  * This function declares a new Paje event type in the trace file that can be used by simulators to declare
212  * application-level marks. This function is independent of which API is used in SimGrid.
213  */
214 void declare_mark(const std::string& mark_type)
215 {
216   /* safe switches. tracing has to be activated and if platform is not traced, we can't deal with marks */
217   if (not TRACE_is_enabled() || not TRACE_needs_platform())
218     return;
219
220   // check if mark_type is already declared
221   if (declared_marks.find(mark_type) != declared_marks.end()) {
222     throw TracingError(XBT_THROW_POINT,
223                        xbt::string_printf("mark_type with name (%s) is already declared", mark_type.c_str()));
224   }
225
226   XBT_DEBUG("MARK,declare %s", mark_type.c_str());
227   Container::get_root()->get_type()->by_name_or_create<EventType>(mark_type);
228   declared_marks.emplace(mark_type);
229 }
230
231 /** @brief Declare a new colored value for a previously declared mark type.
232  *
233  * This function declares a new colored value for a Paje event type in the trace file that can be used by simulators to
234  * declare application-level marks. This function is independent of which API is used in SimGrid. The color needs to be
235  * a string with three numbers separated by spaces in the range [0,1].
236  * A light-gray color can be specified using "0.7 0.7 0.7" as color. If no color is provided, the default color used
237  * will be white ("1 1 1").
238  */
239 void declare_mark_value(const std::string& mark_type, const std::string& mark_value, const std::string& mark_color)
240 {
241   /* safe switches. tracing has to be activated and if platform is not traced, we can't deal with marks */
242   if (not TRACE_is_enabled() || not TRACE_needs_platform())
243     return;
244
245   auto* type = static_cast<EventType*>(Container::get_root()->get_type()->by_name(mark_type));
246   if (not type) {
247     throw TracingError(XBT_THROW_POINT,
248                        xbt::string_printf("mark_type with name (%s) is not declared", mark_type.c_str()));
249   } else {
250     XBT_DEBUG("MARK, declare_value %s %s %s", mark_type.c_str(), mark_value.c_str(), mark_color.c_str());
251     type->add_entity_value(mark_value, mark_color);
252   }
253 }
254
255 /** @brief Create a new instance of a tracing mark type.
256  *
257  * This function creates a mark in the trace file. The first parameter had to be previously declared using
258  * #declare_mark, the second is the identifier for this mark instance. We recommend that the mark_value is a
259  * unique value for the whole simulation. Nevertheless, this is not a strong requirement: the trace will be valid even
260  * if there are multiple mark identifiers for the same trace.
261  */
262 void mark(const std::string& mark_type, const std::string& mark_value)
263 {
264   /* safe switches. tracing has to be activated and if platform is not traced, we can't deal with marks */
265   if (not TRACE_is_enabled() || not TRACE_needs_platform())
266     return;
267
268   // check if mark_type is already declared
269   auto* type = static_cast<EventType*>(Container::get_root()->get_type()->by_name(mark_type));
270   if (not type) {
271     throw TracingError(XBT_THROW_POINT,
272                        xbt::string_printf("mark_type with name (%s) is not declared", mark_type.c_str()));
273   } else {
274     XBT_DEBUG("MARK %s %s", mark_type.c_str(), mark_value.c_str());
275     new NewEvent(simgrid_get_clock(), Container::get_root(), type, type->get_entity_value(mark_value));
276   }
277 }
278
279 /** @brief Get marks that were already declared with #declare_mark. */
280 const std::set<std::string, std::less<>>& get_marks()
281 {
282   return declared_marks;
283 }
284
285 /** @brief Declare a new category.
286  *
287  *  This function should be used to define a user category. The category can be used to differentiate the tasks that
288  *  are created during the simulation (for example, tasks from server1, server2, or request tasks, computation tasks,
289  *  communication tasks). All resource utilization (host power and link bandwidth) will be classified according to the
290  *  task category. Tasks that do not belong to a category are not traced. The color for the category that is being
291  *  declared is random. This function has no effect if a category with the same name has been already declared.
292  *
293  * See @ref outcomes_vizu for details on how to trace the (categorized) resource utilization.
294  */
295 void declare_tracing_category(const std::string& name, const std::string& color)
296 {
297   /* safe switches. tracing has to be activated and if platform is not traced, we can't deal with categories */
298   if (not TRACE_is_enabled() || not TRACE_needs_platform() || not TRACE_categorized())
299     return;
300
301   // check if category is already created
302   if (created_categories.find(name) != created_categories.end())
303     return;
304
305   created_categories.emplace(name);
306
307   // define final_color
308   std::string final_color;
309   if (color.empty()) {
310     // generate a random color
311     double red   = simgrid::xbt::random::uniform_real(0.0, std::nextafter(1.0, 2.0));
312     double green = simgrid::xbt::random::uniform_real(0.0, std::nextafter(1.0, 2.0));
313     double blue  = simgrid::xbt::random::uniform_real(0.0, std::nextafter(1.0, 2.0));
314     final_color  = std::to_string(red) + " " + std::to_string(green) + " " + std::to_string(blue);
315   } else {
316     final_color = std::string(color);
317   }
318
319   XBT_DEBUG("CAT,declare %s, \"%s\" \"%s\"", name.c_str(), color.c_str(), final_color.c_str());
320
321   // define the type of this category on top of hosts and links
322   instr_new_variable_type(name, final_color);
323 }
324
325 /** @brief Get categories that were already declared with #declare_tracing_category.
326  *
327  * See @ref outcomes_vizu for details on how to trace the (categorized) resource utilization.
328  */
329 const std::set<std::string, std::less<>>& get_tracing_categories()
330 {
331   return created_categories;
332 }
333
334 } // namespace instr
335 } // namespace simgrid
336
337 static xbt_dynar_t instr_set_to_dynar(const std::set<std::string, std::less<>>& filter) // XBT_ATTRIB_DEPRECATED_v333
338 {
339   if (not TRACE_is_enabled() || not TRACE_needs_platform())
340     return nullptr;
341
342   xbt_dynar_t ret = xbt_dynar_new (sizeof(char*), &xbt_free_ref);
343   for (auto const& name : filter)
344     xbt_dynar_push_as(ret, char*, xbt_strdup(name.c_str()));
345
346   return ret;
347 }
348
349 void TRACE_category(const char* category) // XBT_ATTRIB_DEPRECATED_v333
350 {
351   simgrid::instr::declare_tracing_category(category);
352 }
353
354 void TRACE_category_with_color(const char* category, const char* color) // XBT_ATTRIB_DEPRECATED_v333
355 {
356   simgrid::instr::declare_tracing_category(category, color);
357 }
358
359 xbt_dynar_t TRACE_get_categories() // XBT_ATTRIB_DEPRECATED_v333
360 {
361   if (not TRACE_is_enabled() || not TRACE_categorized())
362     return nullptr;
363   return instr_set_to_dynar(created_categories);
364 }
365
366 void TRACE_declare_mark(const char* mark_type) // XBT_ATTRIB_DEPRECATED_v333
367 {
368   simgrid::instr::declare_mark(mark_type);
369 }
370
371 void TRACE_declare_mark_value_with_color(const char* mark_type, const char* mark_value,
372                                          const char* mark_color) // XBT_ATTRIB_DEPRECATED_v333
373 {
374   simgrid::instr::declare_mark_value(mark_type, mark_value, mark_color);
375 }
376
377 void TRACE_declare_mark_value(const char* mark_type, const char* mark_value) // XBT_ATTRIB_DEPRECATED_v333
378 {
379   simgrid::instr::declare_mark_value(mark_type, mark_value);
380 }
381
382 void TRACE_mark(const char* mark_type, const char* mark_value) // XBT_ATTRIB_DEPRECATED_v333
383 {
384   simgrid::instr::mark(mark_type, mark_value);
385 }
386
387 xbt_dynar_t TRACE_get_marks() // XBT_ATTRIB_DEPRECATED_v333
388 {
389   if (not TRACE_is_enabled())
390     return nullptr;
391
392   return instr_set_to_dynar(declared_marks);
393 }
394
395 int TRACE_platform_graph_export_graphviz(const char* filename) // XBT_ATTRIB_DEPRECATED_v333
396 {
397   simgrid::instr::platform_graph_export_graphviz(filename);
398   return 1;
399 }
400
401 void TRACE_vm_variable_declare(const char* variable) // XBT_ATTRIB_DEPRECATED_v333
402 {
403   instr_user_variable(0, nullptr, variable, "VM", 0, InstrUserVariable::DECLARE, "", &user_vm_variables);
404 }
405 void TRACE_vm_variable_declare_with_color(const char* variable, const char* color) // XBT_ATTRIB_DEPRECATED_v333
406 {
407   instr_user_variable(0, nullptr, variable, "VM", 0, InstrUserVariable::DECLARE, color, &user_vm_variables);
408 }
409
410 void TRACE_vm_variable_set(const char* vm, const char* variable, double value) // XBT_ATTRIB_DEPRECATED_v333
411 {
412   instr_user_variable(simgrid_get_clock(), vm, variable, "VM", value, InstrUserVariable::SET, "", &user_vm_variables);
413 }
414
415 void TRACE_vm_variable_add(const char* vm, const char* variable, double value) // XBT_ATTRIB_DEPRECATED_v333
416 {
417   instr_user_variable(simgrid_get_clock(), vm, variable, "VM", value, InstrUserVariable::ADD, "", &user_vm_variables);
418 }
419 void TRACE_vm_variable_sub(const char* vm, const char* variable, double value) // XBT_ATTRIB_DEPRECATED_v333
420 {
421   instr_user_variable(simgrid_get_clock(), vm, variable, "VM", value, InstrUserVariable::SUB, "", &user_vm_variables);
422 }
423
424 void TRACE_vm_variable_set_with_time(double time, const char* vm, const char* variable,
425                                      double value) // XBT_ATTRIB_DEPRECATED_v333
426 {
427   instr_user_variable(time, vm, variable, "VM", value, InstrUserVariable::SET, "", &user_vm_variables);
428 }
429
430 void TRACE_vm_variable_add_with_time(double time, const char* vm, const char* variable,
431                                      double value) // XBT_ATTRIB_DEPRECATED_v333
432 {
433   instr_user_variable(time, vm, variable, "VM", value, InstrUserVariable::ADD, "", &user_vm_variables);
434 }
435 void TRACE_vm_variable_sub_with_time(double time, const char* vm, const char* variable,
436                                      double value) // XBT_ATTRIB_DEPRECATED_v333
437 {
438   instr_user_variable(time, vm, variable, "VM", value, InstrUserVariable::SUB, "", &user_vm_variables);
439 }
440
441 void TRACE_host_variable_declare(const char* variable) // XBT_ATTRIB_DEPRECATED_v333
442 {
443   simgrid::instr::declare_host_variable(variable);
444 }
445
446 void TRACE_host_variable_declare_with_color(const char* variable, const char* color) // XBT_ATTRIB_DEPRECATED_v333
447 {
448   simgrid::instr::declare_host_variable(variable, color);
449 }
450
451 void TRACE_host_variable_set(const char* host, const char* variable, double value) // XBT_ATTRIB_DEPRECATED_v333
452 {
453   instr_user_variable(simgrid_get_clock(), host, variable, "HOST", value, InstrUserVariable::SET, "",
454                       &user_host_variables);
455 }
456
457 void TRACE_host_variable_add(const char* host, const char* variable, double value) // XBT_ATTRIB_DEPRECATED_v333
458 {
459   instr_user_variable(simgrid_get_clock(), host, variable, "HOST", value, InstrUserVariable::ADD, "",
460                       &user_host_variables);
461 }
462
463 void TRACE_host_variable_sub(const char* host, const char* variable, double value) // XBT_ATTRIB_DEPRECATED_v333
464 {
465   instr_user_variable(simgrid_get_clock(), host, variable, "HOST", value, InstrUserVariable::SUB, "",
466                       &user_host_variables);
467 }
468
469 void TRACE_host_variable_set_with_time(double time, const char* host, const char* variable,
470                                        double value) // XBT_ATTRIB_DEPRECATED_v333
471 {
472   instr_user_variable(time, host, variable, "HOST", value, InstrUserVariable::SET, "", &user_host_variables);
473 }
474
475 void TRACE_host_variable_add_with_time(double time, const char* host, const char* variable,
476                                        double value) // XBT_ATTRIB_DEPRECATED_v333
477 {
478   instr_user_variable(time, host, variable, "HOST", value, InstrUserVariable::ADD, "", &user_host_variables);
479 }
480
481 void TRACE_host_variable_sub_with_time(double time, const char* host, const char* variable,
482                                        double value) // XBT_ATTRIB_DEPRECATED_v333
483 {
484   instr_user_variable(time, host, variable, "HOST", value, InstrUserVariable::SUB, "", &user_host_variables);
485 }
486
487 xbt_dynar_t TRACE_get_host_variables() // XBT_ATTRIB_DEPRECATED_v333
488 {
489   return instr_set_to_dynar(user_host_variables);
490 }
491
492 void TRACE_link_variable_declare(const char* variable) // XBT_ATTRIB_DEPRECATED_v333
493 {
494   simgrid::instr::declare_link_variable(variable);
495 }
496
497 void TRACE_link_variable_declare_with_color(const char* variable, const char* color) // XBT_ATTRIB_DEPRECATED_v333
498 {
499   simgrid::instr::declare_link_variable(variable, color);
500 }
501
502 void TRACE_link_variable_set(const char* link, const char* variable, double value) // XBT_ATTRIB_DEPRECATED_v333
503 {
504   instr_user_variable(simgrid_get_clock(), link, variable, "LINK", value, InstrUserVariable::SET, "",
505                       &user_link_variables);
506 }
507
508 void TRACE_link_variable_add(const char* link, const char* variable, double value) // XBT_ATTRIB_DEPRECATED_v333
509 {
510   instr_user_variable(simgrid_get_clock(), link, variable, "LINK", value, InstrUserVariable::ADD, "",
511                       &user_link_variables);
512 }
513
514 void TRACE_link_variable_sub(const char* link, const char* variable, double value) // XBT_ATTRIB_DEPRECATED_v333
515 {
516   instr_user_variable(simgrid_get_clock(), link, variable, "LINK", value, InstrUserVariable::SUB, "",
517                       &user_link_variables);
518 }
519
520 void TRACE_link_variable_set_with_time(double time, const char* link, const char* variable,
521                                        double value) // XBT_ATTRIB_DEPRECATED_v333
522 {
523   instr_user_variable(time, link, variable, "LINK", value, InstrUserVariable::SET, "", &user_link_variables);
524 }
525
526 void TRACE_link_variable_add_with_time(double time, const char* link, const char* variable,
527                                        double value) // XBT_ATTRIB_DEPRECATED_v333
528 {
529   instr_user_variable(time, link, variable, "LINK", value, InstrUserVariable::ADD, "", &user_link_variables);
530 }
531
532 void TRACE_link_variable_sub_with_time(double time, const char* link, const char* variable,
533                                        double value) // XBT_ATTRIB_DEPRECATED_v333
534 {
535   instr_user_variable(time, link, variable, "LINK", value, InstrUserVariable::SUB, "", &user_link_variables);
536 }
537
538 void TRACE_link_srcdst_variable_set(const char* src, const char* dst, const char* variable,
539                                     double value) // XBT_ATTRIB_DEPRECATED_v333
540 {
541   instr_user_srcdst_variable(simgrid_get_clock(), src, dst, variable, value, InstrUserVariable::SET);
542 }
543
544 void TRACE_link_srcdst_variable_add(const char* src, const char* dst, const char* variable,
545                                     double value) // XBT_ATTRIB_DEPRECATED_v333
546 {
547   instr_user_srcdst_variable(simgrid_get_clock(), src, dst, variable, value, InstrUserVariable::ADD);
548 }
549
550 void TRACE_link_srcdst_variable_sub(const char* src, const char* dst, const char* variable,
551                                     double value) // XBT_ATTRIB_DEPRECATED_v333
552 {
553   instr_user_srcdst_variable(simgrid_get_clock(), src, dst, variable, value, InstrUserVariable::SUB);
554 }
555
556 void TRACE_link_srcdst_variable_set_with_time(double time, const char* src, const char* dst, const char* variable,
557                                               double value) // XBT_ATTRIB_DEPRECATED_v333
558 {
559   instr_user_srcdst_variable(time, src, dst, variable, value, InstrUserVariable::SET);
560 }
561
562 void TRACE_link_srcdst_variable_add_with_time(double time, const char* src, const char* dst, const char* variable,
563                                               double value) // XBT_ATTRIB_DEPRECATED_v333
564 {
565   instr_user_srcdst_variable(time, src, dst, variable, value, InstrUserVariable::ADD);
566 }
567
568 void TRACE_link_srcdst_variable_sub_with_time(double time, const char* src, const char* dst, const char* variable,
569                                               double value) // XBT_ATTRIB_DEPRECATED_v333
570 {
571   instr_user_srcdst_variable(time, src, dst, variable, value, InstrUserVariable::SUB);
572 }
573
574 xbt_dynar_t TRACE_get_link_variables() // XBT_ATTRIB_DEPRECATED_v333
575 {
576   return instr_set_to_dynar(user_link_variables);
577 }
578
579 /** @ingroup TRACE_user_variables
580  *  @brief Declare a new user state associated to hosts.
581  *
582  *  Declare a user state that will be associated to hosts.
583  *  A user host state can be used to trace application states.
584  *
585  *  @param state The name of the new state to be declared.
586  *
587  *  @see TRACE_host_state_declare_value
588  */
589 void TRACE_host_state_declare (const char *state)
590 {
591   instr_new_user_state_type("HOST", state);
592 }
593
594 /** @ingroup TRACE_user_variables
595  *  @brief Declare a new value for a user state associated to hosts.
596  *
597  *  Declare a value for a state. The color needs to be a string with 3 numbers separated by spaces in the range [0,1].
598  *  A light-gray color can be specified using "0.7 0.7 0.7" as color.
599  *
600  *  @param state The name of the new state to be declared.
601  *  @param value The name of the value
602  *  @param color The color of the value
603  *
604  *  @see TRACE_host_state_declare
605  */
606 void TRACE_host_state_declare_value (const char *state, const char *value, const char *color)
607 {
608   instr_new_value_for_user_state_type (state, value, color);
609 }
610
611 /** @ingroup TRACE_user_variables
612  *  @brief Set the user state to the given value.
613  *
614  *  Change a user state previously declared to the given value.
615  *
616  *  @param host The name of the host to be considered.
617  *  @param state_name The name of the state previously declared.
618  *  @param value_name The new value of the state.
619  *
620  *  @see TRACE_host_state_declare, TRACE_host_push_state, TRACE_host_pop_state, TRACE_host_reset_state
621  */
622 void TRACE_host_set_state(const char* host, const char* state_name, const char* value_name)
623 {
624   simgrid::instr::StateType* state = simgrid::instr::Container::by_name(host)->get_state(state_name);
625   state->add_entity_value(value_name);
626   state->set_event(value_name);
627 }
628
629 /** @ingroup TRACE_user_variables
630  *  @brief Push a new value for a state of a given host.
631  *
632  *  Change a user state previously declared by pushing the new value to the state.
633  *
634  *  @param host The name of the host to be considered.
635  *  @param state_name The name of the state previously declared.
636  *  @param value_name The value to be pushed.
637  *
638  *  @see TRACE_host_state_declare, TRACE_host_set_state, TRACE_host_pop_state, TRACE_host_reset_state
639  */
640 void TRACE_host_push_state(const char* host, const char* state_name, const char* value_name)
641 {
642   simgrid::instr::Container::by_name(host)->get_state(state_name)->push_event(value_name);
643 }
644
645 /** @ingroup TRACE_user_variables
646  *  @brief Pop the last value of a state of a given host.
647  *
648  *  Change a user state previously declared by removing the last value of the state.
649  *
650  *  @param host The name of the host to be considered.
651  *  @param state_name The name of the state to be popped.
652  *
653  *  @see TRACE_host_state_declare, TRACE_host_set_state, TRACE_host_push_state, TRACE_host_reset_state
654  */
655 void TRACE_host_pop_state(const char* host, const char* state_name)
656 {
657   simgrid::instr::Container::by_name(host)->get_state(state_name)->pop_event();
658 }