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"
11 #include "instr/instr_private.h"
12 #include "surf/network_private.h"
21 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_api, instr, "API");
23 void TRACE_category(const char *category)
25 TRACE_category_with_color (category, NULL);
28 void TRACE_category_with_color (const char *category, const char *color)
31 if (!TRACE_is_enabled()) return;
33 if (!(TRACE_categorized() && category != NULL)) return;
35 /* if platform is not traced, we can't deal with categories */
36 if (!TRACE_needs_platform()) return;
38 //check if category is already created
39 char *created = xbt_dict_get_or_null(created_categories, category);
41 xbt_dict_set (created_categories, category, xbt_strdup("1"), NULL);
44 char final_color[INSTR_DEFAULT_STR_SIZE];
46 //generate a random color
47 double red = drand48();
48 double green = drand48();
49 double blue = drand48();
50 snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%f %f %f", red, green, blue);
52 snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%s", color);
55 XBT_DEBUG("CAT,declare %s, %s", category, final_color);
57 //define the type of this category on top of hosts and links
58 instr_new_variable_type (category, final_color);
61 void TRACE_declare_mark(const char *mark_type)
64 if (!TRACE_is_enabled()) return;
66 if (!mark_type) return;
68 XBT_DEBUG("MARK,declare %s", mark_type);
69 PJ_type_event_new(mark_type, NULL, PJ_type_get_root());
72 void TRACE_mark(const char *mark_type, const char *mark_value)
75 if (!TRACE_is_enabled()) return;
77 if (!mark_type || !mark_value) return;
79 XBT_DEBUG("MARK %s %s", mark_type, mark_value);
80 type_t type = PJ_type_get (mark_type, PJ_type_get_root());
82 THROWF (tracing_error, 1, "mark_type with name (%s) not declared before", mark_type);
84 val_t value = PJ_value_get (mark_value, type);
86 value = PJ_value_new (mark_value, NULL, type);
88 new_pajeNewEvent (MSG_get_clock(), PJ_container_get_root(), type, value);
91 static void instr_user_variable(double time,
94 const char *father_type,
96 InstrUserVariable what,
100 if (!TRACE_is_enabled()) return;
102 /* if platform is not traced, we can't deal user variables */
103 if (!TRACE_needs_platform()) return;
106 snprintf(valuestr, 100, "%g", value);
109 case INSTR_US_DECLARE:
110 instr_new_user_variable_type (father_type, variable, color);
114 container_t container = PJ_container_get(resource);
115 type_t type = PJ_type_get (variable, container->type);
116 new_pajeSetVariable(time, container, type, value);
121 container_t container = PJ_container_get(resource);
122 type_t type = PJ_type_get (variable, container->type);
123 new_pajeAddVariable(time, container, type, value);
128 container_t container = PJ_container_get(resource);
129 type_t type = PJ_type_get (variable, container->type);
130 new_pajeSubVariable(time, container, type, value);
134 //TODO: launch exception
139 static void instr_user_srcdst_variable(double time,
142 const char *variable,
143 const char *father_type,
145 InstrUserVariable what)
147 xbt_dynar_t route=NULL;
148 routing_get_route_and_latency (src, dst, &route,NULL);
151 xbt_dynar_foreach (route, i, link) {
152 char *link_name = ((link_CM02_t)link)->lmm_resource.generic_resource.name;
153 instr_user_variable (time, link_name, variable, father_type, value, what, NULL);
157 const char *TRACE_node_name (xbt_node_t node)
159 void *data = xbt_graph_node_get_data(node);
160 char *str = (char*)data;
164 xbt_graph_t TRACE_platform_graph (void)
166 if (!TRACE_is_enabled()) return NULL;
167 return instr_routing_platform_graph ();
170 void TRACE_platform_graph_export_graphviz (xbt_graph_t g, const char *filename)
172 instr_routing_platform_graph_export_graphviz (g, filename);
177 * Derived functions that use instr_user_variable and TRACE_user_srcdst_variable.
178 * They were previously defined as pre-processors directives, but were transformed
179 * into functions so the user can track them using gdb.
182 /* for host variables */
183 void TRACE_host_variable_declare (const char *var)
185 instr_user_variable(0, NULL, var, "HOST", 0, INSTR_US_DECLARE, NULL);
188 void TRACE_host_variable_declare_with_color (const char *var, const char *color)
190 instr_user_variable(0, NULL, var, "HOST", 0, INSTR_US_DECLARE, color);
193 void TRACE_host_variable_set (const char *host, const char *variable, double value)
195 TRACE_host_variable_set_with_time (MSG_get_clock(), host, variable, value);
198 void TRACE_host_variable_add (const char *host, const char *variable, double value)
200 TRACE_host_variable_add_with_time (MSG_get_clock(), host, variable, value);
203 void TRACE_host_variable_sub (const char *host, const char *variable, double value)
205 TRACE_host_variable_sub_with_time (MSG_get_clock(), host, variable, value);
208 void TRACE_host_variable_set_with_time (double time, const char *host, const char *variable, double value)
210 instr_user_variable(time, host, variable, "HOST", value, INSTR_US_SET, NULL);
213 void TRACE_host_variable_add_with_time (double time, const char *host, const char *variable, double value)
215 instr_user_variable(time, host, variable, "HOST", value, INSTR_US_ADD, NULL);
218 void TRACE_host_variable_sub_with_time (double time, const char *host, const char *variable, double value)
220 instr_user_variable(time, host, variable, "HOST", value, INSTR_US_SUB, NULL);
223 /* for link variables */
224 void TRACE_link_variable_declare (const char *var)
226 instr_user_variable (0, NULL, var, "LINK", 0, INSTR_US_DECLARE, NULL);
229 void TRACE_link_variable_declare_with_color (const char *var, const char *color)
231 instr_user_variable (0, NULL, var, "LINK", 0, INSTR_US_DECLARE, color);
234 void TRACE_link_variable_set (const char *link, const char *variable, double value)
236 TRACE_link_variable_set_with_time (MSG_get_clock(), link, variable, value);
239 void TRACE_link_variable_add (const char *link, const char *variable, double value)
241 TRACE_link_variable_add_with_time (MSG_get_clock(), link, variable, value);
244 void TRACE_link_variable_sub (const char *link, const char *variable, double value)
246 TRACE_link_variable_sub_with_time (MSG_get_clock(), link, variable, value);
249 void TRACE_link_variable_set_with_time (double time, const char *link, const char *variable, double value)
251 instr_user_variable (time, link, variable, "LINK", value, INSTR_US_SET, NULL);
254 void TRACE_link_variable_add_with_time (double time, const char *link, const char *variable, double value)
256 instr_user_variable (time, link, variable, "LINK", value, INSTR_US_ADD, NULL);
259 void TRACE_link_variable_sub_with_time (double time, const char *link, const char *variable, double value)
261 instr_user_variable (time, link, variable, "LINK", value, INSTR_US_SUB, NULL);
264 /* for link variables, but with src and dst used for get_route */
265 void TRACE_link_srcdst_variable_set (void *src, void *dst, const char *variable, double value)
267 TRACE_link_srcdst_variable_set_with_time (MSG_get_clock(), src, dst, variable, value);
270 void TRACE_link_srcdst_variable_add (void *src, void *dst, const char *variable, double value)
272 TRACE_link_srcdst_variable_add_with_time (MSG_get_clock(), src, dst, variable, value);
275 void TRACE_link_srcdst_variable_sub (void *src, void *dst, const char *variable, double value)
277 TRACE_link_srcdst_variable_sub_with_time (MSG_get_clock(), src, dst, variable, value);
280 void TRACE_link_srcdst_variable_set_with_time (double time, void *src, void *dst, const char *variable, double value)
282 instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_SET);
285 void TRACE_link_srcdst_variable_add_with_time (double time, void *src, void *dst, const char *variable, double value)
287 instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_ADD);
290 void TRACE_link_srcdst_variable_sub_with_time (double time, void *src, void *dst, const char *variable, double value)
292 instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_SUB);
295 #endif /* HAVE_TRACING */