Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Offer the possibility to change smpi bandwidth and latency factor into tag config...
[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_categorized())
19     return;
20
21   xbt_assert(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_assert(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_assert(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_assert(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     m_host_t host = MSG_host_self();
158     container_t host_container = getContainer(host->name);
159     container_t msg = newContainer(task->name, INSTR_MSG_TASK, host_container);
160     type_t type = getType (task->category, msg->type);
161     new_pajeSetVariable (SIMIX_get_clock(), msg, type, 1);
162
163     type = getType ("MSG_TASK_STATE", msg->type);
164     val_t value = getValueByName ("created", type);
165     new_pajePushState (MSG_get_clock(), msg, type, value);
166
167     type = getType ("MSG_TASK_LINK", getRootType());
168     char key[INSTR_DEFAULT_STR_SIZE];
169     snprintf (key, INSTR_DEFAULT_STR_SIZE, "%lld", task->counter);
170     new_pajeEndLink (MSG_get_clock(), getRootContainer(), type, msg, "SR", key);
171   }
172
173   if (TRACE_msg_process_is_enabled()){
174     int len = INSTR_DEFAULT_STR_SIZE;
175     char str[INSTR_DEFAULT_STR_SIZE];
176
177     container_t process_container = getContainer (instr_process_id(MSG_process_self(), str, len));
178     type_t type = getType ("MSG_PROCESS_STATE", process_container->type);
179     new_pajePopState (MSG_get_clock(), process_container, type);
180
181     char key[INSTR_DEFAULT_STR_SIZE];
182     snprintf (key, INSTR_DEFAULT_STR_SIZE, "p%lld", task->counter);
183     type = getType ("MSG_PROCESS_TASK_LINK", getRootType());
184     new_pajeEndLink(MSG_get_clock(), getRootContainer(), type, process_container, "SR", key);
185   }
186 }
187
188 /* MSG_task_put related functions */
189 int TRACE_msg_task_put_start(m_task_t task)
190 {
191   XBT_DEBUG("PUT,in %p, %lld, %s", task, task->counter, task->category);
192
193   if (TRACE_msg_task_is_enabled()){
194
195     container_t msg = getContainer (task->name);
196     type_t type = getType ("MSG_TASK_STATE", msg->type);
197     new_pajePopState (MSG_get_clock(), msg, type);
198
199     type = getType ("MSG_TASK_LINK", getRootType());
200     char key[INSTR_DEFAULT_STR_SIZE];
201     snprintf (key, INSTR_DEFAULT_STR_SIZE, "%lld", task->counter);
202     new_pajeStartLink(MSG_get_clock(), getRootContainer(), type, msg, "SR", key);
203
204     destroyContainer (msg);
205   }
206
207   if (TRACE_msg_process_is_enabled()){
208     int len = INSTR_DEFAULT_STR_SIZE;
209     char str[INSTR_DEFAULT_STR_SIZE];
210
211     container_t process_container = getContainer (instr_process_id(MSG_process_self(), str, len));
212     type_t type = getType ("MSG_PROCESS_STATE", process_container->type);
213     val_t value = getValueByName ("send", type);
214     new_pajePushState (MSG_get_clock(), process_container, type, value);
215
216     char key[INSTR_DEFAULT_STR_SIZE];
217     snprintf (key, INSTR_DEFAULT_STR_SIZE, "p%lld", task->counter);
218     type = getType ("MSG_PROCESS_TASK_LINK", getRootType());
219     new_pajeStartLink(MSG_get_clock(), getRootContainer(), type, process_container, "SR", key);
220   }
221
222   return 1;
223 }
224
225 void TRACE_msg_task_put_end(void)
226 {
227   XBT_DEBUG("PUT,out");
228
229   if (TRACE_msg_task_is_enabled()){
230     //task no longer exists here
231   }
232
233   if (TRACE_msg_process_is_enabled()){
234     int len = INSTR_DEFAULT_STR_SIZE;
235     char str[INSTR_DEFAULT_STR_SIZE];
236
237     container_t process_container = getContainer (instr_process_id(MSG_process_self(), str, len));
238     type_t type = getType ("MSG_PROCESS_STATE", process_container->type);
239     new_pajePopState (MSG_get_clock(), process_container, type);
240   }
241 }
242
243 #endif /* HAVE_TRACING */