Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[trace] uncategorized resource tracing option is independent from categorized, and...
[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_CATEGORY(tracing, "Tracing Interface");
14
15 static xbt_dict_t defined_types;
16 static xbt_dict_t created_categories;
17
18 int TRACE_start()
19 {
20   // tracing system must be:
21   //    - enabled (with --cfg=tracing:1)
22   //    - already configured (TRACE_global_init already called)
23   if (!(TRACE_is_enabled() && TRACE_is_configured())){
24     return 0;
25   }
26
27   /* open the trace file */
28   TRACE_paje_start();
29
30   /* activate trace */
31   TRACE_activate ();
32
33   /* base type hierarchy:
34    * --cfg=tracing
35    */
36   pajeDefineContainerType("PLATFORM", "0", "platform");
37   pajeDefineContainerType("HOST", "PLATFORM", "HOST");
38   pajeDefineContainerType("LINK", "PLATFORM", "LINK");
39   pajeDefineVariableType("power", "HOST", "power");
40   pajeDefineVariableType("bandwidth", "LINK", "bandwidth");
41   pajeDefineVariableType("latency", "LINK", "latency");
42   pajeDefineEventType("source", "LINK", "source");
43   pajeDefineEventType("destination", "LINK", "destination");
44
45   /* type hierarchy for:
46    * --cfg=tracing/uncategorized
47    */
48   if (TRACE_uncategorized()){
49     pajeDefineVariableTypeWithColor("power_used", "HOST", "power_used", "0.5 0.5 0.5");
50     pajeDefineVariableTypeWithColor("bandwidth_used", "LINK", "bandwidth_used", "0.5 0.5 0.5");
51   }
52
53   /* type hierarchy for:
54    * --cfg=tracing/msg/process
55    * --cfg=tracing/msg/volume
56    */
57   if (TRACE_msg_process_is_enabled() || TRACE_msg_volume_is_enabled()) {
58     //processes grouped by host
59     pajeDefineContainerType("PROCESS", "HOST", "PROCESS");
60   }
61
62   if (TRACE_msg_process_is_enabled()) {
63     pajeDefineStateType("category", "PROCESS", "category");
64     pajeDefineStateType("presence", "PROCESS", "presence");
65   }
66
67   if (TRACE_msg_volume_is_enabled()) {
68     pajeDefineLinkType("volume", "0", "PROCESS", "PROCESS", "volume");
69   }
70
71   /* type hierarchy for:
72    * --cfg=tracing/msg/task
73    */
74   if (TRACE_msg_task_is_enabled()) {
75     //tasks grouped by host
76     pajeDefineContainerType("TASK", "HOST", "TASK");
77     pajeDefineStateType("category", "TASK", "category");
78     pajeDefineStateType("presence", "TASK", "presence");
79   }
80
81   /* type hierarchy for
82    * --cfg=tracing/smpi
83    * --cfg=tracing/smpi/group
84    */
85   if (TRACE_smpi_is_enabled()) {
86     if (TRACE_smpi_is_grouped()){
87       pajeDefineContainerType("MPI_PROCESS", "HOST", "MPI_PROCESS");
88     }else{
89       pajeDefineContainerType("MPI_PROCESS", "PLATFORM", "MPI_PROCESS");
90     }
91     pajeDefineStateType("MPI_STATE", "MPI_PROCESS", "MPI_STATE");
92     pajeDefineLinkType("MPI_LINK", "0", "MPI_PROCESS", "MPI_PROCESS",
93                        "MPI_LINK");
94   }
95
96   /* creating the platform */
97   pajeCreateContainer(MSG_get_clock(), "platform", "PLATFORM", "0",
98                       "simgrid-platform");
99
100   /* other trace initialization */
101   defined_types = xbt_dict_new();
102   created_categories = xbt_dict_new();
103   TRACE_msg_task_alloc();
104   TRACE_category_alloc();
105   TRACE_surf_alloc();
106   TRACE_msg_process_alloc();
107   TRACE_smpi_alloc();
108   return 0;
109 }
110
111 int TRACE_end()
112 {
113   if (!TRACE_is_active())
114     return 1;
115
116   /* close the trace file */
117   TRACE_paje_end();
118
119   /* activate trace */
120   TRACE_desactivate ();
121   return 0;
122 }
123
124 int TRACE_category(const char *category)
125 {
126   return TRACE_category_with_color (category, NULL);
127 }
128
129 int TRACE_category_with_color (const char *category, const char *color)
130 {
131   static int first_time = 1;
132   if (!TRACE_is_active())
133     return 1;
134
135   if (first_time) {
136     TRACE_define_type("user_type", "0", 1);
137     first_time = 0;
138   }
139   return TRACE_create_category_with_color(category, "user_type", "0", color);
140 }
141
142 void TRACE_define_type(const char *type,
143                        const char *parent_type, int final)
144 {
145   char *val_one = NULL;
146   if (!TRACE_is_active())
147     return;
148
149   //check if type is already defined
150   if (xbt_dict_get_or_null(defined_types, type)) {
151     THROW1(tracing_error, TRACE_ERROR_TYPE_ALREADY_DEFINED,
152            "Type %s is already defined", type);
153   }
154   //check if parent_type is already defined
155   if (strcmp(parent_type, "0")
156       && !xbt_dict_get_or_null(defined_types, parent_type)) {
157     THROW1(tracing_error, TRACE_ERROR_TYPE_NOT_DEFINED,
158            "Type (used as parent) %s is not defined", parent_type);
159   }
160
161   pajeDefineContainerType(type, parent_type, type);
162   if (final) {
163     //for m_process_t
164     if (TRACE_msg_process_is_enabled())
165       pajeDefineContainerType("process", type, "process");
166     if (TRACE_msg_process_is_enabled())
167       pajeDefineStateType("process-state", "process", "process-state");
168
169     if (TRACE_msg_task_is_enabled())
170       pajeDefineContainerType("task", type, "task");
171     if (TRACE_msg_task_is_enabled())
172       pajeDefineStateType("task-state", "task", "task-state");
173   }
174   val_one = xbt_strdup("1");
175   xbt_dict_set(defined_types, type, &val_one, xbt_free);
176 }
177
178 int TRACE_create_category(const char *category,
179                           const char *type, const char *parent_category)
180 {
181   return TRACE_create_category_with_color (category, type, parent_category, NULL);
182 }
183
184 int TRACE_create_category_with_color(const char *category,
185                           const char *type,
186                           const char *parent_category,
187                           const char *color)
188 {
189   char state[100];
190   char *val_one = NULL;
191   if (!TRACE_is_active())
192     return 1;
193
194   //check if type is defined
195   if (!xbt_dict_get_or_null(defined_types, type)) {
196     THROW1(tracing_error, TRACE_ERROR_TYPE_NOT_DEFINED,
197            "Type %s is not defined", type);
198     return 1;
199   }
200   //check if parent_category exists
201   if (strcmp(parent_category, "0")
202       && !xbt_dict_get_or_null(created_categories, parent_category)) {
203     THROW1(tracing_error, TRACE_ERROR_CATEGORY_NOT_DEFINED,
204            "Category (used as parent) %s is not created", parent_category);
205     return 1;
206   }
207   //check if category is created
208   if (xbt_dict_get_or_null(created_categories, category)) {
209     return 1;
210   }
211
212   pajeCreateContainer(MSG_get_clock(), category, type, parent_category,
213                       category);
214
215   char final_color[INSTR_DEFAULT_STR_SIZE];
216   if (!color){
217     //generate a random color
218     double red = drand48();
219     double green = drand48();
220     double blue = drand48();
221     snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%f %f %f", red, green, blue);
222   }else{
223     snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%s", color);
224   }
225
226   /* for registering application categories on top of platform */
227   snprintf(state, 100, "b%s", category);
228   if (TRACE_platform_is_enabled())
229     pajeDefineVariableTypeWithColor(state, "LINK", state, final_color);
230   snprintf(state, 100, "p%s", category);
231   if (TRACE_platform_is_enabled())
232     pajeDefineVariableTypeWithColor(state, "HOST", state, final_color);
233
234   val_one = xbt_strdup("1");
235   xbt_dict_set(created_categories, category, &val_one, xbt_free);
236   return 0;
237 }
238
239 void TRACE_declare_mark(const char *mark_type)
240 {
241   if (!TRACE_is_active())
242     return;
243   if (!mark_type)
244     return;
245
246   pajeDefineEventType(mark_type, "0", mark_type);
247 }
248
249 void TRACE_mark(const char *mark_type, const char *mark_value)
250 {
251   if (!TRACE_is_active())
252     return;
253   if (!mark_type || !mark_value)
254     return;
255
256   pajeNewEvent(MSG_get_clock(), mark_type, "0", mark_value);
257 }
258
259 #endif /* HAVE_TRACING */