Logo AND Algorithmique Numérique Distribuée

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