Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[trace] dictionary for holding smx_process_t -> categories no longer necessary with...
[simgrid.git] / src / instr / instr_msg_task.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 "instr/instr_private.h"
8
9 #ifdef HAVE_TRACING
10
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_msg, instr, "MSG");
12
13 static xbt_dict_t task_containers = NULL;
14
15 static char *TRACE_task_alias_container(m_task_t task, m_process_t process,
16                                  m_host_t host, char *output, int len)
17 {
18   if (output) {
19     snprintf(output, len, "%p-%lld-%p-%p", task, task->counter, process,
20              host);
21     return output;
22   } else {
23     return NULL;
24   }
25 }
26
27 static char *TRACE_host_container(m_host_t host, char *output, int len)
28 {
29   if (output) {
30     snprintf(output, len, "%s", MSG_host_get_name(host));
31     return output;
32   } else {
33     return NULL;
34   }
35 }
36
37 char *TRACE_task_container(m_task_t task, char *output, int len)
38 {
39   if (output) {
40     snprintf(output, len, "%p-%lld", task, task->counter);
41     return output;
42   } else {
43     return NULL;
44   }
45 }
46
47 void TRACE_msg_task_alloc(void)
48 {
49   task_containers = xbt_dict_new();
50 }
51
52 void TRACE_msg_task_release(void)
53 {
54   xbt_dict_free(&task_containers);
55 }
56
57 static void TRACE_task_location(m_task_t task)
58 {
59   char container[200];
60   char name[200], alias[200];
61   char *val_one = NULL;
62   m_process_t process = NULL;
63   m_host_t host = NULL;
64   if (!TRACE_msg_task_is_enabled())
65     return;
66   process = MSG_process_self();
67   host = MSG_process_get_host(process);
68
69   //tasks are grouped by host
70   TRACE_host_container(host, container, 200);
71   TRACE_task_container(task, name, 200);
72   TRACE_task_alias_container(task, process, host, alias, 200);
73   //check if task container is already created
74   if (!xbt_dict_get_or_null(task_containers, alias)) {
75     pajeCreateContainer(MSG_get_clock(), alias, "TASK", container, name);
76     pajeSetState(MSG_get_clock(), "category", alias, task->category);
77     val_one = xbt_strdup("1");
78     xbt_dict_set(task_containers, alias, val_one, xbt_free);
79   }
80 }
81
82 static void TRACE_task_location_present(m_task_t task)
83 {
84   char alias[200];
85   m_process_t process = NULL;
86   m_host_t host = NULL;
87   if (!TRACE_msg_task_is_enabled())
88     return;
89   //updating presence state of this task location
90   process = MSG_process_self();
91   host = MSG_process_get_host(process);
92
93   TRACE_task_alias_container(task, process, host, alias, 200);
94   pajePushState(MSG_get_clock(), "presence", alias, "presence");
95 }
96
97 static void TRACE_task_location_not_present(m_task_t task)
98 {
99   char alias[200];
100   m_process_t process = NULL;
101   m_host_t host = NULL;
102   if (!TRACE_msg_task_is_enabled())
103     return;
104   //updating presence state of this task location
105   process = MSG_process_self();
106   host = MSG_process_get_host(process);
107
108   TRACE_task_alias_container(task, process, host, alias, 200);
109   pajePopState(MSG_get_clock(), "presence", alias);
110 }
111
112 /*
113  * TRACE_msg_set_task_category: tracing interface function
114  */
115 void TRACE_msg_set_task_category(m_task_t task, const char *category)
116 {
117   char name[200];
118   if (!TRACE_is_active())
119     return;
120
121   xbt_assert3(task->category == NULL, "Task %p(%s) already has a category (%s).",
122       task, task->name, task->category);
123
124   //set task category
125   task->category = xbt_strdup (category);
126   DEBUG3("MSG task %p(%s), category %s", task, task->name, task->category);
127
128   //tracing task location based on host
129   TRACE_task_location(task);
130   TRACE_task_location_present(task);
131
132   TRACE_task_container(task, name, 200);
133   //create container of type "task" to indicate behavior
134   if (TRACE_msg_task_is_enabled())
135     pajeCreateContainer(MSG_get_clock(), name, "task", category, name);
136   if (TRACE_msg_task_is_enabled())
137     pajePushState(MSG_get_clock(), "task-state", name, "created");
138 }
139
140 /* MSG_task_create related function*/
141 void TRACE_msg_task_create(m_task_t task)
142 {
143   static long long counter = 0;
144   task->counter = counter++;
145   task->category = NULL;
146   DEBUG2("CREATE %p, %lld", task, task->counter);
147 }
148
149 /* MSG_task_execute related functions */
150 void TRACE_msg_task_execute_start(m_task_t task)
151 {
152   char name[200];
153   if (!TRACE_is_active())
154     return;
155
156   if (!task->category)
157     return;
158
159   DEBUG3("EXEC,in %p, %lld, %s", task, task->counter, task->category);
160
161   TRACE_task_container(task, name, 200);
162   if (TRACE_msg_task_is_enabled())
163     pajePushState(MSG_get_clock(), "task-state", name, "execute");
164 }
165
166 void TRACE_msg_task_execute_end(m_task_t task)
167 {
168   char name[200];
169   if (!TRACE_is_active())
170     return;
171
172   if (!task->category)
173     return;
174
175   TRACE_task_container(task, name, 200);
176   if (TRACE_msg_task_is_enabled())
177     pajePopState(MSG_get_clock(), "task-state", name);
178
179   DEBUG3("EXEC,out %p, %lld, %s", task, task->counter, task->category);
180 }
181
182 /* MSG_task_destroy related functions */
183 void TRACE_msg_task_destroy(m_task_t task)
184 {
185   char name[200];
186   if (!TRACE_is_active())
187     return;
188
189   if (!task->category)
190     return;
191
192   TRACE_task_container(task, name, 200);
193   if (TRACE_msg_task_is_enabled())
194     pajeDestroyContainer(MSG_get_clock(), "task", name);
195
196   //finish the location of this task
197   TRACE_task_location_not_present(task);
198
199   DEBUG3("DESTROY %p, %lld, %s", task, task->counter, task->category);
200
201   //free category
202   xbt_free(task->category);
203   return;
204 }
205
206 /* MSG_task_get related functions */
207 void TRACE_msg_task_get_start(void)
208 {
209   if (!TRACE_is_active())
210     return;
211
212   DEBUG0("GET,in");
213 }
214
215 void TRACE_msg_task_get_end(double start_time, m_task_t task)
216 {
217   char name[200];
218   if (!TRACE_is_active())
219     return;
220
221   if (!task->category)
222     return;
223
224   TRACE_task_container(task, name, 200);
225   if (TRACE_msg_task_is_enabled())
226     pajePopState(MSG_get_clock(), "task-state", name);
227
228   TRACE_msg_volume_finish(task);
229
230   TRACE_task_location(task);
231   TRACE_task_location_present(task);
232
233   DEBUG3("GET,out %p, %lld, %s", task, task->counter, task->category);
234 }
235
236 /* MSG_task_put related functions */
237 int TRACE_msg_task_put_start(m_task_t task)
238 {
239   char name[200];
240   if (!TRACE_is_active())
241     return 0;
242
243   if (!task->category)
244     return 0;
245
246   DEBUG3("PUT,in %p, %lld, %s", task, task->counter, task->category);
247
248   TRACE_task_container(task, name, 200);
249   if (TRACE_msg_task_is_enabled())
250     pajePopState(MSG_get_clock(), "task-state", name);
251   if (TRACE_msg_task_is_enabled())
252     pajePushState(MSG_get_clock(), "task-state", name, "communicate");
253
254   TRACE_msg_volume_start(task);
255
256   //trace task location grouped by host
257   TRACE_task_location_not_present(task);
258   return 1;
259 }
260
261 void TRACE_msg_task_put_end(void)
262 {
263   if (!TRACE_is_active())
264     return;
265   DEBUG0("PUT,in");
266 }
267
268 #endif /* HAVE_TRACING */