Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Cope with new way of destroying actions, now if the action is destroyed assume that...
[simgrid.git] / src / instr / instr_interface.c
1 /* Copyright (c) 2010. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #include "simgrid_config.h"
8
9 #ifdef HAVE_TRACING
10
11 #include "instr/instr_private.h"
12 #include "surf/network_private.h"
13
14 typedef enum {
15   INSTR_US_DECLARE,
16   INSTR_US_SET,
17   INSTR_US_ADD,
18   INSTR_US_SUB,
19 } InstrUserVariable;
20
21 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_api, instr, "API");
22
23 void TRACE_category(const char *category)
24 {
25   TRACE_category_with_color (category, NULL);
26 }
27
28 void TRACE_category_with_color (const char *category, const char *color)
29 {
30   if (!(TRACE_categorized() && category != NULL))
31     return;
32
33   xbt_assert (instr_platform_traced(),
34       "%s must be called after environment creation", __FUNCTION__);
35
36   //check if category is already created
37   char *created = xbt_dict_get_or_null(created_categories, category);
38   if (created) return;
39   xbt_dict_set (created_categories, category, xbt_strdup("1"), xbt_free);
40
41   //define final_color
42   char final_color[INSTR_DEFAULT_STR_SIZE];
43   if (!color){
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);
49   }else{
50     snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%s", color);
51   }
52
53   XBT_DEBUG("CAT,declare %s, %s", category, final_color);
54
55   //define the type of this category on top of hosts and links
56   instr_new_variable_type (category, final_color);
57 }
58
59 void TRACE_declare_mark(const char *mark_type)
60 {
61   if (!TRACE_is_enabled())
62     return;
63   if (!mark_type)
64     return;
65
66   XBT_DEBUG("MARK,declare %s", mark_type);
67   getEventType(mark_type, NULL, getRootType());
68 }
69
70 void TRACE_mark(const char *mark_type, const char *mark_value)
71 {
72   if (!TRACE_is_enabled())
73     return;
74   if (!mark_type || !mark_value)
75     return;
76
77   XBT_DEBUG("MARK %s %s", mark_type, mark_value);
78   type_t type = getEventType (mark_type, NULL, getRootContainer()->type);
79   val_t value = getValue (mark_value, NULL, type);
80   new_pajeNewEvent (MSG_get_clock(), getRootContainer(), type, value);
81 }
82
83 static void instr_user_variable(double time,
84                          const char *resource,
85                          const char *variable,
86                          const char *father_type,
87                          double value,
88                          InstrUserVariable what)
89 {
90   if (!TRACE_is_enabled())
91     return;
92
93   xbt_assert (instr_platform_traced(),
94       "%s must be called after environment creation", __FUNCTION__);
95
96   char valuestr[100];
97   snprintf(valuestr, 100, "%g", value);
98
99   switch (what){
100   case INSTR_US_DECLARE:
101     instr_new_user_variable_type (father_type, variable, NULL);
102     break;
103   case INSTR_US_SET:
104   {
105     container_t container = getContainerByName(resource);
106     type_t type = getVariableType (variable, NULL, container->type);
107     new_pajeSetVariable(time, container, type, value);
108     break;
109   }
110   case INSTR_US_ADD:
111   {
112     container_t container = getContainerByName(resource);
113     type_t type = getVariableType (variable, NULL, container->type);
114     new_pajeAddVariable(time, container, type, value);
115     break;
116   }
117   case INSTR_US_SUB:
118   {
119     container_t container = getContainerByName(resource);
120     type_t type = getVariableType (variable, NULL, container->type);
121     new_pajeSubVariable(time, container, type, value);
122     break;
123   }
124   default:
125     //TODO: launch exception
126     break;
127   }
128 }
129
130 static void instr_user_srcdst_variable(double time,
131                               const char *src,
132                               const char *dst,
133                               const char *variable,
134                               const char *father_type,
135                               double value,
136                               InstrUserVariable what)
137 {
138   xbt_dynar_t route = global_routing->get_route (src, dst);
139   unsigned int i;
140   void *link;
141   xbt_dynar_foreach (route, i, link) {
142     char *link_name = ((link_CM02_t)link)->lmm_resource.generic_resource.name;
143     instr_user_variable (time, link_name, variable, father_type, value, what);
144   }
145 }
146
147 const char *TRACE_node_name (xbt_node_t node)
148 {
149   void *data = xbt_graph_node_get_data(node);
150   char *str = (char*)data;
151   return str;
152 }
153
154 xbt_graph_t TRACE_platform_graph (void)
155 {
156   if (!TRACE_is_enabled())
157     return NULL;
158
159   return instr_routing_platform_graph ();
160 }
161
162 void TRACE_platform_graph_export_graphviz (xbt_graph_t g, const char *filename)
163 {
164   instr_routing_platform_graph_export_graphviz (g, filename);
165 }
166
167
168 /*
169  * Derived functions that use instr_user_variable and TRACE_user_srcdst_variable.
170  * They were previously defined as pre-processors directives, but were transformed
171  * into functions so the user can track them using gdb.
172  */
173
174 /* for host variables */
175 void TRACE_host_variable_declare (const char *var)
176 {
177   instr_user_variable(0, NULL, var, "HOST", 0, INSTR_US_DECLARE);
178 }
179
180 void TRACE_host_variable_set (const char *host, const char *variable, double value)
181 {
182   TRACE_host_variable_set_with_time (MSG_get_clock(), host, variable, value);
183 }
184
185 void TRACE_host_variable_add (const char *host, const char *variable, double value)
186 {
187   TRACE_host_variable_add_with_time (MSG_get_clock(), host, variable, value);
188 }
189
190 void TRACE_host_variable_sub (const char *host, const char *variable, double value)
191 {
192   TRACE_host_variable_sub_with_time (MSG_get_clock(), host, variable, value);
193 }
194
195 void TRACE_host_variable_set_with_time (double time, const char *host, const char *variable, double value)
196 {
197   instr_user_variable(time, host, variable, "HOST", value, INSTR_US_SET);
198 }
199
200 void TRACE_host_variable_add_with_time (double time, const char *host, const char *variable, double value)
201 {
202   instr_user_variable(time, host, variable, "HOST", value, INSTR_US_ADD);
203 }
204
205 void TRACE_host_variable_sub_with_time (double time, const char *host, const char *variable, double value)
206 {
207   instr_user_variable(time, host, variable, "HOST", value, INSTR_US_SUB);
208 }
209
210 /* for link variables */
211 void TRACE_link_variable_declare (const char *var)
212 {
213   instr_user_variable (0, NULL, var, "LINK", 0, INSTR_US_DECLARE);
214 }
215
216 void TRACE_link_variable_set (const char *link, const char *variable, double value)
217 {
218   TRACE_link_variable_set_with_time (MSG_get_clock(), link, variable, value);
219 }
220
221 void TRACE_link_variable_add (const char *link, const char *variable, double value)
222 {
223   TRACE_link_variable_add_with_time (MSG_get_clock(), link, variable, value);
224 }
225
226 void TRACE_link_variable_sub (const char *link, const char *variable, double value)
227 {
228   TRACE_link_variable_sub_with_time (MSG_get_clock(), link, variable, value);
229 }
230
231 void TRACE_link_variable_set_with_time (double time, const char *link, const char *variable, double value)
232 {
233   instr_user_variable (time, link, variable, "LINK", value, INSTR_US_SET);
234 }
235
236 void TRACE_link_variable_add_with_time (double time, const char *link, const char *variable, double value)
237 {
238   instr_user_variable (time, link, variable, "LINK", value, INSTR_US_ADD);
239 }
240
241 void TRACE_link_variable_sub_with_time (double time, const char *link, const char *variable, double value)
242 {
243   instr_user_variable (time, link, variable, "LINK", value, INSTR_US_SUB);
244 }
245
246 /* for link variables, but with src and dst used for get_route */
247 void TRACE_link_srcdst_variable_set (const char *src, const char *dst, const char *variable, double value)
248 {
249   TRACE_link_srcdst_variable_set_with_time (MSG_get_clock(), src, dst, variable, value);
250 }
251
252 void TRACE_link_srcdst_variable_add (const char *src, const char *dst, const char *variable, double value)
253 {
254   TRACE_link_srcdst_variable_add_with_time (MSG_get_clock(), src, dst, variable, value);
255 }
256
257 void TRACE_link_srcdst_variable_sub (const char *src, const char *dst, const char *variable, double value)
258 {
259   TRACE_link_srcdst_variable_sub_with_time (MSG_get_clock(), src, dst, variable, value);
260 }
261
262 void TRACE_link_srcdst_variable_set_with_time (double time, const char *src, const char *dst, const char *variable, double value)
263 {
264   instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_SET);
265 }
266
267 void TRACE_link_srcdst_variable_add_with_time (double time, const char *src, const char *dst, const char *variable, double value)
268 {
269   instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_ADD);
270 }
271
272 void TRACE_link_srcdst_variable_sub_with_time (double time, const char *src, const char *dst, const char *variable, double value)
273 {
274   instr_user_srcdst_variable (time, src, dst, variable, "LINK", value, INSTR_US_SUB);
275 }
276
277 #endif /* HAVE_TRACING */