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)
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 (!IS_TRACING || !IS_TRACED(task))
150 TRACE_task_container(task, name, 200);
151 if (IS_TRACING_TASKS)
152 pajePushState(MSG_get_clock(), "task-state", name, "execute");
154 TRACE_msg_category_set(SIMIX_process_self(), task);
157 void TRACE_msg_task_execute_end(m_task_t task)
160 if (!IS_TRACING || !IS_TRACED(task))
163 TRACE_task_container(task, name, 200);
164 if (IS_TRACING_TASKS)
165 pajePopState(MSG_get_clock(), "task-state", name);
167 TRACE_category_unset(SIMIX_process_self());
170 /* MSG_task_destroy related functions */
171 void TRACE_msg_task_destroy(m_task_t task)
174 if (!IS_TRACING || !IS_TRACED(task))
177 TRACE_task_container(task, name, 200);
178 if (IS_TRACING_TASKS)
179 pajeDestroyContainer(MSG_get_clock(), "task", name);
181 //finish the location of this task
182 TRACE_task_location_not_present(task);
185 xbt_free(task->category);
189 /* MSG_task_get related functions */
190 void TRACE_msg_task_get_start(void)
196 void TRACE_msg_task_get_end(double start_time, m_task_t task)
199 if (!IS_TRACING || !IS_TRACED(task))
202 TRACE_task_container(task, name, 200);
203 if (IS_TRACING_TASKS)
204 pajePopState(MSG_get_clock(), "task-state", name);
206 TRACE_msg_volume_finish(task);
208 TRACE_task_location(task);
209 TRACE_task_location_present(task);
212 /* MSG_task_put related functions */
213 int TRACE_msg_task_put_start(m_task_t task)
216 if (!IS_TRACING || !IS_TRACED(task))
219 TRACE_task_container(task, name, 200);
220 if (IS_TRACING_TASKS)
221 pajePopState(MSG_get_clock(), "task-state", name);
222 if (IS_TRACING_TASKS)
223 pajePushState(MSG_get_clock(), "task-state", name, "communicate");
225 TRACE_msg_volume_start(task);
227 //trace task location grouped by host
228 TRACE_task_location_not_present(task);
230 //set current category
231 TRACE_msg_category_set(SIMIX_process_self(), task);
235 void TRACE_msg_task_put_end(void)
240 TRACE_category_unset(SIMIX_process_self());