1 /* Copyright (c) 2010. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include "simgrid_config.h"
10 #include "instr/instr_private.h"
11 #include "surf/network_private.h"
20 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_api, instr, "API");
22 xbt_dict_t created_categories = NULL;
23 xbt_dict_t declared_marks = NULL;
24 xbt_dict_t user_host_variables = NULL;
25 xbt_dict_t user_link_variables = NULL;
26 extern xbt_dict_t trivaNodeTypes;
27 extern xbt_dict_t trivaEdgeTypes;
29 static xbt_dynar_t instr_dict_to_dynar (xbt_dict_t filter)
31 if (!TRACE_is_enabled()) return NULL;
32 if (!TRACE_needs_platform()) return NULL;
34 xbt_dynar_t ret = xbt_dynar_new (sizeof(char*), &xbt_free_ref);
35 xbt_dict_cursor_t cursor = NULL;
37 xbt_dict_foreach(filter, cursor, name, value) {
38 xbt_dynar_push_as (ret, char*, xbt_strdup(name));
43 /** \ingroup TRACE_category
44 * \brief Declare a new category with a random color.
46 * This function should be used to define a user category. The
47 * category can be used to differentiate the tasks that are created
48 * during the simulation (for example, tasks from server1, server2,
49 * or request tasks, computation tasks, communication tasks). All
50 * resource utilization (host power and link bandwidth) will be
51 * classified according to the task category. Tasks that do not
52 * belong to a category are not traced. The color for the category
53 * that is being declared is random. This function has no effect
54 * if a category with the same name has been already declared.
56 * See \ref tracing_tracing for details on how to trace
57 * the (categorized) resource utilization.
59 * \param category The name of the new tracing category to be created.
61 * \see TRACE_category_with_color, MSG_task_set_category, SD_task_set_category
63 void TRACE_category(const char *category)
65 TRACE_category_with_color (category, NULL);
68 /** \ingroup TRACE_category
69 * \brief Declare a new category with a color.
71 * Same as #TRACE_category, but let user specify a color encoded as a
72 * RGB-like string with three floats from 0 to 1. So, to specify a
73 * red color, pass "1 0 0" as color parameter. A light-gray color
74 * can be specified using "0.7 0.7 0.7" as color. This function has
75 * no effect if a category with the same name has been already declared.
77 * See \ref tracing_tracing for details on how to trace
78 * the (categorized) resource utilization.
80 * \param category The name of the new tracing category to be created.
81 * \param color The color of the category (see \ref tracing_tracing to
82 * know how to correctly specify the color)
84 * \see MSG_task_set_category, SD_task_set_category
86 void TRACE_category_with_color (const char *category, const char *color)
89 if (!TRACE_is_enabled()) return;
91 if (!(TRACE_categorized() && category != NULL)) return;
93 /* if platform is not traced, we can't deal with categories */
94 if (!TRACE_needs_platform()) return;
96 //check if category is already created
97 char *created = xbt_dict_get_or_null(created_categories, category);
99 xbt_dict_set (created_categories, category, xbt_strdup("1"), NULL);
102 char final_color[INSTR_DEFAULT_STR_SIZE];
104 //generate a random color
105 double red = drand48();
106 double green = drand48();
107 double blue = drand48();
108 snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%f %f %f", red, green, blue);
110 snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%s", color);
113 XBT_DEBUG("CAT,declare %s, %s", category, final_color);
115 //define the type of this category on top of hosts and links
116 instr_new_variable_type (category, final_color);
120 /** \ingroup TRACE_category
121 * \brief Get declared categories
123 * This function should be used to get categories that were already
124 * declared with #TRACE_category or with #TRACE_category_with_color.
126 * See \ref tracing_tracing for details on how to trace
127 * the (categorized) resource utilization.
129 * \return A dynar with the declared categories, must be freed with xbt_dynar_free.
131 * \see MSG_task_set_category, SD_task_set_category
133 xbt_dynar_t TRACE_get_categories (void)
135 if (!TRACE_is_enabled()) return NULL;
136 if (!TRACE_categorized()) return NULL;
138 return instr_dict_to_dynar (created_categories);
141 /** \ingroup TRACE_mark
142 * \brief Declare a new type for tracing mark.
144 * This function declares a new Paje event
145 * type in the trace file that can be used by
146 * simulators to declare application-level
147 * marks. This function is independent of
148 * which API is used in SimGrid.
150 * \param mark_type The name of the new type.
154 void TRACE_declare_mark(const char *mark_type)
157 if (!TRACE_is_enabled()) return;
159 if (!mark_type) return;
161 //check if mark_type is already declared
162 char *created = xbt_dict_get_or_null(declared_marks, mark_type);
164 xbt_dict_set (declared_marks, mark_type, xbt_strdup("1"), NULL);
166 XBT_DEBUG("MARK,declare %s", mark_type);
167 PJ_type_event_new(mark_type, NULL, PJ_type_get_root());
171 * \ingroup TRACE_mark
172 * \brief Create a new instance of a tracing mark type.
174 * This function creates a mark in the trace file. The
175 * first parameter had to be previously declared using
176 * #TRACE_declare_mark, the second is the identifier
177 * for this mark instance. We recommend that the
178 * mark_value is a unique value for the whole simulation.
179 * Nevertheless, this is not a strong requirement: the
180 * trace will be valid even if there are multiple mark
181 * identifiers for the same trace.
183 * \param mark_type The name of the type for which the new instance will belong.
184 * \param mark_value The name of the new instance mark.
186 * \see TRACE_declare_mark
188 void TRACE_mark(const char *mark_type, const char *mark_value)
191 if (!TRACE_is_enabled()) return;
193 if (!mark_type || !mark_value) return;
195 //check if mark_type is already declared
196 char *created = xbt_dict_get_or_null(declared_marks, mark_type);
199 XBT_DEBUG("MARK %s %s", mark_type, mark_value);
200 type_t type = PJ_type_get (mark_type, PJ_type_get_root());
202 THROWF (tracing_error, 1, "mark_type with name (%s) not declared before", mark_type);
204 val_t value = PJ_value_get (mark_value, type);
206 value = PJ_value_new (mark_value, NULL, type);
208 new_pajeNewEvent (MSG_get_clock(), PJ_container_get_root(), type, value);
211 /** \ingroup TRACE_mark
212 * \brief Get declared marks
214 * This function should be used to get marks that were already
215 * declared with #TRACE_declare_mark.
217 * \return A dynar with the declared marks, must be freed with xbt_dynar_free.
220 xbt_dynar_t TRACE_get_marks (void)
222 if (!TRACE_is_enabled()) return NULL;
224 return instr_dict_to_dynar (declared_marks);
227 static void instr_user_variable(double time,
228 const char *resource,
229 const char *variable,
230 const char *father_type,
232 InstrUserVariable what,
237 if (!TRACE_is_enabled()) return;
239 /* if platform is not traced, we don't allow user variables */
240 if (!TRACE_needs_platform()) return;
242 //check if variable is already declared
243 char *created = xbt_dict_get_or_null(filter, variable);
244 if (what == INSTR_US_DECLARE){
249 xbt_dict_set (filter, variable, xbt_strdup("1"), NULL);
253 //not declared, ignore
259 snprintf(valuestr, 100, "%g", value);
262 case INSTR_US_DECLARE:
263 instr_new_user_variable_type (father_type, variable, color);
267 container_t container = PJ_container_get(resource);
268 type_t type = PJ_type_get (variable, container->type);
269 new_pajeSetVariable(time, container, type, value);
274 container_t container = PJ_container_get(resource);
275 type_t type = PJ_type_get (variable, container->type);
276 new_pajeAddVariable(time, container, type, value);
281 container_t container = PJ_container_get(resource);
282 type_t type = PJ_type_get (variable, container->type);
283 new_pajeSubVariable(time, container, type, value);
287 //TODO: launch exception
292 static void instr_user_srcdst_variable(double time,
295 const char *variable,
296 const char *father_type,
298 InstrUserVariable what)
300 xbt_dynar_t route=NULL;
301 sg_routing_edge_t src_elm = sg_routing_edge_by_name_or_null(src);
302 if(!src_elm) xbt_die("Element '%s' not found!",src);
304 sg_routing_edge_t dst_elm = sg_routing_edge_by_name_or_null(dst);
305 if(!dst_elm) xbt_die("Element '%s' not found!",dst);
307 routing_get_route_and_latency (src_elm, dst_elm, &route,NULL);
310 xbt_dynar_foreach (route, i, link) {
311 char *link_name = ((link_CM02_t)link)->lmm_resource.generic_resource.name;
312 instr_user_variable (time, link_name, variable, father_type, value, what, NULL, user_link_variables);
316 /** \ingroup TRACE_API
317 * \brief Creates a file with the topology of the platform file used for the simulator.
319 * The graph topology will have the following properties: all hosts, links and routers
320 * of the platform file are mapped to graph nodes; routes are mapped to edges.
321 * The platform's AS are not represented in the output.
323 * \param filename The name of the file that will hold the graph.
325 * \return 1 of successful, 0 otherwise.
327 int TRACE_platform_graph_export_graphviz (const char *filename)
329 /* returns 1 if successful, 0 otherwise */
330 if (!TRACE_is_enabled()) return 0;
331 xbt_graph_t g = instr_routing_platform_graph();
332 if (g == NULL) return 0;
333 instr_routing_platform_graph_export_graphviz (g, filename);
334 xbt_graph_free_graph (g, xbt_free, xbt_free, NULL);
339 * Derived functions that use instr_user_variable and TRACE_user_srcdst_variable.
340 * They were previously defined as pre-processors directives, but were transformed
341 * into functions so the user can track them using gdb.
344 /* for host variables */
345 /** \ingroup TRACE_user_variables
346 * \brief Declare a new user variable associated to hosts.
348 * Declare a user variable that will be associated to hosts.
349 * A user host variable can be used to trace user variables
350 * such as the number of tasks in a server, the number of
351 * clients in an application (for hosts), and so on. The color
352 * associated to this new variable will be random.
354 * \param variable The name of the new variable to be declared.
356 * \see TRACE_host_variable_declare_with_color
358 void TRACE_host_variable_declare (const char *variable)
360 instr_user_variable(0, NULL, variable, "HOST", 0, INSTR_US_DECLARE, NULL, user_host_variables);
363 /** \ingroup TRACE_user_variables
364 * \brief Declare a new user variable associated to hosts with a color.
366 * Same as #TRACE_host_variable_declare, but associated a color
367 * to the newly created user host variable. The color needs to be
368 * a string with three numbers separated by spaces in the range [0,1].
369 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
371 * \param variable The name of the new variable to be declared.
372 * \param color The color for the new variable.
375 void TRACE_host_variable_declare_with_color (const char *variable, const char *color)
377 instr_user_variable(0, NULL, variable, "HOST", 0, INSTR_US_DECLARE, color, user_host_variables);
380 /** \ingroup TRACE_user_variables
381 * \brief Set the value of a variable of a host.
383 * \param host The name of the host to be considered.
384 * \param variable The name of the variable to be considered.
385 * \param value The new value of the variable.
387 * \see TRACE_host_variable_declare, TRACE_host_variable_add, TRACE_host_variable_sub
389 void TRACE_host_variable_set (const char *host, const char *variable, double value)
391 TRACE_host_variable_set_with_time (MSG_get_clock(), host, variable, value);
394 /** \ingroup TRACE_user_variables
395 * \brief Add a value to a variable of a host.
397 * \param host The name of the host to be considered.
398 * \param variable The name of the variable to be considered.
399 * \param value The value to be added to the variable.
401 * \see TRACE_host_variable_declare, TRACE_host_variable_set, TRACE_host_variable_sub
403 void TRACE_host_variable_add (const char *host, const char *variable, double value)
405 TRACE_host_variable_add_with_time (MSG_get_clock(), host, variable, value);
408 /** \ingroup TRACE_user_variables
409 * \brief Subtract a value from a variable of a host.
411 * \param host The name of the host to be considered.
412 * \param variable The name of the variable to be considered.
413 * \param value The value to be subtracted from the variable.
415 * \see TRACE_host_variable_declare, TRACE_host_variable_set, TRACE_host_variable_add
417 void TRACE_host_variable_sub (const char *host, const char *variable, double value)
419 TRACE_host_variable_sub_with_time (MSG_get_clock(), host, variable, value);
422 /** \ingroup TRACE_user_variables
423 * \brief Set the value of a variable of a host at a given timestamp.
425 * Same as #TRACE_host_variable_set, but let user specify
426 * the time used to trace it. Users can specify a time that
427 * is not the simulated clock time as defined by the core
428 * simulator. This allows a fine-grain control of time
429 * definition, but should be used with caution since the trace
430 * can be inconsistent if resource utilization traces are also traced.
432 * \param time The timestamp to be used to tag this change of value.
433 * \param host The name of the host to be considered.
434 * \param variable The name of the variable to be considered.
435 * \param value The new value of the variable.
437 * \see TRACE_host_variable_declare, TRACE_host_variable_add_with_time, TRACE_host_variable_sub_with_time
439 void TRACE_host_variable_set_with_time (double time, const char *host, const char *variable, double value)
441 instr_user_variable(time, host, variable, "HOST", value, INSTR_US_SET, NULL, user_host_variables);
444 /** \ingroup TRACE_user_variables
445 * \brief Add a value to a variable of a host at a given timestamp.
447 * Same as #TRACE_host_variable_add, but let user specify
448 * the time used to trace it. Users can specify a time that
449 * is not the simulated clock time as defined by the core
450 * simulator. This allows a fine-grain control of time
451 * definition, but should be used with caution since the trace
452 * can be inconsistent if resource utilization traces are also traced.
454 * \param time The timestamp to be used to tag this change of value.
455 * \param host The name of the host to be considered.
456 * \param variable The name of the variable to be considered.
457 * \param value The value to be added to the variable.
459 * \see TRACE_host_variable_declare, TRACE_host_variable_set_with_time, TRACE_host_variable_sub_with_time
461 void TRACE_host_variable_add_with_time (double time, const char *host, const char *variable, double value)
463 instr_user_variable(time, host, variable, "HOST", value, INSTR_US_ADD, NULL, user_host_variables);
466 /** \ingroup TRACE_user_variables
467 * \brief Subtract a value from a variable of a host at a given timestamp.
469 * Same as #TRACE_host_variable_sub, but let user specify
470 * the time used to trace it. Users can specify a time that
471 * is not the simulated clock time as defined by the core
472 * simulator. This allows a fine-grain control of time
473 * definition, but should be used with caution since the trace
474 * can be inconsistent if resource utilization traces are also traced.
476 * \param time The timestamp to be used to tag this change of value.
477 * \param host The name of the host to be considered.
478 * \param variable The name of the variable to be considered.
479 * \param value The value to be subtracted from the variable.
481 * \see TRACE_host_variable_declare, TRACE_host_variable_set_with_time, TRACE_host_variable_add_with_time
483 void TRACE_host_variable_sub_with_time (double time, const char *host, const char *variable, double value)
485 instr_user_variable(time, host, variable, "HOST", value, INSTR_US_SUB, NULL, user_host_variables);
488 /** \ingroup TRACE_user_variables
489 * \brief Get declared user host variables
491 * This function should be used to get host variables that were already
492 * declared with #TRACE_host_variable_declare or with #TRACE_host_variable_declare_with_color.
494 * \return A dynar with the declared host variables, must be freed with xbt_dynar_free.
496 xbt_dynar_t TRACE_get_host_variables (void)
498 return instr_dict_to_dynar (user_host_variables);
501 /* for link variables */
502 /** \ingroup TRACE_user_variables
503 * \brief Declare a new user variable associated to links.
505 * Declare a user variable that will be associated to links.
506 * A user link variable can be used, for example, to trace
507 * user variables such as the number of messages being
508 * transferred through network links. The color
509 * associated to this new variable will be random.
511 * \param variable The name of the new variable to be declared.
513 * \see TRACE_link_variable_declare_with_color
515 void TRACE_link_variable_declare (const char *variable)
517 instr_user_variable (0, NULL, variable, "LINK", 0, INSTR_US_DECLARE, NULL, user_link_variables);
520 /** \ingroup TRACE_user_variables
521 * \brief Declare a new user variable associated to links with a color.
523 * Same as #TRACE_link_variable_declare, but associated a color
524 * to the newly created user link variable. The color needs to be
525 * a string with three numbers separated by spaces in the range [0,1].
526 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
528 * \param variable The name of the new variable to be declared.
529 * \param color The color for the new variable.
532 void TRACE_link_variable_declare_with_color (const char *variable, const char *color)
534 instr_user_variable (0, NULL, variable, "LINK", 0, INSTR_US_DECLARE, color, user_link_variables);
537 /** \ingroup TRACE_user_variables
538 * \brief Set the value of a variable of a link.
540 * \param link The name of the link to be considered.
541 * \param variable The name of the variable to be considered.
542 * \param value The new value of the variable.
544 * \see TRACE_link_variable_declare, TRACE_link_variable_add, TRACE_link_variable_sub
546 void TRACE_link_variable_set (const char *link, const char *variable, double value)
548 TRACE_link_variable_set_with_time (MSG_get_clock(), link, variable, value);
551 /** \ingroup TRACE_user_variables
552 * \brief Add a value to a variable of a link.
554 * \param link The name of the link to be considered.
555 * \param variable The name of the variable to be considered.
556 * \param value The value to be added to the variable.
558 * \see TRACE_link_variable_declare, TRACE_link_variable_set, TRACE_link_variable_sub
560 void TRACE_link_variable_add (const char *link, const char *variable, double value)
562 TRACE_link_variable_add_with_time (MSG_get_clock(), link, variable, value);
565 /** \ingroup TRACE_user_variables
566 * \brief Subtract a value from a variable of a link.
568 * \param link The name of the link to be considered.
569 * \param variable The name of the variable to be considered.
570 * \param value The value to be subtracted from the variable.
572 * \see TRACE_link_variable_declare, TRACE_link_variable_set, TRACE_link_variable_add
574 void TRACE_link_variable_sub (const char *link, const char *variable, double value)
576 TRACE_link_variable_sub_with_time (MSG_get_clock(), link, variable, value);
579 /** \ingroup TRACE_user_variables
580 * \brief Set the value of a variable of a link at a given timestamp.
582 * Same as #TRACE_link_variable_set, but let user specify
583 * the time used to trace it. Users can specify a time that
584 * is not the simulated clock time as defined by the core
585 * simulator. This allows a fine-grain control of time
586 * definition, but should be used with caution since the trace
587 * can be inconsistent if resource utilization traces are also traced.
589 * \param time The timestamp to be used to tag this change of value.
590 * \param link The name of the link to be considered.
591 * \param variable The name of the variable to be considered.
592 * \param value The new value of the variable.
594 * \see TRACE_link_variable_declare, TRACE_link_variable_add_with_time, TRACE_link_variable_sub_with_time
596 void TRACE_link_variable_set_with_time (double time, const char *link, const char *variable, double value)
598 instr_user_variable (time, link, variable, "LINK", value, INSTR_US_SET, NULL, user_link_variables);
601 /** \ingroup TRACE_user_variables
602 * \brief Add a value to a variable of a link at a given timestamp.
604 * Same as #TRACE_link_variable_add, but let user specify
605 * the time used to trace it. Users can specify a time that
606 * is not the simulated clock time as defined by the core
607 * simulator. This allows a fine-grain control of time
608 * definition, but should be used with caution since the trace
609 * can be inconsistent if resource utilization traces are also traced.
611 * \param time The timestamp to be used to tag this change of value.
612 * \param link The name of the link to be considered.
613 * \param variable The name of the variable to be considered.
614 * \param value The value to be added to the variable.
616 * \see TRACE_link_variable_declare, TRACE_link_variable_set_with_time, TRACE_link_variable_sub_with_time
618 void TRACE_link_variable_add_with_time (double time, const char *link, const char *variable, double value)
620 instr_user_variable (time, link, variable, "LINK", value, INSTR_US_ADD, NULL, user_link_variables);
623 /** \ingroup TRACE_user_variables
624 * \brief Subtract a value from a variable of a link at a given timestamp.
626 * Same as #TRACE_link_variable_sub, but let user specify
627 * the time used to trace it. Users can specify a time that
628 * is not the simulated clock time as defined by the core
629 * simulator. This allows a fine-grain control of time
630 * definition, but should be used with caution since the trace
631 * can be inconsistent if resource utilization traces are also traced.
633 * \param time The timestamp to be used to tag this change of value.
634 * \param link The name of the link to be considered.
635 * \param variable The name of the variable to be considered.
636 * \param value The value to be subtracted from the variable.
638 * \see TRACE_link_variable_declare, TRACE_link_variable_set_with_time, TRACE_link_variable_add_with_time
640 void TRACE_link_variable_sub_with_time (double time, const char *link, const char *variable, double value)
642 instr_user_variable (time, link, variable, "LINK", value, INSTR_US_SUB, NULL, user_link_variables);
645 /* for link variables, but with src and dst used for get_route */
646 /** \ingroup TRACE_user_variables
647 * \brief Set the value of the variable present in the links connecting source and destination.
649 * Same as #TRACE_link_variable_set, but instead of providing the
650 * name of link to be considered, provide the source and destination
651 * hosts. All links that are part of the route between source and
652 * destination will have the variable set to the provided value.
654 * \param src The name of the source host for get route.
655 * \param dst The name of the destination host for get route.
656 * \param variable The name of the variable to be considered.
657 * \param value The new value of the variable.
659 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_add, TRACE_link_srcdst_variable_sub
661 void TRACE_link_srcdst_variable_set (const char *src, const char *dst, const char *variable, double value)
663 TRACE_link_srcdst_variable_set_with_time (MSG_get_clock(), src, dst, variable, value);
666 /** \ingroup TRACE_user_variables
667 * \brief Add a value to the variable present in the links connecting source and destination.
669 * Same as #TRACE_link_variable_add, but instead of providing the
670 * name of link to be considered, provide the source and destination
671 * hosts. All links that are part of the route between source and
672 * destination will have the value passed as parameter added to
673 * the current value of the variable name to be considered.
675 * \param src The name of the source host for get route.
676 * \param dst The name of the destination host for get route.
677 * \param variable The name of the variable to be considered.
678 * \param value The value to be added to the variable.
680 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set, TRACE_link_srcdst_variable_sub
682 void TRACE_link_srcdst_variable_add (const char *src, const char *dst, const char *variable, double value)
684 TRACE_link_srcdst_variable_add_with_time (MSG_get_clock(), src, dst, variable, value);
687 /** \ingroup TRACE_user_variables
688 * \brief Subtract a value from the variable present in the links connecting source and destination.
690 * Same as #TRACE_link_variable_sub, but instead of providing the
691 * name of link to be considered, provide the source and destination
692 * hosts. All links that are part of the route between source and
693 * destination will have the value passed as parameter subtracted from
694 * the current value of the variable name to be considered.
696 * \param src The name of the source host for get route.
697 * \param dst The name of the destination host for get route.
698 * \param variable The name of the variable to be considered.
699 * \param value The value to be subtracted from the variable.
701 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set, TRACE_link_srcdst_variable_add
703 void TRACE_link_srcdst_variable_sub (const char *src, const char *dst, const char *variable, double value)
705 TRACE_link_srcdst_variable_sub_with_time (MSG_get_clock(), src, dst, variable, value);
708 /** \ingroup TRACE_user_variables
709 * \brief Set the value of the variable present in the links connecting source and destination at a given timestamp.
711 * Same as #TRACE_link_srcdst_variable_set, but let user specify
712 * the time used to trace it. Users can specify a time that
713 * is not the simulated clock time as defined by the core
714 * simulator. This allows a fine-grain control of time
715 * definition, but should be used with caution since the trace
716 * can be inconsistent if resource utilization traces are also traced.
718 * \param time The timestamp to be used to tag this change of value.
719 * \param src The name of the source host for get route.
720 * \param dst The name of the destination host for get route.
721 * \param variable The name of the variable to be considered.
722 * \param value The new value of the variable.
724 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_add_with_time, TRACE_link_srcdst_variable_sub_with_time
726 void TRACE_link_srcdst_variable_set_with_time (double time, const char *src, const char *dst, const char *variable, double value)
728 instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_SET);
731 /** \ingroup TRACE_user_variables
732 * \brief Add a value to the variable present in the links connecting source and destination at a given timestamp.
734 * Same as #TRACE_link_srcdst_variable_add, but let user specify
735 * the time used to trace it. Users can specify a time that
736 * is not the simulated clock time as defined by the core
737 * simulator. This allows a fine-grain control of time
738 * definition, but should be used with caution since the trace
739 * can be inconsistent if resource utilization traces are also traced.
741 * \param time The timestamp to be used to tag this change of value.
742 * \param src The name of the source host for get route.
743 * \param dst The name of the destination host for get route.
744 * \param variable The name of the variable to be considered.
745 * \param value The value to be added to the variable.
747 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set_with_time, TRACE_link_srcdst_variable_sub_with_time
749 void TRACE_link_srcdst_variable_add_with_time (double time, const char *src, const char *dst, const char *variable, double value)
751 instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_ADD);
754 /** \ingroup TRACE_user_variables
755 * \brief Subtract a value from the variable present in the links connecting source and destination at a given timestamp.
757 * Same as #TRACE_link_srcdst_variable_sub, but let user specify
758 * the time used to trace it. Users can specify a time that
759 * is not the simulated clock time as defined by the core
760 * simulator. This allows a fine-grain control of time
761 * definition, but should be used with caution since the trace
762 * can be inconsistent if resource utilization traces are also traced.
764 * \param time The timestamp to be used to tag this change of value.
765 * \param src The name of the source host for get route.
766 * \param dst The name of the destination host for get route.
767 * \param variable The name of the variable to be considered.
768 * \param value The value to be subtracted from the variable.
770 * \see TRACE_link_variable_declare, TRACE_link_srcdst_variable_set_with_time, TRACE_link_srcdst_variable_add_with_time
772 void TRACE_link_srcdst_variable_sub_with_time (double time, const char *src, const char *dst, const char *variable, double value)
774 instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_SUB);
777 /** \ingroup TRACE_user_variables
778 * \brief Get declared user link variables
780 * This function should be used to get link variables that were already
781 * declared with #TRACE_link_variable_declare or with #TRACE_link_variable_declare_with_color.
783 * \return A dynar with the declared link variables, must be freed with xbt_dynar_free.
785 xbt_dynar_t TRACE_get_link_variables (void)
787 return instr_dict_to_dynar (user_link_variables);
790 /** \ingroup TRACE_user_variables
791 * \brief Declare a new user state associated to hosts.
793 * Declare a user state that will be associated to hosts.
794 * A user host state can be used to trace application states.
796 * \param state The name of the new state to be declared.
798 * \see TRACE_host_state_declare_value
800 void TRACE_host_state_declare (const char *state)
802 instr_new_user_state_type("HOST", state);
805 /** \ingroup TRACE_user_variables
806 * \brief Declare a new value for a user state associated to hosts.
808 * Declare a value for a state. The color needs to be
809 * a string with three numbers separated by spaces in the range [0,1].
810 * A light-gray color can be specified using "0.7 0.7 0.7" as color.
812 * \param state The name of the new state to be declared.
813 * \param value The name of the value
814 * \param color The color of the value
816 * \see TRACE_host_state_declare
818 void TRACE_host_state_declare_value (const char *state, const char *value, const char *color)
820 instr_new_value_for_user_state_type (state, value, color);
823 /** \ingroup TRACE_user_variables
824 * \brief Set the user state to the given value.
826 * Change a user state previously declared to the given value.
828 * \param host The name of the host to be considered.
829 * \param state The name of the state previously declared.
830 * \param value The new value of the state.
832 * \see TRACE_host_state_declare, TRACE_host_push_state, TRACE_host_pop_state
834 void TRACE_host_set_state (const char *host, const char *state, const char *value)
836 container_t container = PJ_container_get(host);
837 type_t type = PJ_type_get (state, container->type);
838 val_t val = PJ_value_get (value, type);
840 //if user didn't declare a value with a color, user a NULL color
841 PJ_value_new (value, NULL, type);
843 new_pajeSetState(MSG_get_clock(), container, type, val);
846 /** \ingroup TRACE_user_variables
847 * \brief Push a new value for a state of a given host.
849 * Change a user state previously declared by pushing the new value to the state.
851 * \param host The name of the host to be considered.
852 * \param state The name of the state previously declared.
853 * \param value The value to be pushed.
855 * \see TRACE_host_state_declare, TRACE_host_set_state, TRACE_host_pop_state
857 void TRACE_host_push_state (const char *host, const char *state, const char *value)
859 container_t container = PJ_container_get(host);
860 type_t type = PJ_type_get (state, container->type);
861 val_t val = PJ_value_get (value, type);
863 //if user didn't declare a value with a color, user a NULL color
864 PJ_value_new (value, NULL, type);
866 new_pajePushState(MSG_get_clock(), container, type, val);
869 /** \ingroup TRACE_user_variables
870 * \brief Pop the last value of a state of a given host.
872 * Change a user state previously declared by removing the last value of the state.
874 * \param host The name of the host to be considered.
875 * \param state The name of the state to be popped.
877 * \see TRACE_host_state_declare, TRACE_host_set_state, TRACE_host_push_state
879 void TRACE_host_pop_state (const char *host, const char *state)
881 container_t container = PJ_container_get(host);
882 type_t type = PJ_type_get (state, container->type);
883 new_pajePopState(MSG_get_clock(), container, type);
886 /** \ingroup TRACE_API
887 * \brief Get Paje container types that can be mapped to the nodes of a graph.
889 * This function can be used to create a user made
890 * graph configuration file for Triva. Normally, it is
891 * used with the functions defined in \ref TRACE_user_variables.
893 * \return A dynar with the types, must be freed with xbt_dynar_free.
895 xbt_dynar_t TRACE_get_node_types (void)
897 return instr_dict_to_dynar (trivaNodeTypes);
900 /** \ingroup TRACE_API
901 * \brief Get Paje container types that can be mapped to the edges of a graph.
903 * This function can be used to create a user made
904 * graph configuration file for Triva. Normally, it is
905 * used with the functions defined in \ref TRACE_user_variables.
907 * \return A dynar with the types, must be freed with xbt_dynar_free.
909 xbt_dynar_t TRACE_get_edge_types (void)
911 return instr_dict_to_dynar (trivaEdgeTypes);
914 #endif /* HAVE_TRACING */