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)
30 if (!(TRACE_is_active() && category != NULL))
33 xbt_assert (instr_platform_traced(),
34 "%s must be called after environment creation", __FUNCTION__);
36 //check if category is already created
37 char *created = xbt_dict_get_or_null(created_categories, category);
39 xbt_dict_set (created_categories, category, xbt_strdup("1"), xbt_free);
42 char final_color[INSTR_DEFAULT_STR_SIZE];
44 //generate a random color
45 double red = drand48();
46 double green = drand48();
47 double blue = drand48();
48 snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%f %f %f", red, green, blue);
50 snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%s", color);
53 XBT_DEBUG("CAT,declare %s, %s", category, final_color);
55 //define the type of this category on top of hosts and links
56 if (TRACE_categorized ()){
57 instr_new_variable_type (category, final_color);
61 void TRACE_declare_mark(const char *mark_type)
63 if (!TRACE_is_active())
68 XBT_DEBUG("MARK,declare %s", mark_type);
69 getEventType(mark_type, NULL, getRootType());
72 void TRACE_mark(const char *mark_type, const char *mark_value)
74 if (!TRACE_is_active())
76 if (!mark_type || !mark_value)
79 XBT_DEBUG("MARK %s %s", mark_type, mark_value);
80 type_t type = getEventType (mark_type, NULL, getRootContainer()->type);
81 val_t value = getValue (mark_value, NULL, type);
82 new_pajeNewEvent (MSG_get_clock(), getRootContainer(), type, value);
85 static void instr_user_variable(double time,
88 const char *father_type,
90 InstrUserVariable what)
92 if (!TRACE_is_active())
95 xbt_assert (instr_platform_traced(),
96 "%s must be called after environment creation", __FUNCTION__);
99 snprintf(valuestr, 100, "%g", value);
102 case INSTR_US_DECLARE:
103 instr_new_user_variable_type (father_type, variable, NULL);
107 container_t container = getContainerByName(resource);
108 type_t type = getVariableType (variable, NULL, container->type);
109 new_pajeSetVariable(time, container, type, value);
114 container_t container = getContainerByName(resource);
115 type_t type = getVariableType (variable, NULL, container->type);
116 new_pajeAddVariable(time, container, type, value);
121 container_t container = getContainerByName(resource);
122 type_t type = getVariableType (variable, NULL, container->type);
123 new_pajeSubVariable(time, container, type, value);
127 //TODO: launch exception
132 static void instr_user_srcdst_variable(double time,
135 const char *variable,
136 const char *father_type,
138 InstrUserVariable what)
140 xbt_dynar_t route = global_routing->get_route (src, dst);
143 xbt_dynar_foreach (route, i, link) {
144 char *link_name = ((link_CM02_t)link)->lmm_resource.generic_resource.name;
145 instr_user_variable (time, link_name, variable, father_type, value, what);
149 const char *TRACE_node_name (xbt_node_t node)
151 void *data = xbt_graph_node_get_data(node);
152 char *str = (char*)data;
156 xbt_graph_t TRACE_platform_graph (void)
158 if (!TRACE_is_enabled())
161 return instr_routing_platform_graph ();
164 void TRACE_platform_graph_export_graphviz (xbt_graph_t g, const char *filename)
166 instr_routing_platform_graph_export_graphviz (g, filename);
171 * Derived functions that use instr_user_variable and TRACE_user_srcdst_variable.
172 * They were previously defined as pre-processors directives, but were transformed
173 * into functions so the user can track them using gdb.
176 /* for host variables */
177 void TRACE_host_variable_declare (const char *var)
179 instr_user_variable(0, NULL, var, "HOST", 0, INSTR_US_DECLARE);
182 void TRACE_host_variable_set (const char *host, const char *variable, double value)
184 TRACE_host_variable_set_with_time (MSG_get_clock(), host, variable, value);
187 void TRACE_host_variable_add (const char *host, const char *variable, double value)
189 TRACE_host_variable_add_with_time (MSG_get_clock(), host, variable, value);
192 void TRACE_host_variable_sub (const char *host, const char *variable, double value)
194 TRACE_host_variable_sub_with_time (MSG_get_clock(), host, variable, value);
197 void TRACE_host_variable_set_with_time (double time, const char *host, const char *variable, double value)
199 instr_user_variable(time, host, variable, "HOST", value, INSTR_US_SET);
202 void TRACE_host_variable_add_with_time (double time, const char *host, const char *variable, double value)
204 instr_user_variable(time, host, variable, "HOST", value, INSTR_US_ADD);
207 void TRACE_host_variable_sub_with_time (double time, const char *host, const char *variable, double value)
209 instr_user_variable(time, host, variable, "HOST", value, INSTR_US_SUB);
212 /* for link variables */
213 void TRACE_link_variable_declare (const char *var)
215 instr_user_variable (0, NULL, var, "LINK", 0, INSTR_US_DECLARE);
218 void TRACE_link_variable_set (const char *link, const char *variable, double value)
220 TRACE_link_variable_set_with_time (MSG_get_clock(), link, variable, value);
223 void TRACE_link_variable_add (const char *link, const char *variable, double value)
225 TRACE_link_variable_add_with_time (MSG_get_clock(), link, variable, value);
228 void TRACE_link_variable_sub (const char *link, const char *variable, double value)
230 TRACE_link_variable_sub_with_time (MSG_get_clock(), link, variable, value);
233 void TRACE_link_variable_set_with_time (double time, const char *link, const char *variable, double value)
235 instr_user_variable (time, link, variable, "LINK", value, INSTR_US_SET);
238 void TRACE_link_variable_add_with_time (double time, const char *link, const char *variable, double value)
240 instr_user_variable (time, link, variable, "LINK", value, INSTR_US_ADD);
243 void TRACE_link_variable_sub_with_time (double time, const char *link, const char *variable, double value)
245 instr_user_variable (time, link, variable, "LINK", value, INSTR_US_SUB);
248 /* for link variables, but with src and dst used for get_route */
249 void TRACE_link_srcdst_variable_set (const char *src, const char *dst, const char *variable, double value)
251 TRACE_link_srcdst_variable_set_with_time (MSG_get_clock(), src, dst, variable, value);
254 void TRACE_link_srcdst_variable_add (const char *src, const char *dst, const char *variable, double value)
256 TRACE_link_srcdst_variable_add_with_time (MSG_get_clock(), src, dst, variable, value);
259 void TRACE_link_srcdst_variable_sub (const char *src, const char *dst, const char *variable, double value)
261 TRACE_link_srcdst_variable_sub_with_time (MSG_get_clock(), src, dst, variable, value);
264 void TRACE_link_srcdst_variable_set_with_time (double time, const char *src, const char *dst, const char *variable, double value)
266 instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_SET);
269 void TRACE_link_srcdst_variable_add_with_time (double time, const char *src, const char *dst, const char *variable, double value)
271 instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_ADD);
274 void TRACE_link_srcdst_variable_sub_with_time (double time, const char *src, const char *dst, const char *variable, double value)
276 instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_SUB);
279 #endif /* HAVE_TRACING */