Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
- Add SIMIX_context_get_thread_id to the context factory interface.
[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   DEBUG3("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);
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");
58     new_pajePushState (MSG_get_clock(), msg, type, "created");
59   }
60 }
61
62 /* MSG_task_create related function*/
63 void TRACE_msg_task_create(m_task_t task)
64 {
65   static long long counter = 0;
66   task->counter = counter++;
67   task->category = NULL;
68   DEBUG2("CREATE %p, %lld", task, task->counter);
69 }
70
71 /* MSG_task_execute related functions */
72 void TRACE_msg_task_execute_start(m_task_t task)
73 {
74   if (!task->category) return;
75
76   DEBUG3("EXEC,in %p, %lld, %s", task, task->counter, task->category);
77
78   if (TRACE_msg_task_is_enabled()){
79     container_t task_container = getContainer (task->name);
80     type_t type = getType ("MSG_TASK_STATE");
81     new_pajePushState (MSG_get_clock(), task_container, type, "MSG_task_execute");
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");
90     new_pajePushState (MSG_get_clock(), process_container, type, "task_execute");
91   }
92 }
93
94 void TRACE_msg_task_execute_end(m_task_t task)
95 {
96   if (!task->category) return;
97
98   DEBUG3("EXEC,out %p, %lld, %s", task, task->counter, task->category);
99
100   if (TRACE_msg_task_is_enabled()){
101     container_t task_container = getContainer (task->name);
102     type_t type = getType ("MSG_TASK_STATE");
103     new_pajePopState (MSG_get_clock(), task_container, type);
104   }
105
106   if (TRACE_msg_process_is_enabled()){
107     int len = INSTR_DEFAULT_STR_SIZE;
108     char str[INSTR_DEFAULT_STR_SIZE];
109
110     container_t process_container = getContainer (instr_process_id(MSG_process_self(), str, len));
111     type_t type = getType ("MSG_PROCESS_STATE");
112     new_pajePopState (MSG_get_clock(), process_container, type);
113   }
114 }
115
116 /* MSG_task_destroy related functions */
117 void TRACE_msg_task_destroy(m_task_t task)
118 {
119   if (!(TRACE_msg_task_is_enabled() &&
120         task->category)) return;
121
122   //that's the end, let's destroy it
123   destroyContainer (getContainer(task->name));
124
125   DEBUG3("DESTROY %p, %lld, %s", task, task->counter, task->category);
126
127   //free category
128   xbt_free(task->category);
129   task->category = NULL;
130   return;
131 }
132
133 /* MSG_task_get related functions */
134 void TRACE_msg_task_get_start(void)
135 {
136   DEBUG0("GET,in");
137
138   if (TRACE_msg_task_is_enabled()){
139     //task not received yet, nothing to do
140   }
141
142   if (TRACE_msg_process_is_enabled()){
143     int len = INSTR_DEFAULT_STR_SIZE;
144     char str[INSTR_DEFAULT_STR_SIZE];
145
146     container_t process_container = getContainer (instr_process_id(MSG_process_self(), str, len));
147     type_t type = getType ("MSG_PROCESS_STATE");
148     new_pajePushState (MSG_get_clock(), process_container, type, "receive");
149   }
150 }
151
152 void TRACE_msg_task_get_end(double start_time, m_task_t task)
153 {
154   if (!task->category) return;
155
156   DEBUG3("GET,out %p, %lld, %s", task, task->counter, task->category);
157
158   if (TRACE_msg_task_is_enabled()){
159
160     //FIXME
161     //if (TRACE_msg_volume_is_enabled()){
162     //  TRACE_msg_volume_end(task);
163     //}
164
165     m_host_t host = MSG_host_self();
166     container_t host_container = getContainer(host->name);
167     container_t msg = newContainer(task->name, INSTR_MSG_TASK, host_container);
168     type_t type = getType (task->category);
169     new_pajeSetVariable (SIMIX_get_clock(), msg, type, 1);
170
171     type = getType ("MSG_TASK_STATE");
172     new_pajePushState (MSG_get_clock(), msg, type, "created");
173
174     type = getType ("MSG_TASK_LINK");
175     char key[INSTR_DEFAULT_STR_SIZE];
176     snprintf (key, INSTR_DEFAULT_STR_SIZE, "%lld", task->counter);
177     new_pajeEndLink (MSG_get_clock(), getRootContainer(), type, msg, "SR", key);
178   }
179
180   if (TRACE_msg_process_is_enabled()){
181     int len = INSTR_DEFAULT_STR_SIZE;
182     char str[INSTR_DEFAULT_STR_SIZE];
183
184     container_t process_container = getContainer (instr_process_id(MSG_process_self(), str, len));
185     type_t type = getType ("MSG_PROCESS_STATE");
186     new_pajePopState (MSG_get_clock(), process_container, type);
187
188     char key[INSTR_DEFAULT_STR_SIZE];
189     snprintf (key, INSTR_DEFAULT_STR_SIZE, "p%lld", task->counter);
190     type = getType ("MSG_PROCESS_TASK_LINK");
191     new_pajeEndLink(MSG_get_clock(), getRootContainer(), type, process_container, "SR", key);
192   }
193 }
194
195 /* MSG_task_put related functions */
196 int TRACE_msg_task_put_start(m_task_t task)
197 {
198   if (!task->category) return 0;
199
200   DEBUG3("PUT,in %p, %lld, %s", task, task->counter, task->category);
201
202   if (TRACE_msg_task_is_enabled()){
203
204     container_t msg = getContainer (task->name);
205     type_t type = getType ("MSG_TASK_STATE");
206     new_pajePopState (MSG_get_clock(), msg, type);
207
208     type = getType ("MSG_TASK_LINK");
209     char key[INSTR_DEFAULT_STR_SIZE];
210     snprintf (key, INSTR_DEFAULT_STR_SIZE, "%lld", task->counter);
211     new_pajeStartLink(MSG_get_clock(), getRootContainer(), type, msg, "SR", key);
212
213     destroyContainer (msg);
214
215     //FIXME
216     //if (TRACE_msg_volume_is_enabled()){
217     //  TRACE_msg_volume_start(task);
218     //}
219   }
220
221   if (TRACE_msg_process_is_enabled()){
222     int len = INSTR_DEFAULT_STR_SIZE;
223     char str[INSTR_DEFAULT_STR_SIZE];
224
225     container_t process_container = getContainer (instr_process_id(MSG_process_self(), str, len));
226     type_t type = getType ("MSG_PROCESS_STATE");
227     new_pajePushState (MSG_get_clock(), process_container, type, "send");
228
229     char key[INSTR_DEFAULT_STR_SIZE];
230     snprintf (key, INSTR_DEFAULT_STR_SIZE, "p%lld", task->counter);
231     type = getType ("MSG_PROCESS_TASK_LINK");
232     new_pajeStartLink(MSG_get_clock(), getRootContainer(), type, process_container, "SR", key);
233   }
234
235   return 1;
236 }
237
238 void TRACE_msg_task_put_end(void)
239 {
240   DEBUG0("PUT,out");
241
242   if (TRACE_msg_task_is_enabled()){
243     //task no longer exists here
244   }
245
246   if (TRACE_msg_process_is_enabled()){
247     int len = INSTR_DEFAULT_STR_SIZE;
248     char str[INSTR_DEFAULT_STR_SIZE];
249
250     container_t process_container = getContainer (instr_process_id(MSG_process_self(), str, len));
251     type_t type = getType ("MSG_PROCESS_STATE");
252     new_pajePopState (MSG_get_clock(), process_container, type);
253   }
254 }
255
256 #endif /* HAVE_TRACING */