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 xbt_dict_t tasks_created = NULL;
16 * TRACE_msg_set_task_category: tracing interface function
18 void TRACE_msg_set_task_category(m_task_t task, const char *category)
20 if (!tasks_created) tasks_created = xbt_dict_new();
21 if (!TRACE_is_active())
24 xbt_assert3(task->category == NULL, "Task %p(%s) already has a category (%s).",
25 task, task->name, task->category);
26 if (TRACE_msg_task_is_enabled()){
27 xbt_assert2(task->name != NULL,
28 "Task %p(%s) must have a unique name in order to be traced, if --cfg=tracing/msg/task:1 is used.",
30 xbt_assert3(getContainer(task->name)==NULL,
31 "Task %p(%s). Tracing already knows a task with name %s."
32 "The name of each task must be unique, if --cfg=tracing/msg/task:1 is used.", task, task->name, task->name);
35 if (category == NULL) {
36 //if user provides a NULL category, task is no longer traced
37 xbt_free (task->category);
38 task->category = NULL;
43 task->category = xbt_strdup (category);
44 DEBUG3("MSG task %p(%s), category %s", task, task->name, task->category);
46 if (TRACE_msg_task_is_enabled()){
47 m_host_t host = MSG_host_self();
48 container_t host_container = getContainer(host->name);
49 //check to see if there is a container with the task->name
50 container_t msg = getContainer(task->name);
51 xbt_assert3(xbt_dict_get_or_null (tasks_created, task->name) == NULL,
52 "Task %p(%s). Tracing already knows a task with name %s."
53 "The name of each task must be unique, if --cfg=tracing/msg/task:1 is used.", task, task->name, task->name);
54 msg = newContainer(task->name, INSTR_MSG_TASK, host_container);
55 type_t type = getType (task->category);
57 type = newVariableType(task->category, TYPE_VARIABLE, NULL, msg->type);
59 pajeSetVariable(SIMIX_get_clock(), type->id, msg->id, "1");
61 type = getType ("MSG_TASK_STATE");
62 pajePushState (MSG_get_clock(), type->id, msg->id, "created");
64 xbt_dict_set (tasks_created, task->name, xbt_strdup("1"), xbt_free);
68 /* MSG_task_create related function*/
69 void TRACE_msg_task_create(m_task_t task)
71 static long long counter = 0;
72 task->counter = counter++;
73 task->category = NULL;
74 DEBUG2("CREATE %p, %lld", task, task->counter);
77 /* MSG_task_execute related functions */
78 void TRACE_msg_task_execute_start(m_task_t task)
80 if (!(TRACE_is_enabled() &&
81 TRACE_msg_task_is_enabled() &&
82 task->category)) return;
84 DEBUG3("EXEC,in %p, %lld, %s", task, task->counter, task->category);
86 container_t task_container = getContainer (task->name);
87 type_t type = getType ("MSG_TASK_STATE");
88 pajePushState (MSG_get_clock(), type->id, task_container->id, "MSG_task_execute");
91 void TRACE_msg_task_execute_end(m_task_t task)
93 if (!(TRACE_is_enabled() &&
94 TRACE_msg_task_is_enabled() &&
95 task->category)) return;
97 DEBUG3("EXEC,out %p, %lld, %s", task, task->counter, task->category);
99 container_t task_container = getContainer (task->name);
100 type_t type = getType ("MSG_TASK_STATE");
101 pajePopState (MSG_get_clock(), type->id, task_container->id);
104 /* MSG_task_destroy related functions */
105 void TRACE_msg_task_destroy(m_task_t task)
107 if (!tasks_created) tasks_created = xbt_dict_new();
108 if (!(TRACE_is_enabled() &&
109 TRACE_msg_task_is_enabled() &&
110 task->category)) return;
112 //that's the end, let's destroy it
113 destroyContainer (getContainer(task->name));
115 DEBUG3("DESTROY %p, %lld, %s", task, task->counter, task->category);
118 xbt_free(task->category);
119 task->category = NULL;
121 xbt_dict_remove (tasks_created, task->name);
125 /* MSG_task_get related functions */
126 void TRACE_msg_task_get_start(void)
128 if (!(TRACE_is_enabled() &&
129 TRACE_msg_task_is_enabled())) return;
134 void TRACE_msg_task_get_end(double start_time, m_task_t task)
136 if (!(TRACE_is_enabled() &&
137 TRACE_msg_task_is_enabled() &&
138 task->category)) return;
140 DEBUG3("GET,out %p, %lld, %s", task, task->counter, task->category);
143 //if (TRACE_msg_volume_is_enabled()){
144 // TRACE_msg_volume_end(task);
147 m_host_t host = MSG_host_self();
148 container_t host_container = getContainer(host->name);
149 container_t msg = newContainer(task->name, INSTR_MSG_TASK, host_container);
150 type_t type = getType (task->category);
151 pajeSetVariable(SIMIX_get_clock(), type->id, msg->id, "1");
153 type = getType ("MSG_TASK_STATE");
154 pajePushState (MSG_get_clock(), type->id, msg->id, "created");
156 type = getType ("MSG_TASK_LINK");
157 char key[INSTR_DEFAULT_STR_SIZE];
158 snprintf (key, INSTR_DEFAULT_STR_SIZE, "%lld", task->counter);
159 pajeEndLink(MSG_get_clock(), type->id, "0", "SR", msg->id, key);
162 /* MSG_task_put related functions */
163 int TRACE_msg_task_put_start(m_task_t task)
165 if (!(TRACE_is_enabled() &&
166 TRACE_msg_task_is_enabled() &&
167 task->category)) return 0;
169 DEBUG3("PUT,in %p, %lld, %s", task, task->counter, task->category);
171 container_t msg = getContainer (task->name);
172 type_t type = getType ("MSG_TASK_STATE");
173 pajePopState (MSG_get_clock(), type->id, msg->id);
175 type = getType ("MSG_TASK_LINK");
176 char key[INSTR_DEFAULT_STR_SIZE];
177 snprintf (key, INSTR_DEFAULT_STR_SIZE, "%lld", task->counter);
178 pajeStartLink(MSG_get_clock(), type->id, "0", "SR", msg->id, key);
180 destroyContainer (msg);
183 //if (TRACE_msg_volume_is_enabled()){
184 // TRACE_msg_volume_start(task);
190 void TRACE_msg_task_put_end(void)
192 if (!(TRACE_is_enabled() &&
193 TRACE_msg_task_is_enabled())) return;
198 #endif /* HAVE_TRACING */