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");
62 //pajePushState(MSG_get_clock(), "task-state", name, "created");
63 xbt_dict_set (tasks_created, task->name, xbt_strdup("1"), xbt_free);
67 /* MSG_task_create related function*/
68 void TRACE_msg_task_create(m_task_t task)
70 static long long counter = 0;
71 task->counter = counter++;
72 task->category = NULL;
73 DEBUG2("CREATE %p, %lld", task, task->counter);
76 /* MSG_task_execute related functions */
77 void TRACE_msg_task_execute_start(m_task_t task)
79 if (!(TRACE_is_enabled() &&
80 TRACE_msg_task_is_enabled() &&
81 task->category)) return;
83 DEBUG3("EXEC,in %p, %lld, %s", task, task->counter, task->category);
86 //pajePushState(MSG_get_clock(), "task-state", name, "execute");
89 void TRACE_msg_task_execute_end(m_task_t task)
91 if (!(TRACE_is_enabled() &&
92 TRACE_msg_task_is_enabled() &&
93 task->category)) return;
95 DEBUG3("EXEC,out %p, %lld, %s", task, task->counter, task->category);
98 //pajePopState(MSG_get_clock(), "task-state", name);
101 /* MSG_task_destroy related functions */
102 void TRACE_msg_task_destroy(m_task_t task)
104 if (!tasks_created) tasks_created = xbt_dict_new();
105 if (!(TRACE_is_enabled() &&
106 TRACE_msg_task_is_enabled() &&
107 task->category)) return;
109 //that's the end, let's destroy it
110 destroyContainer (getContainer(task->name));
112 DEBUG3("DESTROY %p, %lld, %s", task, task->counter, task->category);
115 xbt_free(task->category);
116 task->category = NULL;
118 xbt_dict_remove (tasks_created, task->name);
122 /* MSG_task_get related functions */
123 void TRACE_msg_task_get_start(void)
125 if (!(TRACE_is_enabled() &&
126 TRACE_msg_task_is_enabled())) return;
131 void TRACE_msg_task_get_end(double start_time, m_task_t task)
133 if (!(TRACE_is_enabled() &&
134 TRACE_msg_task_is_enabled() &&
135 task->category)) return;
137 DEBUG3("GET,out %p, %lld, %s", task, task->counter, task->category);
140 //pajePopState(MSG_get_clock(), "task-state", name);
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");
154 /* MSG_task_put related functions */
155 int TRACE_msg_task_put_start(m_task_t task)
157 if (!(TRACE_is_enabled() &&
158 TRACE_msg_task_is_enabled() &&
159 task->category)) return 0;
161 DEBUG3("PUT,in %p, %lld, %s", task, task->counter, task->category);
163 destroyContainer (getContainer(task->name));
166 //pajePopState(MSG_get_clock(), "task-state", name);
167 //pajePushState(MSG_get_clock(), "task-state", name, "communicate");
170 //if (TRACE_msg_volume_is_enabled()){
171 // TRACE_msg_volume_start(task);
177 void TRACE_msg_task_put_end(void)
179 if (!(TRACE_is_enabled() &&
180 TRACE_msg_task_is_enabled())) return;
185 #endif /* HAVE_TRACING */