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 static xbt_dict_t task_containers = NULL;
13 static char *TRACE_task_alias_container(m_task_t task, m_process_t process,
14 m_host_t host, char *output, int len)
17 snprintf(output, len, "%p-%lld-%p-%p", task, task->counter, process,
25 static char *TRACE_host_container(m_host_t host, char *output, int len)
28 snprintf(output, len, "%s", MSG_host_get_name(host));
35 char *TRACE_task_container(m_task_t task, char *output, int len)
38 snprintf(output, len, "%p-%lld", task, task->counter);
45 void TRACE_msg_task_alloc(void)
47 task_containers = xbt_dict_new();
50 void TRACE_msg_task_release(void)
52 xbt_dict_free(&task_containers);
55 static void TRACE_task_location(m_task_t task)
58 char name[200], alias[200];
60 m_process_t process = NULL;
62 if (!IS_TRACING_TASKS)
64 process = MSG_process_self();
65 host = MSG_process_get_host(process);
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);
80 static void TRACE_task_location_present(m_task_t task)
83 m_process_t process = NULL;
85 if (!IS_TRACING_TASKS)
87 //updating presence state of this task location
88 process = MSG_process_self();
89 host = MSG_process_get_host(process);
91 TRACE_task_alias_container(task, process, host, alias, 200);
92 pajePushState(MSG_get_clock(), "presence", alias, "presence");
95 static void TRACE_task_location_not_present(m_task_t task)
98 m_process_t process = NULL;
100 if (!IS_TRACING_TASKS)
102 //updating presence state of this task location
103 process = MSG_process_self();
104 host = MSG_process_get_host(process);
106 TRACE_task_alias_container(task, process, host, alias, 200);
107 pajePopState(MSG_get_clock(), "presence", alias);
111 * TRACE_msg_set_task_category: tracing interface function
113 void TRACE_msg_set_task_category(m_task_t task, const char *category)
116 if (!TRACE_is_active())
120 task->category = xbt_new(char, strlen(category) + 1);
121 strncpy(task->category, category, strlen(category) + 1);
123 //tracing task location based on host
124 TRACE_task_location(task);
125 TRACE_task_location_present(task);
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");
135 /* MSG_task_create related function*/
136 void TRACE_msg_task_create(m_task_t task)
138 static long long counter = 0;
139 task->counter = counter++;
140 task->category = NULL;
143 /* MSG_task_execute related functions */
144 void TRACE_msg_task_execute_start(m_task_t task)
147 if (!TRACE_is_active())
150 if (!IS_TRACED(task))
153 TRACE_task_container(task, name, 200);
154 if (IS_TRACING_TASKS)
155 pajePushState(MSG_get_clock(), "task-state", name, "execute");
157 TRACE_msg_category_set(SIMIX_process_self(), task);
160 void TRACE_msg_task_execute_end(m_task_t task)
163 if (!TRACE_is_active())
166 if (!IS_TRACED(task))
169 TRACE_task_container(task, name, 200);
170 if (IS_TRACING_TASKS)
171 pajePopState(MSG_get_clock(), "task-state", name);
173 TRACE_category_unset(SIMIX_process_self());
176 /* MSG_task_destroy related functions */
177 void TRACE_msg_task_destroy(m_task_t task)
180 if (!TRACE_is_active())
183 if (!IS_TRACED(task))
186 TRACE_task_container(task, name, 200);
187 if (IS_TRACING_TASKS)
188 pajeDestroyContainer(MSG_get_clock(), "task", name);
190 //finish the location of this task
191 TRACE_task_location_not_present(task);
194 xbt_free(task->category);
198 /* MSG_task_get related functions */
199 void TRACE_msg_task_get_start(void)
201 if (!TRACE_is_active())
205 void TRACE_msg_task_get_end(double start_time, m_task_t task)
208 if (!TRACE_is_active())
211 if (!IS_TRACED(task))
214 TRACE_task_container(task, name, 200);
215 if (IS_TRACING_TASKS)
216 pajePopState(MSG_get_clock(), "task-state", name);
218 TRACE_msg_volume_finish(task);
220 TRACE_task_location(task);
221 TRACE_task_location_present(task);
224 /* MSG_task_put related functions */
225 int TRACE_msg_task_put_start(m_task_t task)
228 if (!TRACE_is_active())
231 if (!IS_TRACED(task))
234 TRACE_task_container(task, name, 200);
235 if (IS_TRACING_TASKS)
236 pajePopState(MSG_get_clock(), "task-state", name);
237 if (IS_TRACING_TASKS)
238 pajePushState(MSG_get_clock(), "task-state", name, "communicate");
240 TRACE_msg_volume_start(task);
242 //trace task location grouped by host
243 TRACE_task_location_not_present(task);
245 //set current category
246 TRACE_msg_category_set(SIMIX_process_self(), task);
250 void TRACE_msg_task_put_end(void)
252 if (!TRACE_is_active())
255 TRACE_category_unset(SIMIX_process_self());
258 #endif /* HAVE_TRACING */