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/private.h"
11 static xbt_dict_t task_containers = NULL;
13 void TRACE_msg_task_alloc(void)
15 task_containers = xbt_dict_new();
18 void TRACE_msg_task_release(void)
20 xbt_dict_free(&task_containers);
23 static void TRACE_task_location(m_task_t task)
26 char name[200], alias[200];
28 m_process_t process = NULL;
30 if (!IS_TRACING_TASKS)
32 process = MSG_process_self();
33 host = MSG_process_get_host(process);
35 //tasks are grouped by host
36 TRACE_host_container(host, container, 200);
37 TRACE_task_container(task, name, 200);
38 TRACE_task_alias_container(task, process, host, alias, 200);
39 //check if task container is already created
40 if (!xbt_dict_get_or_null(task_containers, alias)) {
41 pajeCreateContainer(MSG_get_clock(), alias, "TASK", container, name);
42 pajeSetState(MSG_get_clock(), "category", alias, task->category);
43 val_one = xbt_strdup("1");
44 xbt_dict_set(task_containers, alias, val_one, xbt_free);
48 static void TRACE_task_location_present(m_task_t task)
51 m_process_t process = NULL;
53 if (!IS_TRACING_TASKS)
55 //updating presence state of this task location
56 process = MSG_process_self();
57 host = MSG_process_get_host(process);
59 TRACE_task_alias_container(task, process, host, alias, 200);
60 pajePushState(MSG_get_clock(), "presence", alias, "presence");
63 static void TRACE_task_location_not_present(m_task_t task)
66 m_process_t process = NULL;
68 if (!IS_TRACING_TASKS)
70 //updating presence state of this task location
71 process = MSG_process_self();
72 host = MSG_process_get_host(process);
74 TRACE_task_alias_container(task, process, host, alias, 200);
75 pajePopState(MSG_get_clock(), "presence", alias);
79 * TRACE_msg_set_task_category: tracing interface function
81 void TRACE_msg_set_task_category(m_task_t task, const char *category)
88 task->category = xbt_new(char, strlen(category) + 1);
89 strncpy(task->category, category, strlen(category) + 1);
91 //tracing task location based on host
92 TRACE_task_location(task);
93 TRACE_task_location_present(task);
95 TRACE_task_container(task, name, 200);
96 //create container of type "task" to indicate behavior
98 pajeCreateContainer(MSG_get_clock(), name, "task", category, name);
100 pajePushState(MSG_get_clock(), "task-state", name, "created");
103 /* MSG_task_create related function*/
104 void TRACE_msg_task_create(m_task_t task)
106 static long long counter = 0;
107 task->counter = counter++;
108 task->category = NULL;
111 /* MSG_task_execute related functions */
112 void TRACE_msg_task_execute_start(m_task_t task)
115 if (!IS_TRACING || !IS_TRACED(task))
118 TRACE_task_container(task, name, 200);
119 if (IS_TRACING_TASKS)
120 pajePushState(MSG_get_clock(), "task-state", name, "execute");
122 TRACE_msg_category_set(SIMIX_process_self(), task);
125 void TRACE_msg_task_execute_end(m_task_t task)
128 if (!IS_TRACING || !IS_TRACED(task))
131 TRACE_task_container(task, name, 200);
132 if (IS_TRACING_TASKS)
133 pajePopState(MSG_get_clock(), "task-state", name);
135 TRACE_category_unset(SIMIX_process_self());
138 /* MSG_task_destroy related functions */
139 void TRACE_msg_task_destroy(m_task_t task)
142 if (!IS_TRACING || !IS_TRACED(task))
145 TRACE_task_container(task, name, 200);
146 if (IS_TRACING_TASKS)
147 pajeDestroyContainer(MSG_get_clock(), "task", name);
149 //finish the location of this task
150 TRACE_task_location_not_present(task);
153 xbt_free(task->category);
157 /* MSG_task_get related functions */
158 void TRACE_msg_task_get_start(void)
164 void TRACE_msg_task_get_end(double start_time, m_task_t task)
167 if (!IS_TRACING || !IS_TRACED(task))
170 TRACE_task_container(task, name, 200);
171 if (IS_TRACING_TASKS)
172 pajePopState(MSG_get_clock(), "task-state", name);
174 TRACE_msg_volume_finish(task);
176 TRACE_task_location(task);
177 TRACE_task_location_present(task);
180 /* MSG_task_put related functions */
181 int TRACE_msg_task_put_start(m_task_t task)
184 if (!IS_TRACING || !IS_TRACED(task))
187 TRACE_task_container(task, name, 200);
188 if (IS_TRACING_TASKS)
189 pajePopState(MSG_get_clock(), "task-state", name);
190 if (IS_TRACING_TASKS)
191 pajePushState(MSG_get_clock(), "task-state", name, "communicate");
193 TRACE_msg_volume_start(task);
195 //trace task location grouped by host
196 TRACE_task_location_not_present(task);
198 //set current category
199 TRACE_msg_category_set(SIMIX_process_self(), task);
203 void TRACE_msg_task_put_end(void)
208 TRACE_category_unset(SIMIX_process_self());