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_categorized())
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()){
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);
163 type = getType ("MSG_TASK_STATE", msg->type);
164 val_t value = getValueByName ("created", type);
165 new_pajePushState (MSG_get_clock(), msg, type, value);
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);
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", process_container->type);
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", getRootType());
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 XBT_DEBUG("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", msg->type);
197 new_pajePopState (MSG_get_clock(), msg, type);
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);
204 destroyContainer (msg);
207 if (TRACE_msg_process_is_enabled()){
208 int len = INSTR_DEFAULT_STR_SIZE;
209 char str[INSTR_DEFAULT_STR_SIZE];
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);
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);
225 void TRACE_msg_task_put_end(void)
227 XBT_DEBUG("PUT,out");
229 if (TRACE_msg_task_is_enabled()){
230 //task no longer exists here
233 if (TRACE_msg_process_is_enabled()){
234 int len = INSTR_DEFAULT_STR_SIZE;
235 char str[INSTR_DEFAULT_STR_SIZE];
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);
243 #endif /* HAVE_TRACING */