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_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.",
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);
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 XBT_DEBUG("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_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);
53 type = getVariableType(task->category, NULL, msg->type);
55 new_pajeSetVariable (SIMIX_get_clock(), msg, type, 1);
57 type = getType ("MSG_TASK_STATE", msg->type);
58 val_t value = getValueByName ("created", type);
59 new_pajePushState (MSG_get_clock(), msg, type, value);
63 /* MSG_task_create related function*/
64 void TRACE_msg_task_create(m_task_t task)
66 static long long counter = 0;
67 task->counter = counter++;
68 task->category = NULL;
69 XBT_DEBUG("CREATE %p, %lld", task, task->counter);
72 /* MSG_task_execute related functions */
73 void TRACE_msg_task_execute_start(m_task_t task)
75 XBT_DEBUG("EXEC,in %p, %lld, %s", task, task->counter, task->category);
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);
84 if (TRACE_msg_process_is_enabled()){
85 int len = INSTR_DEFAULT_STR_SIZE;
86 char str[INSTR_DEFAULT_STR_SIZE];
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);
95 void TRACE_msg_task_execute_end(m_task_t task)
97 XBT_DEBUG("EXEC,out %p, %lld, %s", task, task->counter, task->category);
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);
105 if (TRACE_msg_process_is_enabled()){
106 int len = INSTR_DEFAULT_STR_SIZE;
107 char str[INSTR_DEFAULT_STR_SIZE];
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);
115 /* MSG_task_destroy related functions */
116 void TRACE_msg_task_destroy(m_task_t task)
118 XBT_DEBUG("DESTROY %p, %lld, %s", task, task->counter, task->category);
120 if (TRACE_msg_task_is_enabled()){
121 //that's the end, let's destroy it
122 destroyContainer (getContainer(task->name));
126 xbt_free(task->category);
127 task->category = NULL;
131 /* MSG_task_get related functions */
132 void TRACE_msg_task_get_start(void)
136 if (TRACE_msg_task_is_enabled()){
137 //task not received yet, nothing to do
140 if (TRACE_msg_process_is_enabled()){
141 int len = INSTR_DEFAULT_STR_SIZE;
142 char str[INSTR_DEFAULT_STR_SIZE];
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);
151 void TRACE_msg_task_get_end(double start_time, m_task_t task)
153 XBT_DEBUG("GET,out %p, %lld, %s", task, task->counter, task->category);
155 if (TRACE_msg_task_is_enabled()){
158 //if (TRACE_msg_volume_is_enabled()){
159 // TRACE_msg_volume_end(task);
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);
168 type = getType ("MSG_TASK_STATE", msg->type);
169 val_t value = getValueByName ("created", type);
170 new_pajePushState (MSG_get_clock(), msg, type, value);
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);
178 if (TRACE_msg_process_is_enabled()){
179 int len = INSTR_DEFAULT_STR_SIZE;
180 char str[INSTR_DEFAULT_STR_SIZE];
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);
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);
193 /* MSG_task_put related functions */
194 int TRACE_msg_task_put_start(m_task_t task)
196 XBT_DEBUG("PUT,in %p, %lld, %s", task, task->counter, task->category);
198 if (TRACE_msg_task_is_enabled()){
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);
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);
209 destroyContainer (msg);
212 //if (TRACE_msg_volume_is_enabled()){
213 // TRACE_msg_volume_start(task);
217 if (TRACE_msg_process_is_enabled()){
218 int len = INSTR_DEFAULT_STR_SIZE;
219 char str[INSTR_DEFAULT_STR_SIZE];
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);
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);
235 void TRACE_msg_task_put_end(void)
237 XBT_DEBUG("PUT,out");
239 if (TRACE_msg_task_is_enabled()){
240 //task no longer exists here
243 if (TRACE_msg_process_is_enabled()){
244 int len = INSTR_DEFAULT_STR_SIZE;
245 char str[INSTR_DEFAULT_STR_SIZE];
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);
253 #endif /* HAVE_TRACING */