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");
13 static xbt_dict_t task_containers = NULL;
15 static char *TRACE_task_alias_container(m_task_t task, m_process_t process,
16 m_host_t host, char *output, int len)
19 snprintf(output, len, "%p-%lld-%p-%p", task, task->counter, process,
27 static char *TRACE_host_container(m_host_t host, char *output, int len)
30 snprintf(output, len, "%s", MSG_host_get_name(host));
37 char *TRACE_task_container(m_task_t task, char *output, int len)
40 snprintf(output, len, "%p-%lld", task, task->counter);
47 void TRACE_msg_task_alloc(void)
49 task_containers = xbt_dict_new();
52 void TRACE_msg_task_release(void)
54 xbt_dict_free(&task_containers);
57 static void TRACE_task_location(m_task_t task)
60 char name[200], alias[200];
62 m_process_t process = NULL;
64 if (!TRACE_msg_task_is_enabled())
66 process = MSG_process_self();
67 host = MSG_process_get_host(process);
69 //tasks are grouped by host
70 TRACE_host_container(host, container, 200);
71 TRACE_task_container(task, name, 200);
72 TRACE_task_alias_container(task, process, host, alias, 200);
73 //check if task container is already created
74 if (!xbt_dict_get_or_null(task_containers, alias)) {
75 pajeCreateContainer(MSG_get_clock(), alias, "TASK", container, name);
76 pajeSetState(MSG_get_clock(), "category", alias, task->category);
77 val_one = xbt_strdup("1");
78 xbt_dict_set(task_containers, alias, val_one, xbt_free);
82 static void TRACE_task_location_present(m_task_t task)
85 m_process_t process = NULL;
87 if (!TRACE_msg_task_is_enabled())
89 //updating presence state of this task location
90 process = MSG_process_self();
91 host = MSG_process_get_host(process);
93 TRACE_task_alias_container(task, process, host, alias, 200);
94 pajePushState(MSG_get_clock(), "presence", alias, "presence");
97 static void TRACE_task_location_not_present(m_task_t task)
100 m_process_t process = NULL;
101 m_host_t host = NULL;
102 if (!TRACE_msg_task_is_enabled())
104 //updating presence state of this task location
105 process = MSG_process_self();
106 host = MSG_process_get_host(process);
108 TRACE_task_alias_container(task, process, host, alias, 200);
109 pajePopState(MSG_get_clock(), "presence", alias);
113 * TRACE_msg_set_task_category: tracing interface function
115 void TRACE_msg_set_task_category(m_task_t task, const char *category)
118 if (!TRACE_is_active())
121 xbt_assert3(task->category == NULL, "Task %p(%s) already has a category (%s).",
122 task, task->name, task->category);
125 task->category = xbt_strdup (category);
126 DEBUG3("MSG task %p(%s), category %s", task, task->name, task->category);
128 //tracing task location based on host
129 TRACE_task_location(task);
130 TRACE_task_location_present(task);
132 TRACE_task_container(task, name, 200);
133 //create container of type "task" to indicate behavior
134 if (TRACE_msg_task_is_enabled())
135 pajeCreateContainer(MSG_get_clock(), name, "task", category, name);
136 if (TRACE_msg_task_is_enabled())
137 pajePushState(MSG_get_clock(), "task-state", name, "created");
140 /* MSG_task_create related function*/
141 void TRACE_msg_task_create(m_task_t task)
143 static long long counter = 0;
144 task->counter = counter++;
145 task->category = NULL;
146 DEBUG2("CREATE %p, %lld", task, task->counter);
149 /* MSG_task_execute related functions */
150 void TRACE_msg_task_execute_start(m_task_t task)
153 if (!TRACE_is_active())
159 DEBUG3("EXEC,in %p, %lld, %s", task, task->counter, task->category);
161 TRACE_task_container(task, name, 200);
162 if (TRACE_msg_task_is_enabled())
163 pajePushState(MSG_get_clock(), "task-state", name, "execute");
166 void TRACE_msg_task_execute_end(m_task_t task)
169 if (!TRACE_is_active())
175 TRACE_task_container(task, name, 200);
176 if (TRACE_msg_task_is_enabled())
177 pajePopState(MSG_get_clock(), "task-state", name);
179 DEBUG3("EXEC,out %p, %lld, %s", task, task->counter, task->category);
182 /* MSG_task_destroy related functions */
183 void TRACE_msg_task_destroy(m_task_t task)
186 if (!TRACE_is_active())
192 TRACE_task_container(task, name, 200);
193 if (TRACE_msg_task_is_enabled())
194 pajeDestroyContainer(MSG_get_clock(), "task", name);
196 //finish the location of this task
197 TRACE_task_location_not_present(task);
199 DEBUG3("DESTROY %p, %lld, %s", task, task->counter, task->category);
202 xbt_free(task->category);
206 /* MSG_task_get related functions */
207 void TRACE_msg_task_get_start(void)
209 if (!TRACE_is_active())
215 void TRACE_msg_task_get_end(double start_time, m_task_t task)
218 if (!TRACE_is_active())
224 TRACE_task_container(task, name, 200);
225 if (TRACE_msg_task_is_enabled())
226 pajePopState(MSG_get_clock(), "task-state", name);
228 if (TRACE_msg_volume_is_enabled()){
229 TRACE_msg_volume_finish(task);
232 TRACE_task_location(task);
233 TRACE_task_location_present(task);
235 DEBUG3("GET,out %p, %lld, %s", task, task->counter, task->category);
238 /* MSG_task_put related functions */
239 int TRACE_msg_task_put_start(m_task_t task)
242 if (!TRACE_is_active())
248 DEBUG3("PUT,in %p, %lld, %s", task, task->counter, task->category);
250 TRACE_task_container(task, name, 200);
251 if (TRACE_msg_task_is_enabled())
252 pajePopState(MSG_get_clock(), "task-state", name);
253 if (TRACE_msg_task_is_enabled())
254 pajePushState(MSG_get_clock(), "task-state", name, "communicate");
256 if (TRACE_msg_volume_is_enabled()){
257 TRACE_msg_volume_start(task);
260 //trace task location grouped by host
261 TRACE_task_location_not_present(task);
265 void TRACE_msg_task_put_end(void)
267 if (!TRACE_is_active())
272 #endif /* HAVE_TRACING */