Logo AND Algorithmique Numérique Distribuée

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