Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
0c19542bf8fbc36f69901d8f08bba6efad38e03a
[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 /*
14  * TRACE_msg_set_task_category: tracing interface function
15  */
16 void TRACE_msg_set_task_category(m_task_t task, const char *category)
17 {
18   if (!TRACE_is_active())
19     return;
20
21   xbt_assert3(task->category == NULL, "Task %p(%s) already has a category (%s).",
22       task, task->name, task->category);
23   if (TRACE_msg_task_is_enabled()){
24     xbt_assert2(task->name != NULL,
25         "Task %p(%s) must have a unique name in order to be traced, if --cfg=tracing/msg/task:1 is used.",
26         task, task->name);
27     xbt_assert3(getContainer(task->name)==NULL,
28         "Task %p(%s). Tracing already knows a task with name %s."
29         "The name of each task must be unique, if --cfg=tracing/msg/task:1 is used.", task, task->name, task->name);
30   }
31
32   if (category == NULL) {
33     //if user provides a NULL category, task is no longer traced
34     xbt_free (task->category);
35     task->category = NULL;
36     return;
37   }
38
39   //set task category
40   task->category = xbt_strdup (category);
41   XBT_DEBUG("MSG task %p(%s), category %s", task, task->name, task->category);
42
43   if (TRACE_msg_task_is_enabled()){
44     m_host_t host = MSG_host_self();
45     container_t host_container = getContainer(host->name);
46     //check to see if there is a container with the task->name
47     xbt_assert3(getContainer(task->name) == NULL,
48         "Task %p(%s). Tracing already knows a task with name %s."
49         "The name of each task must be unique, if --cfg=tracing/msg/task:1 is used.", task, task->name, task->name);
50     container_t msg = newContainer(task->name, INSTR_MSG_TASK, host_container);
51     type_t type = getType (task->category, msg->type);
52     if (!type){
53       type = getVariableType(task->category, NULL, msg->type);
54     }
55     new_pajeSetVariable (SIMIX_get_clock(), msg, type, 1);
56
57     type = getType ("MSG_TASK_STATE", msg->type);
58     val_t value = getValueByName ("created", type);
59     new_pajePushState (MSG_get_clock(), msg, type, value);
60   }
61 }
62
63 /* MSG_task_create related function*/
64 void TRACE_msg_task_create(m_task_t task)
65 {
66   static long long counter = 0;
67   task->counter = counter++;
68   task->category = NULL;
69   XBT_DEBUG("CREATE %p, %lld", task, task->counter);
70 }
71
72 /* MSG_task_execute related functions */
73 void TRACE_msg_task_execute_start(m_task_t task)
74 {
75   XBT_DEBUG("EXEC,in %p, %lld, %s", task, task->counter, task->category);
76
77   if (TRACE_msg_task_is_enabled()){
78     container_t task_container = getContainer (task->name);
79     type_t type = getType ("MSG_TASK_STATE", task_container->type);
80     val_t value = getValueByName ("MSG_task_execute", type);
81     new_pajePushState (MSG_get_clock(), task_container, type, value);
82   }
83
84   if (TRACE_msg_process_is_enabled()){
85     int len = INSTR_DEFAULT_STR_SIZE;
86     char str[INSTR_DEFAULT_STR_SIZE];
87
88     container_t process_container = getContainer (instr_process_id(MSG_process_self(), str, len));
89     type_t type = getType ("MSG_PROCESS_STATE", process_container->type);
90     val_t value = getValueByName ("task_execute", type);
91     new_pajePushState (MSG_get_clock(), process_container, type, value);
92   }
93 }
94
95 void TRACE_msg_task_execute_end(m_task_t task)
96 {
97   XBT_DEBUG("EXEC,out %p, %lld, %s", task, task->counter, task->category);
98
99   if (TRACE_msg_task_is_enabled()){
100     container_t task_container = getContainer (task->name);
101     type_t type = getType ("MSG_TASK_STATE", task_container->type);
102     new_pajePopState (MSG_get_clock(), task_container, type);
103   }
104
105   if (TRACE_msg_process_is_enabled()){
106     int len = INSTR_DEFAULT_STR_SIZE;
107     char str[INSTR_DEFAULT_STR_SIZE];
108
109     container_t process_container = getContainer (instr_process_id(MSG_process_self(), str, len));
110     type_t type = getType ("MSG_PROCESS_STATE", process_container->type);
111     new_pajePopState (MSG_get_clock(), process_container, type);
112   }
113 }
114
115 /* MSG_task_destroy related functions */
116 void TRACE_msg_task_destroy(m_task_t task)
117 {
118   XBT_DEBUG("DESTROY %p, %lld, %s", task, task->counter, task->category);
119
120   if (TRACE_msg_task_is_enabled()){
121     //that's the end, let's destroy it
122     destroyContainer (getContainer(task->name));
123   }
124
125   //free category
126   xbt_free(task->category);
127   task->category = NULL;
128   return;
129 }
130
131 /* MSG_task_get related functions */
132 void TRACE_msg_task_get_start(void)
133 {
134   XBT_DEBUG("GET,in");
135
136   if (TRACE_msg_task_is_enabled()){
137     //task not received yet, nothing to do
138   }
139
140   if (TRACE_msg_process_is_enabled()){
141     int len = INSTR_DEFAULT_STR_SIZE;
142     char str[INSTR_DEFAULT_STR_SIZE];
143
144     container_t process_container = getContainer (instr_process_id(MSG_process_self(), str, len));
145     type_t type = getType ("MSG_PROCESS_STATE", process_container->type);
146     val_t value = getValueByName ("receive", type);
147     new_pajePushState (MSG_get_clock(), process_container, type, value);
148   }
149 }
150
151 void TRACE_msg_task_get_end(double start_time, m_task_t task)
152 {
153   XBT_DEBUG("GET,out %p, %lld, %s", task, task->counter, task->category);
154
155   if (TRACE_msg_task_is_enabled()){
156
157     //FIXME
158     //if (TRACE_msg_volume_is_enabled()){
159     //  TRACE_msg_volume_end(task);
160     //}
161
162     m_host_t host = MSG_host_self();
163     container_t host_container = getContainer(host->name);
164     container_t msg = newContainer(task->name, INSTR_MSG_TASK, host_container);
165     type_t type = getType (task->category, msg->type);
166     new_pajeSetVariable (SIMIX_get_clock(), msg, type, 1);
167
168     type = getType ("MSG_TASK_STATE", msg->type);
169     val_t value = getValueByName ("created", type);
170     new_pajePushState (MSG_get_clock(), msg, type, value);
171
172     type = getType ("MSG_TASK_LINK", getRootType());
173     char key[INSTR_DEFAULT_STR_SIZE];
174     snprintf (key, INSTR_DEFAULT_STR_SIZE, "%lld", task->counter);
175     new_pajeEndLink (MSG_get_clock(), getRootContainer(), type, msg, "SR", key);
176   }
177
178   if (TRACE_msg_process_is_enabled()){
179     int len = INSTR_DEFAULT_STR_SIZE;
180     char str[INSTR_DEFAULT_STR_SIZE];
181
182     container_t process_container = getContainer (instr_process_id(MSG_process_self(), str, len));
183     type_t type = getType ("MSG_PROCESS_STATE", process_container->type);
184     new_pajePopState (MSG_get_clock(), process_container, type);
185
186     char key[INSTR_DEFAULT_STR_SIZE];
187     snprintf (key, INSTR_DEFAULT_STR_SIZE, "p%lld", task->counter);
188     type = getType ("MSG_PROCESS_TASK_LINK", getRootType());
189     new_pajeEndLink(MSG_get_clock(), getRootContainer(), type, process_container, "SR", key);
190   }
191 }
192
193 /* MSG_task_put related functions */
194 int TRACE_msg_task_put_start(m_task_t task)
195 {
196   XBT_DEBUG("PUT,in %p, %lld, %s", task, task->counter, task->category);
197
198   if (TRACE_msg_task_is_enabled()){
199
200     container_t msg = getContainer (task->name);
201     type_t type = getType ("MSG_TASK_STATE", msg->type);
202     new_pajePopState (MSG_get_clock(), msg, type);
203
204     type = getType ("MSG_TASK_LINK", getRootType());
205     char key[INSTR_DEFAULT_STR_SIZE];
206     snprintf (key, INSTR_DEFAULT_STR_SIZE, "%lld", task->counter);
207     new_pajeStartLink(MSG_get_clock(), getRootContainer(), type, msg, "SR", key);
208
209     destroyContainer (msg);
210
211     //FIXME
212     //if (TRACE_msg_volume_is_enabled()){
213     //  TRACE_msg_volume_start(task);
214     //}
215   }
216
217   if (TRACE_msg_process_is_enabled()){
218     int len = INSTR_DEFAULT_STR_SIZE;
219     char str[INSTR_DEFAULT_STR_SIZE];
220
221     container_t process_container = getContainer (instr_process_id(MSG_process_self(), str, len));
222     type_t type = getType ("MSG_PROCESS_STATE", process_container->type);
223     val_t value = getValueByName ("send", type);
224     new_pajePushState (MSG_get_clock(), process_container, type, value);
225
226     char key[INSTR_DEFAULT_STR_SIZE];
227     snprintf (key, INSTR_DEFAULT_STR_SIZE, "p%lld", task->counter);
228     type = getType ("MSG_PROCESS_TASK_LINK", getRootType());
229     new_pajeStartLink(MSG_get_clock(), getRootContainer(), type, process_container, "SR", key);
230   }
231
232   return 1;
233 }
234
235 void TRACE_msg_task_put_end(void)
236 {
237   XBT_DEBUG("PUT,out");
238
239   if (TRACE_msg_task_is_enabled()){
240     //task no longer exists here
241   }
242
243   if (TRACE_msg_process_is_enabled()){
244     int len = INSTR_DEFAULT_STR_SIZE;
245     char str[INSTR_DEFAULT_STR_SIZE];
246
247     container_t process_container = getContainer (instr_process_id(MSG_process_self(), str, len));
248     type_t type = getType ("MSG_PROCESS_STATE", process_container->type);
249     new_pajePopState (MSG_get_clock(), process_container, type);
250   }
251 }
252
253 #endif /* HAVE_TRACING */