Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
gtnets tracing possible again, updated to latest routing
[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
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_api, instr, "API");
14
15 void TRACE_category(const char *category)
16 {
17   TRACE_category_with_color (category, NULL);
18 }
19
20 void TRACE_category_with_color (const char *category, const char *color)
21 {
22   if (!(TRACE_is_active() && category != NULL))
23     return;
24
25   xbt_assert (instr_platform_traced(),
26       "%s must be called after environment creation", __FUNCTION__);
27
28   //check if category is already created
29   char *created = xbt_dict_get_or_null(created_categories, category);
30   if (created) return;
31   xbt_dict_set (created_categories, category, xbt_strdup("1"), xbt_free);
32
33   //define final_color
34   char final_color[INSTR_DEFAULT_STR_SIZE];
35   if (!color){
36     //generate a random color
37     double red = drand48();
38     double green = drand48();
39     double blue = drand48();
40     snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%f %f %f", red, green, blue);
41   }else{
42     snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%s", color);
43   }
44
45   XBT_DEBUG("CAT,declare %s, %s", category, final_color);
46
47 //FIXME
48 //  -  if (final) {
49 //  -    //for m_process_t
50 //  -    if (TRACE_msg_process_is_enabled())
51 //  -      pajeDefineContainerType("process", type, "process");
52 //  -    if (TRACE_msg_process_is_enabled())
53 //  -      pajeDefineStateType("process-state", "process", "process-state");
54 //  -
55 //  -    if (TRACE_msg_task_is_enabled())
56 //  -      pajeDefineContainerType("task", type, "task");
57 //  -    if (TRACE_msg_task_is_enabled())
58 //  -      pajeDefineStateType("task-state", "task", "task-state");
59 //  -  }
60
61   //define the type of this category on top of hosts and links
62   if (TRACE_categorized ()){
63     instr_new_user_variable_type (category, final_color);
64   }
65 }
66
67 void TRACE_declare_mark(const char *mark_type)
68 {
69   if (!TRACE_is_active())
70     return;
71   if (!mark_type)
72     return;
73
74   XBT_DEBUG("MARK,declare %s", mark_type);
75   getEventType(mark_type, NULL, getRootType());
76 }
77
78 void TRACE_mark(const char *mark_type, const char *mark_value)
79 {
80   if (!TRACE_is_active())
81     return;
82   if (!mark_type || !mark_value)
83     return;
84
85   XBT_DEBUG("MARK %s %s", mark_type, mark_value);
86   type_t type = getEventType (mark_type, NULL, getRootContainer()->type);
87   val_t value = getValue (mark_value, NULL, type);
88   new_pajeNewEvent (MSG_get_clock(), getRootContainer(), type, value);
89 }
90
91
92 void TRACE_user_link_variable(double time, const char *resource,
93                               const char *variable,
94                               double value, const char *what)
95 {
96   if (!TRACE_is_active())
97     return;
98
99   xbt_assert (instr_platform_traced(),
100       "%s must be called after environment creation", __FUNCTION__);
101
102   char valuestr[100];
103   snprintf(valuestr, 100, "%g", value);
104
105   if (strcmp(what, "declare") == 0) {
106     instr_new_user_link_variable_type (variable, NULL);
107   } else{
108     container_t container = getContainerByName (resource);
109     type_t type = getVariableType (variable, NULL, container->type);
110     if (strcmp(what, "set") == 0) {
111       new_pajeSetVariable(time, container, type, value);
112     } else if (strcmp(what, "add") == 0) {
113       new_pajeAddVariable(time, container, type, value);
114     } else if (strcmp(what, "sub") == 0) {
115       new_pajeSubVariable(time, container, type, value);
116     }
117   }
118 }
119
120 void TRACE_user_host_variable(double time, const char *variable,
121                               double value, const char *what)
122 {
123   if (!TRACE_is_active())
124     return;
125
126   xbt_assert (instr_platform_traced(),
127       "%s must be called after environment creation", __FUNCTION__);
128
129   char valuestr[100];
130   snprintf(valuestr, 100, "%g", value);
131
132   if (strcmp(what, "declare") == 0) {
133     instr_new_user_host_variable_type (variable, NULL);
134   } else{
135     char *host_name = MSG_host_self()->name;
136     container_t container = getContainerByName(host_name);
137     type_t type = getVariableType (variable, NULL, container->type);
138     if (strcmp(what, "set") == 0) {
139       new_pajeSetVariable(time, container, type, value);
140     } else if (strcmp(what, "add") == 0) {
141       new_pajeAddVariable(time, container, type, value);
142     } else if (strcmp(what, "sub") == 0) {
143       new_pajeSubVariable(time, container, type, value);
144     }
145   }
146 }
147
148 const char *TRACE_node_name (xbt_node_t node)
149 {
150   void *data = xbt_graph_node_get_data(node);
151   char *str = (char*)data;
152   return str;
153 }
154
155 xbt_graph_t TRACE_platform_graph (void)
156 {
157   if (!TRACE_is_active())
158     return NULL;
159
160   return instr_routing_platform_graph ();
161 }
162
163 void TRACE_platform_graph_export_graphviz (xbt_graph_t g, const char *filename)
164 {
165   instr_routing_platform_graph_export_graphviz (g, filename);
166 }
167
168 #endif /* HAVE_TRACING */