1 /* Copyright (c) 2010. The SimGrid Team.
2 * All rights reserved. */
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. */
7 #include "instr/instr_private.h"
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_msg, instr, "MSG");
14 * TRACE_msg_set_task_category: tracing interface function
16 void TRACE_msg_set_task_category(m_task_t task, const char *category)
18 if (!TRACE_is_active())
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.",
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);
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;
40 task->category = xbt_strdup (category);
41 DEBUG3("MSG task %p(%s), category %s", task, task->name, task->category);
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);
53 type = getVariableType(task->category, NULL, msg->type);
55 new_pajeSetVariable (SIMIX_get_clock(), msg, type, 1);
57 type = getType ("MSG_TASK_STATE");
58 new_pajePushState (MSG_get_clock(), msg, type, "created");
62 /* MSG_task_create related function*/
63 void TRACE_msg_task_create(m_task_t task)
65 static long long counter = 0;
66 task->counter = counter++;
67 task->category = NULL;
68 DEBUG2("CREATE %p, %lld", task, task->counter);
71 /* MSG_task_execute related functions */
72 void TRACE_msg_task_execute_start(m_task_t task)
74 DEBUG3("EXEC,in %p, %lld, %s", task, task->counter, task->category);
76 if (TRACE_msg_task_is_enabled()){
77 container_t task_container = getContainer (task->name);
78 type_t type = getType ("MSG_TASK_STATE");
79 new_pajePushState (MSG_get_clock(), task_container, type, "MSG_task_execute");
82 if (TRACE_msg_process_is_enabled()){
83 int len = INSTR_DEFAULT_STR_SIZE;
84 char str[INSTR_DEFAULT_STR_SIZE];
86 container_t process_container = getContainer (instr_process_id(MSG_process_self(), str, len));
87 type_t type = getType ("MSG_PROCESS_STATE");
88 new_pajePushState (MSG_get_clock(), process_container, type, "task_execute");
92 void TRACE_msg_task_execute_end(m_task_t task)
94 DEBUG3("EXEC,out %p, %lld, %s", task, task->counter, task->category);
96 if (TRACE_msg_task_is_enabled()){
97 container_t task_container = getContainer (task->name);
98 type_t type = getType ("MSG_TASK_STATE");
99 new_pajePopState (MSG_get_clock(), task_container, type);
102 if (TRACE_msg_process_is_enabled()){
103 int len = INSTR_DEFAULT_STR_SIZE;
104 char str[INSTR_DEFAULT_STR_SIZE];
106 container_t process_container = getContainer (instr_process_id(MSG_process_self(), str, len));
107 type_t type = getType ("MSG_PROCESS_STATE");
108 new_pajePopState (MSG_get_clock(), process_container, type);
112 /* MSG_task_destroy related functions */
113 void TRACE_msg_task_destroy(m_task_t task)
115 DEBUG3("DESTROY %p, %lld, %s", task, task->counter, task->category);
117 if (TRACE_msg_task_is_enabled()){
118 //that's the end, let's destroy it
119 destroyContainer (getContainer(task->name));
123 xbt_free(task->category);
124 task->category = NULL;
128 /* MSG_task_get related functions */
129 void TRACE_msg_task_get_start(void)
133 if (TRACE_msg_task_is_enabled()){
134 //task not received yet, nothing to do
137 if (TRACE_msg_process_is_enabled()){
138 int len = INSTR_DEFAULT_STR_SIZE;
139 char str[INSTR_DEFAULT_STR_SIZE];
141 container_t process_container = getContainer (instr_process_id(MSG_process_self(), str, len));
142 type_t type = getType ("MSG_PROCESS_STATE");
143 new_pajePushState (MSG_get_clock(), process_container, type, "receive");
147 void TRACE_msg_task_get_end(double start_time, m_task_t task)
149 DEBUG3("GET,out %p, %lld, %s", task, task->counter, task->category);
151 if (TRACE_msg_task_is_enabled()){
154 //if (TRACE_msg_volume_is_enabled()){
155 // TRACE_msg_volume_end(task);
158 m_host_t host = MSG_host_self();
159 container_t host_container = getContainer(host->name);
160 container_t msg = newContainer(task->name, INSTR_MSG_TASK, host_container);
161 type_t type = getType (task->category);
162 new_pajeSetVariable (SIMIX_get_clock(), msg, type, 1);
164 type = getType ("MSG_TASK_STATE");
165 new_pajePushState (MSG_get_clock(), msg, type, "created");
167 type = getType ("MSG_TASK_LINK");
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);
173 if (TRACE_msg_process_is_enabled()){
174 int len = INSTR_DEFAULT_STR_SIZE;
175 char str[INSTR_DEFAULT_STR_SIZE];
177 container_t process_container = getContainer (instr_process_id(MSG_process_self(), str, len));
178 type_t type = getType ("MSG_PROCESS_STATE");
179 new_pajePopState (MSG_get_clock(), process_container, type);
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");
184 new_pajeEndLink(MSG_get_clock(), getRootContainer(), type, process_container, "SR", key);
188 /* MSG_task_put related functions */
189 int TRACE_msg_task_put_start(m_task_t task)
191 DEBUG3("PUT,in %p, %lld, %s", task, task->counter, task->category);
193 if (TRACE_msg_task_is_enabled()){
195 container_t msg = getContainer (task->name);
196 type_t type = getType ("MSG_TASK_STATE");
197 new_pajePopState (MSG_get_clock(), msg, type);
199 type = getType ("MSG_TASK_LINK");
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);
204 destroyContainer (msg);
207 //if (TRACE_msg_volume_is_enabled()){
208 // TRACE_msg_volume_start(task);
212 if (TRACE_msg_process_is_enabled()){
213 int len = INSTR_DEFAULT_STR_SIZE;
214 char str[INSTR_DEFAULT_STR_SIZE];
216 container_t process_container = getContainer (instr_process_id(MSG_process_self(), str, len));
217 type_t type = getType ("MSG_PROCESS_STATE");
218 new_pajePushState (MSG_get_clock(), process_container, type, "send");
220 char key[INSTR_DEFAULT_STR_SIZE];
221 snprintf (key, INSTR_DEFAULT_STR_SIZE, "p%lld", task->counter);
222 type = getType ("MSG_PROCESS_TASK_LINK");
223 new_pajeStartLink(MSG_get_clock(), getRootContainer(), type, process_container, "SR", key);
229 void TRACE_msg_task_put_end(void)
233 if (TRACE_msg_task_is_enabled()){
234 //task no longer exists here
237 if (TRACE_msg_process_is_enabled()){
238 int len = INSTR_DEFAULT_STR_SIZE;
239 char str[INSTR_DEFAULT_STR_SIZE];
241 container_t process_container = getContainer (instr_process_id(MSG_process_self(), str, len));
242 type_t type = getType ("MSG_PROCESS_STATE");
243 new_pajePopState (MSG_get_clock(), process_container, type);
247 #endif /* HAVE_TRACING */